From 8da6ea990a89b752e0e40d7dbf82b6761850f4e7 Mon Sep 17 00:00:00 2001 From: talio Date: Mon, 24 Jun 2019 09:49:23 +0300 Subject: Fix node filter properties value fix node filter properties value to be list> Change-Id: Iafb31c4f94f10d0493ef2bce622019958a995639 Issue-ID: SDC-2381 Signed-off-by: talio --- .../be/components/impl/ServiceBusinessLogic.java | 3 +- .../sdc/be/servlets/ServiceFilterServlet.java | 4 +-- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 34 +++++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java index 2c0af5fec5..df56ccc1e4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceBusinessLogic.java @@ -2862,7 +2862,7 @@ public class ServiceBusinessLogic extends ComponentBusinessLogic { } public Either 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; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java index 3daca3f28c..b539265721 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ServiceFilterServlet.java @@ -101,7 +101,7 @@ public class ServiceFilterServlet extends AbstractValidationsServlet { Either 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 actionResponse; actionResponse = businessLogic .addOrDeleteServiceFilter(serviceIdLower, ciId, NodeFilterConstraintAction.DELETE, - null, index, modifier, true); + null, null, index, modifier, true); if (actionResponse.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 603da09a1d..0d3836b1c9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -1324,25 +1324,43 @@ public class ToscaExportHandler { origProperties.isEmpty()) { return; } + Map> propertyMapCopy = new HashMap<>(); for(RequirementNodeFilterPropertyDataDefinition propertyDataDefinition : origProperties.getListToscaDataDefinition()) { - Map> 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>> propertiesCopy, + Entry> entry) { + Map> tempMap = new HashMap<>(); + tempMap.put(entry.getKey(), entry.getValue()); + propertiesCopy.add(tempMap); } private static class CustomRepresenter extends Representer { -- cgit 1.2.3-korg