summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/InterfaceUtils.java84
1 files changed, 16 insertions, 68 deletions
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
index 7a36d92c76..feef31cbc1 100644
--- 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
@@ -15,19 +15,13 @@
*/
package org.openecomp.sdc.be.model.jsontitan.utils;
+import org.apache.commons.collections.CollectionUtils;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+
import java.util.Collection;
import java.util.Formatter;
-import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
-import org.apache.commons.collections.CollectionUtils;
-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.datatypes.elements.OperationOutputDefinition;
-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.common.util.ValidationUtils;
public class InterfaceUtils {
@@ -35,80 +29,34 @@ 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) {
+ Collection<InterfaceDefinition> interfaces,
+ String componentName) {
if (CollectionUtils.isEmpty(interfaces)) {
return Optional.empty();
}
- String toscaName = createInterfaceToscaResourceName(resourceName);
+ String toscaName = createInterfaceToscaResourceName(componentName);
return interfaces.stream().filter(
- interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
- .getToscaResourceName().equals(toscaName)).findAny();
+ interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
+ .getToscaResourceName().equals(toscaName)).findAny();
}
public static Collection<InterfaceDefinition> getInterfaceDefinitionListFromToscaName(Collection<InterfaceDefinition> interfaces,
- String resourceName) {
- if(CollectionUtils.isEmpty(interfaces)){
+ String componentName) {
+ if (CollectionUtils.isEmpty(interfaces)) {
return CollectionUtils.EMPTY_COLLECTION;
}
- String toscaName = createInterfaceToscaResourceName(resourceName);
+ String toscaName = createInterfaceToscaResourceName(componentName);
return interfaces.stream().filter(
- interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
- .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
+ interfaceDefinition -> interfaceDefinition.getToscaResourceName() != null && interfaceDefinition
+ .getToscaResourceName().equals(toscaName)).collect(Collectors.toList());
}
- public static String createInterfaceToscaResourceName(String resourceName) {
+ public static String createInterfaceToscaResourceName(String componentName) {
StringBuilder sb = new StringBuilder();
- try(Formatter formatter = new Formatter(sb)){
- return formatter.format(INTERFACE_TOSCA_RESOURCE_NAME, ValidationUtils.convertToSystemName(resourceName)).toString();
+ try (Formatter formatter = new Formatter(sb)) {
+ return formatter.format(INTERFACE_TOSCA_RESOURCE_NAME, ValidationUtils.convertToSystemName(componentName)).toString();
}
}
-
- public static void createInputOutput(Operation operation, List<InputDefinition> inputs, List<InputDefinition> outputs) throws IllegalStateException {
- ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
- if (inputDefinitionListDataDefinition != null) {
- return;
- }
- List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition();
- List<OperationInputDefinition> convertedInputs = inputListToscaDataDefinition.stream()
- .map(input -> convertInput(input, inputs))
- .collect(Collectors.toList());
-
- ListDataDefinition<OperationOutputDefinition> outputDefinitionListDataDefinition = operation.getOutputs();
- if (outputDefinitionListDataDefinition != null) {
- return;
- }
- List<OperationOutputDefinition> outputListToscaDataDefinition = outputDefinitionListDataDefinition.getListToscaDataDefinition();
- List<OperationOutputDefinition> convertedOutputs = outputListToscaDataDefinition.stream()
- .map(output -> convertOutput(output, outputs) )
- .collect(Collectors.toList());
-
- inputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
- inputDefinitionListDataDefinition.getListToscaDataDefinition().addAll(convertedInputs);
- outputDefinitionListDataDefinition.getListToscaDataDefinition().clear();
- outputDefinitionListDataDefinition.getListToscaDataDefinition().addAll(convertedOutputs);
- }
-
- 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());
- }
-
- private static OperationOutputDefinition convertOutput(OperationOutputDefinition output,
- List<InputDefinition> outputs) throws IllegalStateException {
- Optional<InputDefinition> anyOutputDefinition = outputs.stream()
- .filter(op -> op.getUniqueId().equals(output.getUniqueId())).findAny();
- if (anyOutputDefinition.isPresent()) {
- return new OperationOutputDefinition(output.getLabel(),new InputDataDefinition(anyOutputDefinition.get()));
- }
- throw new IllegalStateException("Could not find output :"+ output.getLabel());
- }
-
}