Fix exception thrown in ToscaElementOperation 68/118368/1
authorMichaelMorris <michael.morris@est.tech>
Mon, 22 Feb 2021 14:59:48 +0000 (14:59 +0000)
committerMichael Morris <michael.morris@est.tech>
Wed, 24 Feb 2021 10:38:15 +0000 (10:38 +0000)
This is caused by the absence of the metadataKeys property in the category definitions already in the DB

Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3486
Change-Id: I58062955f3d79ca2b9496ce60f9d0c09aa6147fa

catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java

index 5dbce38..32f7e14 100644 (file)
@@ -27,6 +27,7 @@ import com.google.gson.reflect.TypeToken;
 import fj.data.Either;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.EnumMap;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -1041,7 +1042,10 @@ public abstract class ToscaElementOperation extends BaseOperation {
         
         Type listTypeSubcat = new TypeToken<List<MetadataKeyDataDefinition>>() {
         }.getType();
-        List<MetadataKeyDataDefinition> metadataKeys = getGson().fromJson((String) subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeSubcat);
+        List<MetadataKeyDataDefinition> metadataKeys =
+                subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson().fromJson(
+                        (String) subCategoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(),
+                        listTypeSubcat) : Collections.emptyList();
         subcategory.setMetadataKeys(metadataKeys);
         
         Either<Vertex, JanusGraphOperationStatus> parentVertex = janusGraphDao.getParentVertex(subCategoryV, EdgeLabelEnum.SUB_CATEGORY, JsonParseFlagEnum.NoParse);
@@ -1077,7 +1081,10 @@ public abstract class ToscaElementOperation extends BaseOperation {
 
         Type listTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {
         }.getType();
-        List<MetadataKeyDataDefinition> metadataKeys = getGson().fromJson((String) categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeCat);
+        List<MetadataKeyDataDefinition> metadataKeys =
+                categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).isPresent() ? getGson().fromJson(
+                        (String) categoryV.property(GraphPropertyEnum.METADATA_KEYS.getProperty()).value(), listTypeCat)
+                        : Collections.emptyList();
         category.setMetadataKeys(metadataKeys);
         
         categories.add(category);