2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdnc.config.params.transformer;
25 import java.io.IOException;
26 import java.util.List;
28 import org.apache.commons.lang3.StringUtils;
29 import org.openecomp.sdnc.config.params.data.Parameter;
30 import org.openecomp.sdnc.config.params.data.PropertyDefinition;
32 import com.fasterxml.jackson.core.JsonParseException;
33 import com.fasterxml.jackson.databind.JsonMappingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
35 import com.fasterxml.jackson.databind.SerializationFeature;
36 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
38 public class ArtificatTransformer {
41 public String convertPDToYaml(PropertyDefinition propertyDefinition) throws JsonParseException, JsonMappingException, IOException{
42 String yamlContent = null;
43 if(propertyDefinition != null){
44 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
45 mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
46 yamlContent = mapper.writeValueAsString(propertyDefinition);
51 public String transformYamlToJson(String yaml) throws JsonParseException, JsonMappingException, IOException {
52 ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
53 Object obj = yamlReader.readValue(yaml, Object.class);
54 ObjectMapper jsonWriter = new ObjectMapper();
55 jsonWriter.enable(SerializationFeature.INDENT_OUTPUT);
56 return jsonWriter.writeValueAsString(obj);
59 public PropertyDefinition convertYAMLToPD(String pdContent) throws JsonParseException, JsonMappingException, IOException{
60 PropertyDefinition propertyDefinition = null;
61 if(StringUtils.isNotBlank(pdContent)){
62 ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
63 propertyDefinition = mapper.readValue(pdContent, PropertyDefinition.class);
65 return propertyDefinition;
68 public String convertYAMLToParams(String pdContent) throws JsonParseException, JsonMappingException, IOException{
69 String paramJson = null;
70 if(StringUtils.isNotBlank(pdContent)){
71 paramJson = convertPdToParams(convertYAMLToPD(pdContent));
76 public String convertPdToParams(PropertyDefinition propertyDefinition) throws JsonParseException, JsonMappingException, IOException{
77 String paramJson = null;
78 if(propertyDefinition != null && propertyDefinition.getParameters() != null){
79 List<Parameter> parameters = propertyDefinition.getParameters();