Implement hiding mechanism
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsonjanusgraph / operations / TopologyTemplateOperation.java
index 91176a9..603e09b 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.stream.Collectors;
 import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
@@ -152,7 +153,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
             return Either.right(associateInstProperties);
         }
         StorageOperationStatus associateInstInputs = associateInstInputsToComponent(topologyTemplateVertex, topologyTemplate);
-        if (associateInstProperties != StorageOperationStatus.OK) {
+        if (associateInstInputs != StorageOperationStatus.OK) {
             return Either.right(associateInstInputs);
         }
         StorageOperationStatus associateInstGroups = associateInstGroupsToComponent(topologyTemplateVertex, topologyTemplate);
@@ -184,7 +185,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
             return Either.right(associateInterfaces);
         }
         StorageOperationStatus associatePathProperties = associateForwardingPathToResource(topologyTemplateVertex, topologyTemplate);
-        if (associateCapProperties != StorageOperationStatus.OK) {
+        if (associatePathProperties != StorageOperationStatus.OK) {
             return Either.right(associatePathProperties);
         }
         final StorageOperationStatus associateServiceToModel = associateComponentToModel(topologyTemplateVertex, topologyTemplate,
@@ -386,15 +387,15 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
     }
 
     public StorageOperationStatus associateInstInterfacesToComponent(
-            GraphVertex nodeTypeVertex,
-            Map<String, MapInterfaceDataDefinition> instInterfaces
+        GraphVertex nodeTypeVertex,
+        Map<String, MapInterfaceDataDefinition> instInterfaces
     ) {
         if (instInterfaces != null && !instInterfaces.isEmpty()) {
             Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(
-                    nodeTypeVertex,
-                    VertexTypeEnum.INST_INTERFACES,
-                    EdgeLabelEnum.INST_INTERFACES,
-                    instInterfaces);
+                nodeTypeVertex,
+                VertexTypeEnum.INST_INTERFACES,
+                EdgeLabelEnum.INST_INTERFACES,
+                instInterfaces);
             if (associateElementToData.isRight()) {
                 return associateElementToData.right().value();
             }
@@ -419,8 +420,8 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
                 List<String> uniqueKeys = new ArrayList<>(i.getValue().getMapToscaDataDefinition().keySet());
                 List<String> pathKeys = new ArrayList<>();
                 pathKeys.add(i.getKey());
-                StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS, VertexTypeEnum.INST_INPUTS,
-                    uniqueKeys, pathKeys, JsonPresentationFields.NAME);
+                StorageOperationStatus status = deleteToscaDataDeepElements(nodeTypeVertex, EdgeLabelEnum.INST_INPUTS,
+                    uniqueKeys, pathKeys);
                 if (status != StorageOperationStatus.OK) {
                     return;
                 }
@@ -1183,14 +1184,15 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
         category.setUniqueId(categoryV.getUniqueId());
         category.setNormalizedName((String) metadataProperties.get(GraphPropertyEnum.NORMALIZED_NAME));
         category.setName((String) metadataProperties.get(GraphPropertyEnum.NAME));
-        final Boolean useServiceSubstitutionForNestedServices = (Boolean) metadataProperties
-            .get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
+        final Object useServiceSubstitutionForNestedServices = metadataProperties.get(GraphPropertyEnum.USE_SUBSTITUTION_FOR_NESTED_SERVICES);
         category.setUseServiceSubstitutionForNestedServices(
-            useServiceSubstitutionForNestedServices == null ? false : useServiceSubstitutionForNestedServices);
+            useServiceSubstitutionForNestedServices != null && (boolean) useServiceSubstitutionForNestedServices);
         Type listTypeCat = new TypeToken<List<String>>() {
         }.getType();
-        List<String> iconsfromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
-        category.setIcons(iconsfromJsonCat);
+        category.setNotApplicableMetadataKeys(
+            (getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.NOT_APPLICABLE_METADATA_KEYS.getProperty()), listTypeCat)));
+        List<String> iconsFromJsonCat = getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.ICONS.getProperty()), listTypeCat);
+        category.setIcons(iconsFromJsonCat);
         category.setModels((getGson().fromJson((String) metadataProperties.get(GraphPropertyEnum.MODEL.getProperty()), listTypeCat)));
         final Type metadataKeysTypeCat = new TypeToken<List<MetadataKeyDataDefinition>>() {
         }.getType();
@@ -1576,7 +1578,7 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
     }
 
     public StorageOperationStatus removePolicyFromToscaElement(GraphVertex componentV, String policyId) {
-        return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policyId, JsonPresentationFields.UNIQUE_ID);
+        return deleteToscaDataElement(componentV, EdgeLabelEnum.POLICIES, policyId);
     }
 
     public StorageOperationStatus updateGroupOfToscaElement(GraphVertex componentV, GroupDefinition groupDefinition) {
@@ -1585,9 +1587,12 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
     }
 
     private void fillPolicyDefinition(GraphVertex componentV, PolicyDefinition policyDefinition, int counter) {
-        String policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
-            policyDefinition.getPolicyTypeName(), counter);
-        policyDefinition.setName(policyName);
+        String policyName = policyDefinition.getName();
+        if (StringUtils.isBlank(policyName)) {
+            policyName = buildSubComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME),
+                policyDefinition.getPolicyTypeName(), counter);
+            policyDefinition.setName(policyName);
+        }
         policyDefinition.setInvariantName(policyName);
         policyDefinition.setComponentName((String) componentV.getJsonMetadataField(JsonPresentationFields.NAME));
         policyDefinition.setUniqueId(UniqueIdBuilder.buildPolicyUniqueId(componentV.getUniqueId(), policyName));