diff options
author | a.sreekumar <ajith.sreekumar@est.tech> | 2020-01-21 17:07:50 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@est.tech> | 2020-01-22 15:11:27 +0000 |
commit | 2a7cbf33a8b53bb83d43bf1adca7e6a8658cb262 (patch) | |
tree | 73d5216fa7a752ace2b26769251eaf7032293e04 /models-pdp/src/main/java/org | |
parent | af4d20eb737dc7670e811d5272416eec06da1960 (diff) |
Handling supported policy type during PdpGroup Update
Change-Id: I469125c232af9d78a55c3dfa71cb701cb3864015
Issue-ID: POLICY-2023
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'models-pdp/src/main/java/org')
3 files changed, 34 insertions, 19 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java index 6d5f804f8..b6886bef1 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -81,9 +81,10 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> { /** * Validates that appropriate fields are populated for an incoming call to the PAP REST API. * + * @param updateGroupFlow if the operation is pdp group update * @return the validation result */ - public ValidationResult validatePapRest() { + public ValidationResult validatePapRest(boolean updateGroupFlow) { BeanValidationResult result = new BeanValidationResult("group", this); /* @@ -91,7 +92,8 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> { */ result.validateNotNull("name", name); - result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, PdpSubGroup::validatePapRest); + result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, + (PdpSubGroup pdpSubGroup) -> pdpSubGroup.validatePapRest(updateGroupFlow)); if (pdpSubgroups != null && pdpSubgroups.isEmpty()) { result.addResult(new ObjectValidationResult(SUBGROUP_FIELD, pdpSubgroups, ValidationStatus.INVALID, diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java index 06194eaba..269130b07 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroups.java @@ -3,6 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,20 +67,28 @@ public class PdpGroups { * @return the validation result */ public ValidationResult validatePapRest() { - BeanValidationResult result = new BeanValidationResult(GROUPS_FIELD, this); - - result.validateNotNullList(GROUPS_FIELD, groups, PdpGroup::validatePapRest); + ValidationResult result = new BeanValidationResult(GROUPS_FIELD, this); + ((BeanValidationResult) result).validateNotNullList(GROUPS_FIELD, groups, + (PdpGroup pdpGroup) -> pdpGroup.validatePapRest(false)); if (!result.isValid()) { return result; } // verify that the same group doesn't appear more than once + return checkForDuplicateGroups(result); + } + + /** + * Validates that there are no duplicate PdpGroups with the same name. + * + * @param result the validation result + * @return the validation result + */ + public ValidationResult checkForDuplicateGroups(ValidationResult result) { List<String> names = groups.stream().map(PdpGroup::getName).collect(Collectors.toList()); - if (groups.size() == new HashSet<>(names).size()) { - return result; + if (groups.size() != new HashSet<>(names).size()) { + result = new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names"); } - - // different sizes implies duplicates - return new ObjectValidationResult(GROUPS_FIELD, names, ValidationStatus.INVALID, "duplicate group names"); + return result; } } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java index 236cc858a..e3e33b454 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpSubGroup.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -78,19 +78,23 @@ public class PdpSubGroup { * Validates that appropriate fields are populated for an incoming call to the PAP * REST API. * + * @param updateGroupFlow if the operation is pdp group update * @return the validation result */ - public ValidationResult validatePapRest() { + public ValidationResult validatePapRest(boolean updateGroupFlow) { BeanValidationResult result = new BeanValidationResult("group", this); result.validateNotNull("pdpType", pdpType); - result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes, - ToscaPolicyTypeIdentifier::validatePapRest); - result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest); + // When doing PdpGroup Update operation, supported policy types and policies doesn't have to be validated. + if (!updateGroupFlow) { + result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest); + result.validateNotNullList("supportedPolicyTypes", supportedPolicyTypes, + ToscaPolicyTypeIdentifier::validatePapRest); - if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) { - result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes, - ValidationStatus.INVALID, "empty list")); + if (supportedPolicyTypes != null && supportedPolicyTypes.isEmpty()) { + result.addResult(new ObjectValidationResult("supportedPolicyTypes", supportedPolicyTypes, + ValidationStatus.INVALID, "empty list")); + } } if (desiredInstanceCount <= 0) { |