Consolidate PolicyRestAdapter setup
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / adapter / PolicyRestAdapter.java
index edadf53..97e6e9e 100644 (file)
@@ -2,14 +2,14 @@
  * ============LICENSE_START=======================================================
  * ONAP-PAP-REST
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,10 +29,10 @@ import org.onap.policy.rest.jpa.OnapName;
 public class PolicyRestAdapter {
 
     /*
-     * 
+     *
      * Note : Make Sure if any variables are added in PolicyRestAdapter.java, add them to PolicyElasticData.java file
-     * 
-     * 
+     *
+     *
      */
 
     // Common
@@ -62,6 +62,7 @@ public class PolicyRestAdapter {
     private String finalPolicyPath;
     private String version;
     private String jsonBody;
+    private String uiJsonBody;
     private String apiflag;
     private String prevJsonBody;
     private Integer highestVersion;
@@ -129,14 +130,6 @@ public class PolicyRestAdapter {
     private String blackListEntryType;
     private String rawXacmlPolicy;
 
-    public String getRawXacmlPolicy() {
-        return rawXacmlPolicy;
-    }
-
-    public void setRawXacmlPolicy(String rawXacmlPolicy) {
-        this.rawXacmlPolicy = rawXacmlPolicy;
-    }
-
     // Rainy Day Decision
     private RainyDayParams rainyday;
     private Map<String, String> rainydayMap;
@@ -1145,4 +1138,71 @@ public class PolicyRestAdapter {
     public void setBlackListEntryType(String blackListEntryType) {
         this.blackListEntryType = blackListEntryType;
     }
+
+    public String getRawXacmlPolicy() {
+        return rawXacmlPolicy;
+    }
+
+    public void setRawXacmlPolicy(String rawXacmlPolicy) {
+        this.rawXacmlPolicy = rawXacmlPolicy;
+    }
+
+    public String getUiJsonBody() {
+        return uiJsonBody;
+    }
+
+    public void setUiJsonBody(String uiJsonBody) {
+        this.uiJsonBody = uiJsonBody;
+    }
+
+    public boolean setupUsingAttribute(String attributeId, String value) {
+        switch (attributeId) {
+            case "ONAPName":
+                this.setOnapName(value);
+                OnapName tempOnapName = new OnapName();
+                tempOnapName.setOnapName(value);
+                this.setOnapNameField(tempOnapName);
+                return true;
+            case "RiskType":
+                this.setRiskType(value);
+                return true;
+            case "RiskLevel":
+                this.setRiskLevel(value);
+                return true;
+            case "guard":
+                this.setGuard(value);
+                return true;
+            case "ConfigName":
+                this.setConfigName(value);
+                return true;
+            case "uuid":
+                this.setUuid(value);
+                return true;
+            case "location":
+                this.setLocation(value);
+                return true;
+            case "TTLDate":
+                if (!value.contains("NA")) {
+                    this.setTtlDate(PolicyRestAdapter.convertDate(value));
+                    return true;
+                }
+                return false;
+            default:
+                return false;
+        }
+    }
+
+    /**
+     * Function to convert date.
+     *
+     * @param dateTimeToLive input date value.
+     * @return
+     */
+    private static String convertDate(String dateTimeToLive) {
+        String formatDate = null;
+        if (dateTimeToLive.contains("-")) {
+            formatDate = dateTimeToLive.replace("-", "/");
+        }
+        return formatDate;
+    }
 }