X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-pdp%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fpdp%2Fconcepts%2FPdpGroup.java;h=8f03e7d46a64719e566720f49e0a3adab9ab2063;hb=4415cacfa096f1d36e544d8c80280659471fda47;hp=4cb0ac54e19aa66740be917c0e16b865658d32cd;hpb=aca88111b78129371aebd6d2c9250a8abb9cc2ac;p=policy%2Fmodels.git 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 4cb0ac54e..8f03e7d46 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,7 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. + * Copyright (C) 2019-2020,2023 Nordix Foundation. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ package org.onap.policy.models.pdp.concepts; +import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -28,8 +29,8 @@ import java.util.Map; import java.util.stream.Collectors; import lombok.Data; import lombok.NoArgsConstructor; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.models.base.PfKey; @@ -45,6 +46,8 @@ import org.onap.policy.models.pdp.enums.PdpState; @Data @NoArgsConstructor public class PdpGroup implements PfNameVersion, Comparable { + private static final String SUBGROUP_FIELD = "pdpSubgroups"; + private String name; private String description; private PdpState pdpGroupState; @@ -66,7 +69,7 @@ public class PdpGroup implements PfNameVersion, Comparable { this.description = source.description; this.pdpGroupState = source.pdpGroupState; this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties)); - this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new); + this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new, new ArrayList<>(0)); } @Override @@ -77,21 +80,22 @@ public class PdpGroup implements PfNameVersion, Comparable { /** * 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() { - BeanValidationResult result = new BeanValidationResult("group", this); + public ValidationResult validatePapRest(boolean updateGroupFlow) { + var result = new BeanValidationResult("group", this); /* * Don't care about state, because we override it. Ok if description is null. */ result.validateNotNull("name", name); - result.validateNotNullList("pdpSubgroups", pdpSubgroups, PdpSubGroup::validatePapRest); + result.validateNotNullList(SUBGROUP_FIELD, pdpSubgroups, + (PdpSubGroup pdpSubGroup) -> pdpSubGroup.validatePapRest(updateGroupFlow)); if (pdpSubgroups != null && pdpSubgroups.isEmpty()) { - result.addResult(new ObjectValidationResult("pdpSubgroups", pdpSubgroups, ValidationStatus.INVALID, - "is empty")); + result.addResult(SUBGROUP_FIELD, pdpSubgroups, ValidationStatus.INVALID, "is empty"); } checkDuplicateSubgroups(result); @@ -116,17 +120,18 @@ public class PdpGroup implements PfNameVersion, Comparable { } // different sizes implies duplicates - result.addResult(new ObjectValidationResult("pdpSubgroups", pdpTypes, ValidationStatus.INVALID, - "duplicate subgroups")); + result.addResult(SUBGROUP_FIELD, pdpTypes, ValidationStatus.INVALID, "duplicate subgroups"); } @Override + @GsonJsonIgnore public String getVersion() { // We need to pass a version for keying in the database return PfKey.NULL_KEY_VERSION; } @Override + @GsonJsonIgnore public void setVersion(String version) { // Just ignore any version that is set }