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;
@Component
public class ToscaMetadataParserWithDictionarySupport implements ToscaMetadataParser {
+ @Autowired
+ private ToscaMetadataExecutor toscaMetadataExecutor;
+
@Autowired
private DictionaryService dictionaryService;
* @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;
}
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 =