Changed to unmaintained
[appc.git] / appc-config / appc-config-params / provider / src / main / java / org / onap / sdnc / config / params / transformer / ArtificatTransformer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2018 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.sdnc.config.params.transformer;
27
28 import java.io.IOException;
29 import org.apache.commons.lang3.StringUtils;
30 import org.onap.sdnc.config.params.data.PropertyDefinition;
31 import com.fasterxml.jackson.core.JsonParseException;
32 import com.fasterxml.jackson.databind.JsonMappingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.SerializationFeature;
35 import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
36
37 public class ArtificatTransformer {
38
39
40     public String convertPDToYaml(PropertyDefinition propertyDefinition)
41             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)
52             throws JsonParseException, JsonMappingException, IOException {
53         ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
54         Object obj = yamlReader.readValue(yaml, Object.class);
55         ObjectMapper jsonWriter = new ObjectMapper();
56         jsonWriter.enable(SerializationFeature.INDENT_OUTPUT);
57         return jsonWriter.writeValueAsString(obj);
58     }
59
60     public PropertyDefinition convertYAMLToPD(String pdContent)
61             throws JsonParseException, JsonMappingException, IOException {
62         PropertyDefinition propertyDefinition = null;
63         if (StringUtils.isNotBlank(pdContent)) {
64             ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
65             propertyDefinition = mapper.readValue(pdContent, PropertyDefinition.class);
66         }
67         return propertyDefinition;
68     }
69 }