diff options
Diffstat (limited to 'src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java b/src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java index 349ccee9..8aff9668 100644 --- a/src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java +++ b/src/main/java/org/onap/clamp/clds/tosca/update/parser/metadata/ToscaMetadataParserWithDictionarySupport.java @@ -29,10 +29,11 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Optional; -import org.json.JSONArray; import org.onap.clamp.clds.tosca.JsonEditorSchemaConstants; import org.onap.clamp.clds.tosca.ToscaSchemaConstants; import org.onap.clamp.clds.tosca.update.elements.ToscaElementProperty; +import org.onap.clamp.clds.tosca.update.execution.ToscaMetadataExecutor; +import org.onap.clamp.loop.service.Service; import org.onap.clamp.tosca.DictionaryElement; import org.onap.clamp.tosca.DictionaryService; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +43,9 @@ import org.springframework.stereotype.Component; public class ToscaMetadataParserWithDictionarySupport implements ToscaMetadataParser { @Autowired + private ToscaMetadataExecutor toscaMetadataExecutor; + + @Autowired private DictionaryService dictionaryService; /** @@ -50,9 +54,10 @@ public class ToscaMetadataParserWithDictionarySupport implements ToscaMetadataPa * @param toscaElementProperty The property metadata as Json Object * @return The jsonObject structure that must be added to the json schema */ - public JsonObject processAllMetadataElement(ToscaElementProperty toscaElementProperty) { + public JsonObject processAllMetadataElement(ToscaElementProperty toscaElementProperty, Service serviceModel) { if (dictionaryService != null) { - return parseMetadataPossibleValues(toscaElementProperty.getItems(), dictionaryService); + return parseMetadataPossibleValues(toscaElementProperty.getItems(), dictionaryService, serviceModel, + toscaMetadataExecutor); } else { return null; @@ -60,38 +65,32 @@ public class ToscaMetadataParserWithDictionarySupport implements ToscaMetadataPa } private static JsonObject parseMetadataPossibleValues(LinkedHashMap<String, Object> childNodeMap, - DictionaryService dictionaryService) { + DictionaryService dictionaryService, Service serviceModel, + ToscaMetadataExecutor toscaMetadataExecutor) { JsonObject childObject = new JsonObject(); if (childNodeMap.containsKey(ToscaSchemaConstants.METADATA) && childNodeMap.get(ToscaSchemaConstants.METADATA) != null) { - LinkedHashMap<String, Object> metadataMap = - (LinkedHashMap<String, Object>) childNodeMap.get(ToscaSchemaConstants.METADATA); - if (metadataMap != null) { - metadataMap.entrySet().stream().forEach(constraint -> { - if (constraint.getKey() - .equalsIgnoreCase(ToscaSchemaConstants.METADATA_CLAMP_POSSIBLE_VALUES)) { - JSONArray validValuesArray = new JSONArray(); - if (constraint.getValue() instanceof ArrayList<?>) { - boolean processDictionary = ((ArrayList<?>) constraint.getValue()) - .stream().anyMatch(value -> (value instanceof String - && ((String) value).contains(ToscaSchemaConstants.DICTIONARY))); - if (processDictionary) { - ((ArrayList<?>) constraint.getValue()).stream().forEach(value -> { - if ((value instanceof String && ((String) value) - .contains(ToscaSchemaConstants.DICTIONARY))) { - processDictionaryElements((String) value, childObject, dictionaryService); - } - - }); - } - } + ((LinkedHashMap<String, Object>) childNodeMap.get(ToscaSchemaConstants.METADATA)).forEach((key, + value) -> { + if (key.equalsIgnoreCase(ToscaSchemaConstants.METADATA_CLAMP_POSSIBLE_VALUES)) { + if (((String) value).contains(ToscaSchemaConstants.DICTIONARY)) { + processDictionaryElements((String) value, childObject, dictionaryService); } - }); - } + if (((String) value).contains("ClampExecution:")) { + executeClampProcess(((String) value).replaceAll("ClampExecution:", ""), childObject, + serviceModel, toscaMetadataExecutor); + } + } + }); } return childObject; } + private static void executeClampProcess(String processInfo, JsonObject childObject, Service serviceModel, + ToscaMetadataExecutor toscaMetadataExecutor) { + toscaMetadataExecutor.executeTheProcess(processInfo, childObject, serviceModel); + } + private static void processDictionaryElements(String dictionaryReference, JsonObject childObject, DictionaryService dictionaryService) { String[] dictionaryKeyArray = |