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=========================================================
21 package org.openecomp.sdc.be.tosca.utils;
23 import org.openecomp.sdc.be.datatypes.elements.Annotation;
24 import org.openecomp.sdc.be.model.DataTypeDefinition;
25 import org.openecomp.sdc.be.model.InputDefinition;
26 import org.openecomp.sdc.be.tosca.PropertyConvertor;
27 import org.openecomp.sdc.be.tosca.ToscaExportHandler;
28 import org.openecomp.sdc.be.tosca.model.ToscaAnnotation;
29 import org.openecomp.sdc.be.tosca.model.ToscaInput;
30 import org.openecomp.sdc.be.tosca.model.ToscaProperty;
31 import org.openecomp.sdc.common.log.wrappers.Logger;
33 import java.util.HashMap;
34 import java.util.List;
37 @org.springframework.stereotype.Component
38 public class InputConverter {
39 private PropertyConvertor propertyConvertor;
40 private static final Logger log = Logger.getLogger(ToscaExportHandler.class);
43 public InputConverter() {
44 this.propertyConvertor = PropertyConvertor.getInstance();
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 to tosca ");
61 Map<String, ToscaProperty> inputs = new HashMap<>();
62 if (inputDef != null) {
63 inputDef.forEach(i -> {
64 //Extract input the same as property
65 ToscaProperty toscaProperty = propertyConvertor.convertProperty(dataTypes, i,
66 PropertyConvertor.PropertyType.INPUT);
67 //now that we have Tosca property we create new object called tosca input which drives from it
68 ToscaInput toscaInput = new ToscaInput(toscaProperty);
69 List<Annotation> annotations = i.getAnnotations();
70 extractAnnotations(dataTypes, toscaInput, annotations);
71 inputs.put(i.getName(), toscaInput);
77 private void extractAnnotations(Map<String, DataTypeDefinition> dataTypes, ToscaInput toscaInput, List<Annotation> annotationsList) {
78 if (annotationsList != null) {
79 annotationsList.forEach(inputAnnotation -> {
80 ToscaAnnotation annotation = new ToscaAnnotation();
81 if ((inputAnnotation.getType()) != null) {
82 annotation.setType(inputAnnotation.getType());
84 if (inputAnnotation.getDescription() != null) {
85 annotation.setDescription(inputAnnotation.getDescription());
87 if (inputAnnotation.getProperties() != null) {
88 Map<String, Object> properties = new HashMap<>();
89 inputAnnotation.getProperties().forEach(k -> {
90 propertyConvertor.convertAndAddValue(dataTypes,properties,k, k::getValue);
92 annotation.setProperties(properties);
94 toscaInput.addAnnotation(inputAnnotation.getName(), annotation);