diff options
author | 2019-04-23 13:27:55 -0400 | |
---|---|---|
committer | 2019-04-24 13:07:50 -0400 | |
commit | cccfb11b59becaaf86adc4c88600bd70f2519b0d (patch) | |
tree | fbab9aabd089f0943a5bdbfd5a97e1fa80e674c4 /main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java | |
parent | a6cb1f27c8fe26b02abbd6a3fcf876ec306e6a5a (diff) |
Validate supported types3.0.2-ONAP
When a group is created, PAP should verify that the "supported types"
exist in the DB.
Address potential sonar issue.
Address potential sonar issue in similar block of code.
Change-Id: Ib830550bc37d4ebe42c8782f3f874e463f3f51c2
Issue-ID: POLICY-1688
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java index ee66b35c..fa721054 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeployProvider.java @@ -251,6 +251,7 @@ public class PdpGroupDeployProvider extends ProviderBase { BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp); + result.addResult(validateSupportedTypes(data, subgrp)); result.addResult(validatePolicies(data, subgrp)); return result; @@ -345,32 +346,46 @@ public class PdpGroupDeployProvider extends ProviderBase { } /** - * Performs additional validations of the policies within a subgroup. + * Performs additional validations of the supported policy types within a subgroup. * * @param data session data * @param subgrp the subgroup to be validated * @param result the validation result * @throws PfModelException if an error occurred */ - private ValidationResult validatePolicies(SessionData data, PdpSubGroup subgrp) throws PfModelException { + private ValidationResult validateSupportedTypes(SessionData data, PdpSubGroup subgrp) throws PfModelException { BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp); - for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) { - try { - ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident)); + for (ToscaPolicyTypeIdentifier type : subgrp.getSupportedPolicyTypes()) { + if (data.getPolicyType(type) == null) { + result.addResult(new ObjectValidationResult("policy type", type, ValidationStatus.INVALID, + "unknown policy type")); + } + } - if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) { - result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID, - "not a supported policy for the subgroup")); - } + return result; + } - } catch (PfModelException e) { - if (e.getErrorResponse().getResponseCode() != Status.NOT_FOUND) { - throw e; - } + /** + * Performs additional validations of the policies within a subgroup. + * + * @param data session data + * @param subgrp the subgroup to be validated + * @param result the validation result + * @throws PfModelException if an error occurred + */ + private ValidationResult validatePolicies(SessionData data, PdpSubGroup subgrp) throws PfModelException { + BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp); + for (ToscaPolicyIdentifier ident : subgrp.getPolicies()) { + ToscaPolicy policy = data.getPolicy(new ToscaPolicyIdentifierOptVersion(ident)); + if (policy == null) { result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID, "unknown policy")); + + } else if (!subgrp.getSupportedPolicyTypes().contains(policy.getTypeIdentifier())) { + result.addResult(new ObjectValidationResult("policy", ident, ValidationStatus.INVALID, + "not a supported policy for the subgroup")); } } |