diff options
author | xuegao <xg353y@intl.att.com> | 2020-01-06 13:15:05 +0100 |
---|---|---|
committer | xuegao <xg353y@intl.att.com> | 2020-01-06 16:12:14 +0100 |
commit | bcbc25bbb78876db27fc326aadf89086200c3c76 (patch) | |
tree | 841b0a81993274ca10933ecb72774ade33082d6c /src/main/java | |
parent | c488fed6bb0d06acad9aefda54e77c5c687eb941 (diff) |
Add refresh op policy json api
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>
Diffstat (limited to 'src/main/java')
3 files changed, 29 insertions, 0 deletions
diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java index 72726fa3f..64874a32d 100644 --- a/src/main/java/org/onap/clamp/loop/LoopController.java +++ b/src/main/java/org/onap/clamp/loop/LoopController.java @@ -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); + } } diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java index d1ab0e396..303ae683a 100644 --- a/src/main/java/org/onap/clamp/loop/LoopService.java +++ b/src/main/java/org/onap/clamp/loop/LoopService.java @@ -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); + } } diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java index 14112694e..486210ea9 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java @@ -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(); + } + } } |