diff options
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")); } } |