39de6b3e85c1cccb2122b43bc429fa7663901a22
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / scheduler / SchedulerUtil.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the “License”);
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.openecomp.portalapp.portal.scheduler;
39
40 import java.text.DateFormat;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43
44 import org.openecomp.portalapp.portal.scheduler.restobjects.GetTimeSlotsRestObject;
45 import org.openecomp.portalapp.portal.scheduler.restobjects.PostCreateNewVnfRestObject;
46 import org.openecomp.portalapp.portal.scheduler.restobjects.PostSubmitVnfChangeRestObject;
47 import org.openecomp.portalapp.portal.scheduler.wrapper.GetTimeSlotsWrapper;
48 import org.openecomp.portalapp.portal.scheduler.wrapper.PostCreateNewVnfWrapper;
49 import org.openecomp.portalapp.portal.scheduler.wrapper.PostSubmitVnfChangeTimeSlotsWrapper;
50 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
51
52 import com.fasterxml.jackson.databind.ObjectMapper;
53
54 public class SchedulerUtil {
55
56         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SchedulerUtil.class);
57
58         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
59
60         public static GetTimeSlotsWrapper getTimeSlotsWrapResponse(GetTimeSlotsRestObject<String> rs) {
61
62                 String resp_str = "";
63                 int status = 0;
64
65                 if (rs != null) {
66                         resp_str = rs.get();
67                         status = rs.getStatusCode();
68                 }
69
70                 GetTimeSlotsWrapper w = new GetTimeSlotsWrapper();
71
72                 w.setEntity(resp_str);
73                 w.setStatus(status);
74
75                 return (w);
76         }
77
78         public static PostSubmitVnfChangeTimeSlotsWrapper postSubmitNewVnfWrapResponse(
79                         PostSubmitVnfChangeRestObject<String> rs) {
80
81                 String resp_str = "";
82                 int status = 0;
83                 String uuid = "";
84
85                 if (rs != null) {
86                         resp_str = rs.get();
87                         status = rs.getStatusCode();
88                         uuid = rs.getUUID();
89                 }
90
91                 PostSubmitVnfChangeTimeSlotsWrapper w = new PostSubmitVnfChangeTimeSlotsWrapper();
92
93                 w.setEntity(resp_str);
94                 w.setStatus(status);
95                 w.setUuid(uuid);
96
97                 return (w);
98         }
99
100         public static PostCreateNewVnfWrapper postCreateNewVnfWrapResponse(PostCreateNewVnfRestObject<String> rs) {
101
102                 String resp_str = "";
103                 int status = 0;
104                 String uuid = "";
105
106                 if (rs != null) {
107                         resp_str = rs.get();
108                         status = rs.getStatusCode();
109                         uuid = rs.getUUID();
110                 }
111
112                 PostCreateNewVnfWrapper w = new PostCreateNewVnfWrapper();
113
114                 w.setEntity(resp_str);
115                 w.setStatus(status);
116                 w.setUuid(uuid);
117
118                 return (w);
119         }
120
121         public static <T> String convertPojoToString(T t) throws com.fasterxml.jackson.core.JsonProcessingException {
122
123                 String methodName = "convertPojoToString";
124                 ObjectMapper mapper = new ObjectMapper();
125                 String r_json_str = "";
126                 if (t != null) {
127                         try {
128                                 r_json_str = mapper.writeValueAsString(t);
129                         } catch (com.fasterxml.jackson.core.JsonProcessingException j) {
130                                 logger.debug(EELFLoggerDelegate.debugLogger,
131                                                 dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json");
132                         }
133                 }
134                 return (r_json_str);
135         }
136
137 }