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 com.fasterxml.jackson.databind.DeserializationFeature;
\r
24 import com.fasterxml.jackson.databind.ObjectMapper;
\r
25 import java.io.IOException;
\r
26 import org.openecomp.mso.bpmn.core.domain.AllottedResource;
\r
27 import org.openecomp.mso.bpmn.core.domain.NetworkResource;
\r
28 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
\r
29 import org.openecomp.mso.bpmn.core.domain.ServiceInstance;
\r
30 import org.openecomp.mso.bpmn.core.domain.VnfResource;
\r
32 public class DecomposeJsonUtil {
\r
34 private static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
\r
36 private DecomposeJsonUtil() {
\r
39 private static ObjectMapper createObjectMapper() {
\r
40 ObjectMapper om = new ObjectMapper();
\r
41 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
46 * Method to construct Service Decomposition object converting JSON structure
\r
48 * @param jsonString input in JSON format confirming ServiceDecomposition
\r
49 * @return decoded object
\r
50 * @throws JsonDecomposingException thrown when decoding json fails
\r
52 public static ServiceDecomposition jsonToServiceDecomposition(String jsonString) throws JsonDecomposingException {
\r
54 return OBJECT_MAPPER.readValue(jsonString, ServiceDecomposition.class);
\r
55 } catch (IOException e) {
\r
56 throw new JsonDecomposingException("Exception while converting json to service decomposition", e);
\r
61 * Method to construct Service Decomposition object converting JSON structure
\r
63 * @param jsonString input in JSON format confirming ServiceDecomposition
\r
64 * @param serviceInstanceId service instance id to be put in decoded ServiceDecomposition
\r
65 * @return decoded object
\r
66 * @throws JsonDecomposingException thrown when decoding json fails
\r
68 public static ServiceDecomposition jsonToServiceDecomposition(String jsonString, String serviceInstanceId)
\r
69 throws JsonDecomposingException {
\r
70 ServiceDecomposition serviceDecomposition = jsonToServiceDecomposition(jsonString);
\r
71 ServiceInstance serviceInstance = new ServiceInstance();
\r
72 serviceInstance.setInstanceId(serviceInstanceId);
\r
73 serviceDecomposition.setServiceInstance(serviceInstance);
\r
74 return serviceDecomposition;
\r
78 * Method to construct Resource Decomposition object converting JSON structure
\r
80 * @param jsonString input in JSON format confirming ResourceDecomposition
\r
81 * @return decoded object
\r
82 * @throws JsonDecomposingException thrown when decoding json fails
\r
84 public static VnfResource jsonToVnfResource(String jsonString) throws JsonDecomposingException {
\r
86 return OBJECT_MAPPER.readValue(jsonString, VnfResource.class);
\r
87 } catch (IOException e) {
\r
88 throw new JsonDecomposingException("Exception while converting json to vnf resource", e);
\r
93 * Method to construct Resource Decomposition object converting JSON structure
\r
95 * @param jsonString input in JSON format confirming ResourceDecomposition
\r
96 * @return decoded object
\r
97 * @throws JsonDecomposingException thrown when decoding json fails
\r
99 public static NetworkResource jsonToNetworkResource(String jsonString) throws JsonDecomposingException {
\r
101 return OBJECT_MAPPER.readValue(jsonString, NetworkResource.class);
\r
102 } catch (IOException e) {
\r
103 throw new JsonDecomposingException("Exception while converting json to network resource", e);
\r
108 * Method to construct Resource Decomposition object converting JSON structure
\r
110 * @param jsonString - input in JSON format confirming ResourceDecomposition
\r
111 * @return decoded object
\r
112 * @throws JsonDecomposingException thrown when decoding json fails
\r
114 public static AllottedResource jsonToAllottedResource(String jsonString) throws JsonDecomposingException {
\r
116 return OBJECT_MAPPER.readValue(jsonString, AllottedResource.class);
\r
117 } catch (IOException e) {
\r
118 throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
\r