diff options
author | shrek2000 <orenkle@amdocs.com> | 2019-02-12 15:17:19 +0200 |
---|---|---|
committer | Priyanshu Agarwal <pagarwal@amdocs.com> | 2019-02-13 03:22:35 +0000 |
commit | 4cedea9f7bc216df6e4ece4386b5a7b5a536671f (patch) | |
tree | d4b7425b5f731007881a6866bb18c8a033040d8f | |
parent | 92142a52059341a9c44b3818328134ab6d66b744 (diff) |
Fix duplicated constants
Add dependent child service to service
Issue-ID: SDC-1987
Change-Id: I630c4c84c705f9af7d346598de9b478d3dda940a
Signed-off-by: shrek2000 <orenkle@amdocs.com>
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/ConstraintConvertor.java | 84 | ||||
-rw-r--r-- | catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java | 3 |
2 files changed, 42 insertions, 45 deletions
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<String> SUPPORTED_CONSTRAINT_LIST = + private static Set<String> 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<String> SUPPORTED_FUNCTIONS = ImmutableSet.of(GET_INPUT, GET_PROPERTY); + + private static Set<String> 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<String> value = (List<String>) 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<String> value = (List<String>) entry.getValue(); + uiConstraint.setSourceName(value.get(0)); + uiConstraint.setValue(value.get(1)); + return uiConstraint; } - return false; + return null; } public List<String> convertToList(List<UIConstraint> 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); } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java index e6969bc5c2..36e5148286 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/ToscaFunctions.java @@ -5,7 +5,8 @@ package org.openecomp.sdc.be.model.tosca; */ public enum ToscaFunctions { - GET_INPUT("get_input"); + GET_INPUT("get_input"), + GET_PROPERTY("get_property"); private String functionName; |