From 4a5b82998fdd61e84e81b298043c5ef8feafac24 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Tue, 17 Jul 2018 17:18:51 +0530 Subject: Revert - Workflow Operation output tosca Reverting changes to export workflow operation outputs to TOSCA template Change-Id: I0d50fd8eea0200efa3102494a0aadd1527d39a8b Issue-ID: SDC-1450 Signed-off-by: ojasdubey --- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 2 +- .../sdc/be/tosca/model/ToscaAttribute.java | 69 --------------- .../model/ToscaLifecycleOperationDefinition.java | 19 ++--- .../sdc/be/tosca/model/ToscaNodeType.java | 9 -- .../tosca/utils/InterfacesOperationsToscaUtil.java | 99 +++------------------- 5 files changed, 21 insertions(+), 177 deletions(-) delete mode 100644 catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaAttribute.java (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 4455c3205a..8d8eac36b9 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -577,10 +577,10 @@ public class ToscaExportHandler { inputDef.forEach(i -> { ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false); inputs.put(i.getName(), property); + addInterfaceDefinitionElement(component, toscaNodeType); }); if (!inputs.isEmpty()) { toscaNodeType.setProperties(inputs); - addInterfaceDefinitionElement(component, toscaNodeType); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaAttribute.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaAttribute.java deleted file mode 100644 index c32eed9d7a..0000000000 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaAttribute.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2016-2018 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openecomp.sdc.be.tosca.model; - -public class ToscaAttribute { - - private String type; - private String description; - private Object _defaultp_; - private String status; - private EntrySchema entry_schema; - - public ToscaAttribute() { - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Object getDefaultp() { - return _defaultp_; - } - - public void setDefaultp(Object defaultp) { - this._defaultp_ = defaultp; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public EntrySchema getEntry_schema() { - return entry_schema; - } - - public void setEntry_schema(EntrySchema entry_schema) { - this.entry_schema = entry_schema; - } -} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java index 3317778bfa..f801ac0264 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaLifecycleOperationDefinition.java @@ -19,12 +19,16 @@ package org.openecomp.sdc.be.tosca.model; import java.util.Map; import java.util.Objects; +/** + * @author KATYR + * @since March 26, 2018 + */ + public class ToscaLifecycleOperationDefinition { private String description; private String implementation; private Map inputs; - private Map outputs; public String getImplementation() { @@ -43,13 +47,6 @@ public class ToscaLifecycleOperationDefinition { this.inputs = inputs; } - public Map getOutputs() { - return outputs; - } - - public void setOutputs(Map outputs) { - this.outputs = outputs; - } @Override public boolean equals(Object o) { @@ -60,13 +57,13 @@ public class ToscaLifecycleOperationDefinition { return false; } ToscaLifecycleOperationDefinition that = (ToscaLifecycleOperationDefinition) o; - return Objects.equals(implementation, that.implementation) && Objects.equals(inputs, that.inputs) - && Objects.equals(outputs, that.outputs); + return Objects.equals(implementation, that.implementation) && Objects.equals(inputs, that.inputs); } @Override public int hashCode() { - return Objects.hash(implementation, inputs, outputs); + + return Objects.hash(implementation, inputs); } public String getDescription() { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java index b6763ad6a1..0d0cfb27b7 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeType.java @@ -33,7 +33,6 @@ public class ToscaNodeType { private String description; private Map properties; - private Map attributes; private Map interfaces; //ToscaInterfaceDefinition private Map capabilities; @@ -47,14 +46,6 @@ public class ToscaNodeType { this.properties = properties; } - public Map getAttributes() { - return attributes; - } - - public void setAttributes(Map attributes) { - this.attributes = attributes; - } - public Map getCapabilities() { return capabilities; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java index 81b5c99460..8c9c63af03 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java @@ -16,31 +16,30 @@ package org.openecomp.sdc.be.tosca.utils; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; - import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; -import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.Product; import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.Service; -import org.openecomp.sdc.be.tosca.model.ToscaAttribute; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceDefinition; import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType; import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition; import org.openecomp.sdc.be.tosca.model.ToscaNodeType; import org.openecomp.sdc.be.tosca.model.ToscaProperty; +/** + * @author KATYR + * @since March 20, 2018 + */ public class InterfacesOperationsToscaUtil { @@ -51,10 +50,8 @@ public class InterfacesOperationsToscaUtil { private static final String DEFAULT_HAS_UNDERSCORE = "_default"; private static final String DOT = "."; private static final String DEFAULT_INPUT_TYPE = "string"; - private static final String DEFAULT_OUTPUT_TYPE = "string"; private static final String SELF = "SELF"; private static final String GET_PROPERTY = "get_property"; - private static final String GET_OPERATION_OUTPUT = "get_operation_output"; private static final String DEFAULTP = "defaultp"; private InterfacesOperationsToscaUtil() { @@ -123,7 +120,7 @@ public class InterfacesOperationsToscaUtil { toscaInterfaceDefinition.setType(toscaResourceName); final Map operations = interfaceDefinition.getOperations(); Map toscaOperations = new HashMap<>(); - String interfaceName = getLastPartOfName(toscaResourceName); + String operationArtifactPath; for (Map.Entry operationEntry : operations.entrySet()) { ToscaLifecycleOperationDefinition toscaOperation = new ToscaLifecycleOperationDefinition(); @@ -135,8 +132,8 @@ public class InterfacesOperationsToscaUtil { toscaOperation.setImplementation(operationArtifactPath); } toscaOperation.setDescription(operationEntry.getValue().getDescription()); - fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType); - fillToscaOperationOutputs(operationEntry.getValue(), toscaOperation, interfaceName, nodeType); + fillToscaOperationInputs(operationEntry.getValue(), toscaOperation); + toscaOperations.put(operationEntry.getValue().getName(), toscaOperation); } @@ -182,8 +179,7 @@ public class InterfacesOperationsToscaUtil { } private static void fillToscaOperationInputs(OperationDataDefinition operation, - ToscaLifecycleOperationDefinition toscaOperation, - ToscaNodeType nodeType) { + ToscaLifecycleOperationDefinition toscaOperation) { if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) { toscaOperation.setInputs(null); return; @@ -193,55 +189,15 @@ public class InterfacesOperationsToscaUtil { for (OperationInputDefinition input : operation.getInputs().getListToscaDataDefinition()) { ToscaProperty toscaInput = new ToscaProperty(); toscaInput.setDescription(input.getDescription()); - String mappedPropertyName = getLastPartOfName(input.getInputId()); - toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType)); - toscaInput.setDefaultp(createDefaultValue(mappedPropertyName)); + toscaInput.setType(DEFAULT_INPUT_TYPE); + + toscaInput.setDefaultp(createDefaultValue(getLastPartOfName(input.getInputId()))); toscaInputs.put(input.getName(), toscaInput); } toscaOperation.setInputs(toscaInputs); } - private static void fillToscaOperationOutputs(OperationDataDefinition operation, - ToscaLifecycleOperationDefinition toscaOperation, - String interfaceName, - ToscaNodeType nodeType) { - if (Objects.isNull(operation.getOutputs()) || operation.getOutputs().isEmpty()) { - toscaOperation.setOutputs(null); - return; - } - Map toscaOutputs = new HashMap<>(); - for (OperationOutputDefinition output : operation.getOutputs().getListToscaDataDefinition()) { - if (Objects.nonNull(output.getInputId())) { - ToscaAttribute toscaOutput = new ToscaAttribute(); - toscaOutput.setDescription(output.getDescription()); - String outputName = output.getName(); - String mappedAttributeName = getLastPartOfName(output.getInputId()); - toscaOutput.setType(getOperationOutputType(mappedAttributeName, nodeType)); - toscaOutputs.put(outputName, toscaOutput); - createDefaultValueForMappedAttribute(nodeType, mappedAttributeName, outputName, interfaceName, - operation.getName()); - } - } - toscaOperation.setOutputs(toscaOutputs); - } - - private static String getOperationInputType(String inputName, ToscaNodeType nodeType) { - if (nodeType.getProperties() != null - && nodeType.getProperties().containsKey(inputName)) { - return nodeType.getProperties().get(inputName).getType(); - } - return DEFAULT_INPUT_TYPE; - } - - private static String getOperationOutputType(String inputName, ToscaNodeType nodeType) { - if (nodeType.getProperties() != null - && nodeType.getProperties().containsKey(inputName)) { - return nodeType.getProperties().get(inputName).getType(); - } - return DEFAULT_OUTPUT_TYPE; - } - private static Map> createDefaultValue(String propertyName) { Map> getPropertyMap = new HashMap<>(); List values = new ArrayList<>(); @@ -252,41 +208,10 @@ public class InterfacesOperationsToscaUtil { return getPropertyMap; } - private static Map> createAttributeDefaultValue(String outputName, - String interfaceName, - String operationName) { - Map> attributeDefaultValue = new HashMap<>(); - List values = new ArrayList<>(); - values.add(SELF); - values.add(interfaceName); - values.add(operationName); - values.add(outputName); - attributeDefaultValue.put(GET_OPERATION_OUTPUT, values); - return attributeDefaultValue; - } - - private static void createDefaultValueForMappedAttribute(ToscaNodeType nodeType, String mappedAttributeName, - String outputName, String interfaceName, String operationName) { - if (Objects.isNull(nodeType.getAttributes())) { - nodeType.setAttributes(new HashMap<>()); - } - if (!nodeType.getAttributes().containsKey(mappedAttributeName)) { - ToscaAttribute toscaAttribute = new ToscaAttribute(); - toscaAttribute.setType(getOperationOutputType(mappedAttributeName, nodeType)); - nodeType.getAttributes().put(mappedAttributeName, toscaAttribute); - } - nodeType.getAttributes().get(mappedAttributeName) - .setDefaultp(createAttributeDefaultValue(outputName, interfaceName, operationName)); - } private static Map getObjectAsMap(Object obj) { - ObjectMapper objectMapper = new ObjectMapper(); - if (obj instanceof ToscaInterfaceDefinition) { - //Prevent empty field serialization in interface definition - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - } Map objectAsMap = - obj instanceof Map ? (Map) obj : objectMapper.convertValue(obj, Map.class); + obj instanceof Map ? (Map) obj : new ObjectMapper().convertValue(obj, Map.class); if (objectAsMap.containsKey(DEFAULT)) { Object defaultValue = objectAsMap.get(DEFAULT); -- cgit 1.2.3-korg