summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-06-26 17:32:09 +0300
committerPavel Aharoni <pa0916@att.com>2017-06-26 17:32:41 +0300
commit53b4ab6e88e4e7359534e6ca84e884005c7153b4 (patch)
tree4236812d294e1ae1a0ca6651f0db54e993be69b2 /src/main/java
parentb29c5c244b23bbf549bc4e7637019e28ed48b0c4 (diff)
[SDC-39] filter nt props values by string
Change-Id: Ic03853b58e97bfcacf1f82449fb4f498acfc347c Signed-off-by: Pavel Aharoni <pa0916@att.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java14
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java26
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java63
3 files changed, 101 insertions, 2 deletions
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
index eeb23b4..83bd29d 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -23,6 +23,7 @@ import java.util.List;
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;
@@ -335,6 +336,15 @@ public interface ISdcCsarHelper {
*/
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.
*
@@ -342,7 +352,7 @@ public interface ISdcCsarHelper {
* @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.
@@ -350,5 +360,5 @@ public interface ISdcCsarHelper {
* @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);
}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java
new file mode 100644
index 0000000..0f7810f
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/FilterType.java
@@ -0,0 +1,26 @@
+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);
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index 1c4b71b..4a3f73e 100644
--- a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -42,6 +42,7 @@ import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
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;
@@ -576,6 +577,68 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
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");