diff options
author | JvD_Ericsson <jeff.van.dam@est.tech> | 2023-10-06 09:12:37 +0100 |
---|---|---|
committer | MichaelMorris <michael.morris@est.tech> | 2023-10-06 16:54:29 +0100 |
commit | 4f058c098678ea01f8a01250dbf9bac4b77b6744 (patch) | |
tree | 84e667e3baf4d27f747bc2826ecafc3ff6beab47 /catalog-be | |
parent | ee6e389e64b55615800a81ce43a41fa3e7ff93ce (diff) |
Milestone import support
Issue-ID: SDC-4646
Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Change-Id: I90da530a84c757a07c3ef903201f89869d223b8c
Diffstat (limited to 'catalog-be')
4 files changed, 82 insertions, 59 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java index 46ec9aa244..3eb8d786b9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceDefinitionHandler.java @@ -46,6 +46,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -65,6 +66,7 @@ import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaFunction; import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; +import org.openecomp.sdc.be.datatypes.enums.ActivityTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ConstraintType; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; @@ -273,22 +275,29 @@ public class InterfaceDefinitionHandler { final LinkedHashMap<String, Object> activitiesValue = (LinkedHashMap<String, Object>) value; if (activitiesValue.containsKey(ACTIVITIES.getElementName())) { final List<Object> milestoneActivities = (List<Object>) activitiesValue.get(ACTIVITIES.getElementName()); - for (Object activityValue : milestoneActivities) { - ActivityDataDefinition activity = new ActivityDataDefinition(); - if (activityValue instanceof Map) { - Map<String, Object> activityMap = (Map<String, Object>) activityValue; - if (activityMap.containsKey(INPUTS.getElementName())) { - activity.setInputs(handleInterfaceOperationInputs((Map<String, Object>) activityMap.get(INPUTS.getElementName()))); - } - if (activityMap.containsKey(TYPE.getElementName()) && activityMap.containsKey(WORKFLOW.getElementName())) { - activity.setType((String) activityMap.get(TYPE.getElementName())); - activity.setWorkflow((String) activityMap.get(WORKFLOW.getElementName())); - activities.add(activity); - } else { - return new ListDataDefinition<>(); + for (Object activity : milestoneActivities) { + if (activity instanceof Map) { + final Map<String, Object> activityMap = (Map<String, Object>) activity; + for (Entry<String, Object> activityValue : activityMap.entrySet()) { + if (activityValue.getValue() instanceof Map) { + ActivityDataDefinition activityDef = new ActivityDataDefinition(); + Map<String, Object> activityValueMap = (Map<String, Object>) activityValue.getValue(); + if (activityValueMap.containsKey(INPUTS.getElementName())) { + activityDef.setInputs( + handleActivityInterfaceOperationInputs((Map<String, Object>) activityValueMap.get(INPUTS.getElementName()))); + } + if (ActivityTypeEnum.getEnum(activityValue.getKey()).isPresent() && + activityValueMap.containsKey(WORKFLOW.getElementName())) { + activityDef.setWorkflow((String) activityValueMap.get(WORKFLOW.getElementName())); + activityDef.setType(activityValue.getKey()); + activities.add(activityDef); + } else { + return new ListDataDefinition<>(); + } + } else { + return new ListDataDefinition<>(); + } } - } else { - return new ListDataDefinition<>(); } } } else { @@ -298,6 +307,30 @@ public class InterfaceDefinitionHandler { return activities; } + private ListDataDefinition<OperationInputDefinition> handleActivityInterfaceOperationInputs(Map<String, Object> activityInputs) { + final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>(); + final String defaultType = "tosca.dataTypes.tmf.milestoneJeopardyData"; + for (final Entry<String, Object> interfaceInput : activityInputs.entrySet()) { + final OperationInputDefinition operationInput = new OperationInputDefinition(); + operationInput.setUniqueId(UUID.randomUUID().toString()); + operationInput.setInputId(operationInput.getUniqueId()); + operationInput.setName(interfaceInput.getKey()); + operationInput.setType(defaultType); + if (Objects.nonNull(interfaceInput.getValue())) { + if (interfaceInput.getValue() instanceof Map) { + Map<String, Object> valueMap = (Map<String, Object>) interfaceInput.getValue(); + if (valueMap.containsKey("jeopardyType") && valueMap.containsKey("name") && + valueMap.containsKey("eventType") && valueMap.containsKey("message")) { + operationInput.setValue(new Gson().toJson(interfaceInput.getValue())); + } + } + } + inputs.add(operationInput); + } + return inputs; + + } + private ListDataDefinition<OperationInputDefinition> handleInterfaceOperationInputs(final Map<String, Object> interfaceInputs) { final ListDataDefinition<OperationInputDefinition> inputs = new ListDataDefinition<>(); for (final Entry<String, Object> interfaceInput : interfaceInputs.entrySet()) { @@ -406,7 +439,7 @@ public class InterfaceDefinitionHandler { if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map && ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("timeout")) { final Object timeOut = ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("timeout"); - artifactDataDefinition.setTimeout((Integer)timeOut); + artifactDataDefinition.setTimeout((Integer) timeOut); } if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof String) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java index fa5261806c..97657f06bf 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java @@ -360,7 +360,7 @@ public class InterfacesOperationsConverter { ToscaActivity toscaActivity = new ToscaActivity(); toscaActivity.setWorkflow(activity.getWorkflow()); Map<String, Object> inputs = getToscaActivityInputs(activity.getInputs(), dataTypes); - if (!inputs.isEmpty()) { + if (MapUtils.isNotEmpty(inputs)) { toscaActivity.setInputs(inputs); } toscaActivityMap.put(activity.getType(), toscaActivity); diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml index b94b5ab11b..108c43f547 100644 --- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml +++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-legacy.yaml @@ -49,34 +49,24 @@ start: milestones: on_failure: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 on_success: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 - inputs: - string: - type: string - value: testString - complex: - type: tosca.datatypes.nfv.VirtualCpu - value: - virtual_cpu_oversubscription_policy: pol - cpu_architecture: cpu - virtual_cpu_clock: 27Hz - vdu_cpu_requirements: - 'k1': 'v1' - 'k2': 'v2' - virtual_cpu_pinning: - virtual_cpu_pinning_policy: pol - virtual_cpu_pinning_rule: - - 1 - - 2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 + inputs: + string: + testString + complex: + jeopardyType: test + name: name + eventType: type + message: message filters: - my_attribute: equal: @@ -100,10 +90,10 @@ start: minLength: 4 on_timeout: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 stop: implementation: "camunda/executeAction" inputs: diff --git a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml index 8adcdcf4cf..0eb1db33a9 100644 --- a/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml +++ b/catalog-be/src/test/resources/interfaceDefinition/interfaceDefinition-tosca1.3.yaml @@ -44,22 +44,22 @@ operations: milestones: on_failure: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 on_success: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 on_timeout: activities: - - type: delegate - workflow: workflow1 - - type: delegate - workflow: workflow2 + - delegate: + workflow: workflow1 + - delegate: + workflow: workflow2 stop: implementation: "camunda/executeAction" inputs: |