Merge "Added @Override annotation to method signature"
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / json / DecomposeJsonUtil.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\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
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 \r
21 package org.openecomp.mso.bpmn.core.json;\r
22 \r
23 import java.io.Serializable;\r
24 import java.io.IOException;\r
25 \r
26 \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
31 \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
36 \r
37 import org.openecomp.mso.logger.MsoLogger;\r
38 \r
39 public class DecomposeJsonUtil implements Serializable {\r
40         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);\r
41         /**\r
42          * \r
43          */\r
44         private static final long serialVersionUID = 1L;\r
45 \r
46         /**\r
47          * Method to construct Service Decomposition object converting\r
48          * JSON structure\r
49          * \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
55          */\r
56         public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {\r
57         \r
58         ServiceDecomposition serviceDecomposition = new ServiceDecomposition();\r
59         ObjectMapper om = new ObjectMapper();\r
60         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
61        \r
62                 try {\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
70                 }\r
71                 \r
72                 return serviceDecomposition;\r
73         }\r
74         \r
75         /**\r
76          * Method to construct Resource Decomposition object converting\r
77          * JSON structure\r
78          * \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
84          */\r
85         public static VnfResource JsonToVnfResource(String jsonString) {\r
86         \r
87         VnfResource vnfResource = new VnfResource();\r
88         ObjectMapper om = new ObjectMapper();\r
89         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
90        \r
91                 try {\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
99                 }\r
100                 return vnfResource;\r
101         }\r
102         \r
103         /**\r
104          * Method to construct Resource Decomposition object converting\r
105          * JSON structure\r
106          * \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
112          */\r
113         public static NetworkResource JsonToNetworkResource(String jsonString) {\r
114         \r
115         NetworkResource networkResource = new NetworkResource();\r
116         ObjectMapper om = new ObjectMapper();\r
117         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
118        \r
119                 try {\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
127                 }\r
128                 return networkResource;\r
129         }\r
130         \r
131         /**\r
132          * Method to construct Resource Decomposition object converting\r
133          * JSON structure\r
134          * \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
140          */\r
141         public static AllottedResource JsonToAllottedResource(String jsonString) {\r
142         \r
143                 AllottedResource allottedResource = new AllottedResource();\r
144         ObjectMapper om = new ObjectMapper();\r
145         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
146        \r
147                 try {\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
155                 }\r
156                 return allottedResource;\r
157         }\r
158 }