2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.params.transformer;
26 import java.io.IOException;
27 import java.util.List;
28 import org.apache.commons.lang3.StringUtils;
29 import org.onap.sdnc.config.params.data.Parameter;
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;
70 public String convertYAMLToParams(String pdContent)
71 throws JsonParseException, JsonMappingException, IOException {
72 String paramJson = null;
73 if (StringUtils.isNotBlank(pdContent)) {
74 paramJson = convertPdToParams(convertYAMLToPD(pdContent));
79 public String convertPdToParams(PropertyDefinition propertyDefinition)
80 throws JsonParseException, JsonMappingException, IOException {
81 String paramJson = null;
82 if (propertyDefinition != null && propertyDefinition.getParameters() != null) {
83 List<Parameter> parameters = propertyDefinition.getParameters();