Implement hiding mechanism
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsonjanusgraph / operations / TopologyTemplateOperation.java
index 7742cbf..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,
@@ -385,6 +386,23 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
         return StorageOperationStatus.OK;
     }
 
+    public StorageOperationStatus associateInstInterfacesToComponent(
+        GraphVertex nodeTypeVertex,
+        Map<String, MapInterfaceDataDefinition> instInterfaces
+    ) {
+        if (instInterfaces != null && !instInterfaces.isEmpty()) {
+            Either<GraphVertex, StorageOperationStatus> associateElementToData = associateElementToData(
+                nodeTypeVertex,
+                VertexTypeEnum.INST_INTERFACES,
+                EdgeLabelEnum.INST_INTERFACES,
+                instInterfaces);
+            if (associateElementToData.isRight()) {
+                return associateElementToData.right().value();
+            }
+        }
+        return StorageOperationStatus.OK;
+    }
+
     public StorageOperationStatus associateInstGroupsToComponent(GraphVertex nodeTypeVertex, Map<String, MapGroupsDataDefinition> instGroups) {
         if (instGroups != null && !instGroups.isEmpty()) {
             Either<GraphVertex, StorageOperationStatus> assosiateElementToData = associateElementToData(nodeTypeVertex, VertexTypeEnum.INST_GROUPS,
@@ -402,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;
                 }
@@ -583,6 +601,21 @@ public class TopologyTemplateOperation extends ToscaElementOperation {
         return StorageOperationStatus.OK;
     }
 
+    public StorageOperationStatus associateOutputsToComponent(final GraphVertex nodeTypeVertex,
+                                                              final Map<String, ? extends AttributeDataDefinition> outputs,
+                                                              final String id) {
+        if (MapUtils.isNotEmpty(outputs)) {
+            outputs.values().stream().filter(e -> e.getUniqueId() == null)
+                .forEach(e -> e.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(id, e.getName())));
+            final Either<GraphVertex, StorageOperationStatus> associateElementToData
+                = associateElementToData(nodeTypeVertex, VertexTypeEnum.OUTPUTS, EdgeLabelEnum.OUTPUTS, outputs);
+            if (associateElementToData.isRight()) {
+                return associateElementToData.right().value();
+            }
+        }
+        return StorageOperationStatus.OK;
+    }
+
     private GraphVertex fillMetadata(GraphVertex nodeTypeVertex, TopologyTemplate topologyTemplate, JsonParseFlagEnum flag) {
         nodeTypeVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
         fillCommonMetadata(nodeTypeVertex, topologyTemplate);
@@ -1151,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();
@@ -1544,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) {
@@ -1553,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));