Changed identifiers to concept identifiers
[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  *  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.NonNull;
28 import org.onap.policy.common.parameters.BeanValidationResult;
29 import org.onap.policy.common.parameters.ValidationResult;
30 import org.onap.policy.models.base.PfUtils;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
32
33 /**
34  * A deployment (i.e., set of policies) for all PDPs of the same pdp type running within a
35  * particular domain.
36  */
37 @Data
38 public class DeploymentSubGroup {
39
40     public enum Action {
41         POST,       // all listed policies are to be added
42         DELETE,     // all listed policies are to be deleted
43         PATCH       // update the deployment so that the policies match exactly
44     }
45
46     private String pdpType;
47     private Action action;
48     private List<ToscaConceptIdentifier> policies;
49
50     /**
51      * Constructs the object.
52      */
53     public DeploymentSubGroup() {
54         super();
55     }
56
57     /**
58      * Constructs the object, making a deep copy from the source.
59      *
60      * @param source source from which to copy fields
61      */
62     public DeploymentSubGroup(@NonNull final DeploymentSubGroup source) {
63         this.pdpType = source.pdpType;
64         this.action = source.action;
65         this.policies = PfUtils.mapList(source.policies, ToscaConceptIdentifier::new, new ArrayList<>(0));
66     }
67
68     /**
69      * Validates that appropriate fields are populated for an incoming call to the PAP
70      * REST API.
71      *
72      * @return the validation result
73      */
74     public ValidationResult validatePapRest() {
75         BeanValidationResult result = new BeanValidationResult("group", this);
76
77         result.validateNotNull("pdpType", pdpType);
78         result.validateNotNull("action", action);
79         result.validateNotNullList("policies", policies, ToscaConceptIdentifier::validatePapRest);
80
81         return result;
82     }
83 }