From 33e00cd1d7d580a2fdafad771d54e29bb455cb5d Mon Sep 17 00:00:00 2001 From: vempo Date: Tue, 3 Oct 2017 20:04:37 +0300 Subject: Update group members ids Issue-Id: SDC-427 Change-Id: If7a476adfac7c56c97e14330e4fddcc6d9f2d293 Signed-off-by: vempo --- .../sdc/tosca/services/DataModelUtil.java | 10 +++++ .../openecomp/sdc/tosca/services/ToscaUtil.java | 52 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main') 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 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 metadata) { @@ -63,6 +69,50 @@ public class ToscaUtil { } + public static Optional getSubstitutableGroupMemberId(String heatFileName, + ServiceTemplate serviceTemplate){ + + Map nodeTemplates = + DataModelUtil.getNodeTemplates(serviceTemplate); + + if(MapUtils.isEmpty(nodeTemplates)){ + return Optional.empty(); + } + + String heatFileNameWithoutExt = FileUtils.getFileWithoutExtention(heatFileName); + + for(Map.Entry 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 nodeTemplateEntry) { + Map properties = + nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() : + nodeTemplateEntry.getValue().getProperties(); + + Map serviceTemplateFilter = + properties.containsKey(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME)? + (Map) 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. -- cgit 1.2.3-korg