TOSCA Consolidation Data - Refactoring Part 4 35/58435/2
authoreleonorali <eleonoral@amdocs.com>
Wed, 1 Aug 2018 13:28:50 +0000 (16:28 +0300)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Sun, 5 Aug 2018 13:32:31 +0000 (13:32 +0000)
Some additional minor changes

Change-Id: Ia0a89b8cfba9ed5b4ead06ab42b93421d79a4beb
Issue-ID: SDC-1330
Signed-off-by: eleonorali <eleonoral@amdocs.com>
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/SubInterfaceConsolidationDataHandler.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java

index 6dc44f9..d1b4148 100644 (file)
@@ -1,4 +1,3 @@
-/*
 /*
  * Copyright © 2016-2018 European Support Limited
  *
@@ -80,7 +79,7 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
 
 
         throw new UnsupportedOperationException(
-                "API removeParamNameFromAttrFuncList " + "not supported for SubInterfaceConsolidationDataHandler");
+                "API removeParamNameFromAttrFuncList doesn't supported for SubInterfaceConsolidationDataHandler");
     }
 
     @Override
@@ -190,12 +189,9 @@ public class SubInterfaceConsolidationDataHandler implements ConsolidationDataHa
         if (MapUtils.isEmpty(resourceIdTranslatedResourceIdMap)) {
             return Optional.empty();
         }
-        for (Map.Entry<String, String> entry : resourceIdTranslatedResourceIdMap.entrySet()) {
-            if (entry.getValue().equals(parentPortNodeTemplateId)) {
-                return Optional.of(entry.getKey());
-            }
-        }
-        return Optional.empty();
+        return resourceIdTranslatedResourceIdMap.entrySet().stream()
+               .filter(entry -> entry.getValue().equals(parentPortNodeTemplateId))
+                        .findFirst().map(Map.Entry::getKey);
     }
 
     private TranslateTo createTranslateTo(FunctionTranslator functionTranslator, String resourceId,
index 01e6017..e7c32e1 100644 (file)
@@ -39,9 +39,9 @@ import org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslatio
 
 import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.TRANS_MAPPING_DELIMITER_CHAR;
 
-/**
- * Utility class for consolidation data collection helper methods.
- */
+    /**
    * Utility class for consolidation data collection helper methods.
   */
     public class ConsolidationDataUtil {
 
     private static final String UNDERSCORE = "_";
@@ -192,24 +192,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.
 
     }
 
-    /**
-     * Checks if the current HEAT resource if of type compute.
-     *
-     * @param heatOrchestrationTemplate the heat orchestration template
-     * @param resourceId                the resource id
-     * @return true if the resource is of compute type and false otherwise
-     */
-    public static boolean isComputeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
-                                                   String resourceId) {
-        String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
-        Map<String, ImplementationConfiguration> supportedComputeResources =
-                TranslationContext.getSupportedConsolidationComputeResources();
-        if (supportedComputeResources.containsKey(resourceType)) {
-            return supportedComputeResources.get(resourceType).isEnable();
-        }
-        return false;
-    }
-
     /**
      * Checks if the current HEAT resource if of type compute.
      *
@@ -226,24 +208,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.
         return false;
     }
 
-    /**
-     * Checks if the current HEAT resource if of type port.
-     *
-     * @param heatOrchestrationTemplate the heat orchestration template
-     * @param resourceId                the resource id
-     * @return true if the resource is of port type and false otherwise
-     */
-    public static boolean isPortResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
-                                                String resourceId) {
-        String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
-        Map<String, ImplementationConfiguration> supportedPortResources =
-                TranslationContext.getSupportedConsolidationPortResources();
-        if (supportedPortResources.containsKey(resourceType)) {
-            return supportedPortResources.get(resourceType).isEnable();
-        }
-        return false;
-    }
-
     /**
      * Checks if the current HEAT resource if of type port.
      *
@@ -260,21 +224,6 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.
         return false;
     }
 
-    /**
-     * Checks if the current HEAT resource if of type volume.
-     *
-     * @param heatOrchestrationTemplate the heat orchestration template
-     * @param resourceId                the resource id
-     * @return true if the resource is of volume type and false otherwise
-     */
-    public static boolean isVolumeResource(HeatOrchestrationTemplate heatOrchestrationTemplate,
-                                                  String resourceId) {
-        String resourceType = heatOrchestrationTemplate.getResources().get(resourceId).getType();
-        return resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
-                       || resourceType.equals(HeatResourcesTypes.CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE
-                                                      .getHeatResource());
-    }
-
     /**
      * Checks if the current HEAT resource if of type volume.
      *
@@ -403,19 +352,19 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConfigConstants.
     }
 
     private static String getToscaPropertyName(FunctionTranslator functionTranslator) {
-        String toscaPropertyName = functionTranslator.getPropertyName();
         HeatOrchestrationTemplate heatOrchestrationTemplate = functionTranslator.getHeatOrchestrationTemplate();
         Resource resource = heatOrchestrationTemplate.getResources().get(functionTranslator.getResourceId());
-        boolean isNestedResource = HeatToToscaUtil.isNestedResource(resource);
-        if (!isNestedResource) {
-            String heatPropertyName = toscaPropertyName;
-            //For handling get_attr in inner levels for complex properties
-            if (toscaPropertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
-                heatPropertyName =
-                        toscaPropertyName.substring(0, toscaPropertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
-            }
-            toscaPropertyName = HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(),
-                    resource.getType(), heatPropertyName);
+        String toscaPropertyName = functionTranslator.getPropertyName();
+        if (!HeatToToscaUtil.isNestedResource(resource)) {
+            return HeatToToscaUtil.getToscaPropertyName(functionTranslator.getContext(),
+                    resource.getType(), getHeatPropertyName(toscaPropertyName));
+        }
+        return toscaPropertyName;
+    }
+
+    private static String getHeatPropertyName(String toscaPropertyName) {
+        if (toscaPropertyName.contains(TRANS_MAPPING_DELIMITER_CHAR)) {
+            return toscaPropertyName.substring(0, toscaPropertyName.indexOf(TRANS_MAPPING_DELIMITER_CHAR));
         }
         return toscaPropertyName;
     }
index bd8b558..2d283d3 100644 (file)
@@ -652,9 +652,10 @@ public class HeatToToscaUtil {
         Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource);
         HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
                 context.getFileContent(nestedHeatFileName.get()), HeatOrchestrationTemplate.class);
-        if (Objects.nonNull(nestedHeatOrchestrationTemplate.getResources())) {
-            for (String innerResourceId : nestedHeatOrchestrationTemplate.getResources().keySet()) {
-                if (ConsolidationDataUtil.isComputeResource(nestedHeatOrchestrationTemplate, innerResourceId)) {
+        Map<String, Resource> resources = nestedHeatOrchestrationTemplate.getResources();
+        if (Objects.nonNull(resources)) {
+            for (Resource innerResource : resources.values()) {
+                if (ConsolidationDataUtil.isComputeResource(innerResource)) {
                     return true;
                 }
             }