summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-09-06 08:33:09 +0300
committerOren Kleks <orenkle@amdocs.com>2018-09-09 04:34:45 +0000
commitf450879a13742c710173e6e2ccad74aa21e342fc (patch)
tree7f022116c48ab53caa7977b43280da5296776e2f /common
parent82df2327ace0160a3db30f070350ca014f9f2510 (diff)
Add support for service substitution filter
Change-Id: Id320380b83f072e0b8f5a81831111cbe96957d78 Issue-ID: SDC-1740 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'common')
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java73
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java57
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java52
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelNormalizeUtil.java101
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java15
5 files changed, 226 insertions, 72 deletions
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java
index 2c95568a66..be34394e34 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java
@@ -16,13 +16,9 @@
package org.onap.sdc.tosca.datatypes.model;
-import org.apache.commons.collections4.CollectionUtils;
-import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
-
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.onap.sdc.tosca.services.DataModelNormalizeUtil;
public class NodeFilter {
@@ -35,79 +31,16 @@ public class NodeFilter {
}
public void setCapabilities(List<Map<String, CapabilityFilter>> capabilities) {
- this.capabilities = getNormalizeCapabilities(capabilities);
+ this.capabilities = DataModelNormalizeUtil.getNormalizeCapabilitiesFilter(capabilities);
}
public void setProperties(List<Map<String, List<Constraint>>> properties) {
- this.properties = getNormalizeProperties(properties);
+ this.properties = DataModelNormalizeUtil.getNormalizePropertiesFilter(properties);
}
public List<Map<String, List<Constraint>>> getProperties() {
return properties;
}
- private List<Map<String, List<Constraint>>> getNormalizeProperties(List<Map<String, List<Constraint>>> properties) {
- if (CollectionUtils.isEmpty(properties)) {
- return properties;
- }
- List<Map<String, List<Constraint>>> normalizeProperties = new ArrayList<>();
- for (Map<String, List<Constraint>> propertyEntry : properties) {
- Map<String, List<Constraint>> normalizePropertyEntry = getNormalizePropertyEntry(propertyEntry);
- normalizeProperties.add(normalizePropertyEntry);
- }
- return normalizeProperties;
-
- }
-
- private Map<String, List<Constraint>> getNormalizePropertyEntry(Map<String, List<Constraint>> propertyEntry) {
- Map<String, List<Constraint>> normalizePropertyEntry = new HashMap<>();
- String propertyKey = propertyEntry.keySet().iterator().next(); //only one entry exist in the map
- List<Constraint> constraints = propertyEntry.get(propertyKey);
- List<Constraint> normalizeConstraints = getNormalizeConstrains(constraints);
- normalizePropertyEntry.put(propertyKey, normalizeConstraints);
- return normalizePropertyEntry;
- }
-
- private List<Constraint> getNormalizeConstrains(List<Constraint> constraints) {
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- List<Constraint> normalizeConstraints = new ArrayList<>();
- for (Object constraintObj : constraints) {
- Constraint normalizeConstraint = toscaExtensionYamlUtil
- .yamlToObject(toscaExtensionYamlUtil.objectToYaml(constraintObj),
- Constraint.class);
- normalizeConstraints.add(normalizeConstraint);
- }
- return normalizeConstraints;
- }
-
- public List<Map<String, CapabilityFilter>> getNormalizeCapabilities(List<Map<String, CapabilityFilter>> capabilities) {
- if (CollectionUtils.isEmpty(capabilities)) {
- return capabilities;
- }
- List<Map<String, CapabilityFilter>> normalizeCapabilities = new ArrayList<>();
- for (Map<String, CapabilityFilter> capabilityEntry : capabilities) {
- Map<String, CapabilityFilter> normalizeCapabilityEntry = getNormalizeCapabilityEntry(capabilityEntry);
- normalizeCapabilities.add(normalizeCapabilityEntry);
- }
- return normalizeCapabilities;
- }
-
- private Map<String, CapabilityFilter> getNormalizeCapabilityEntry(Map<String, CapabilityFilter> capabilityEntry) {
- Map<String, CapabilityFilter> normalizeCapabilityEntry = new HashMap<>();
- String capabilityKey = capabilityEntry.keySet().iterator().next(); //only one entry exist in the map
- Object capabilityFilterObj = capabilityEntry.get(capabilityKey);
- CapabilityFilter normalizeCapabilityFilter = getNormalizeCapabilityFilter(capabilityFilterObj);
- normalizeCapabilityEntry.put(capabilityKey, normalizeCapabilityFilter);
- return normalizeCapabilityEntry;
- }
-
- private CapabilityFilter getNormalizeCapabilityFilter(Object capabilityFilterObj) {
- ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
- CapabilityFilter capabilityFilter = toscaExtensionYamlUtil.yamlToObject(
- toscaExtensionYamlUtil.objectToYaml(capabilityFilterObj), CapabilityFilter.class);
- capabilityFilter.setProperties(getNormalizeProperties(capabilityFilter.getProperties()));
-
- return capabilityFilter;
- }
}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java
new file mode 100644
index 0000000000..8f3aa20a48
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionFilter.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.tosca.datatypes.model.extension;
+
+
+import java.util.List;
+
+import java.util.Map;
+import org.onap.sdc.tosca.datatypes.model.Constraint;
+import org.onap.sdc.tosca.services.DataModelNormalizeUtil;
+
+public class SubstitutionFilter {
+
+ private List<Map<String, List<Constraint>>> properties;
+
+ public List<Map<String, List<Constraint>>> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(List<Map<String, List<Constraint>>> properties) {
+ this.properties = DataModelNormalizeUtil.getNormalizePropertiesFilter(properties);
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof SubstitutionFilter)) {
+ return false;
+ }
+
+ SubstitutionFilter that = (SubstitutionFilter) o;
+
+ return getProperties() != null ? getProperties().equals(that.getProperties()) : that.getProperties() == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return getProperties() != null ? getProperties().hashCode() : 0;
+ }
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java
new file mode 100644
index 0000000000..1fa3719571
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/SubstitutionMappingExt.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.tosca.datatypes.model.extension;
+
+import org.onap.sdc.tosca.datatypes.model.SubstitutionMapping;
+
+public class SubstitutionMappingExt extends SubstitutionMapping {
+
+ private SubstitutionFilter substitution_filter;
+
+ public SubstitutionFilter getSubstitution_filter() {
+ return substitution_filter;
+ }
+
+ public void setSubstitution_filter(SubstitutionFilter substitution_filter) {
+ this.substitution_filter = substitution_filter;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof SubstitutionMappingExt)) {
+ return false;
+ }
+
+ SubstitutionMappingExt that = (SubstitutionMappingExt) o;
+
+ return getSubstitution_filter() != null ? getSubstitution_filter().equals(that.getSubstitution_filter()) :
+ that.getSubstitution_filter() == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return getSubstitution_filter() != null ? getSubstitution_filter().hashCode() : 0;
+ }
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelNormalizeUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelNormalizeUtil.java
new file mode 100644
index 0000000000..b8a950cd85
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/DataModelNormalizeUtil.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.sdc.tosca.services;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.datatypes.model.CapabilityFilter;
+import org.onap.sdc.tosca.datatypes.model.Constraint;
+
+public class DataModelNormalizeUtil {
+
+ private DataModelNormalizeUtil() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ public static List<Map<String, CapabilityFilter>> getNormalizeCapabilitiesFilter(
+ List<Map<String, CapabilityFilter>> capabilitiesFilter) {
+ if (CollectionUtils.isEmpty(capabilitiesFilter)) {
+ return capabilitiesFilter;
+ }
+ List<Map<String, CapabilityFilter>> normalizeCapabilities = new ArrayList<>();
+ for (Map<String, CapabilityFilter> capabilityFilterEntry : capabilitiesFilter) {
+ Map<String, CapabilityFilter> normalizeCapabilityEntry = getNormalizeCapabilityFilterEntry(capabilityFilterEntry);
+ normalizeCapabilities.add(normalizeCapabilityEntry);
+ }
+ return normalizeCapabilities;
+ }
+
+ private static Map<String, CapabilityFilter> getNormalizeCapabilityFilterEntry(
+ Map<String, CapabilityFilter> capabilityFilterEntry) {
+ Map<String, CapabilityFilter> normalizeCapabilityEntry = new HashMap<>();
+ String capabilityKey = capabilityFilterEntry.keySet().iterator().next(); //only one entry exist in the map
+ Object capabilityFilterObj = capabilityFilterEntry.get(capabilityKey);
+ CapabilityFilter normalizeCapabilityFilter = getNormalizeCapabilityFilter(capabilityFilterObj);
+ normalizeCapabilityEntry.put(capabilityKey, normalizeCapabilityFilter);
+ return normalizeCapabilityEntry;
+ }
+
+ private static CapabilityFilter getNormalizeCapabilityFilter(Object capabilityFilterObj) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ CapabilityFilter capabilityFilter = toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(capabilityFilterObj), CapabilityFilter.class);
+ capabilityFilter.setProperties(getNormalizePropertiesFilter(capabilityFilter.getProperties()));
+
+ return capabilityFilter;
+ }
+
+ public static List<Map<String, List<Constraint>>> getNormalizePropertiesFilter(
+ List<Map<String, List<Constraint>>> properties) {
+ if (CollectionUtils.isEmpty(properties)) {
+ return properties;
+ }
+ List<Map<String, List<Constraint>>> normalizeProperties = new ArrayList<>();
+ for (Map<String, List<Constraint>> propertyFilterEntry : properties) {
+ Map<String, List<Constraint>> normalizePropertyEntry = getNormalizePropertyFilterEntry(propertyFilterEntry);
+ normalizeProperties.add(normalizePropertyEntry);
+ }
+ return normalizeProperties;
+
+ }
+
+ private static Map<String, List<Constraint>> getNormalizePropertyFilterEntry(
+ Map<String, List<Constraint>> propertyFilterEntry) {
+ Map<String, List<Constraint>> normalizePropertyEntry = new HashMap<>();
+ String propertyKey = propertyFilterEntry.keySet().iterator().next(); //only one entry exist in the map
+ List<Constraint> constraints = propertyFilterEntry.get(propertyKey);
+ List<Constraint> normalizeConstraints = getNormalizeConstrains(constraints);
+ normalizePropertyEntry.put(propertyKey, normalizeConstraints);
+ return normalizePropertyEntry;
+ }
+
+ private static List<Constraint> getNormalizeConstrains(List<Constraint> constraints) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ List<Constraint> normalizeConstraints = new ArrayList<>();
+ for (Object constraintObj : constraints) {
+ Constraint normalizeConstraint = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(constraintObj),
+ Constraint.class);
+ normalizeConstraints.add(normalizeConstraint);
+ }
+ return normalizeConstraints;
+ }
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
index 4b8436197d..eecbdc6a7e 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java
@@ -16,6 +16,7 @@
package org.onap.sdc.tosca.services;
+import java.beans.IntrospectionException;
import org.onap.sdc.tosca.error.ToscaRuntimeException;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.introspector.Property;
@@ -23,8 +24,6 @@ import org.yaml.snakeyaml.introspector.PropertyUtils;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.NodeId;
-import java.beans.IntrospectionException;
-
public class ToscaExtensionYamlUtil extends YamlUtil {
@@ -36,6 +35,10 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
"org.onap.sdc.tosca.datatypes.model.RequirementAssignment";
public static final String TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT =
"org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment";
+ public static final String TOSCA_MODEL_SUBSTITUTION_MAPPING =
+ "org.onap.sdc.tosca.datatypes.model.SubstitutionMapping";
+ public static final String TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING =
+ "org.onap.sdc.tosca.datatypes.model.extension.SubstitutionMappingExt";
@Override
public <T> Constructor getConstructor(Class<T> typClass) {
@@ -59,6 +62,9 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
if (type.equals(Class.forName(TOSCA_MODEL_REQUIREMENT_ASSIGNMENT))) {
classType = Class.forName(TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT);
}
+ if (type.equals(Class.forName(TOSCA_MODEL_SUBSTITUTION_MAPPING))) {
+ classType = Class.forName(TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING);
+ }
} catch (ClassNotFoundException ex) {
throw new ToscaRuntimeException(ex);
}
@@ -89,6 +95,11 @@ public class ToscaExtensionYamlUtil extends YamlUtil {
Object extendHeatObject = extendHeatClass.newInstance();
// create JavaBean
return super.constructJavaBean2ndStep(node, extendHeatObject);
+ } else if (type.equals(Class.forName(TOSCA_MODEL_SUBSTITUTION_MAPPING))) {
+ Class extendHeatClass = Class.forName(TOSCA_MODEL_EXT_SUBSTITUTION_MAPPING);
+ Object extendHeatObject = extendHeatClass.newInstance();
+ // create JavaBean
+ return super.constructJavaBean2ndStep(node, extendHeatObject);
} else {
// create JavaBean
return super.constructJavaBean2ndStep(node, object);