Commit 84462caf authored by Mohamed Khalil Labidi's avatar Mohamed Khalil Labidi
Browse files

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

parent 67901d21
......@@ -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