aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java
diff options
context:
space:
mode:
authorOfir Sonsino <os0695@att.com>2018-01-31 17:19:00 +0200
committerOfir Sonsino <os0695@att.com>2018-01-31 17:19:00 +0200
commit1cfb08779ea0e00be69e072a940b3063e049fe6b (patch)
tree6602a900387c8393ed0dcd81c0539381632903c6 /vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java
parent2f20b001b9243e0f8b44aecc768ec265fd538732 (diff)
org.onap migration
Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d Issue-ID: VID-86 Signed-off-by: Ofir Sonsino <os0695@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/policy/PolicyUtil.java71
1 files changed, 71 insertions, 0 deletions
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<String> 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 <T> 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
+ }
+}