2  * ============LICENSE_START=======================================================
 
   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
 
  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.
 
  19  * SPDX-License-Identifier: Apache-2.0
 
  20  * ============LICENSE_END=========================================================
 
  23 package org.onap.policy.pdp.xacml.application.common;
 
  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;
 
  30 public class XacmlUpdatePolicyUtils {
 
  32     private XacmlUpdatePolicyUtils() {
 
  37      * This method updates a root PolicySetType by adding in a PolicyType as a reference.
 
  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
 
  43     public static PolicySetType updateXacmlRootPolicy(PolicySetType rootPolicy, PolicyType... referencedPolicies) {
 
  44         ObjectFactory factory = new ObjectFactory();
 
  46         // Iterate each policy
 
  48         for (PolicyType referencedPolicy : referencedPolicies) {
 
  49             IdReferenceType reference = new IdReferenceType();
 
  50             reference.setValue(referencedPolicy.getPolicyId());
 
  54             rootPolicy.getPolicySetOrPolicyOrPolicySetIdReference().add(factory.createPolicySetIdReference(reference));
 
  57         // Return the updated object
 
  63      * This method updates a root PolicySetType by adding in a PolicyType as a reference.
 
  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
 
  69     public static PolicySetType updateXacmlRootPolicy(PolicySetType rootPolicy, PolicySetType... referencedPolicySets) {
 
  70         ObjectFactory factory = new ObjectFactory();
 
  72         // Iterate each policy
 
  74         for (PolicySetType referencedPolicySet : referencedPolicySets) {
 
  75             IdReferenceType reference = new IdReferenceType();
 
  76             reference.setValue(referencedPolicySet.getPolicySetId());
 
  80             rootPolicy.getPolicySetOrPolicyOrPolicySetIdReference().add(factory.createPolicySetIdReference(reference));
 
  83         // Return the updated object