diff options
author | 2018-02-01 12:22:30 -0500 | |
---|---|---|
committer | 2018-02-01 12:37:59 -0500 | |
commit | 06f456d8d06840a21f48531b0bd35b1a429b10f9 (patch) | |
tree | a72db2dbec1a520589e98809d03424cf81c6aab1 /PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java | |
parent | 066fc4529f36d210a4a4700e8dbfd2cb42f4dc66 (diff) |
Reduce technical debt and add JUnit
* Addressed some very simple cyclic complexity
* Added simple JUnit tests and finished others
* Removed useless assignments
Issue-ID: POLICY-477
Change-Id: Ic919bbf78ad2732a430c32f1feb3c88678be710d
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java')
-rw-r--r-- | PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java index 447e7cb26..6772f5a9b 100644 --- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java +++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java @@ -32,34 +32,39 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class NotificationUnMarshal { + private NotificationUnMarshal() { + // Empty constructor + } + public static StdPDPNotification notificationJSON(String json) throws IOException{ ObjectMapper mapper = new ObjectMapper(); StdPDPNotification notification = mapper.readValue(json, StdPDPNotification.class); - if(notification!=null&¬ification.getLoadedPolicies()!=null){ - Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>(); - for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){ - StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy; - if(notification.getRemovedPolicies()!=null){ - Boolean updated = false; - for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ - String regex = ".(\\d)*.xml"; - if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){ - updated = true; - break; - } - } - if(updated){ - stdLoadedPolicy.setUpdateType(UpdateType.UPDATE); - }else{ - stdLoadedPolicy.setUpdateType(UpdateType.NEW); - } - }else{ - stdLoadedPolicy.setUpdateType(UpdateType.NEW); - } - stdLoadedPolicies.add(stdLoadedPolicy); - } - notification.setLoadedPolicies(stdLoadedPolicies); + if(notification == null || notification.getLoadedPolicies() == null){ + return notification; } + Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>(); + for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){ + StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy; + if(notification.getRemovedPolicies()!=null){ + Boolean updated = false; + for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){ + String regex = ".(\\d)*.xml"; + if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){ + updated = true; + break; + } + } + if(updated){ + stdLoadedPolicy.setUpdateType(UpdateType.UPDATE); + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + }else{ + stdLoadedPolicy.setUpdateType(UpdateType.NEW); + } + stdLoadedPolicies.add(stdLoadedPolicy); + } + notification.setLoadedPolicies(stdLoadedPolicies); return notification; } } |