1710 Rebase - Second Attempt
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / json / DecomposeJsonUtil.java
1 package org.openecomp.mso.bpmn.core.json;\r
2 \r
3 import java.io.Serializable;\r
4 import java.io.IOException;\r
5 \r
6 \r
7 import org.openecomp.mso.bpmn.core.domain.AllottedResource;\r
8 import org.openecomp.mso.bpmn.core.domain.NetworkResource;\r
9 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;\r
10 import org.openecomp.mso.bpmn.core.domain.VnfResource;\r
11 \r
12 import com.fasterxml.jackson.core.JsonParseException;\r
13 import com.fasterxml.jackson.databind.DeserializationFeature;\r
14 import com.fasterxml.jackson.databind.JsonMappingException;\r
15 import com.fasterxml.jackson.databind.ObjectMapper;\r
16 \r
17 public class DecomposeJsonUtil implements Serializable {\r
18         \r
19         /**\r
20          * \r
21          */\r
22         private static final long serialVersionUID = 1L;\r
23 \r
24         /**\r
25          * Method to construct Service Decomposition object converting\r
26          * JSON structure\r
27          * \r
28          * @param jsonString - input in JSON format confirming ServiceDecomposition\r
29          * @return - ServiceDecomposition object\r
30          * @throws IOException \r
31          * @throws JsonMappingException \r
32          * @throws JsonParseException \r
33          */\r
34         public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {\r
35         \r
36         ServiceDecomposition serviceDecomposition = new ServiceDecomposition();\r
37         ObjectMapper om = new ObjectMapper();\r
38         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
39        \r
40                 try {\r
41                         serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);\r
42                 } catch (JsonParseException e) {\r
43                         // TODO Auto-generated catch block\r
44                         e.printStackTrace();\r
45                 } catch (JsonMappingException e) {\r
46                         // TODO Auto-generated catch block\r
47                         e.printStackTrace();\r
48                 } catch (IOException e) {\r
49                         // TODO Auto-generated catch block\r
50                         e.printStackTrace();\r
51                 }\r
52                 \r
53                 return serviceDecomposition;\r
54         }\r
55         \r
56         /**\r
57          * Method to construct Resource Decomposition object converting\r
58          * JSON structure\r
59          * \r
60          * @param jsonString - input in JSON format confirming ResourceDecomposition\r
61          * @return - ServiceDecomposition object\r
62          * @throws IOException \r
63          * @throws JsonMappingException \r
64          * @throws JsonParseException \r
65          */\r
66         public static VnfResource JsonToVnfResource(String jsonString) {\r
67         \r
68         VnfResource vnfResource = new VnfResource();\r
69         ObjectMapper om = new ObjectMapper();\r
70         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
71        \r
72                 try {\r
73                         vnfResource = om.readValue(jsonString, VnfResource.class);\r
74                 } catch (JsonParseException e) {\r
75                         // TODO Auto-generated catch block\r
76                         e.printStackTrace();\r
77                 } catch (JsonMappingException e) {\r
78                         // TODO Auto-generated catch block\r
79                         e.printStackTrace();\r
80                 } catch (IOException e) {\r
81                         // TODO Auto-generated catch block\r
82                         e.printStackTrace();\r
83                 }\r
84                 return vnfResource;\r
85         }\r
86         \r
87         /**\r
88          * Method to construct Resource Decomposition object converting\r
89          * JSON structure\r
90          * \r
91          * @param jsonString - input in JSON format confirming ResourceDecomposition\r
92          * @return - ServiceDecomposition object\r
93          * @throws IOException \r
94          * @throws JsonMappingException \r
95          * @throws JsonParseException \r
96          */\r
97         public static NetworkResource JsonToNetworkResource(String jsonString) {\r
98         \r
99         NetworkResource networkResource = new NetworkResource();\r
100         ObjectMapper om = new ObjectMapper();\r
101         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
102        \r
103                 try {\r
104                         networkResource = om.readValue(jsonString, NetworkResource.class);\r
105                 } catch (JsonParseException e) {\r
106                         // TODO Auto-generated catch block\r
107                         e.printStackTrace();\r
108                 } catch (JsonMappingException e) {\r
109                         // TODO Auto-generated catch block\r
110                         e.printStackTrace();\r
111                 } catch (IOException e) {\r
112                         // TODO Auto-generated catch block\r
113                         e.printStackTrace();\r
114                 }\r
115                 return networkResource;\r
116         }\r
117         \r
118         /**\r
119          * Method to construct Resource Decomposition object converting\r
120          * JSON structure\r
121          * \r
122          * @param jsonString - input in JSON format confirming ResourceDecomposition\r
123          * @return - ServiceDecomposition object\r
124          * @throws IOException \r
125          * @throws JsonMappingException \r
126          * @throws JsonParseException \r
127          */\r
128         public static AllottedResource JsonToAllottedResource(String jsonString) {\r
129         \r
130                 AllottedResource allottedResource = new AllottedResource();\r
131         ObjectMapper om = new ObjectMapper();\r
132         om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);\r
133        \r
134                 try {\r
135                         allottedResource = om.readValue(jsonString, AllottedResource.class);\r
136                 } catch (JsonParseException e) {\r
137                         // TODO Auto-generated catch block\r
138                         e.printStackTrace();\r
139                 } catch (JsonMappingException e) {\r
140                         // TODO Auto-generated catch block\r
141                         e.printStackTrace();\r
142                 } catch (IOException e) {\r
143                         // TODO Auto-generated catch block\r
144                         e.printStackTrace();\r
145                 }\r
146                 return allottedResource;\r
147         }\r
148 }