Commit 2e949775 authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

Merge branch 'fix-getAllCloudImages' into 'proactive-dev'

Fix NPE bug in getAllCloudImages wen cloudID is not found or no clouds are registered

See merge request !86
parents 67901d21 84462caf
......@@ -364,12 +364,18 @@ public class PAGateway {
List<Image> allImages = EntityManagerHelper.createQuery("SELECT img FROM Image img",
Image.class).getResultList();
PACloud paCloud = EntityManagerHelper.find(PACloud.class, cloudID);
JSONArray imagesArray = connectorIaasGateway.getImages(paCloud.getDummyInfrastructureName());
List<String> imagesIDs = IntStream.range(0, imagesArray.length())
.mapToObj(imagesArray::get)
.map(blaBla -> ((JSONObject)blaBla).optString("id")).collect(Collectors.toList());
allImages.stream().filter(blaTest -> imagesIDs.contains(blaTest.getId())).forEach(filteredImages::add);
return filteredImages;
if (paCloud != null) {
JSONArray imagesArray = connectorIaasGateway.getImages(paCloud.getDummyInfrastructureName());
List<String> imagesIDs = IntStream.range(0, imagesArray.length())
.mapToObj(imagesArray::get)
.map(blaBla -> ((JSONObject)blaBla).optString("id")).collect(Collectors.toList());
LOGGER.debug("Filtering images related to cloud ID \'" + cloudID + "\'.");
allImages.stream().filter(blaTest -> imagesIDs.contains(blaTest.getId())).forEach(filteredImages::add);
return filteredImages;
} else {
LOGGER.warn("Cloud ID \'" + cloudID + "\' is not found in DB. getAllCloudImages() will return all images.");
return allImages;
}
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment