1 package org.onap.vid.policy;
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
7 import org.glassfish.jersey.client.ClientResponse;
8 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
9 import org.onap.vid.policy.PolicyResponseWrapper;
10 import org.onap.vid.policy.PolicyUtil;
11 import org.onap.vid.policy.RestObject;
13 import com.fasterxml.jackson.databind.ObjectMapper;
15 public class PolicyUtil {
17 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyUtil.class);
19 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
21 public static PolicyResponseWrapper wrapResponse ( String body, int statusCode ) {
23 PolicyResponseWrapper w = new PolicyResponseWrapper();
24 w.setStatus (statusCode);
30 public static PolicyResponseWrapper wrapResponse (ClientResponse cres) {
33 resp_str = cres.readEntity(String.class);
35 int statuscode = cres.getStatus();
36 PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, statuscode );
40 public static PolicyResponseWrapper wrapResponse (RestObject<String> rs) {
45 status = rs.getStatusCode();
47 PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, status );
51 public static <T> String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException {
53 String methodName = "convertPojoToString";
54 ObjectMapper mapper = new ObjectMapper();
55 String r_json_str = "";
58 r_json_str = mapper.writeValueAsString(t);
60 catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
61 logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json");
68 public static void main(String[] args) {
69 // TODO Auto-generated method stub