Add NSS libraries to images
[policy/xacml-pdp.git] / applications / common / src / main / java / org / onap / policy / pdp / xacml / application / common / XacmlUpdatePolicyUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2019 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pdp.xacml.application.common;
24
25 import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType;
26 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory;
27 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
28 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
29
30 public class XacmlUpdatePolicyUtils {
31
32     private XacmlUpdatePolicyUtils() {
33         super();
34     }
35
36     /**
37      * This method updates a root PolicySetType by adding in a PolicyType as a reference.
38      *
39      * @param rootPolicy Root PolicySet being updated
40      * @param referencedPolicies A list of PolicyType being added as a references
41      * @return the rootPolicy PolicySet object
42      */
43     public static PolicySetType updateXacmlRootPolicy(PolicySetType rootPolicy, PolicyType... referencedPolicies) {
44         ObjectFactory factory = new ObjectFactory();
45         //
46         // Iterate each policy
47         //
48         for (PolicyType referencedPolicy : referencedPolicies) {
49             IdReferenceType reference = new IdReferenceType();
50             reference.setValue(referencedPolicy.getPolicyId());
51             //
52             // Add it in
53             //
54             rootPolicy.getPolicySetOrPolicyOrPolicySetIdReference().add(factory.createPolicySetIdReference(reference));
55         }
56         //
57         // Return the updated object
58         //
59         return rootPolicy;
60     }
61
62     /**
63      * This method updates a root PolicySetType by adding in a PolicyType as a reference.
64      *
65      * @param rootPolicy Root PolicySet being updated
66      * @param referencedPolicySets A list of PolicySetType being added as a references
67      * @return the rootPolicy PolicySet object
68      */
69     public static PolicySetType updateXacmlRootPolicy(PolicySetType rootPolicy, PolicySetType... referencedPolicySets) {
70         ObjectFactory factory = new ObjectFactory();
71         //
72         // Iterate each policy
73         //
74         for (PolicySetType referencedPolicySet : referencedPolicySets) {
75             IdReferenceType reference = new IdReferenceType();
76             reference.setValue(referencedPolicySet.getPolicySetId());
77             //
78             // Add it in
79             //
80             rootPolicy.getPolicySetOrPolicyOrPolicySetIdReference().add(factory.createPolicySetIdReference(reference));
81         }
82         //
83         // Return the updated object
84         //
85         return rootPolicy;
86     }
87
88 }