X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2FLoopController.java;h=d230eb976b16c748448d536c3b26d7d030891a2d;hb=723de7f63f0951d0cfe7a23956cf9d00128809b1;hp=a02fa9333a624d1033c8f98ad09d4ae2f8bc70e5;hpb=da09b9285c8f4ffe6bfd563285580ccce70cdd20;p=clamp.git diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java index a02fa933..d230eb97 100644 --- a/src/main/java/org/onap/clamp/loop/LoopController.java +++ b/src/main/java/org/onap/clamp/loop/LoopController.java @@ -24,13 +24,11 @@ package org.onap.clamp.loop; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; - +import java.io.IOException; 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; @@ -41,16 +39,19 @@ import org.springframework.stereotype.Controller; public class LoopController { private final LoopService loopService; - private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken>() { - }.getType(); - private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken>() { - }.getType(); + private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken>() {}.getType(); + + private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken>() {}.getType(); @Autowired public LoopController(LoopService loopService) { this.loopService = loopService; } + public Loop createLoop(String loopName, String templateName) { + return loopService.createLoopFromTemplate(loopName, templateName); + } + public List getLoopNames() { return loopService.getClosedLoopNames(); } @@ -61,31 +62,35 @@ public class LoopController { /** * Update the Operational Policy properties. - * @param loopName The loop name + * + * @param loopName The loop name * @param operationalPoliciesJson The new Operational Policy properties * @return The updated loop */ public Loop updateOperationalPolicies(String loopName, JsonArray operationalPoliciesJson) { - List operationalPolicies = JsonUtils.GSON - .fromJson(operationalPoliciesJson, OPERATIONAL_POLICY_TYPE); + List operationalPolicies = JsonUtils.GSON_JPA_MODEL.fromJson(operationalPoliciesJson, + OPERATIONAL_POLICY_TYPE); return loopService.updateAndSaveOperationalPolicies(loopName, operationalPolicies); } /** - * Update the whole array of MicroService policies properties - * @param loopName The loop name - * @param microServicePoliciesJson The array of all 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 * @return The updated loop */ public Loop updateMicroservicePolicies(String loopName, JsonArray microServicePoliciesJson) { - List microservicePolicies = JsonUtils.GSON - .fromJson(microServicePoliciesJson, MICROSERVICE_POLICY_TYPE); + List microservicePolicies = JsonUtils.GSON_JPA_MODEL.fromJson(microServicePoliciesJson, + MICROSERVICE_POLICY_TYPE); return loopService.updateAndSaveMicroservicePolicies(loopName, microservicePolicies); } /** - * Update the global properties - * @param loopName The loop name + * Update the global properties. + * + * @param loopName The loop name * @param globalProperties The updated global properties * @return The updated loop */ @@ -94,8 +99,42 @@ public class LoopController { } /** - * Update one MicroService policy properties - * @param loopName The loop name + * 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) throws IOException { + return loopService.addOperationalPolicy(loopName, policyType, policyVersion); + } + + /** + * This method remove 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 removeOperationalPolicy(String loopName, String policyType, String policyVersion) { + return loopService.removeOperationalPolicy(loopName, policyType, policyVersion); + } + + /** + * This method deletes the loop. + * + * @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 */ @@ -104,12 +143,23 @@ public class LoopController { } /** - * Get the SVG representation of the loop + * Get the SVG representation of the loop. + * * @param loopName The loop name * @return The SVG representation */ - public String getSVGRepresentation(String loopName) { - return loopService.getClosedLoopModelSVG(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); } }