From 8bad2ad828fad2f5f99a9a291ca0f5c51b62e4ca Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Wed, 30 May 2018 09:48:40 +0100 Subject: Fixing Sonar bugs and code smells Change-Id: I661cd409d01320fe11a29b7ea72b9e8f70e72a6c Issue-ID: POLICY-856 Signed-off-by: waqas.ikram --- .../model/policymodel/concepts/AxPolicies.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'model/policy-model/src') diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java index 248e4fdae..1937edac0 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicies.java @@ -225,19 +225,15 @@ public class AxPolicies extends AxConcept implements AxConceptGetter { "policyMap may not be empty")); } else { for (final Entry policyEntry : policyMap.entrySet()) { - if (policyEntry.getKey().equals(AxArtifactKey.getNullKey())) { + final AxArtifactKey entryKey = policyEntry.getKey(); + if (entryKey.equals(AxArtifactKey.getNullKey())) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "key on policy entry " + policyEntry.getKey() + " may not be the null key")); + "key on policy entry " + entryKey + " may not be the null key")); } else if (policyEntry.getValue() == null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "value on policy entry " + policyEntry.getKey() + " may not be null")); + "value on policy entry " + entryKey + " may not be null")); } else { - if (!policyEntry.getKey().equals(policyEntry.getValue().getKey())) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), - ValidationResult.INVALID, "key on policy entry key " + policyEntry.getKey() - + " does not equal policy value key " + policyEntry.getValue().getKey())); - } - + validate(result, policyEntry, entryKey); result = policyEntry.getValue().validate(result); } } @@ -246,6 +242,15 @@ public class AxPolicies extends AxConcept implements AxConceptGetter { return result; } + private void validate(final AxValidationResult result, final Entry policyEntry, + final AxArtifactKey entryKey) { + if (!entryKey.equals(policyEntry.getValue().getKey())) { + result.addValidationMessage( + new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key on policy entry key " + + entryKey + " does not equal policy value key " + policyEntry.getValue().getKey())); + } + } + /* * (non-Javadoc) * -- cgit 1.2.3-korg