From 558d8d0d2d958ff3b18fb2f6e04cab14d8ff2da3 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Thu, 29 Mar 2018 10:37:45 +0530 Subject: Added new files requied for operation Added new files requied for workflow operation Change-Id: I561185415a7e82aa75772c6c0b4b1a206b547699 Issue-ID: SDC-1060 Signed-off-by: mojahidi --- .../java/org/openecomp/sdc/be/model/Resource.java | 25 ++--- .../be/model/jsontitan/utils/InterfaceUtils.java | 123 +++++++++++++++++++++ 2 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index 5310d5a00c..8e38beb2c6 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -27,11 +27,10 @@ import java.util.Map; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; -import org.openecomp.sdc.be.datatypes.elements.WorkflowOperationDataDefinition; -import static java.util.stream.Collectors.groupingBy; + public class Resource extends Component implements Serializable { private static final long serialVersionUID = -6811540567661368482L; @@ -60,7 +59,7 @@ public class Resource extends Component implements Serializable { private List defaultCapabilities; - private Map workflowOperations; + private Map interfaceOperations; // private List additionalInformation; @@ -155,12 +154,12 @@ public class Resource extends Component implements Serializable { .setLicenseType(licenseType); } - public Map getWorkflowOperations() { - return workflowOperations; + public Map getInterfaceOperations() { + return interfaceOperations; } - public void setWorkflowOperations(Map workflowOperations) { - this.workflowOperations = workflowOperations; + public void setInterfaceOperations(Map interfaceOperations) { + this.interfaceOperations = interfaceOperations; } @Override @@ -177,7 +176,7 @@ public class Resource extends Component implements Serializable { result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); result = prime * result + ((properties == null) ? 0 : properties.hashCode()); result = prime * result + ((derivedList == null) ? 0 : derivedList.hashCode()); - result = prime * result + ((workflowOperations == null) ? 0 : workflowOperations.hashCode()); + result = prime * result + ((interfaceOperations == null) ? 0 : interfaceOperations.hashCode()); // result = prime * result + ((requirements == null) ? 0 : // requirements.hashCode()); return result; @@ -223,10 +222,10 @@ public class Resource extends Component implements Serializable { return false; } else if (!properties.equals(other.properties)) return false; - if (workflowOperations == null) { - if (other.workflowOperations != null) + if (interfaceOperations == null) { + if (other.interfaceOperations != null) return false; - } else if (!workflowOperations.equals(other.workflowOperations)) + } else if (!interfaceOperations.equals(other.interfaceOperations)) return false; return super.equals(obj); } @@ -238,7 +237,7 @@ public class Resource extends Component implements Serializable { // + ", capabilities=" + capabilities + ", requirements=" + // requirements + ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation - + ", workflowOperations=" + workflowOperations + + ", interfaceOperations=" + interfaceOperations + "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]"; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java new file mode 100644 index 0000000000..df9702949a --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java @@ -0,0 +1,123 @@ +/* + * 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.model.jsontitan.utils; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Resource; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Formatter; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +public class InterfaceUtils { + + public static final String INTERFACE_TOSCA_RESOURCE_NAME = "org.openecomp.interfaces.node.lifecycle.%s"; + + public static final Optional getInterfaceDefinitionFromToscaName( + Collection interfaces, + String resourceName) { + if (CollectionUtils.isEmpty(interfaces)) { + return Optional.empty(); + } + + String toscaName = createInterfaceToscaResourceName(resourceName); + return interfaces.stream().filter( + interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition + .getToscaResourceName().equals(toscaName)).findAny(); + } + + public static Collection getInterfaceDefinitionListFromToscaName(Collection interfaces, + String resourceName) { + if(CollectionUtils.isEmpty(interfaces)){ + return CollectionUtils.EMPTY_COLLECTION; + } + + String toscaName = createInterfaceToscaResourceName(resourceName); + return interfaces.stream().filter( + interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition + .getToscaResourceName().equals(toscaName)).collect(Collectors.toList()); + } + + public static String createInterfaceToscaResourceName(String resourceName) { + StringBuilder sb = new StringBuilder(); + Formatter formatter = new Formatter(sb); + return formatter.format(INTERFACE_TOSCA_RESOURCE_NAME, resourceName).toString(); + } + + public static Map getInterfaceOperationsFromInterfaces( + Map interfaces, + Resource resource) throws IllegalStateException { + if (MapUtils.isEmpty(interfaces)) { + return Collections.EMPTY_MAP; + } + Optional optionalInterface = getInterfaceDefinitionFromToscaName( + interfaces.values(), resource.getName()); + if (!optionalInterface.isPresent()) { + return Collections.EMPTY_MAP; + } + InterfaceDefinition interfaceDefinition = optionalInterface.get(); + interfaceDefinition.getOperationsMap().values().stream() + .forEach(operation -> createInput(operation, resource.getInputs())); + return interfaceDefinition.getOperationsMap(); + + } + + private static void createInput(Operation operation, List inputs) throws IllegalStateException { + ListDataDefinition inputDefinitionListDataDefinition = operation.getInputs(); + if (inputDefinitionListDataDefinition != null) { + return; + } + List listToscaDataDefinition = inputDefinitionListDataDefinition + .getListToscaDataDefinition(); + List convertedInputs = listToscaDataDefinition.stream() + .map(input -> convertInput(input, inputs)) + .collect(Collectors.toList()); + inputDefinitionListDataDefinition.getListToscaDataDefinition().clear(); + inputDefinitionListDataDefinition.getListToscaDataDefinition().addAll(convertedInputs); + } + + private static OperationInputDefinition convertInput(OperationInputDefinition input, + List inputs) throws IllegalStateException { + Optional anyInputDefinition = inputs.stream() + .filter(inp -> inp.getUniqueId().equals(input.getUniqueId())).findAny(); + if (anyInputDefinition.isPresent()) { + return new OperationInputDefinition(input.getLabel(),new InputDataDefinition(anyInputDefinition.get())); + } + throw new IllegalStateException("Could not find input :"+ input.getLabel()); + } + + public static List getOperationsFromInterface(Map interfaces) { + List operationData = new ArrayList<>(); + if (!MapUtils.isEmpty(interfaces)) { + operationData = interfaces.values().stream() + .filter(a -> MapUtils.isNotEmpty(a.getOperationsMap())) + .map(a-> new ArrayList<>(a.getOperationsMap().values())).flatMap(List::stream).collect(Collectors.toList()); + } + return operationData; + } +} -- cgit 1.2.3-korg