Add check for null for policies and policy types 34/123734/3
authorsaul.gill <saul.gill@est.tech>
Tue, 31 Aug 2021 08:33:32 +0000 (09:33 +0100)
committerAjith Sreekumar <ajith.sreekumar@bell.ca>
Thu, 2 Sep 2021 09:01:17 +0000 (09:01 +0000)
Add check when reading policies and policy types from db

Issue-ID: POLICY-3606
Change-Id: I7a1d96e4be1841243619e89c31dabc3e761dd17a
Signed-off-by: saul.gill <saul.gill@est.tech>
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java

index 98efd19..919d187 100644 (file)
@@ -104,13 +104,16 @@ public class ToscaEntity implements PfNameVersion {
         // Declare the return map
         Map<ToscaEntityKey, T> entityMap = new LinkedHashMap<>();
 
+        if (listOfMapsOfEntities == null) {
+            return entityMap;
+        }
+
         for (Map<String, T> mapOfEntities : listOfMapsOfEntities) {
             for (T entityEntry : mapOfEntities.values()) {
                 if (entityMap.containsKey(entityEntry.getKey())) {
                     throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                            "list of map of entities contains more than one entity with key " + entityEntry.getKey());
+                        "list of map of entities contains more than one entity with key " + entityEntry.getKey());
                 }
-
                 entityMap.put(entityEntry.getKey(), entityEntry);
             }
         }
@@ -129,10 +132,14 @@ public class ToscaEntity implements PfNameVersion {
         // Declare the return map
         Map<ToscaEntityKey, T> entityMap = new LinkedHashMap<>();
 
+        if (mapOfEntities == null) {
+            return entityMap;
+        }
+
         for (T entityEntry : mapOfEntities.values()) {
             if (entityMap.containsKey(entityEntry.getKey())) {
                 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
-                        "list of map of entities contains more than one entity with key " + entityEntry.getKey());
+                    "list of map of entities contains more than one entity with key " + entityEntry.getKey());
             }
 
             entityMap.put(entityEntry.getKey(), entityEntry);