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.Serializable;
\r
24 import java.io.IOException;
\r
27 import org.openecomp.mso.bpmn.core.domain.AllottedResource;
\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.VnfResource;
\r
32 import com.fasterxml.jackson.core.JsonParseException;
\r
33 import com.fasterxml.jackson.databind.DeserializationFeature;
\r
34 import com.fasterxml.jackson.databind.JsonMappingException;
\r
35 import com.fasterxml.jackson.databind.ObjectMapper;
\r
37 import org.openecomp.mso.logger.MsoLogger;
\r
39 public class DecomposeJsonUtil implements Serializable {
\r
40 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
\r
44 private static final long serialVersionUID = 1L;
\r
47 * Method to construct Service Decomposition object converting
\r
50 * @param jsonString - input in JSON format confirming ServiceDecomposition
\r
51 * @return - ServiceDecomposition object
\r
52 * @throws IOException
\r
53 * @throws JsonMappingException
\r
54 * @throws JsonParseException
\r
56 public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {
\r
58 ServiceDecomposition serviceDecomposition = new ServiceDecomposition();
\r
59 ObjectMapper om = new ObjectMapper();
\r
60 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
63 serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);
\r
64 } catch (JsonParseException e) {
\r
65 LOGGER.debug("JsonParseException :",e);
\r
66 } catch (JsonMappingException e) {
\r
67 LOGGER.debug("JsonMappingException :",e);
\r
68 } catch (IOException e) {
\r
69 LOGGER.debug("IOException :",e);
\r
72 return serviceDecomposition;
\r
76 * Method to construct Resource Decomposition object converting
\r
79 * @param jsonString - input in JSON format confirming ResourceDecomposition
\r
80 * @return - ServiceDecomposition object
\r
81 * @throws IOException
\r
82 * @throws JsonMappingException
\r
83 * @throws JsonParseException
\r
85 public static VnfResource JsonToVnfResource(String jsonString) {
\r
87 VnfResource vnfResource = new VnfResource();
\r
88 ObjectMapper om = new ObjectMapper();
\r
89 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
92 vnfResource = om.readValue(jsonString, VnfResource.class);
\r
93 } catch (JsonParseException e) {
\r
94 LOGGER.debug("JsonParseException :",e);
\r
95 } catch (JsonMappingException e) {
\r
96 LOGGER.debug("JsonMappingException :",e);
\r
97 } catch (IOException e) {
\r
98 LOGGER.debug("IOException :",e);
\r
100 return vnfResource;
\r
104 * Method to construct Resource Decomposition object converting
\r
107 * @param jsonString - input in JSON format confirming ResourceDecomposition
\r
108 * @return - ServiceDecomposition object
\r
109 * @throws IOException
\r
110 * @throws JsonMappingException
\r
111 * @throws JsonParseException
\r
113 public static NetworkResource JsonToNetworkResource(String jsonString) {
\r
115 NetworkResource networkResource = new NetworkResource();
\r
116 ObjectMapper om = new ObjectMapper();
\r
117 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
120 networkResource = om.readValue(jsonString, NetworkResource.class);
\r
121 } catch (JsonParseException e) {
\r
122 LOGGER.debug("Exception :",e);
\r
123 } catch (JsonMappingException e) {
\r
124 LOGGER.debug("Exception :",e);
\r
125 } catch (IOException e) {
\r
126 LOGGER.debug("Exception :",e);
\r
128 return networkResource;
\r
132 * Method to construct Resource Decomposition object converting
\r
135 * @param jsonString - input in JSON format confirming ResourceDecomposition
\r
136 * @return - ServiceDecomposition object
\r
137 * @throws IOException
\r
138 * @throws JsonMappingException
\r
139 * @throws JsonParseException
\r
141 public static AllottedResource JsonToAllottedResource(String jsonString) {
\r
143 AllottedResource allottedResource = new AllottedResource();
\r
144 ObjectMapper om = new ObjectMapper();
\r
145 om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
\r
148 allottedResource = om.readValue(jsonString, AllottedResource.class);
\r
149 } catch (JsonParseException e) {
\r
150 LOGGER.debug("Exception :",e);
\r
151 } catch (JsonMappingException e) {
\r
152 LOGGER.debug("Exception :",e);
\r
153 } catch (IOException e) {
\r
154 LOGGER.debug("Exception :",e);
\r
156 return allottedResource;
\r