1a1fe228dc50375ae7c29414e780c5a41ef0af01
[policy/models.git] / models-pdp / src / main / java / org / onap / policy / models / pdp / concepts / DeploymentSubGroup.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.pdp.concepts;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import lombok.Data;
26 import lombok.NonNull;
27 import org.onap.policy.common.parameters.BeanValidationResult;
28 import org.onap.policy.common.parameters.ValidationResult;
29 import org.onap.policy.models.base.PfUtils;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
31
32 /**
33  * A deployment (i.e., set of policies) for all PDPs of the same pdp type running within a
34  * particular domain.
35  */
36 @Data
37 public class DeploymentSubGroup {
38
39     public enum Action {
40         POST,       // all listed policies are to be added
41         DELETE,     // all listed policies are to be deleted
42         PATCH       // update the deployment so that the policies match exactly
43     }
44
45     private String pdpType;
46     private Action action;
47     private List<ToscaPolicyIdentifier> policies;
48
49     /**
50      * Constructs the object.
51      */
52     public DeploymentSubGroup() {
53         super();
54     }
55
56     /**
57      * Constructs the object, making a deep copy from the source.
58      *
59      * @param source source from which to copy fields
60      */
61     public DeploymentSubGroup(@NonNull final DeploymentSubGroup source) {
62         this.pdpType = source.pdpType;
63         this.action = source.action;
64         this.policies = PfUtils.mapList(source.policies, ToscaPolicyIdentifier::new, new ArrayList<>(0));
65     }
66
67     /**
68      * Validates that appropriate fields are populated for an incoming call to the PAP
69      * REST API.
70      *
71      * @return the validation result
72      */
73     public ValidationResult validatePapRest() {
74         BeanValidationResult result = new BeanValidationResult("group", this);
75
76         result.validateNotNull("pdpType", pdpType);
77         result.validateNotNull("action", action);
78         result.validateNotNullList("policies", policies, ToscaPolicyIdentifier::validatePapRest);
79
80         return result;
81     }
82 }