Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / scheduler / SchedulerUtil.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 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.onap.portalapp.portal.scheduler;
39
40 import java.text.DateFormat;
41 import java.text.SimpleDateFormat;
42 import java.util.Date;
43
44 import org.onap.portalapp.portal.scheduler.restobjects.GetTimeSlotsRestObject;
45 import org.onap.portalapp.portal.scheduler.restobjects.PostCreateNewVnfRestObject;
46 import org.onap.portalapp.portal.scheduler.restobjects.PostSubmitVnfChangeRestObject;
47 import org.onap.portalapp.portal.scheduler.wrapper.GetTimeSlotsWrapper;
48 import org.onap.portalapp.portal.scheduler.wrapper.PostCreateNewVnfWrapper;
49 import org.onap.portalapp.portal.scheduler.wrapper.PostSubmitVnfChangeTimeSlotsWrapper;
50 import org.onap.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 (PostSubmitVnfChangeRestObject<String> rs) {     
79                 
80                 String resp_str = "";
81                 int status = 0;
82                 String uuid = "";
83                 
84                 if ( rs != null ) {
85                         resp_str = rs.get();
86                         status = rs.getStatusCode();
87                         uuid = rs.getUUID();
88                 }
89                                 
90                 PostSubmitVnfChangeTimeSlotsWrapper w = new PostSubmitVnfChangeTimeSlotsWrapper();
91                 
92                 w.setEntity(resp_str);
93                 w.setStatus (status);
94                 w.setUuid(uuid);
95                 
96                 return (w);
97         }
98         
99         public static PostCreateNewVnfWrapper postCreateNewVnfWrapResponse (PostCreateNewVnfRestObject<String> rs) {    
100                 
101                 String resp_str = "";
102                 int status = 0;
103                 String uuid = "";
104                 
105                 if ( rs != null ) {
106                         resp_str = rs.get();
107                         status = rs.getStatusCode();
108                         uuid = rs.getUUID();
109                 }
110                                 
111                 PostCreateNewVnfWrapper w = new PostCreateNewVnfWrapper();
112                 
113                 w.setEntity(resp_str);
114                 w.setStatus (status);
115                 w.setUuid(uuid);
116                 
117                 return (w);
118         }
119         
120         public static <T> String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException {
121                 
122                 String methodName = "convertPojoToString";
123                 ObjectMapper mapper = new ObjectMapper();
124                 String r_json_str = "";
125             if ( t != null ) {
126                     try {
127                         r_json_str = mapper.writeValueAsString(t);
128                     }
129                     catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
130                         logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " +  methodName + " Unable to parse object as json");
131                     }
132             }
133             return (r_json_str);
134         }
135         
136 }