X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Floop%2FLoopService.java;h=af1f58ba7b5fae2745cdb42ab9770f5a4cb287c6;hb=e916ac28ba46ff7cad64f1a3150b128ba4772c70;hp=953a59471c74dc7eb2c22dc5058eb8c60f84a8a7;hpb=8063862aeed5341f32cb6d95e212ed99e43e57c7;p=clamp.git diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index 953a5947..af1f58ba 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -24,14 +24,14 @@ package org.onap.clamp.loop; import com.google.gson.JsonObject; +import java.io.IOException; import java.util.List; import java.util.Set; import javax.persistence.EntityNotFoundException; -import org.apache.commons.lang3.RandomStringUtils; +import org.onap.clamp.clds.tosca.update.ToscaConverterWithDictionarySupport; import org.onap.clamp.loop.template.LoopTemplatesService; import org.onap.clamp.loop.template.PolicyModel; import org.onap.clamp.loop.template.PolicyModelsService; -import org.onap.clamp.policy.Policy; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.microservice.MicroServicePolicyService; import org.onap.clamp.policy.operational.OperationalPolicy; @@ -57,6 +57,9 @@ public class LoopService { @Autowired private LoopTemplatesService loopTemplateService; + @Autowired + private ToscaConverterWithDictionarySupport toscaConverter; + Loop saveOrUpdateLoop(Loop loop) { return loopsRepository.save(loop); } @@ -76,12 +79,13 @@ public class LoopService { /** * Creates a Loop Instance from Loop Template Name. * - * @param loopName Name of the Loop to be created + * @param loopName Name of the Loop to be created * @param templateName Loop Template to used for Loop * @return Loop Instance */ public Loop createLoopFromTemplate(String loopName, String templateName) { - return loopsRepository.save(new Loop(loopName,loopTemplateService.getLoopTemplate(templateName))); + return loopsRepository + .save(new Loop(loopName, loopTemplateService.getLoopTemplate(templateName), toscaConverter)); } /** @@ -104,30 +108,29 @@ public class LoopService { /** * This method add an operational policy to a loop instance. + * This creates an operational policy from the policy model info and not the loop element model * - * @param loopName The loop name - * @param policyType The policy model type + * @param loopName The loop name + * @param policyType The policy model type * @param policyVersion The policy model version * @return The loop modified */ - Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) { + Loop addOperationalPolicy(String loopName, String policyType, String policyVersion) throws IOException { Loop loop = getLoop(loopName); PolicyModel policyModel = policyModelsService.getPolicyModel(policyType, policyVersion); if (policyModel == null) { return null; } loop.addOperationalPolicy( - new OperationalPolicy(Policy.generatePolicyName("OPERATIONAL", loop.getModelService().getName(), - loop.getModelService().getVersion(), RandomStringUtils.randomAlphanumeric(3), - RandomStringUtils.randomAlphanumeric(4)), loop, null, policyModel, null, null, null)); + new OperationalPolicy(loop, loop.getModelService(), policyModel, toscaConverter)); return loopsRepository.saveAndFlush(loop); } /** * This method remove an operational policy to a loop instance. * - * @param loopName The loop name - * @param policyType The policy model type + * @param loopName The loop name + * @param policyType The policy model type * @param policyVersion The policy model version * @return The loop modified */ @@ -138,8 +141,8 @@ public class LoopService { return null; } for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { - if (opPolicy.getPolicyModel().getPolicyModelType().equals(policyType) && - opPolicy.getPolicyModel().getVersion().equals(policyVersion)) { + if (opPolicy.getPolicyModel().getPolicyModelType().equals(policyType) + && opPolicy.getPolicyModel().getVersion().equals(policyVersion)) { loop.removeOperationalPolicy(opPolicy); break; } @@ -176,20 +179,5 @@ public class LoopService { return loopsRepository.findById(loopName) .orElseThrow(() -> new EntityNotFoundException("Couldn't find closed loop named: " + loopName)); } - - /** - * Api to refresh the Operational Policy UI window. - * - * @param loopName The loop Name - * @return The refreshed loop object - */ - public Loop refreshOpPolicyJsonRepresentation(String loopName) { - Loop loop = findClosedLoopByName(loopName); - Set policyList = loop.getOperationalPolicies(); - for (OperationalPolicy policy : policyList) { - policy.updateJsonRepresentation(); - } - loop.setOperationalPolicies(policyList); - return loopsRepository.save(loop); - } } +