Add refresh op policy json api 19/100019/2
authorxuegao <xg353y@intl.att.com>
Mon, 6 Jan 2020 12:15:05 +0000 (13:15 +0100)
committerxuegao <xg353y@intl.att.com>
Mon, 6 Jan 2020 15:12:14 +0000 (16:12 +0100)
Add the new api to refresh the operational policy json representation
values.

Issue-ID: CLAMP-585
Change-Id: I8c494f8d5f7ee8672f054444c368fdb396fb208f
Signed-off-by: xuegao <xg353y@intl.att.com>
src/main/java/org/onap/clamp/loop/LoopController.java
src/main/java/org/onap/clamp/loop/LoopService.java
src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
src/main/resources/clds/camel/rest/clamp-api-v2.xml
src/main/resources/clds/camel/routes/loop-flows.xml

index 72726fa..64874a3 100644 (file)
@@ -117,4 +117,14 @@ public class LoopController {
         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);
+    }
 }
index d1ab0e3..303ae68 100644 (file)
@@ -111,4 +111,14 @@ public class LoopService {
         return loopsRepository.findById(loopName)
             .orElseThrow(() -> new EntityNotFoundException("Couldn't find closed loop named: " + loopName));
     }
+
+    public Loop refreshOpPolicyJsonRepresentation(String loopName) {
+        Loop loop = findClosedLoopByName(loopName);
+        Set<OperationalPolicy> policyList = loop.getOperationalPolicies();
+        for (OperationalPolicy policy : policyList) {
+            policy.updateJsonRepresentation();
+        }
+        loop.setOperationalPolicies(policyList);
+        return loopsRepository.save(loop);
+    }
 }
index 1411269..486210e 100644 (file)
@@ -247,4 +247,13 @@ public class OperationalPolicy implements Serializable, Policy {
         return result;
     }
 
+    public void updateJsonRepresentation () {
+        try {
+            this.jsonRepresentation = OperationalPolicyRepresentationBuilder
+                    .generateOperationalPolicySchema(loop.getModelService());
+        } catch (JsonSyntaxException | IOException | NullPointerException e) {
+            logger.error("Unable to generate the operational policy Schema ... ", e);
+            this.jsonRepresentation = new JsonObject();
+        }
+    }
 }
index cf99625..a0a3eb1 100644 (file)
                                </doTry>
                        </route>
                </put>
+               <put
+                       uri="/v2/loop/refreshOpPolicyJsonSchema/{loopName}"
+                       outType="org.onap.clamp.loop.Loop"
+                       produces="application/json">
+                       <route>
+                               <removeHeaders
+                                       pattern="*"
+                                       excludePattern="loopName" />
+                               <doTry>
+                                       <log
+                                               loggingLevel="INFO"
+                                               message="Refresh Operational Policy UI for loop: ${header.loopName}" />
+                                       <to
+                                               uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'REFRESH OP Policy UI request')" />
+                                       <to
+                                               uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+                                       <to uri="direct:load-loop" />
+                                       <to
+                                               uri="bean:org.onap.clamp.loop.LoopController?method=refreshOpPolicyJsonRepresentation(${header.loopName})" />
+                                       <log
+                                               loggingLevel="INFO"
+                                               message="REFRESH request successfully executed for loop: ${header.loopName}" />
+                                       <to
+                                               uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH request successfully executed','INFO',${exchangeProperty[loopObject]})" />
+                                       <to
+                                               uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
+                                       <doCatch>
+                                               <exception>java.lang.Exception</exception>
+                                               <handled>
+                                                       <constant>false</constant>
+                                               </handled>
+                                               <to
+                                                       uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" />
+                                               <log
+                                                       loggingLevel="ERROR"
+                                                       message="REFRESH request failed for loop: ${header.loopName}" />
+                                               <to
+                                                       uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('REFRESH request failed, Error reported: ${exception} - Body: ${exception.responseBody}','ERROR',${exchangeProperty[loopObject]})" />
+                                       </doCatch>
+                               </doTry>
+                       </route>
+               </put>
                <put
                        uri="/v2/loop/undeploy/{loopName}"
                        outType="org.onap.clamp.loop.Loop"
index 036e8ef..57d32f0 100644 (file)
@@ -17,7 +17,6 @@
                        <stop />
                </when>
        </route>
-
        <route id="update-policy-status-for-loop">
                <from uri="direct:update-policy-status-for-loop" />
                <setProperty propertyName="policyComponent">