Fix bug in operational policy
[clamp.git] / src / main / java / org / onap / clamp / loop / LoopController.java
index 7d41e48..7ee088c 100644 (file)
@@ -26,10 +26,8 @@ package org.onap.clamp.loop;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.reflect.TypeToken;
-
 import java.lang.reflect.Type;
 import java.util.List;
-
 import org.onap.clamp.clds.util.JsonUtils;
 import org.onap.clamp.policy.microservice.MicroServicePolicy;
 import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -42,6 +40,7 @@ public class LoopController {
     private final LoopService loopService;
     private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
     }.getType();
+
     private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
     }.getType();
 
@@ -50,6 +49,10 @@ public class LoopController {
         this.loopService = loopService;
     }
 
+    public Loop createLoop(String loopName, String templateName) {
+        return loopService.createLoopFromTemplate(loopName, templateName);
+    }
+
     public List<String> getLoopNames() {
         return loopService.getClosedLoopNames();
     }
@@ -61,40 +64,35 @@ public class LoopController {
     /**
      * Update the Operational Policy properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param operationalPoliciesJson
-     *        The new Operational Policy properties
+     * @param loopName                The loop name
+     * @param operationalPoliciesJson The new Operational Policy properties
      * @return The updated loop
      */
     public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) {
         List<OperationalPolicy> operationalPolicies = JsonUtils.GSON.fromJson(operationalPoliciesJson,
-            OPERATIONAL_POLICY_TYPE);
+                OPERATIONAL_POLICY_TYPE);
         return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies);
     }
 
     /**
-     * Update the whole array of MicroService policies properties
+     * Update the whole array of MicroService policies properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param microServicePoliciesJson
-     *        The array of all MicroService policies properties
+     * @param loopName                 The loop name
+     * @param microServicePoliciesJson The array of all MicroService policies
+     *                                 properties
      * @return The updated loop
      */
     public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) {
         List<MicroServicePolicy> microservicePolicies = JsonUtils.GSON.fromJson(microServicePoliciesJson,
-            MICROSERVICE_POLICY_TYPE);
+                MICROSERVICE_POLICY_TYPE);
         return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies);
     }
 
     /**
-     * Update the global properties
+     * Update the global properties.
      *
-     * @param loopName
-     *        The loop name
-     * @param globalProperties
-     *        The updated global properties
+     * @param loopName         The loop name
+     * @param globalProperties The updated global properties
      * @return The updated loop
      */
     public Loop updateGlobalPropertiesJson(String loopName, JsonObject globalProperties) {
@@ -102,12 +100,31 @@ public class LoopController {
     }
 
     /**
-     * Update one MicroService policy properties
+     * This method add an operational policy to a loop instance.
+     *
+     * @param loopName      The loop name
+     * @param policyType    The policy model type
+     * @param policyVersion The policy model  version
+     * @return The loop modified
+     */
+    public Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) {
+        return loopService.addOperationalPolicy(loopName, policyType, policyVersion);
+    }
+
+    /**
+     * This method deletes the loop.
      *
-     * @param loopName
-     *        The loop name
-     * @param newMicroservicePolicy
-     *        The new MicroService policy properties
+     * @param loopName The loop Name
+     */
+    public void deleteLoop(String loopName) {
+        loopService.deleteLoop(loopName);
+    }
+
+    /**
+     * Update one MicroService policy properties.
+     *
+     * @param loopName              The loop name
+     * @param newMicroservicePolicy The new MicroService policy properties
      * @return The updated MicroService policy
      */
     public MicroServicePolicy updateMicroservicePolicy(String loopName, MicroServicePolicy newMicroservicePolicy) {
@@ -115,14 +132,23 @@ public class LoopController {
     }
 
     /**
-     * Get the SVG representation of the loop
+     * Get the SVG representation of the loop.
      *
-     * @param loopName
-     *        The loop name
+     * @param loopName The loop name
      * @return The SVG representation
      */
-    public String getSVGRepresentation(String loopName) {
+    public String getSvgRepresentation(String loopName) {
         Loop loop = loopService.getLoop(loopName);
         return loop != null ? loop.getSvgRepresentation() : null;
     }
+
+    /**
+     * Refresh the Operational Policy Json representation of the loop.
+     *
+     * @param loopName The loop name
+     * @return The refreshed Loop
+     */
+    public Loop refreshOpPolicyJsonRepresentation(String loopName) {
+        return loopService.refreshOpPolicyJsonRepresentation(loopName);
+    }
 }