1 package org.openecomp.sdc.be.tosca.utils;
3 import org.openecomp.sdc.be.datatypes.elements.Annotation;
4 import org.openecomp.sdc.be.model.DataTypeDefinition;
5 import org.openecomp.sdc.be.model.InputDefinition;
6 import org.openecomp.sdc.be.tosca.PropertyConvertor;
7 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
8 import org.openecomp.sdc.be.tosca.model.ToscaAnnotation;
9 import org.openecomp.sdc.be.tosca.model.ToscaInput;
10 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
11 import org.openecomp.sdc.common.log.wrappers.Logger;
13 import java.util.HashMap;
14 import java.util.List;
17 @org.springframework.stereotype.Component
18 public class InputConverter {
19 private PropertyConvertor propertyConvertor;
20 private static final Logger log = Logger.getLogger(ToscaExportHandler.class);
23 public InputConverter() {
24 this.propertyConvertor = PropertyConvertor.getInstance();
28 * This is the converter made for input
29 * input is derived from properties and is similar to properties
30 * now that it was added annotations , we created a new convertetor for it
37 * list of properties */
38 public Map<String, ToscaProperty> convertInputs( List<InputDefinition> inputDef,Map<String, DataTypeDefinition> dataTypes) {
39 log.debug("convert inputs to to tosca ");
41 Map<String, ToscaProperty> inputs = new HashMap<>();
42 if (inputDef != null) {
43 inputDef.forEach(i -> {
44 //Extract input the same as property
45 ToscaProperty toscaProperty = propertyConvertor.convertProperty(dataTypes, i, false);
46 //now that we have Tosca property we create new object called tosca input which drives from it
47 ToscaInput toscaInput = new ToscaInput(toscaProperty);
48 List<Annotation> annotations = i.getAnnotations();
49 extractAnnotations(dataTypes, toscaInput, annotations);
50 inputs.put(i.getName(), toscaInput);
56 private void extractAnnotations(Map<String, DataTypeDefinition> dataTypes, ToscaInput toscaInput, List<Annotation> annotationsList) {
57 if (annotationsList != null) {
58 annotationsList.forEach(inputAnnotation -> {
59 ToscaAnnotation annotation = new ToscaAnnotation();
60 if ((inputAnnotation.getType()) != null) {
61 annotation.setType(inputAnnotation.getType());
63 if (inputAnnotation.getDescription() != null) {
64 annotation.setDescription(inputAnnotation.getDescription());
66 if (inputAnnotation.getProperties() != null) {
67 Map<String, Object> properties = new HashMap<>();
68 inputAnnotation.getProperties().forEach(k -> {
69 propertyConvertor.convertAndAddValue(dataTypes,properties,k, k::getValue);
71 annotation.setProperties(properties);
73 toscaInput.addAnnotation(inputAnnotation.getName(), annotation);