Initial commit for appc-config-params
[appc.git] / appc-config / appc-config-params / provider / src / main / java / org / openecomp / sdnc / config / params / transformer / ArtificatTransformer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
10  * 
11  *         http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * 
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.openecomp.sdnc.config.params.transformer;
24
25 import java.io.IOException;
26 import java.util.List;
27
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;
31
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;
37
38 public class ArtificatTransformer {
39
40
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);            
47                 }
48                 return yamlContent;
49         }
50
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);
57         }
58
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);
64                 }
65                 return propertyDefinition;
66         }
67
68         public String convertYAMLToParams(String pdContent) throws JsonParseException, JsonMappingException, IOException{
69                 String paramJson = null;
70                 if(StringUtils.isNotBlank(pdContent)){
71                         paramJson = convertPdToParams(convertYAMLToPD(pdContent));
72                 }
73                 return paramJson;
74         }
75
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();
80
81                 }
82                 return paramJson;
83         }
84
85 }