Fix node filter properties value 65/90365/2
authortalio <tali.orenbach@amdocs.com>
Mon, 24 Jun 2019 06:49:23 +0000 (09:49 +0300)
committerAvi Gaffa <avi.gaffa@amdocs.com>
Mon, 24 Jun 2019 07:40:17 +0000 (07:40 +0000)
fix node filter properties value to be list<map<string, list>>

Change-Id: Iafb31c4f94f10d0493ef2bce622019958a995639
Issue-ID: SDC-2381
Signed-off-by: talio <tali.orenbach@amdocs.com>
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java

index 2c0af5f..df56ccc 100644 (file)
@@ -2862,7 +2862,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
     }
 
     public Either<CINodeFilterDataDefinition, ResponseFormat> addOrDeleteServiceFilter(String serviceId, String componentInstanceId,
-            NodeFilterConstraintAction action, String constraint, int position, User inUser, boolean lock) {
+            NodeFilterConstraintAction action, String propertyName, String constraint, int position, User inUser, boolean lock) {
         String errorContext =  "createIfNotAlreadyExistServiceFilter";
         User user = validateUserExists(inUser, errorContext, true);
         validateUserRole(user, Arrays.asList(Role.DESIGNER, Role.ADMIN));
@@ -2913,6 +2913,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic {
             switch (action) {
                 case ADD:
                     RequirementNodeFilterPropertyDataDefinition newProperty = new RequirementNodeFilterPropertyDataDefinition();
+                    newProperty.setName(propertyName);
                     newProperty.setConstraints(Collections.singletonList(constraint));
                     result = serviceFilterOperation.addNewProperty(serviceId, componentInstanceId,serviceFilter,newProperty);
                     break;
index 3daca3f..b539265 100644 (file)
@@ -101,7 +101,7 @@ public class ServiceFilterServlet extends AbstractValidationsServlet {
             Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
             String constraint = new ConstraintConvertor().convert(uiConstraint);
             actionResponse = businessLogic
-                                     .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.ADD,
+                                     .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.ADD, uiConstraint.getServicePropertyName(),
                                              constraint, -1, modifier, true);
 
             if (actionResponse.isRight()) {
@@ -224,7 +224,7 @@ public class ServiceFilterServlet extends AbstractValidationsServlet {
             Either<CINodeFilterDataDefinition, ResponseFormat> actionResponse;
             actionResponse = businessLogic
                                      .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.DELETE,
-                                             null, index, modifier, true);
+                                             null, null,  index, modifier, true);
 
             if (actionResponse.isRight()) {
 
index 603da09..0d3836b 100644 (file)
@@ -1324,25 +1324,43 @@ public class ToscaExportHandler {
                    origProperties.isEmpty()) {
             return;
         }
+        Map<String, List<Object>> propertyMapCopy = new HashMap<>();
         for(RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) {
-            Map<String, List<Object>> propertyMapCopy = new HashMap<>();
             for(String propertyInfoEntry : propertyDataDefinition.getConstraints()) {
                 Map propertyValObj =  new YamlUtil().yamlToObject(propertyInfoEntry, Map.class);
-                if (propertyMapCopy.containsKey(propertyDataDefinition.getName())){
-                    propertyMapCopy.get(propertyDataDefinition.getName()).add(propertyValObj);
+                String propertyName = propertyDataDefinition.getName();
+                if (propertyMapCopy.containsKey(propertyName)){
+                    addPropertyConstraintValueToList(propertyName, propertyValObj, propertyMapCopy.get(propertyName));
                 } else {
-                    if (propertyDataDefinition.getName() != null) {
-                        List propsList =new ArrayList();
-                        propsList.add(propertyValObj);
-                        propertyMapCopy.put(propertyDataDefinition.getName(), propsList);
+                    if (propertyName != null) {
+                        List propsList = new ArrayList();
+                        addPropertyConstraintValueToList(propertyName, propertyValObj, propsList);
+                        propertyMapCopy.put(propertyName, propsList);
                     } else {
                         propertyMapCopy.putAll(propertyValObj);
                     }
                 }
             }
-            propertiesCopy.add(propertyMapCopy);
         }
+        propertyMapCopy.entrySet().stream().forEach(entry ->
+            addCalculatedConstraintsIntoPropertiesList(propertiesCopy, entry));
+    }
+
+    private void addPropertyConstraintValueToList(String propertyName, Map propertyValObj, List propsList) {
+        if(propertyValObj.containsKey(propertyName)) {
+            propsList.add(propertyValObj.get(propertyName));
+        } else {
+            propsList.add(propertyValObj);
+        }
+    }
+
+
 
+    private void addCalculatedConstraintsIntoPropertiesList(List<Map<String, List<Object>>> propertiesCopy,
+            Entry<String, List<Object>> entry) {
+        Map<String, List<Object>> tempMap = new HashMap<>();
+        tempMap.put(entry.getKey(), entry.getValue());
+        propertiesCopy.add(tempMap);
     }
 
     private static class CustomRepresenter extends Representer {