summaryrefslogtreecommitdiffstats
path: root/catalog-model
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java25
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java123
2 files changed, 135 insertions, 13 deletions
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<String> defaultCapabilities;
- private Map<String, WorkflowOperationDataDefinition> workflowOperations;
+ private Map<String, InterfaceOperationDataDefinition> interfaceOperations;
// private List<AdditionalInformationDefinition> additionalInformation;
@@ -155,12 +154,12 @@ public class Resource extends Component implements Serializable {
.setLicenseType(licenseType);
}
- public Map<String, WorkflowOperationDataDefinition> getWorkflowOperations() {
- return workflowOperations;
+ public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() {
+ return interfaceOperations;
}
- public void setWorkflowOperations(Map<String, WorkflowOperationDataDefinition> workflowOperations) {
- this.workflowOperations = workflowOperations;
+ public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> 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<InterfaceDefinition> getInterfaceDefinitionFromToscaName(
+ Collection<InterfaceDefinition> 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<InterfaceDefinition> getInterfaceDefinitionListFromToscaName(Collection<InterfaceDefinition> 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<String, Operation> getInterfaceOperationsFromInterfaces(
+ Map<String, InterfaceDefinition> interfaces,
+ Resource resource) throws IllegalStateException {
+ if (MapUtils.isEmpty(interfaces)) {
+ return Collections.EMPTY_MAP;
+ }
+ Optional<InterfaceDefinition> 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<InputDefinition> inputs) throws IllegalStateException {
+ ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
+ if (inputDefinitionListDataDefinition != null) {
+ return;
+ }
+ List<OperationInputDefinition> listToscaDataDefinition = inputDefinitionListDataDefinition
+ .getListToscaDataDefinition();
+ List<OperationInputDefinition> 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<InputDefinition> inputs) throws IllegalStateException {
+ Optional<InputDefinition> 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<Operation> getOperationsFromInterface(Map<String, InterfaceDefinition> interfaces) {
+ List<Operation> 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;
+ }
+}