2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.xacml.rest.model;
23 import java.util.Collection;
24 import java.util.HashSet;
27 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
28 import org.onap.policy.xacml.std.pap.StdPDPGroup;
30 import com.att.research.xacml.api.pap.PDPPolicy;
32 public class RemoveGroupPolicy {
35 //Container from where we are fetching the policies
36 private static PDPPolicyContainer policyContainer;
38 private final RemoveGroupPolicy self = this;
39 private StdPDPGroup updatedObject;
40 private final StdPDPGroup group;
41 private boolean isSaved = false;
43 public RemoveGroupPolicy(StdPDPGroup group) {
49 public void prepareToRemove(PDPPolicy policy) {
51 if (this.group == null) {
55 RemoveGroupPolicy.policyContainer = new PDPPolicyContainer(group);
57 RemoveGroupPolicy.policyContainer.removeItem(policy);
65 @SuppressWarnings("unchecked")
66 protected void doSave() {
67 if (this.group == null) {
71 //StdPDPGroup pdpGroup = (StdPDPGroup) group;
72 StdPDPGroup updatedGroupObject = new StdPDPGroup(
74 group.isDefaultGroup(),
76 group.getDescription(),
79 // replace the original set of Policies with the set from the container (possibly modified by the user)
80 Set<PDPPolicy> changedPolicies = new HashSet<>();
81 changedPolicies.addAll((Collection<PDPPolicy>) RemoveGroupPolicy.policyContainer.getItemIds());
82 updatedGroupObject.setPolicies(changedPolicies);
83 updatedGroupObject.setOnapPdps(this.group.getOnapPdps());
85 // replace the original set of PIP Configs with the set from the container
86 updatedGroupObject.setPipConfigs(this.group.getPipConfigs());
88 // copy those things that the user cannot change from the original to the new object
89 updatedGroupObject.setStatus(this.group.getStatus());
91 this.updatedObject = updatedGroupObject;
94 public boolean isRemoved() {
98 public OnapPDPGroup getUpdatedObject() {
99 return this.updatedObject;