2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.tosca.utils;
22 import java.util.HashMap;
23 import java.util.List;
25 import org.openecomp.sdc.be.datatypes.elements.Annotation;
26 import org.openecomp.sdc.be.model.DataTypeDefinition;
27 import org.openecomp.sdc.be.model.InputDefinition;
28 import org.openecomp.sdc.be.tosca.PropertyConvertor;
29 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
30 import org.openecomp.sdc.be.tosca.model.ToscaAnnotation;
31 import org.openecomp.sdc.be.tosca.model.ToscaInput;
32 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import org.springframework.beans.factory.annotation.Autowired;
36 @org.springframework.stereotype.Component
37 public class InputConverter {
39 private static final Logger log = Logger.getLogger(ToscaExportHandler.class);
40 private PropertyConvertor propertyConvertor;
43 public InputConverter(PropertyConvertor propertyConvertor) {
44 this.propertyConvertor = propertyConvertor;
48 * This is the converter made for input
49 * input is derived from properties and is similar to properties
50 * now that it was added annotations , we created a new convertetor for it
57 * list of properties */
58 public Map<String, ToscaProperty> convertInputs(List<InputDefinition> inputDef, Map<String, DataTypeDefinition> dataTypes) {
59 log.debug("convert inputs to tosca");
60 Map<String, ToscaProperty> inputs = new HashMap<>();
61 if (inputDef != null) {
62 inputDef.forEach(i -> {
63 //Extract input the same as property
64 ToscaProperty toscaProperty = propertyConvertor.convertProperty(dataTypes, i, PropertyConvertor.PropertyType.INPUT);
65 //now that we have Tosca property we create new object called tosca input which drives from it
66 ToscaInput toscaInput = new ToscaInput(toscaProperty);
67 List<Annotation> annotations = i.getAnnotations();
68 extractAnnotations(dataTypes, toscaInput, annotations);
69 inputs.put(i.getName(), toscaInput);
75 private void extractAnnotations(Map<String, DataTypeDefinition> dataTypes, ToscaInput toscaInput, List<Annotation> annotationsList) {
76 if (annotationsList != null) {
77 annotationsList.forEach(inputAnnotation -> {
78 ToscaAnnotation annotation = new ToscaAnnotation();
79 if ((inputAnnotation.getType()) != null) {
80 annotation.setType(inputAnnotation.getType());
82 if (inputAnnotation.getDescription() != null) {
83 annotation.setDescription(inputAnnotation.getDescription());
85 if (inputAnnotation.getProperties() != null) {
86 Map<String, Object> properties = new HashMap<>();
87 inputAnnotation.getProperties().forEach(k -> {
88 propertyConvertor.convertAndAddValue(dataTypes, properties, k, k::getValue);
90 annotation.setProperties(properties);
92 toscaInput.addAnnotation(inputAnnotation.getName(), annotation);