2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.mso.bpmn.core.json;
\r
23 import java.io.IOException;
\r
24 import java.io.Serializable;
\r
26 import org.openecomp.mso.bpmn.core.domain.AllottedResource;
\r
27 import org.openecomp.mso.bpmn.core.domain.ConfigResource;
\r
28 import org.openecomp.mso.bpmn.core.domain.NetworkResource;
\r
29 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
\r
30 import org.openecomp.mso.bpmn.core.domain.ServiceInstance;
\r
31 import org.openecomp.mso.bpmn.core.domain.VnfResource;
\r
33 import com.fasterxml.jackson.databind.DeserializationFeature;
\r
34 import com.fasterxml.jackson.databind.ObjectMapper;
\r
36 public class DecomposeJsonUtil implements Serializable {
\r
38 private static final long serialVersionUID = 1L;
\r
40 private static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
\r
42 private DecomposeJsonUtil() {
\r
45 private static ObjectMapper createObjectMapper() {
\r
46 ObjectMapper om = new ObjectMapper();
\r
47 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
52 * Method to construct Service Decomposition object converting JSON structure
\r
54 * @param jsonString input in JSON format confirming ServiceDecomposition
\r
55 * @return decoded object
\r
56 * @throws JsonDecomposingException thrown when decoding json fails
\r
58 public static ServiceDecomposition jsonToServiceDecomposition(String jsonString) throws JsonDecomposingException {
\r
60 ObjectMapper om = new ObjectMapper();
\r
61 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
62 om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
\r
63 return om.readValue(jsonString, ServiceDecomposition.class);
\r
64 } catch (IOException e) {
\r
65 throw new JsonDecomposingException("Exception while converting json to service decomposition", e);
\r
70 * Method to construct Service Decomposition object converting JSON structure
\r
72 * @param jsonString input in JSON format confirming ServiceDecomposition
\r
73 * @param serviceInstanceId service instance id to be put in decoded ServiceDecomposition
\r
74 * @return decoded object
\r
75 * @throws JsonDecomposingException thrown when decoding json fails
\r
77 public static ServiceDecomposition jsonToServiceDecomposition(String jsonString, String serviceInstanceId)
\r
78 throws JsonDecomposingException {
\r
79 ServiceDecomposition serviceDecomposition = jsonToServiceDecomposition(jsonString);
\r
80 ServiceInstance serviceInstance = new ServiceInstance();
\r
81 serviceInstance.setInstanceId(serviceInstanceId);
\r
82 serviceDecomposition.setServiceInstance(serviceInstance);
\r
83 return serviceDecomposition;
\r
87 * Method to construct Resource Decomposition object converting JSON structure
\r
89 * @param jsonString input in JSON format confirming ResourceDecomposition
\r
90 * @return decoded object
\r
91 * @throws JsonDecomposingException thrown when decoding json fails
\r
93 public static VnfResource jsonToVnfResource(String jsonString) throws JsonDecomposingException {
\r
95 return OBJECT_MAPPER.readValue(jsonString, VnfResource.class);
\r
96 } catch (IOException e) {
\r
97 throw new JsonDecomposingException("Exception while converting json to vnf resource", e);
\r
102 * Method to construct Resource Decomposition object converting JSON structure
\r
104 * @param jsonString input in JSON format confirming ResourceDecomposition
\r
105 * @return decoded object
\r
106 * @throws JsonDecomposingException thrown when decoding json fails
\r
108 public static NetworkResource jsonToNetworkResource(String jsonString) throws JsonDecomposingException {
\r
110 return OBJECT_MAPPER.readValue(jsonString, NetworkResource.class);
\r
111 } catch (IOException e) {
\r
112 throw new JsonDecomposingException("Exception while converting json to network resource", e);
\r
117 * Method to construct Resource Decomposition object converting JSON structure
\r
119 * @param jsonString - input in JSON format confirming ResourceDecomposition
\r
120 * @return decoded object
\r
121 * @throws JsonDecomposingException thrown when decoding json fails
\r
123 public static AllottedResource jsonToAllottedResource(String jsonString) throws JsonDecomposingException {
\r
125 return OBJECT_MAPPER.readValue(jsonString, AllottedResource.class);
\r
126 } catch (IOException e) {
\r
127 throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
\r
131 public static ConfigResource jsonToConfigResource(String jsonString) throws JsonDecomposingException {
\r
133 return OBJECT_MAPPER.readValue(jsonString, ConfigResource.class);
\r
134 } catch (IOException e) {
\r
135 throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
\r