diff options
6 files changed, 96 insertions, 63 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: diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/activities-list/activities-list.component.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/activities-list/activities-list.component.ts index b265464f86..ac9daa4b33 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/activities-list/activities-list.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/activities-list/activities-list.component.ts @@ -143,20 +143,30 @@ export class ActivitiesListComponent implements OnInit { } collectInputNames(index: number) { - return this.activities[index].inputs.listToscaDataDefinition.map((input) => input.name); + if (this.activities[index].inputs) { + return this.activities[index].inputs.listToscaDataDefinition.map((input) => input.name); + } + return []; } onAddInput(inputOperationParameter: InputOperationParameter, index: number) { + if (!this.activities[index].inputs) { + let input = new class implements IOperationParamsList { + listToscaDataDefinition: Array<InputOperationParameter> = []; + } + this.activities[index].inputs = input; + } this.activities[index].inputs.listToscaDataDefinition.push(inputOperationParameter); this.activities[index].inputs.listToscaDataDefinition = Array.from(this.activities[index].inputs.listToscaDataDefinition); + this.emitOnActivityChange(); } getInputs(index: number) { - if (this.activities[index].inputs.listToscaDataDefinition) { + if (this.activities[index].inputs && this.activities[index].inputs.listToscaDataDefinition) { let test: InputOperationParameter[] = this.activities[index].inputs.listToscaDataDefinition; return test; } - return {}; + return []; } onInputValueChange(changedInput: InputOperationParameter, index: number) { diff --git a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/add-input/add-input.component.ts b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/add-input/add-input.component.ts index 5620d193a8..d3b596ef69 100644 --- a/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/add-input/add-input.component.ts +++ b/catalog-ui/src/app/ng2/pages/composition/interface-operatons/operation-creator/add-input/add-input.component.ts @@ -145,7 +145,7 @@ export class AddInputComponent implements OnInit { showAddInput() { if (this.defaultType) { - this.inputToAdd.type = this.dataTypeMap.get(this.defaultType) ? this.defaultType : undefined; + this.onChangeInputType(this.defaultType); } this.showForm = true; this.showAddLink = false; |