diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils')
3 files changed, 95 insertions, 21 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java index eb187e0120..a332e6401a 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/ForwardingPathToscaUtil.java @@ -1,13 +1,6 @@ package org.openecomp.sdc.be.tosca.utils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - +import fj.data.Either; import org.apache.commons.collections.MapUtils; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition; @@ -16,11 +9,12 @@ import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; -import org.openecomp.sdc.be.tosca.CapabiltyRequirementConvertor; +import org.openecomp.sdc.be.tosca.CapabilityRequirementConverter; import org.openecomp.sdc.be.tosca.model.ToscaNodeTemplate; import org.openecomp.sdc.be.tosca.model.ToscaTemplateRequirement; -import fj.data.Either; +import java.util.*; +import java.util.Collection; /** * @author KATYR @@ -35,7 +29,7 @@ public class ForwardingPathToscaUtil { public static final String FORWARDER = "forwarder"; public static void addForwardingPaths(Service service, Map<String, ToscaNodeTemplate> - nodeTemplates, CapabiltyRequirementConvertor capabiltyRequirementConvertor, Map<String, Component> originComponents, ToscaOperationFacade toscaOperationFacade) { + nodeTemplates, CapabilityRequirementConverter capabiltyRequirementConvertor, Map<String, Component> originComponents, ToscaOperationFacade toscaOperationFacade) { for (String forwardingPathName : service.getForwardingPaths().keySet()) { ToscaNodeTemplate forwardingPathNodeTemplate = new ToscaNodeTemplate(); @@ -70,7 +64,7 @@ public class ForwardingPathToscaUtil { } private static List<Map<String, ToscaTemplateRequirement>> convertPathElementsToRequirements( - List<ForwardingPathElementDataDefinition> pathElements, Service service, CapabiltyRequirementConvertor capabiltyRequirementConvertor, Map<String, Component> originComponents,ToscaOperationFacade toscaOperationFacade) { + List<ForwardingPathElementDataDefinition> pathElements, Service service, CapabilityRequirementConverter capabiltyRequirementConvertor, Map<String, Component> originComponents, ToscaOperationFacade toscaOperationFacade) { List<Map<String, ToscaTemplateRequirement>> toscaRequirements = new ArrayList<>(); for (int i = 0; i <= pathElements.size() -1 ; i++) { final ForwardingPathElementDataDefinition element = pathElements.get(i); @@ -85,8 +79,8 @@ public class ForwardingPathToscaUtil { } private static String fetchNodeName(Service service, String nodeId) { - if (service.getComponentInstanceById(nodeId).isPresent()) { - return service.getComponentInstanceById(nodeId).get().getName(); + if (service.getComponentInstanceByName(nodeId).isPresent()) { + return service.getComponentInstanceByName(nodeId).get().getName(); } else { return ""; } @@ -108,8 +102,8 @@ public class ForwardingPathToscaUtil { /** * @todo handle errors. */ - private static String fetchCPName(Service service, String nodeID, String cpName, CapabiltyRequirementConvertor capabiltyRequirementConvertor, Map<String, Component> originComponents, ToscaOperationFacade toscaOperationFacade) { - Optional<ComponentInstance> componentInstance = service.getComponentInstanceById(nodeID); + private static String fetchCPName(Service service, String nodeID, String cpName, CapabilityRequirementConverter capabiltyRequirementConvertor, Map<String, Component> originComponents, ToscaOperationFacade toscaOperationFacade) { + Optional<ComponentInstance> componentInstance = service.getComponentInstanceByName(nodeID); ComponentInstance componentInstanceVal = componentInstance.get(); String name = componentInstanceVal.getNormalizedName(); Component component = originComponents.get(componentInstanceVal.getComponentUid()); @@ -120,12 +114,12 @@ public class ForwardingPathToscaUtil { } } - CapabilityDefinition capability = componentInstanceVal.getCapabilities().values().stream().flatMap(capabilityDefinitions -> capabilityDefinitions.stream()) - .filter(capabilityDefinition -> capabilityDefinition.getUniqueId().equals(cpName)).findAny().get(); + CapabilityDefinition capability = componentInstanceVal.getCapabilities().values().stream().flatMap(Collection::stream) + .filter(capabilityDefinition -> capabilityDefinition.getName().equals(cpName)).findAny().get(); List<String> path = capability.getPath(); List<String> reducedPath = new ArrayList<>(path); reducedPath.remove(reducedPath.size() - 1); - Either<String, Boolean> stringBooleanEither = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, component, reducedPath, capability.getName()); + Either<String, Boolean> stringBooleanEither = capabiltyRequirementConvertor.buildSubstitutedName(originComponents, component, reducedPath, capability.getName(), null); return name + "." + stringBooleanEither.left().value(); } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java new file mode 100644 index 0000000000..f6619b9aaa --- /dev/null +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InputConverter.java @@ -0,0 +1,80 @@ +package org.openecomp.sdc.be.tosca.utils; + +import org.openecomp.sdc.be.datatypes.elements.Annotation; +import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.tosca.PropertyConvertor; +import org.openecomp.sdc.be.tosca.ToscaExportHandler; +import org.openecomp.sdc.be.tosca.model.ToscaAnnotation; +import org.openecomp.sdc.be.tosca.model.ToscaInput; +import org.openecomp.sdc.be.tosca.model.ToscaProperty; +import org.openecomp.sdc.common.log.wrappers.Logger; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@org.springframework.stereotype.Component +public class InputConverter { + private PropertyConvertor propertyConvertor; + private static final Logger log = Logger.getLogger(ToscaExportHandler.class); + + + public InputConverter() { + this.propertyConvertor = PropertyConvertor.getInstance(); + + } + /** + * This is the converter made for input + * input is derived from properties and is similar to properties + * now that it was added annotations , we created a new convertetor for it + * Input + * List of annotation + * Annotation: + * name + * type + * description + * list of properties */ + public Map<String, ToscaProperty> convertInputs( List<InputDefinition> inputDef,Map<String, DataTypeDefinition> dataTypes) { + log.debug("convert inputs to to tosca "); + + Map<String, ToscaProperty> inputs = new HashMap<>(); + if (inputDef != null) { + inputDef.forEach(i -> { + //Extract input the same as property + ToscaProperty toscaProperty = propertyConvertor.convertProperty(dataTypes, i, false); + //now that we have Tosca property we create new object called tosca input which drives from it + ToscaInput toscaInput = new ToscaInput(toscaProperty); + List<Annotation> annotations = i.getAnnotations(); + extractAnnotations(dataTypes, toscaInput, annotations); + inputs.put(i.getName(), toscaInput); + }); + } + return inputs; + } + + private void extractAnnotations(Map<String, DataTypeDefinition> dataTypes, ToscaInput toscaInput, List<Annotation> annotationsList) { + if (annotationsList != null) { + annotationsList.forEach(inputAnnotation -> { + ToscaAnnotation annotation = new ToscaAnnotation(); + if ((inputAnnotation.getType()) != null) { + annotation.setType(inputAnnotation.getType()); + } + if (inputAnnotation.getDescription() != null) { + annotation.setDescription(inputAnnotation.getDescription()); + } + if (inputAnnotation.getProperties() != null) { + Map<String, Object> properties = new HashMap<>(); + inputAnnotation.getProperties().forEach(k -> { + propertyConvertor.convertAndAddValue(dataTypes,properties,k, k::getValue); + }); + annotation.setProperties(properties); + } + toscaInput.addAnnotation(inputAnnotation.getName(), annotation); + }); + } + } +} + + + diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java index 82c7623fe2..5d0b4466c6 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/OperationArtifactUtil.java @@ -16,11 +16,11 @@ package org.openecomp.sdc.be.tosca.utils; -import java.io.File; - import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.tosca.CsarUtils; +import java.io.File; + public class OperationArtifactUtil { |