# OpenECOMP SDC-Tosca
-\r
+
 
 ---
 ---
  
 *** to be completed on rrelease ***
 
+# Release notes for versions
+
+1.1.31-SNAPSHOT
+
+Initial after separating into separate repo
+
+
+
+-------------------------------
+
+1.1.1-SNAPSHOT
+
+Added toString of Function (GetInput, etc.)
+
+Allowed two arguments for GetInput - name of list input and index in list
 
        <artifactId>sdc-tosca</artifactId>\r
        <name>SDC Tosca Parser</name>\r
        <description>SDC Tosca Parser JAR file for use by consumers</description>\r
-       <version>1.1.31-SNAPSHOT</version>\r
+       <version>1.1.32-SNAPSHOT</version>\r
        <packaging>jar</packaging>\r
 \r
        <properties>\r
                <dependency>\r
                        <groupId>org.openecomp.sdc.jtosca</groupId>\r
                        <artifactId>jtosca</artifactId>\r
-                       <version>1.1.0-SNAPSHOT</version>\r
+                       <version>1.1.1-SNAPSHOT</version>\r
                </dependency>\r
 \r
 \r
 
 import java.util.Map;
 
 import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.tosca.parser.impl.FilterType;
 import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
 import org.openecomp.sdc.toscaparser.api.Group;
 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
         */
        public String getNodeTemplateCustomizationUuid(NodeTemplate nt);
 
+    /**
+     * Filter Node Template properties equals/contains specific pattern
+     * @param nodeTemplate Node Template to filter its properties
+     * @param filterType filter by equals/contains
+     * @param pattern value to filter with it
+     * @return Map <b>full path to a property</b> mapped to <b>property value<b/> filtered by type & pattern
+     */
+       public Map<String, Object> filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern);
+    
        /**
         * Get all node templates by sdcType for parent Node Template.
         *
         * @param sdcType - the SDC type of the node.
         * @return node templates of this SDC type.
         */
-       List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType);
+       public List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate parentNodeTemplate, SdcTypes sdcType);
 
        /**
         * Get all node templates by sdcType for this CSAR service.
         * @param sdcType - the SDC type of the node.
         * @return service node templates of this SDC type.
         */
-       List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType);
+       public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType);
 }
 
--- /dev/null
+package org.openecomp.sdc.tosca.parser.impl;
+
+public enum FilterType {
+
+    CONTAINS("contains"){
+        @Override
+        public boolean isMatch(String value, String pattern) {
+            return value.contains(pattern);
+        }
+    },
+    EQUALS("equals"){
+        @Override
+        public boolean isMatch(String value, String pattern) {
+            return value.equals(pattern);
+        }
+    };
+
+    String filterName;
+
+    FilterType(String name) {
+        this.filterName = name;
+    }
+
+    public abstract boolean isMatch(String value, String pattern);
+
+}
 
 import org.openecomp.sdc.toscaparser.api.elements.Metadata;
 import org.openecomp.sdc.toscaparser.api.elements.NodeType;
 import org.openecomp.sdc.toscaparser.api.functions.Function;
+import org.openecomp.sdc.toscaparser.api.functions.GetInput;
 import org.openecomp.sdc.toscaparser.api.parameters.Input;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
         return new ArrayList<>();
     }
 
+    public Map<String, Object> filterNodeTemplatePropertiesByValue(NodeTemplate nodeTemplate, FilterType filterType, String pattern) {
+        Map<String, Object> filterMap = new HashMap<>();
+
+        if (nodeTemplate == null) {
+            log.error("filterNodeTemplatePropertiesByValue nodeTemplate is null");
+            return filterMap;
+        }
+
+        if (filterType == null) {
+            log.error("filterNodeTemplatePropertiesByValue filterType is null");
+            return filterMap;
+        }
+
+        if (GeneralUtility.isEmptyString(pattern)) {
+            log.error("filterNodeTemplatePropertiesByValue pattern string is empty");
+            return filterMap;
+        }
+
+        Map<String, Property> ntProperties = nodeTemplate.getProperties();
+
+        if (ntProperties != null && ntProperties.size() > 0) {
+
+            for (Property current : ntProperties.values()) {
+                filterProperties(current.getValue(), current.getName(), filterType, pattern, filterMap);
+            }
+        }
+
+        log.trace("filterNodeTemplatePropertiesByValue - filterMap value: {}", filterMap);
+
+        return filterMap;
+    }
+
+    /************************************* helper functions ***********************************/
+    private Map<String, Object> filterProperties(Object property, String path, FilterType filterType, String pattern, Map<String, Object> filterMap) {
+
+        if (property instanceof Map) {
+            for (Map.Entry<String, Object> item: ((Map<String, Object>) property).entrySet()) {
+                if (item.getKey().equals("get_input")) {
+                    String itemToStr = item.getKey() + ":" + item.getValue().toString();
+                    filterProperties(itemToStr, path, filterType, pattern, filterMap);
+                } else {
+                    path += PATH_DELIMITER + item.getKey();
+                    filterProperties(item.getValue(), path, filterType, pattern, filterMap);
+                }
+            }
+        } else if (property instanceof List) {
+            for (Object item: (List<Object>)property) {
+                filterProperties(item, path, filterType, pattern, filterMap);
+            }
+        } else if (property instanceof Function) {
+            if (filterType.isMatch(property.toString(), pattern)) {
+                filterMap.put(path, property);
+            }
+        } else {
+            if (filterType.isMatch(property.toString(), pattern)) {
+                filterMap.put(path, property);
+            }
+        }
+
+        return filterMap;
+    }
+
     public List<NodeTemplate> getServiceNodeTemplateBySdcType(SdcTypes sdcType) {
         if (sdcType == null) {
             log.error("getServiceNodeTemplateBySdcType - sdcType is null or empty");
 
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.FilterType;
 import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
 import org.openecomp.sdc.toscaparser.api.Group;
 import org.openecomp.sdc.toscaparser.api.NodeTemplate;
        }
        //endregion
 
+    //region filterNodeTemplatePropertiesByValue
+    @Test
+    public void testFilterNodeTemplatePropertiesByContains() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        boolean isChecked = false;
+        for (NodeTemplate vfc: vfcs) {
+            if(vfc.getName().equalsIgnoreCase("abstract_ddc"))
+            {
+                isChecked = true;
+                Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfc, FilterType.CONTAINS, "get_input");
+
+                assertEquals(16, filteredInputs.size());
+                assertEquals("get_input:vnf_id", filteredInputs.get("compute_ddc_metadata#vf_module_id#vnf_id"));
+                               assertEquals("get_input:[ddc_int_imbl_v6_ips, 3]", filteredInputs.get("port_ddc_int_imbl__port_fixed_ips#ip_address"));
+
+                break;
+            }
+
+        }
+        assertTrue(isChecked);
+    }
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByDummyContains() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.CONTAINS, "dummy");
+        assertNotNull(filteredInputs);
+        assertEquals(0, filteredInputs.size());
+    }
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByEquals() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        boolean isChecked = false;
+        for (NodeTemplate vfc: vfcs) {
+            if(vfc.getName().equalsIgnoreCase("abstract_ddc"))
+            {
+                isChecked = true;
+                Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfc, FilterType.EQUALS, "ddc");
+
+                assertEquals(2, filteredInputs.size());
+                assertEquals("ddc", filteredInputs.get("vm_type_tag"));
+                assertEquals("ddc", filteredInputs.get("nfc_naming_code"));
+                break;
+            }
+
+        }
+        assertTrue(isChecked);
+    }
+    
        //region getServiceNodeTemplateBySdcType
        @Test
        public void testServiceNodeTemplateBySdcType() {
                assertEquals(0, vfcList.size());
        }
        //endregion
+           
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByDummyEquals() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfcs.get(0), FilterType.EQUALS, "dummy");
+        assertNotNull(filteredInputs);
+        assertEquals(0, filteredInputs.size());
+    }
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByNullFilterType() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfcs.get(11), null, "ddc");
+        assertNotNull(filteredInputs);
+        assertEquals(0, filteredInputs.size());
+    }
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByNullPattern() {
+        List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+        Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(vfcs.get(11), FilterType.EQUALS, null);
+        assertNotNull(filteredInputs);
+        assertEquals(0, filteredInputs.size());
+    }
+
+    @Test
+    public void testFilterNodeTemplatePropertiesByNullVfc() {
+        Map<String, Object> filteredInputs = complexCps.filterNodeTemplatePropertiesByValue(null, FilterType.EQUALS, "ddc");
+        assertNotNull(filteredInputs);
+        assertEquals(0, filteredInputs.size());
+    }
+    //endregion
 }