Revert "Fix 'Wrong Inputs creation on (Add Service)'"
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / property / DefaultPropertyDeclarator.java
index 07d5ba0..0412516 100644 (file)
@@ -126,7 +126,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
 
     private Either<List<PolicyDefinition>, StorageOperationStatus> declarePropertiesAsPolicies(Component component, PROPERTYOWNER propertiesOwner,
                                                                                                List<ComponentInstancePropInput> propsToDeclare) {
-        PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(),
+        PropertiesDeclarationData policyProperties = createPoliciesAndOverridePropertiesValues(propertiesOwner.getUniqueId(), propertiesOwner,
             propsToDeclare);
         return updatePropertiesValues(component, propertiesOwner.getUniqueId(), policyProperties.getPropertiesToUpdate()).left()
             .map(updatePropsRes -> policyProperties.getPoliciesToCreate());
@@ -144,7 +144,8 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
             .map(updatePropsRes -> inputsProperties.getInputsToCreate());
     }
 
-    private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, List<ComponentInstancePropInput> propsToDeclare) {
+    private PropertiesDeclarationData createPoliciesAndOverridePropertiesValues(String componentId, PROPERTYOWNER propertiesOwner,
+                                                                                List<ComponentInstancePropInput> propsToDeclare) {
         List<PROPERTYTYPE> declaredProperties = new ArrayList<>();
         List<PolicyDefinition> policies = new ArrayList<>();
         propsToDeclare.forEach(property -> policies.add(declarePropertyPolicy(componentId, declaredProperties, property)));
@@ -249,7 +250,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
         if (propertyCapability.isPresent()) {
             String capName = propertyCapability.get().getName();
             if (capName.contains(".")) {
-                capName = capName.replace(".", UNDERSCORE);
+                capName = capName.replaceAll("\\.", UNDERSCORE);
             }
             generatedInputPrefix =
                 generatedInputPrefix == null || generatedInputPrefix.isEmpty() ? capName : generatedInputPrefix + UNDERSCORE + capName;
@@ -314,12 +315,12 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
         input.setInputPath(propertiesName);
         input.setInstanceUniqueId(propertiesOwner.getUniqueId());
         input.setPropertyId(propInput.getUniqueId());
-        if (Objects.isNull(input.getSubPropertyInputPath()) || (StringUtils.isNotEmpty(propertiesName) && input.getSubPropertyInputPath()
+        if (Objects.isNull(input.getSubPropertyInputPath()) || (Objects.nonNull(propertiesName) && input.getSubPropertyInputPath()
             .substring(input.getSubPropertyInputPath().lastIndexOf('#')).equals(propertiesName.substring(propertiesName.lastIndexOf('#'))))) {
             input.setParentPropertyType(propInput.getType());
             input.setSubPropertyInputPath(propertiesName);
         }
-        changePropertyValueToGetInputValue(parsedPropNames, input, prop, complexProperty);
+        changePropertyValueToGetInputValue(inputName, parsedPropNames, input, prop, complexProperty);
         if (prop instanceof IComponentInstanceConnectedElement) {
             ((IComponentInstanceConnectedElement) prop).setComponentInstanceId(propertiesOwner.getUniqueId());
             ((IComponentInstanceConnectedElement) prop).setComponentInstanceName(propertiesOwner.getName());
@@ -327,43 +328,42 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
         return input;
     }
 
-    private void changePropertyValueToGetInputValue(String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
+    private void changePropertyValueToGetInputValue(String inputName, String[] parsedPropNames, InputDefinition input, PropertyDataDefinition prop,
                                                     boolean complexProperty) {
         JSONObject jsonObject = new JSONObject();
-        final String value = prop.getValue();
-        final String inputName = input.getName();
+        String value = prop.getValue();
         if (value == null || value.isEmpty()) {
             if (complexProperty) {
                 jsonObject = createJSONValueForProperty(parsedPropNames.length - 1, parsedPropNames, jsonObject, inputName);
                 prop.setValue(jsonObject.toJSONString());
             } else {
-                jsonObject.put(GET_INPUT, inputName);
+                jsonObject.put(GET_INPUT, input.getName());
                 prop.setValue(jsonObject.toJSONString());
             }
         } else {
-            final Object objValue = new Yaml().load(value);
+            Object objValue = new Yaml().load(value);
             if (objValue instanceof Map || objValue instanceof List) {
                 if (!complexProperty) {
-                    jsonObject.put(GET_INPUT, inputName);
+                    jsonObject.put(GET_INPUT, input.getName());
                     prop.setValue(jsonObject.toJSONString());
                 } else {
-                    final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
+                    Map<String, Object> mappedToscaTemplate = (Map<String, Object>) objValue;
                     createInputValue(mappedToscaTemplate, 1, parsedPropNames, inputName);
-                    final String json = gson.toJson(mappedToscaTemplate);
+                    String json = gson.toJson(mappedToscaTemplate);
                     prop.setValue(json);
                 }
             } else {
-                jsonObject.put(GET_INPUT, inputName);
+                jsonObject.put(GET_INPUT, input.getName());
                 prop.setValue(jsonObject.toJSONString());
             }
         }
         if (CollectionUtils.isEmpty(prop.getGetInputValues())) {
             prop.setGetInputValues(new ArrayList<>());
         }
-        final List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
-        final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
+        List<GetInputValueDataDefinition> getInputValues = prop.getGetInputValues();
+        GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition();
         getInputValueDataDefinition.setInputId(input.getUniqueId());
-        getInputValueDataDefinition.setInputName(inputName);
+        getInputValueDataDefinition.setInputName(input.getName());
         getInputValues.add(getInputValueDataDefinition);
     }
 
@@ -460,7 +460,8 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
             if (result.isLeft()) {
                 modifiedMappedToscaTemplate = (Map) result.left().value();
             } else {
-                log.warn("Map cleanup failed -> {}", result.right().value());    //continue, don't break operation
+                log.warn("Map cleanup failed -> " + result.right().value()
+                    .toString());    //continue, don't break operation
             }
             value = gson.toJson(modifiedMappedToscaTemplate);
         }
@@ -545,10 +546,11 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
         boolean isEmpty = true;
         if (element != null) {
             if (element instanceof Map) {
-                final Map map = (Map) element;
-                if (MapUtils.isNotEmpty(map)) {
-                    for (final Object key : map.keySet()) {
-                        final Object value = map.get(key);
+                if (MapUtils.isEmpty((Map) element)) {
+                    isEmpty = true;
+                } else {
+                    for (Object key : ((Map) (element)).keySet()) {
+                        Object value = ((Map) (element)).get(key);
                         isEmpty &= isEmptyNestedMap(value);
                     }
                 }
@@ -558,7 +560,7 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
         }
         return isEmpty;
     }
-    //@returns true if map nested maps are all empty
+    //@returns true iff map nested maps are all empty
 
     private class PropertiesDeclarationData {