Use lombok for errors pap, pdp, sim-dmaap, sim-pdp
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / concepts / DeploymentSubGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
4  *  Modifications Copyright (C) 2021 Nordix Foundation.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.pdp.concepts;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import lombok.Data;
27 import lombok.NoArgsConstructor;
28 import lombok.NonNull;
29 import org.onap.policy.common.parameters.BeanValidationResult;
30 import org.onap.policy.common.parameters.ValidationResult;
31 import org.onap.policy.models.base.PfUtils;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
33
34 /**
35  * A deployment (i.e., set of policies) for all PDPs of the same pdp type running within a
36  * particular domain.
37  */
38 @Data
39 @NoArgsConstructor
40 public class DeploymentSubGroup {
41
42     public enum Action {
43         POST,       // all listed policies are to be added
44         DELETE,     // all listed policies are to be deleted
45         PATCH       // update the deployment so that the policies match exactly
46     }
47
48     private String pdpType;
49     private Action action;
50     private List<ToscaConceptIdentifier> policies;
51
52     /**
53      * Constructs the object, making a deep copy from the source.
54      *
55      * @param source source from which to copy fields
56      */
57     public DeploymentSubGroup(@NonNull final DeploymentSubGroup source) {
58         this.pdpType = source.pdpType;
59         this.action = source.action;
60         this.policies = PfUtils.mapList(source.policies, ToscaConceptIdentifier::new, new ArrayList<>(0));
61     }
62
63     /**
64      * Validates that appropriate fields are populated for an incoming call to the PAP
65      * REST API.
66      *
67      * @return the validation result
68      */
69     public ValidationResult validatePapRest() {
70         var result = new BeanValidationResult("group", this);
71
72         result.validateNotNull("pdpType", pdpType);
73         result.validateNotNull("action", action);
74         result.validateNotNullList("policies", policies, ToscaConceptIdentifier::validatePapRest);
75
76         return result;
77     }
78 }