aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManzon, Inna (im453s) <im453s@intl.att.com>2018-09-12 18:32:18 +0300
committerMichael Lando <ml636r@att.com>2018-09-27 11:57:59 +0000
commit9fb95e3c9e9ab5c239445c1511219686133437de (patch)
tree425dbf4b49abcdfb9e8b5c34bd660118e5751386
parent6fefab672f8ee763b561b0f67681e4f5b09418bc (diff)
Tosca Parser - property value resolving
Change-Id: Ib0d2a0918d8d97d1e4988a8eeb7823f5957fa26f Issue-ID: SDC-1757 Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java18
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java14
-rw-r--r--src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java17
-rw-r--r--src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java19
-rw-r--r--version.properties2
6 files changed, 56 insertions, 16 deletions
diff --git a/pom.xml b/pom.xml
index 386b5d7..4177612 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>org.onap.sdc.jtosca</groupId>
<artifactId>jtosca</artifactId>
- <version>1.4.4-SNAPSHOT</version>
+ <version>1.4.5-SNAPSHOT</version>
<name>sdc-jtosca</name>
<properties>
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
index 078dc44..637329e 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
@@ -197,16 +197,24 @@ public abstract class EntityTemplate {
public LinkedHashMap<String,Property> getProperties() {
LinkedHashMap<String,Property> props = new LinkedHashMap<>();
for(Property po: getPropertiesObjects()) {
- props.put(((Property)po).getName(),po);
+ props.put(po.getName(),po);
}
return props;
}
public Object getPropertyValue(String name) {
- LinkedHashMap<String,Property> props = getProperties();
- Property p = (Property)props.get(name);
- return p != null ? p.getValue() : null;
- }
+ LinkedHashMap<String,Property> props = getProperties();
+ Property p = props.get(name);
+ return p != null ? p.getValue() : null;
+ }
+
+ public String getPropertyType(String name) {
+ Property property = getProperties().get(name);
+ if (property != null) {
+ return property.getType();
+ }
+ return null;
+ }
public ArrayList<InterfacesDef> getInterfaces() {
if(_interfaces == null) {
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
index 73b2341..270e908 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
@@ -1,6 +1,8 @@
package org.onap.sdc.toscaparser.api;
import static org.onap.sdc.toscaparser.api.elements.EntityType.TOSCA_DEF;
+
+import com.google.common.collect.Lists;
import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
import java.util.ArrayList;
@@ -27,6 +29,7 @@ public class NodeTemplate extends EntityTemplate {
private static final String METADATA = "metadata";
+
@SuppressWarnings("unchecked")
public NodeTemplate(String name,
LinkedHashMap<String,Object> ntnodeTemplates,
@@ -247,6 +250,17 @@ public class NodeTemplate extends EntityTemplate {
}
}
+ public Object getPropertyValueFromTemplatesByName(String propertyName) {
+ LinkedHashMap<String,Object> nodeObject = (LinkedHashMap<String,Object>) templates.get(name);
+ if (nodeObject != null) {
+ LinkedHashMap<String,Object> properties = (LinkedHashMap<String, Object>)nodeObject.get(PROPERTIES);
+ if (properties != null) {
+ return properties.get(propertyName);
+ }
+ }
+ return null;
+ }
+
private Metadata _metaData() {
if(entityTpl.get(METADATA) != null) {
return new Metadata((Map<String,Object>)entityTpl.get(METADATA));
diff --git a/src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java b/src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java
index 7897495..24d5a18 100644
--- a/src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java
+++ b/src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java
@@ -57,11 +57,10 @@ public class GetInput extends Function {
return ((ArrayList) value).get((Integer) args.get(1));
}
/* commented out for network cloud (SDNC)
- else{
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE273",String.format(
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE273",String.format(
"GetInputError: cannot resolve input name \"%s\", the expected structure is an argument with a name of input type list and a second argument with an index in the list", args.get(0))));
- return null;
- }*/
+ return null;
+*/
}
return value;
}
@@ -78,11 +77,13 @@ public class GetInput extends Function {
if ( args.get(1) instanceof Integer
&& ((ArrayList) inputDef.getDefault()).size()> ((Integer)args.get(1)).intValue()) {
return ((ArrayList) inputDef.getDefault()).get(((Integer)args.get(1)).intValue());
- }else{
- ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE274",(String.format(
- "GetInputError: cannot resolve input Def name \"%s\", the expected structure is an argument with a name of input type list and a second argument with an index in the list", args.get(0)))));
- return null;
}
+/*
+ commented out for network cloud (SDNC)
+ ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE274",(String.format(
+ "GetInputError: cannot resolve input Def name \"%s\", the expected structure is an argument with a name of input type list and a second argument with an index in the list", args.get(0)))));
+ return null;
+*/
}
return inputDef.getDefault();
}
diff --git a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
index 7d0c54c..6fc8771 100644
--- a/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
+++ b/src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
@@ -14,6 +14,7 @@ import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class JToscaImportTest {
@@ -94,7 +95,23 @@ public class JToscaImportTest {
assertTrue(inputs.stream().filter(i -> i.getAnnotations() != null).collect(Collectors.toList()).isEmpty());
}
- private void validateInputsAnnotations(List<Input> inputs) {
+ @Test
+ public void testGetPropertyNameTest() throws JToscaException {
+
+ String fileStr = JToscaImportTest.class.getClassLoader().getResource("csars/service-AdiodVmxVpeBvService-csar.csar").getFile();
+ File file = new File(fileStr);
+ ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
+ NodeTemplate nodeTemplate = toscaTemplate.getNodeTemplates().get(0);
+
+ ArrayList<String> valueList = (ArrayList<String>)nodeTemplate.getPropertyValueFromTemplatesByName("vmxvpfe_sriov41_0_port_vlanfilter");
+ assertEquals(4, valueList.size());
+
+ assertEquals("vPE", (String) nodeTemplate.getPropertyValueFromTemplatesByName("nf_role"));
+
+ assertNull(nodeTemplate.getPropertyValueFromTemplatesByName("test"));
+ }
+
+ private void validateInputsAnnotations(List<Input> inputs) {
List<Input> inputsWithAnnotations = inputs.stream().filter(i -> i.getAnnotations() != null)
.collect(Collectors.toList());
assertTrue(!inputs.isEmpty());
diff --git a/version.properties b/version.properties
index 49feeb5..d1722d6 100644
--- a/version.properties
+++ b/version.properties
@@ -5,7 +5,7 @@
major=1
minor=4
-patch=4
+patch=5
base_version=${major}.${minor}.${patch}