diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java')
-rw-r--r-- | openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/ToscaUtil.java | 46 |
1 files changed, 12 insertions, 34 deletions
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 7c8e48ac88..66230250d5 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 @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.tosca.services; import java.util.Collections; @@ -26,7 +25,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; - import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.collections4.MapUtils; @@ -66,11 +64,9 @@ public class ToscaUtil { if (metadata.get(ToscaConstants.ST_METADATA_FILE_NAME) != null) { return metadata.get(ToscaConstants.ST_METADATA_FILE_NAME); } else if (metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) != null) { - return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) - + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; + return metadata.get(ToscaConstants.ST_METADATA_TEMPLATE_NAME) + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; } - return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; - + return UUID.randomUUID().toString() + ToscaConstants.SERVICE_TEMPLATE_FILE_POSTFIX; } public static String getServiceTemplateFileName(String templateName) { @@ -79,59 +75,41 @@ public class ToscaUtil { return getServiceTemplateFileName(metadata); } - public static Optional<String> getSubstitutableGroupMemberId(String heatFileName, - ServiceTemplate serviceTemplate) { - - Map<String, NodeTemplate> nodeTemplates = - DataModelUtil.getNodeTemplates(serviceTemplate); - + 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)) { + 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) { + private static boolean isGroupMemberIdSubstitutable(String heatFileNameWithoutExt, String subServiceTemplateName) { return subServiceTemplateName.startsWith(heatFileNameWithoutExt); } - private static String getSubstitutionServiceTemplateNameFromProperties( - Map.Entry<String, NodeTemplate> nodeTemplateEntry) { + private static String getSubstitutionServiceTemplateNameFromProperties(Map.Entry<String, NodeTemplate> nodeTemplateEntry) { Map<String, Object> properties = - nodeTemplateEntry.getValue().getProperties() == null ? Collections.emptyMap() : - nodeTemplateEntry.getValue().getProperties(); - + 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(); - + 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. * * @param serviceTemplateMap the service template map * @param serviceTemplate the service template */ - public static void addServiceTemplateToMapWithKeyFileName( - Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) { + public static void addServiceTemplateToMapWithKeyFileName(Map<String, ServiceTemplate> serviceTemplateMap, ServiceTemplate serviceTemplate) { serviceTemplateMap.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate); } } |