From 1cfb08779ea0e00be69e072a940b3063e049fe6b Mon Sep 17 00:00:00 2001 From: Ofir Sonsino Date: Wed, 31 Jan 2018 17:19:00 +0200 Subject: org.onap migration Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d Issue-ID: VID-86 Signed-off-by: Ofir Sonsino --- .../main/java/org/onap/vid/policy/PolicyUtil.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java (limited to 'vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java new file mode 100644 index 000000000..608352845 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java @@ -0,0 +1,71 @@ +package org.onap.vid.policy; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.glassfish.jersey.client.ClientResponse; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.policy.PolicyResponseWrapper; +import org.onap.vid.policy.PolicyUtil; +import org.onap.vid.policy.RestObject; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class PolicyUtil { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PolicyUtil.class); + + final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + public static PolicyResponseWrapper wrapResponse ( String body, int statusCode ) { + + PolicyResponseWrapper w = new PolicyResponseWrapper(); + w.setStatus (statusCode); + w.setEntity(body); + + return w; + } + + public static PolicyResponseWrapper wrapResponse (ClientResponse cres) { + String resp_str = ""; + if ( cres != null ) { + resp_str = cres.readEntity(String.class); + } + int statuscode = cres.getStatus(); + PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, statuscode ); + return (w); + } + + public static PolicyResponseWrapper wrapResponse (RestObject rs) { + String resp_str = ""; + int status = 0; + if ( rs != null ) { + resp_str = rs.get(); + status = rs.getStatusCode(); + } + PolicyResponseWrapper w = PolicyUtil.wrapResponse ( resp_str, status ); + return (w); + } + + public static String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException { + + String methodName = "convertPojoToString"; + ObjectMapper mapper = new ObjectMapper(); + String r_json_str = ""; + if ( t != null ) { + try { + r_json_str = mapper.writeValueAsString(t); + } + catch ( com.fasterxml.jackson.core.JsonProcessingException j ) { + logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json"); + } + } + return (r_json_str); + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + } +} -- cgit 1.2.3-korg