aboutsummaryrefslogtreecommitdiffstats
path: root/common/onap-tosca-datatype
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-08-04 14:16:00 +0200
committersebdet <sebastien.determe@intl.att.com>2020-09-08 13:45:31 +0200
commit30670accb070b20c1c770d1ebbd6d72e24fee2db (patch)
tree8ddb5d70500aa1b3baa4e262de411e8394e22e6a /common/onap-tosca-datatype
parenta8a96339680fa1c4df5577285442e902b5637631 (diff)
Upgrade to java 11
MOve SDC to Java 11, this is one of the PR to move to Jdk 11, jenkins will have to be changed as well Issue-ID: SDC-2725 Change-Id: I85f13f14ba8004f6e9656093a837465a2e4af3e1 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Signed-off-by: xuegao <xg353y@intl.att.com> Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'common/onap-tosca-datatype')
-rw-r--r--common/onap-tosca-datatype/pom.xml10
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java64
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java6
3 files changed, 76 insertions, 4 deletions
diff --git a/common/onap-tosca-datatype/pom.xml b/common/onap-tosca-datatype/pom.xml
index 9a621e02f1..e6c6bc5b28 100644
--- a/common/onap-tosca-datatype/pom.xml
+++ b/common/onap-tosca-datatype/pom.xml
@@ -33,7 +33,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
- <version>1.17</version>
+ <version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
@@ -90,4 +90,12 @@
<scope>test</scope>
</dependency>
</dependencies>
+ <build>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
+ </build>
</project>
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java
index 82f1581fa9..ae1ca01673 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/datatypes/model/NodeTemplate.java
@@ -20,16 +20,23 @@
package org.onap.sdc.tosca.datatypes.model;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
+
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.onap.sdc.tosca.error.ToscaRuntimeException;
+import org.onap.sdc.tosca.services.ToscaExtensionYamlUtil;
import org.onap.sdc.tosca.services.YamlUtil;
+import org.yaml.snakeyaml.constructor.ConstructorException;
@Getter
@@ -37,6 +44,7 @@ import org.onap.sdc.tosca.services.YamlUtil;
@EqualsAndHashCode
public class NodeTemplate implements Template, Cloneable {
+ private static final String INVALID_TOSCA_REQUIREMENT_SECTION = "Invalid TOSCA requirement section";
private String type;
private String description;
private Map<String, String> metadata;
@@ -50,6 +58,62 @@ public class NodeTemplate implements Template, Cloneable {
private NodeFilter node_filter;
private String copy;
+ public void setRequirements(List requirementAssignmentObj) {
+ this.requirements = convertToscaRequirementAssignment(requirementAssignmentObj);
+ }
+
+ public static List<Map<String, RequirementAssignment>> convertToscaRequirementAssignment(List<?> requirementAssignmentObj) {
+
+ List<Map<String, RequirementAssignment>> convertedRequirements = new ArrayList<>();
+ if (CollectionUtils.isEmpty(requirementAssignmentObj)) {
+ return null;
+ }
+ for (Object requirementEntry : requirementAssignmentObj) {
+ convertToscaRequirementAssignmentEntry(convertedRequirements, requirementEntry);
+ }
+ return convertedRequirements;
+ }
+
+ private static void convertToscaRequirementAssignmentEntry(List<Map<String, RequirementAssignment>> convertedRequirements, Object requirementEntry) {
+ if (requirementEntry instanceof Map) {
+ try {
+ Set<Map.Entry<String, RequirementAssignment>> requirementEntries = ((Map)requirementEntry).entrySet();
+ for (Map.Entry<String, RequirementAssignment> toscaRequirements : requirementEntries) {
+ String key = toscaRequirements.getKey();
+ Object requirementValue = toscaRequirements.getValue();
+ if (requirementValue instanceof Map) {
+ RequirementAssignment requirementObject;
+ try {
+ YamlUtil yamlUtil = new YamlUtil();
+ requirementObject = yamlUtil
+ .yamlToObject(yamlUtil.objectToYaml(requirementValue), RequirementAssignment.class);
+ } catch (ConstructorException ex) {
+ // The requirement might contains extended attribute, so try to parse it into RequirementAssignmentExt as well
+ ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
+ requirementObject = toscaExtensionYamlUtil
+ .yamlToObject(toscaExtensionYamlUtil.objectToYaml(requirementValue), RequirementAssignment.class);
+ }
+ Map<String, RequirementAssignment> convertedToscaRequirement = new HashMap<>();
+ convertedToscaRequirement.put(key, requirementObject);
+ convertedRequirements.add(convertedToscaRequirement);
+ } else if (requirementValue instanceof RequirementAssignment) {
+ Map<String, RequirementAssignment> convertedToscaRequirement = new HashMap<>();
+ convertedToscaRequirement.put(key, (RequirementAssignment)requirementValue);
+ convertedRequirements.add(convertedToscaRequirement);
+ }
+ }
+ } catch (Exception ex) {
+ throw new ToscaRuntimeException(INVALID_TOSCA_REQUIREMENT_SECTION, ex);
+ }
+ }
+ }
+
+ public void addRequirements(Map<String, RequirementAssignment> newRequirement) {
+ if (CollectionUtils.isEmpty(this.requirements)) {
+ this.requirements = new ArrayList<Map<String, RequirementAssignment>>();
+ }
+ this.requirements.add(newRequirement);
+ }
public Map<String, InterfaceDefinitionTemplate> getNormalizeInterfaces() {
if (MapUtils.isEmpty(interfaces)) {
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java
index b9f2b838c2..e265d4bd8b 100644
--- a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/datatypes/model/NodeTemplateTest.java
@@ -75,17 +75,17 @@ public class NodeTemplateTest {
@Test
public void shouldHaveValidGettersAndSetters() {
- assertThat(NodeTemplate.class, hasValidGettersAndSettersExcluding("normalizeInterfaces"));
+ assertThat(NodeTemplate.class, hasValidGettersAndSettersExcluding("requirements", "normalizeInterfaces"));
}
@Test
public void shouldHaveValidEquals() {
- assertThat(NodeTemplate.class, hasValidBeanEqualsExcluding("normalizeInterfaces"));
+ assertThat(NodeTemplate.class, hasValidBeanEqualsExcluding("requirements", "normalizeInterfaces"));
}
@Test
public void shouldHaveValidHashCode() {
- assertThat(NodeTemplate.class, hasValidBeanHashCodeExcluding("normalizeInterfaces"));
+ assertThat(NodeTemplate.class, hasValidBeanHashCodeExcluding("requirements", "normalizeInterfaces"));
}
private InterfaceDefinitionTemplate createInterfaceDefinitionTemplate() {