Unit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / ONAP-REST / src / main / java / org / onap / policy / rest / adapter / PolicyRestAdapter.java
index 0a3f46c..e7879a8 100644 (file)
@@ -23,7 +23,9 @@ package org.onap.policy.rest.adapter;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.persistence.EntityManagerFactory;
+
 import org.onap.policy.rest.jpa.OnapName;
 
 public class PolicyRestAdapter {
@@ -1154,4 +1156,55 @@ public class PolicyRestAdapter {
     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.setName(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;
+    }
 }