2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.sdnc.config.params.transformer;
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;
37 public class ArtificatTransformer {
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);
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);
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);
67 return propertyDefinition;