summaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype
diff options
context:
space:
mode:
authorshiria <shiri.amichai@amdocs.com>2018-07-02 11:10:56 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-07-02 09:10:51 +0000
commit6d7284b5bcbbf6f57b843c5f30a50e9387b5ece8 (patch)
treea3e1b2e8af332d1472e81392f421e59f4d0ef37d /common/onap-tosca-datatype
parent82fa3004cc68ef367e4f210900619743eb9abc95 (diff)
Fix getFlat for datatype
Fix getFlat when we driven from primitive type like string Adding support for service filter as tosca extension Issue-ID: SDC-1455 Change-Id: I57f05af13b394239ca55b71a946d69f56675bf19 Signed-off-by: shiria <shiri.amichai@amdocs.com>
Diffstat (limited to 'common/onap-tosca-datatype')
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeFilter.java89
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/RequirementAssignment.java31
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/ServiceFilter.java34
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/error/ToscaRuntimeException.java32
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/ToscaExtensionYamlUtil.java112
5 files changed, 229 insertions, 69 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 d1d07b56e6..5f3d46504d 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
@@ -1,9 +1,6 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * 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
@@ -15,33 +12,83 @@
* 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.
- * ============LICENSE_END=========================================================
*/
package org.onap.sdc.tosca.datatypes.model;
+import org.apache.commons.collections4.CollectionUtils;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
+
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class NodeFilter {
- List<Map<String, List<Constraint>>> properties;
- List<Map<String, CapabilityFilter>> capabilities;
+ private List<Map<String, List<Constraint>>> properties;
+ private List<Map<String, CapabilityFilter>> capabilities;
+
+ //can't not be removed, in used in snake yaml
+ public List<Map<String, CapabilityFilter>> getCapabilities() {
+ return capabilities;
+ }
+
+ public void setCapabilities(List<Map<String, CapabilityFilter>> capabilities) {
+ this.capabilities = capabilities;
+ }
+
+ //can't not be removed, in used in snake yaml
+ public List<Map<String, List<Constraint>>> getProperties() {
+ return properties;
+ }
+
- public List<Map<String, CapabilityFilter>> getCapabilities() {
- return capabilities;
- }
+ //use this function in order to get node filter properties instead of getProperties function
+ public List<Map<String, List<Constraint>>> getNormalizeProperties() {
+ return getNormalizeProperties(properties);
+ }
- public void setCapabilities(List<Map<String, CapabilityFilter>> capabilities) {
- this.capabilities = capabilities;
- }
+ private List<Map<String, List<Constraint>>> getNormalizeProperties(List<Map<String, List<Constraint>>> properties) {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ if (CollectionUtils.isEmpty(properties)) {
+ return properties;
+ }
+ for (Map<String, List<Constraint>> propertyConstraintsEntity : properties) {
+ String propertyKey = propertyConstraintsEntity.keySet().iterator().next();
+ List<Constraint> constraints = propertyConstraintsEntity.get(propertyKey);
+ Iterator<Constraint> iterator = constraints.iterator();
+ while (iterator.hasNext()) {
+ Constraint constraintObj = iterator.next();
+ Constraint constraint = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(constraintObj),
+ Constraint.class);
+ constraints.remove(constraintObj);
+ constraints.add(constraint);
+ }
+ }
+ return properties;
+ }
- public List<Map<String, List<Constraint>>> getProperties() {
- return properties;
- }
+ //use this function in order to get node filter capabilities instead of getCapabilities function
+ public List<Map<String, CapabilityFilter>> getNormalizeCapabilities() {
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ if (CollectionUtils.isEmpty(capabilities)) {
+ return capabilities;
+ }
+ for (Map<String, CapabilityFilter> capabilityEntry : capabilities) {
+ String capabilityKey = capabilityEntry.keySet().iterator().next();
+ Object capabilityFilterObj = capabilityEntry.get(capabilityKey);
+ CapabilityFilter capabilityFilter = toscaExtensionYamlUtil.yamlToObject(
+ toscaExtensionYamlUtil.objectToYaml(capabilityFilterObj), CapabilityFilter.class);
+ capabilityFilter.setProperties(getNormalizeProperties(capabilityFilter.getProperties()));
+ capabilityEntry.remove(capabilityKey);
+ capabilityEntry.put(capabilityKey, capabilityFilter);
+ }
+ return capabilities;
+ }
- public void setProperties(List<Map<String, List<Constraint>>> properties) {
- this.properties = properties;
- }
+ public void setProperties(List<Map<String, List<Constraint>>> properties) {
+ this.properties = properties;
+ }
}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/RequirementAssignment.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/RequirementAssignment.java
new file mode 100644
index 0000000000..07aed2b466
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/RequirementAssignment.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+
+public class RequirementAssignment extends org.onap.sdc.tosca.datatypes.model.RequirementAssignment{
+ private ServiceFilter service_filter;
+
+
+ public ServiceFilter getService_filter() {
+ return service_filter;
+ }
+
+ public void setService_filter(ServiceFilter servicefilter) {
+ this.service_filter = servicefilter;
+ }
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/ServiceFilter.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/ServiceFilter.java
new file mode 100644
index 0000000000..8423d5e293
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/extension/ServiceFilter.java
@@ -0,0 +1,34 @@
+/*
+ * 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.NodeFilter;
+
+
+public class ServiceFilter extends NodeFilter {
+
+ Object tosca_id;
+
+ public Object getTosca_id() {
+ return tosca_id;
+ }
+
+ public void setTosca_id(Object toscaId) {
+ this.tosca_id = toscaId;
+ }
+
+}
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/error/ToscaRuntimeException.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/error/ToscaRuntimeException.java
new file mode 100644
index 0000000000..10c67bc4df
--- /dev/null
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/error/ToscaRuntimeException.java
@@ -0,0 +1,32 @@
+/*
+ * 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.error;
+
+public class ToscaRuntimeException extends RuntimeException {
+
+ public ToscaRuntimeException(String message) {
+ super(message);
+ }
+
+ public ToscaRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ToscaRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
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 efd4982541..4b8436197d 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
@@ -1,5 +1,5 @@
/*
- * Copyright © 2016-2017 European Support Limited
+ * 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.
@@ -16,6 +16,7 @@
package org.onap.sdc.tosca.services;
+import org.onap.sdc.tosca.error.ToscaRuntimeException;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.introspector.PropertyUtils;
@@ -27,60 +28,75 @@ import java.beans.IntrospectionException;
public class ToscaExtensionYamlUtil extends YamlUtil {
- @Override
- public <T> Constructor getConstructor(Class<T> typClass) {
- return new ToscaWithHeatExtensionConstructor(typClass);
- }
+ public static final String TOSCA_MODEL_PARAMETER_DEFINITION =
+ "org.onap.sdc.tosca.datatypes.model.ParameterDefinition";
+ public static final String TOSCA_MODEL_EXT_PARAMETER_DEFINITION =
+ "org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt";
+ public static final String TOSCA_MODEL_REQUIREMENT_ASSIGNMENT =
+ "org.onap.sdc.tosca.datatypes.model.RequirementAssignment";
+ public static final String TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT =
+ "org.onap.sdc.tosca.datatypes.model.extension.RequirementAssignment";
- @Override
- protected PropertyUtils getPropertyUtils() {
- return new ToscaPropertyUtilsWithHeatExtension();
- }
+ @Override
+ public <T> Constructor getConstructor(Class<T> typClass) {
+ return new ToscaWithHeatExtensionConstructor(typClass);
+ }
- public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
@Override
- public Property getProperty(Class<? extends Object> type, String name)
- throws IntrospectionException {
- Class<? extends Object> classType = type;
- try {
- if (type
- .equals(Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) {
- classType = Class
- .forName("org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
- }
- } catch (ClassNotFoundException ex) {
- throw new RuntimeException(ex);
- }
- return super.getProperty(classType, name);
+ protected PropertyUtils getPropertyUtils() {
+ return new ToscaPropertyUtilsWithHeatExtension();
}
- }
- protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor {
- public ToscaWithHeatExtensionConstructor(Class<?> theRoot) {
- super(theRoot);
- yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct());
+ public class ToscaPropertyUtilsWithHeatExtension extends MyPropertyUtils {
+
+ @Override
+ public Property getProperty(Class<? extends Object> type, String name) throws IntrospectionException {
+ Class<? extends Object> classType = type;
+ try {
+ if (type.equals(Class.forName(TOSCA_MODEL_PARAMETER_DEFINITION))) {
+ classType = Class.forName(TOSCA_MODEL_EXT_PARAMETER_DEFINITION);
+ }
+ if (type.equals(Class.forName(TOSCA_MODEL_REQUIREMENT_ASSIGNMENT))) {
+ classType = Class.forName(TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT);
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new ToscaRuntimeException(ex);
+ }
+ return super.getProperty(classType, name);
+ }
}
- class MyPersistentObjectConstruct extends Constructor.ConstructMapping {
- @Override
- protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
- Class type = node.getType();
- try {
- if (type.equals(
- Class.forName("org.onap.sdc.tosca.datatypes.model.ParameterDefinition"))) {
- Class extendHeatClass = Class.forName(
- "org.onap.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt");
- Object extendHeatObject = extendHeatClass.newInstance();
- // create JavaBean
- return super.constructJavaBean2ndStep(node, extendHeatObject);
- } else {
- // create JavaBean
- return super.constructJavaBean2ndStep(node, object);
- }
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
- throw new RuntimeException(ex);
+ protected class ToscaWithHeatExtensionConstructor extends StrictMapAppenderConstructor {
+
+ public ToscaWithHeatExtensionConstructor(Class<?> theRoot) {
+ super(theRoot);
+ yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct());
+ }
+
+ class MyPersistentObjectConstruct extends Constructor.ConstructMapping {
+
+ @Override
+ protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
+ Class type = node.getType();
+ try {
+ if (type.equals(Class.forName(TOSCA_MODEL_PARAMETER_DEFINITION))) {
+ Class extendHeatClass = Class.forName(TOSCA_MODEL_EXT_PARAMETER_DEFINITION);
+ Object extendHeatObject = extendHeatClass.newInstance();
+ // create JavaBean
+ return super.constructJavaBean2ndStep(node, extendHeatObject);
+ } else if (type.equals(Class.forName(TOSCA_MODEL_REQUIREMENT_ASSIGNMENT))) {
+ Class extendHeatClass = Class.forName(TOSCA_MODEL_EXT_REQUIREMENT_ASSIGNMENT);
+ Object extendHeatObject = extendHeatClass.newInstance();
+ // create JavaBean
+ return super.constructJavaBean2ndStep(node, extendHeatObject);
+ } else {
+ // create JavaBean
+ return super.constructJavaBean2ndStep(node, object);
+ }
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
+ throw new ToscaRuntimeException(ex);
+ }
+ }
}
- }
}
- }
}