2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.vid.mso;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
26 import org.glassfish.jersey.client.ClientResponse;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.openecomp.vid.controller.MsoController;
30 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class MsoUtil {
38 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
40 /** The Constant dateFormat. */
41 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
46 * @param body the body
47 * @param statusCode the status code
48 * @return the mso response wrapper
50 public static MsoResponseWrapper wrapResponse ( String body, int statusCode ) {
52 MsoResponseWrapper w = new MsoResponseWrapper();
53 w.setStatus (statusCode);
62 * @param cres the cres
63 * @return the mso response wrapper
65 public static MsoResponseWrapper wrapResponse (ClientResponse cres) {
68 resp_str = cres.readEntity(String.class);
70 int statuscode = cres.getStatus();
71 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, statuscode );
79 * @return the mso response wrapper
81 public static MsoResponseWrapper wrapResponse (RestObject<String> rs) {
86 status = rs.getStatusCode();
88 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, status );
93 * Convert pojo to string.
95 * @param <T> the generic type
98 * @throws JsonProcessingException the json processing exception
100 public static <T> String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException {
102 String methodName = "convertPojoToString";
103 ObjectMapper mapper = new ObjectMapper();
104 String r_json_str = "";
107 r_json_str = mapper.writeValueAsString(t);
109 catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
110 logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json");
119 * @param args the arguments
121 public static void main(String[] args) {
122 // TODO Auto-generated method stub