From 4cedea9f7bc216df6e4ece4386b5a7b5a536671f Mon Sep 17 00:00:00 2001 From: shrek2000 Date: Tue, 12 Feb 2019 15:17:19 +0200 Subject: Fix duplicated constants Add dependent child service to service Issue-ID: SDC-1987 Change-Id: I630c4c84c705f9af7d346598de9b478d3dda940a Signed-off-by: shrek2000 --- .../be/datamodel/utils/ConstraintConvertor.java | 84 +++++++++++----------- 1 file changed, 40 insertions(+), 44 deletions(-) (limited to 'catalog-be/src') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java index e05ef92431..ca59a0dda1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import org.openecomp.sdc.be.model.tosca.ToscaFunctions; import org.openecomp.sdc.be.model.tosca.constraints.ConstraintType; import org.openecomp.sdc.be.ui.model.UIConstraint; import org.slf4j.Logger; @@ -25,31 +26,28 @@ public class ConstraintConvertor { public static final String PROPERTY_CONSTRAINT = "property"; public static final String SERVICE_INPUT_CONSTRAINT = "service_input"; public static final String SELF = "SELF"; - private static final Set SUPPORTED_CONSTRAINT_LIST = + private static Set SUPPORTED_CONSTRAINT_LIST = ImmutableSet.of(EQUAL_OPERATOR, GREATER_THAN_OPERATOR, LESS_THAN_OPERATOR); - private static final String GET_INPUT = "get_input"; - private static final String GET_PROPERTY = "get_property"; - private static final Set SUPPORTED_FUNCTIONS = ImmutableSet.of(GET_INPUT, GET_PROPERTY); + + private static Set SUPPORTED_FUNCTIONS = + ImmutableSet.of(ToscaFunctions.GET_INPUT.getFunctionName(), ToscaFunctions.GET_PROPERTY.getFunctionName()); public UIConstraint convert(String inConstraint) { Yaml yamlSource = new Yaml(); UIConstraint uiConstraint = new UIConstraint(); Object content1 = yamlSource.load(inConstraint); - if (content1 instanceof Map) { - Map map1 = (Map) content1; - Object key = map1.keySet().iterator().next(); - uiConstraint.setServicePropertyName(key.toString()); - Object content2 = map1.get(key); - if (content2 instanceof Map && handleServiceConstraint(uiConstraint, (Map) content2)) { - return uiConstraint; - } + if (!(content1 instanceof Map)) { + return null; } - return null; - } - - private boolean handleServiceConstraint(UIConstraint uiConstraint, Map content2) { - Map map2 = content2; + Map map1 = (Map) content1; + Object key = map1.keySet().iterator().next(); + uiConstraint.setServicePropertyName(key.toString()); + Object content2 = map1.get(key); + if (!(content2 instanceof Map)) { + return null; + } + Map map2 = (Map) content2; Object key2 = map2.keySet().iterator().next(); final String operator = key2.toString(); if (SUPPORTED_CONSTRAINT_LIST.contains(operator)) { @@ -59,40 +57,38 @@ public class ConstraintConvertor { if (content3 instanceof String || content3 instanceof Number || content3 instanceof Boolean) { uiConstraint.setValue(content3); uiConstraint.setSourceType(STATIC_CONSTRAINT); - return true; + return uiConstraint; } else if (content3 instanceof List) { List list1 = (List) content3; uiConstraint.setSourceType(STATIC_CONSTRAINT); uiConstraint.setValue(list1); - return true; + return uiConstraint; } else if (content3 instanceof Map) { - Map map3 = (Map) content3; - Map.Entry entry = (Map.Entry) map3.entrySet().iterator().next(); - final String firstKey = entry.getKey().toString().trim(); - if (handleSupportedFunctions(uiConstraint, entry, firstKey)) { - return true; - } - uiConstraint.setValue(content3); - return true; + return handleMap(uiConstraint, content3); } - return false; + return null; } - private boolean handleSupportedFunctions(UIConstraint uiConstraint, Map.Entry entry, String firstKey) { - if (SUPPORTED_FUNCTIONS.contains(firstKey)) { - if (GET_INPUT.equals(firstKey)) { - uiConstraint.setSourceType(SERVICE_INPUT_CONSTRAINT); - uiConstraint.setValue(entry.getValue()); - return true; - } else if (GET_PROPERTY.equals(firstKey)) { - uiConstraint.setSourceType(PROPERTY_CONSTRAINT); - final List value = (List) entry.getValue(); - uiConstraint.setSourceName(value.get(0)); - uiConstraint.setValue(value.get(1)); - return true; - } + private UIConstraint handleMap(UIConstraint uiConstraint, Object content3) { + Map map3 = (Map) content3; + Map.Entry entry = (Map.Entry) map3.entrySet().iterator().next(); + final String firstKey = entry.getKey().toString().trim(); + if (!SUPPORTED_FUNCTIONS.contains(firstKey)) { + uiConstraint.setValue(content3); + return uiConstraint; + } + if (ToscaFunctions.GET_INPUT.getFunctionName().equals(firstKey)) { + uiConstraint.setSourceType(SERVICE_INPUT_CONSTRAINT); + uiConstraint.setValue(entry.getValue()); + return uiConstraint; + } else if (ToscaFunctions.GET_PROPERTY.getFunctionName().equals(firstKey)) { + uiConstraint.setSourceType(PROPERTY_CONSTRAINT); + final List value = (List) entry.getValue(); + uiConstraint.setSourceName(value.get(0)); + uiConstraint.setValue(value.get(1)); + return uiConstraint; } - return false; + return null; } public List convertToList(List uiConstraints) { @@ -120,10 +116,10 @@ public class ConstraintConvertor { map2.put(uiConstraint.getConstraintOperator(), value); } else if (uiConstraint.getSourceType().equals(PROPERTY_CONSTRAINT)) { List list1 = Arrays.asList(uiConstraint.getSourceName(), uiConstraint.getValue()); - Map map3 = ImmutableMap.of(GET_PROPERTY, list1); + Map map3 = ImmutableMap.of(ToscaFunctions.GET_PROPERTY.getFunctionName(), list1); map2.put(uiConstraint.getConstraintOperator(), map3); } else if (uiConstraint.getSourceType().equals(SERVICE_INPUT_CONSTRAINT)) { - Map map3 = ImmutableMap.of(GET_INPUT, uiConstraint.getValue()); + Map map3 = ImmutableMap.of(ToscaFunctions.GET_INPUT.getFunctionName(), uiConstraint.getValue()); map2.put(uiConstraint.getConstraintOperator(), map3); } -- cgit 1.2.3-korg