2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.pdp.concepts;
23 import java.util.HashSet;
24 import java.util.List;
28 import lombok.ToString;
29 import org.onap.policy.common.parameters.BeanValidationResult;
30 import org.onap.policy.common.parameters.ObjectValidationResult;
31 import org.onap.policy.common.parameters.ValidationResult;
32 import org.onap.policy.common.parameters.ValidationStatus;
35 * Batch modification of a deployment groups via the PDP Group deployment REST API.
40 public class DeploymentGroups {
41 private static final String GROUPS_FIELD = "groups";
43 private List<DeploymentGroup> groups;
46 * Validates that appropriate fields are populated for an incoming call to the PAP
49 * @return the validation result
51 public ValidationResult validatePapRest() {
52 var result = new BeanValidationResult(GROUPS_FIELD, this);
54 result.validateNotNullList(GROUPS_FIELD, groups, DeploymentGroup::validatePapRest);
55 if (!result.isValid()) {
59 // verify that the same group doesn't appear more than once
60 Set<String> sawGroup = new HashSet<>();
61 for (DeploymentGroup group : groups) {
62 String name = group.getName();
63 if (sawGroup.contains(name)) {
64 return new ObjectValidationResult(GROUPS_FIELD, name, ValidationStatus.INVALID, "duplicate group name");