Tosca Parser - property value resolving
authorManzon, Inna (im453s) <im453s@intl.att.com>
Wed, 12 Sep 2018 15:32:18 +0000 (18:32 +0300)
committerMichael Lando <ml636r@att.com>
Thu, 27 Sep 2018 11:57:59 +0000 (11:57 +0000)
Change-Id: Ib0d2a0918d8d97d1e4988a8eeb7823f5957fa26f
Issue-ID: SDC-1757
Signed-off-by: Manzon, Inna (im453s) <im453s@intl.att.com>
pom.xml
src/main/java/org/onap/sdc/toscaparser/api/EntityTemplate.java
src/main/java/org/onap/sdc/toscaparser/api/NodeTemplate.java
src/main/java/org/onap/sdc/toscaparser/api/functions/GetInput.java
src/test/java/org/onap/sdc/toscaparser/api/JToscaImportTest.java
version.properties

diff --git a/pom.xml b/pom.xml
index 386b5d7..4177612 100644 (file)
--- 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>
 
index 078dc44..637329e 100644 (file)
@@ -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) {
index 73b2341..270e908 100644 (file)
@@ -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));
index 7897495..24d5a18 100644 (file)
@@ -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();
                }
index 7d0c54c..6fc8771 100644 (file)
@@ -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());
index 49feeb5..d1722d6 100644 (file)
@@ -5,7 +5,7 @@
 
 major=1
 minor=4
-patch=4
+patch=5
 
 base_version=${major}.${minor}.${patch}