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=========================================================
20 package org.onap.policy.xacml.std.pap;
22 import java.io.Serializable;
23 import java.util.Collections;
24 import java.util.HashSet;
27 import com.att.research.xacml.api.pap.PDPPIPConfig;
28 import com.att.research.xacml.api.pap.PDPPolicy;
29 import com.att.research.xacml.api.pap.PDPStatus;
30 import com.fasterxml.jackson.annotation.JsonIgnore;
32 public class StdPDPStatus implements Serializable, PDPStatus {
33 private static final long serialVersionUID = 1L;
35 private Status status = Status.UNKNOWN;
37 private Set<String> loadErrors = new HashSet<>();
39 private Set<String> loadWarnings = new HashSet<>();
41 private transient Set<PDPPolicy> loadedPolicies = new HashSet<>();
43 private transient Set<PDPPolicy> loadedRootPolicies = new HashSet<>();
45 private transient Set<PDPPolicy> failedPolicies = new HashSet<>();
47 private transient Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>();
49 private transient Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>();
51 public StdPDPStatus() {
53 // Default constructor
57 public void set(StdPDPStatus newStatus) {
58 this.status = newStatus.status;
59 this.loadErrors.clear();
60 this.loadErrors.addAll(newStatus.getLoadErrors());
61 this.loadWarnings.clear();
62 this.loadWarnings.addAll(newStatus.getLoadWarnings());
63 this.loadedPolicies.clear();
64 this.loadedPolicies.addAll(newStatus.getLoadedPolicies());
65 this.loadedRootPolicies.clear();
66 this.loadedRootPolicies.addAll(newStatus.getLoadedRootPolicies());
67 this.failedPolicies.clear();
68 this.failedPolicies.addAll(newStatus.getFailedPolicies());
69 this.loadedPIPConfigs.clear();
70 this.loadedPIPConfigs.addAll(newStatus.getLoadedPipConfigs());
71 this.failedPIPConfigs.clear();
72 this.failedPIPConfigs.addAll(newStatus.getFailedPipConfigs());
78 public Status getStatus() {
82 public void setStatus(Status status) {
87 public Set<String> getLoadErrors() {
88 return Collections.unmodifiableSet(this.loadErrors);
91 public void setLoadErrors(Set<String> errors) {
92 this.loadErrors = errors;
95 public void addLoadError(String error) {
96 this.loadErrors.add(error);
100 public Set<String> getLoadWarnings() {
101 return Collections.unmodifiableSet(this.loadWarnings);
104 public void setLoadWarnings(Set<String> warnings) {
105 this.loadWarnings = warnings;
108 public void addLoadWarning(String warning) {
109 this.loadWarnings.add(warning);
113 public Set<PDPPolicy> getLoadedPolicies() {
114 return Collections.unmodifiableSet(this.loadedPolicies);
117 public void setLoadedPolicies(Set<PDPPolicy> policies) {
118 this.loadedPolicies = policies;
121 public void addLoadedPolicy(PDPPolicy policy) {
122 this.loadedPolicies.add(policy);
126 public Set<PDPPolicy> getLoadedRootPolicies() {
127 return Collections.unmodifiableSet(this.loadedRootPolicies);
130 public void setLoadedRootPolicies(Set<PDPPolicy> policies) {
131 this.loadedRootPolicies = policies;
134 public void addRootPolicy(PDPPolicy policy) {
135 this.loadedRootPolicies.add(policy);
138 public void addAllLoadedRootPolicies(Set<PDPPolicy> policies) {
139 this.loadedRootPolicies.addAll(policies);
143 public Set<PDPPolicy> getFailedPolicies() {
144 return Collections.unmodifiableSet(this.failedPolicies);
147 public void setFailedPolicies(Set<PDPPolicy> policies) {
148 this.failedPolicies = policies;
151 public void addFailedPolicy(PDPPolicy policy) {
152 this.failedPolicies.add(policy);
156 public boolean policiesOK() {
157 if (!this.failedPolicies.isEmpty()) {
164 public Set<PDPPIPConfig> getLoadedPipConfigs() {
165 return Collections.unmodifiableSet(this.loadedPIPConfigs);
168 public void setLoadedPipConfigs(Set<PDPPIPConfig> configs) {
169 this.loadedPIPConfigs = configs;
172 public void addLoadedPipConfig(PDPPIPConfig config) {
173 this.loadedPIPConfigs.add(config);
177 public Set<PDPPIPConfig> getFailedPipConfigs() {
178 return Collections.unmodifiableSet(this.failedPIPConfigs);
181 public void setFailedPipConfigs(Set<PDPPIPConfig> configs) {
182 this.failedPIPConfigs = configs;
185 public void addFailedPipConfig(PDPPIPConfig config) {
186 this.failedPIPConfigs.add(config);
190 public boolean pipConfigOK() {
191 if (!this.failedPIPConfigs.isEmpty()) {
199 public boolean isOk() {
200 if (!this.policiesOK()) {
203 if (!this.pipConfigOK()) {
206 return this.status == Status.UP_TO_DATE;
210 public int hashCode() {
211 final int prime = 31;
215 + (failedPIPConfigs.hashCode());
216 result = prime * result
217 + (failedPolicies.hashCode());
218 result = prime * result
219 + (loadErrors.hashCode());
220 result = prime * result
221 + (loadWarnings.hashCode());
224 + (loadedPIPConfigs.hashCode());
225 result = prime * result
226 + (loadedPolicies.hashCode());
227 result = prime * result + (status.hashCode());
232 public boolean equals(Object obj) {
237 if (getClass() != obj.getClass())
239 StdPDPStatus other = (StdPDPStatus) obj;
240 if (!failedPIPConfigs.equals(other.failedPIPConfigs))
242 if (!failedPolicies.equals(other.failedPolicies))
244 if (!loadErrors.equals(other.loadErrors))
246 if (!loadWarnings.equals(other.loadWarnings))
248 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs))
250 if (!loadedPolicies.equals(other.loadedPolicies))
252 if (status != other.status)
258 public String toString() {
259 return "StdPDPStatus [status=" + status + ", loadErrors=" + loadErrors
260 + ", loadWarnings=" + loadWarnings + ", loadedPolicies="
261 + loadedPolicies + ", loadedRootPolicies=" + loadedRootPolicies
262 + ", failedPolicies=" + failedPolicies
263 + ", loadedPIPConfigs=" + loadedPIPConfigs
264 + ", failedPIPConfigs=" + failedPIPConfigs + "]";