diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-03 20:04:37 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-03 20:06:51 +0300 |
commit | 33e00cd1d7d580a2fdafad771d54e29bb455cb5d (patch) | |
tree | 15f2f1c08313eac8633aaf3935e0df1dcae9a74c /openecomp-be/lib/openecomp-tosca-lib | |
parent | 2e4d90a7a3c76deb582df234a1b474daeb37ae30 (diff) |
Update group members ids
Issue-Id: SDC-427
Change-Id: If7a476adfac7c56c97e14330e4fddcc6d9f2d293
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib')
2 files changed, 61 insertions, 1 deletions
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java index 26596b994f..7c1dfdcafd 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/DataModelUtil.java @@ -198,6 +198,16 @@ public class DataModelUtil { mdcDataDebugMessage.debugExitMessage(null, null); } + public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate){ + if (Objects.isNull(serviceTemplate) + || Objects.isNull(serviceTemplate.getTopology_template()) + || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())){ + return new HashMap<>(); + } + + return serviceTemplate.getTopology_template().getNode_templates(); + } + /** * Add node template. * diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java index f3bf3280dc..3b7db49fee 100644 --- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java +++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java @@ -20,10 +20,16 @@ package org.openecomp.sdc.tosca.services; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.UUID; /** @@ -50,7 +56,7 @@ public class ToscaUtil { /** * Gets service template file name. * - * @param metaData the file name + * @param metadata the file name * @return the service template file name */ public static String getServiceTemplateFileName(Map<String, String> metadata) { @@ -63,6 +69,50 @@ public class ToscaUtil { } + public static Optional<String> getSubstitutableGroupMemberId(String heatFileName, + ServiceTemplate serviceTemplate){ + + Map<String, NodeTemplate> nodeTemplates = + DataModelUtil.getNodeTemplates(serviceTemplate); + + if(MapUtils.isEmpty(nodeTemplates)){ + return Optional.empty(); + } + + String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName); + + for(Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()){ + String subServiceTemplateName = + getSubstitutionServiceTemplateNameFromProperties(nodeTemplateEntry); + + if(Objects.nonNull(subServiceTemplateName) + && isGroupMemberIdSubstitutable(heatFileNameWithoutExt, subServiceTemplateName)){ + return Optional.of(nodeTemplateEntry.getKey()); + } + } + + return Optional.empty(); + } + + private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt, + String subServiceTemplateName) { + return subServiceTemplateName.startsWith(heatFileNameWithoutExt); + } + + private static String getSubstitutionServiceTemplateNameFromProperties( + Map.Entry<String, NodeTemplate> nodeTemplateEntry) { + Map<String, Object> properties = + nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() : + nodeTemplateEntry.getValue().getProperties(); + + Map<String, Object> serviceTemplateFilter = + properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)? + (Map<String, Object>) properties.get(ToscaConstants + .SERVICE_TEMPLATE_FILTER_PROPERTY_NAME) : Collections.emptyMap(); + + return (String) serviceTemplateFilter.get(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME); + } + /** * Add service template to map with key file name. |