2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.pdp.concepts;
24 import java.util.HashSet;
25 import java.util.LinkedHashMap;
26 import java.util.List;
30 import lombok.NoArgsConstructor;
31 import org.onap.policy.common.parameters.BeanValidationResult;
32 import org.onap.policy.common.parameters.ObjectValidationResult;
33 import org.onap.policy.common.parameters.ValidationResult;
34 import org.onap.policy.common.parameters.ValidationStatus;
35 import org.onap.policy.models.base.PfNameVersion;
36 import org.onap.policy.models.base.PfUtils;
37 import org.onap.policy.models.pdp.enums.PdpState;
40 * Class to represent a PDPGroup, which groups multiple PDPSubGroup entities together for
41 * a particular domain.
43 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
47 public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> {
49 * In the future, we'll eliminate the "version" field. Until then, the version of
50 * every group should always be this fixed value.
52 public static final String VERSION = "1.0.0";
55 private String version;
56 private String description;
57 private PdpState pdpGroupState;
58 private Map<String, String> properties;
59 private List<PdpSubGroup> pdpSubgroups;
62 * Note: removed "@NotNull" annotation from the constructor argument, because it
63 * cannot be covered by a junit test, as the superclass does the check and throws an
68 * Constructs the object, making a deep copy from the source.
70 * @param source source from which to copy fields
72 public PdpGroup(PdpGroup source) {
73 this.name = source.name;
74 this.version = source.version;
75 this.description = source.description;
76 this.pdpGroupState = source.pdpGroupState;
77 this.properties = (source.properties == null ? null : new LinkedHashMap<>(source.properties));
78 this.pdpSubgroups = PfUtils.mapList(source.pdpSubgroups, PdpSubGroup::new);
82 public int compareTo(final PdpGroup other) {
83 return compareNameVersion(this, other);
87 * Validates that appropriate fields are populated for an incoming call to the PAP
90 * @return the validation result
92 public ValidationResult validatePapRest() {
93 BeanValidationResult result = new BeanValidationResult("group", this);
96 * Don't care about version or state, because we override them. Ok if description
100 result.validateNotNull("name", name);
101 result.validateNotNullList("pdpSubgroups", pdpSubgroups, PdpSubGroup::validatePapRest);
103 checkDuplicateSubgroups(result);
109 * Checks for duplicate subgroups.
111 * @param result where to place validation results
113 private void checkDuplicateSubgroups(BeanValidationResult result) {
114 if (pdpSubgroups == null) {
118 Set<String> set = new HashSet<>();
120 for (PdpSubGroup subgrp : pdpSubgroups) {
121 if (subgrp == null) {
125 String pdpType = subgrp.getPdpType();
126 if (pdpType == null) {
130 if (!set.add(pdpType)) {
131 result.addResult(new ObjectValidationResult("subgroups", pdpType, ValidationStatus.INVALID,
132 "duplicate subgroup"));