2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-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.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.xacml.std.pap;
23 import com.att.research.xacml.api.pap.PDPPIPConfig;
24 import com.att.research.xacml.api.pap.PDPPolicy;
25 import com.att.research.xacml.api.pap.PDPStatus;
26 import com.fasterxml.jackson.annotation.JsonIgnore;
28 import java.io.Serializable;
29 import java.util.Collections;
30 import java.util.HashSet;
32 import lombok.ToString;
35 public class StdPDPStatus implements Serializable, PDPStatus {
36 private static final long serialVersionUID = 1L;
38 private Status status = Status.UNKNOWN;
40 private Set<String> loadErrors = new HashSet<>();
42 private Set<String> loadWarnings = new HashSet<>();
44 private transient Set<PDPPolicy> loadedPolicies = new HashSet<>();
46 private transient Set<PDPPolicy> loadedRootPolicies = new HashSet<>();
48 private transient Set<PDPPolicy> failedPolicies = new HashSet<>();
50 private transient Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<>();
52 private transient Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>();
54 public StdPDPStatus() {
56 // Default constructor
60 public void set(StdPDPStatus newStatus) {
61 this.status = newStatus.status;
62 this.loadErrors.clear();
63 this.loadErrors.addAll(newStatus.getLoadErrors());
64 this.loadWarnings.clear();
65 this.loadWarnings.addAll(newStatus.getLoadWarnings());
66 this.loadedPolicies.clear();
67 this.loadedPolicies.addAll(newStatus.getLoadedPolicies());
68 this.loadedRootPolicies.clear();
69 this.loadedRootPolicies.addAll(newStatus.getLoadedRootPolicies());
70 this.failedPolicies.clear();
71 this.failedPolicies.addAll(newStatus.getFailedPolicies());
72 this.loadedPIPConfigs.clear();
73 this.loadedPIPConfigs.addAll(newStatus.getLoadedPipConfigs());
74 this.failedPIPConfigs.clear();
75 this.failedPIPConfigs.addAll(newStatus.getFailedPipConfigs());
79 public Status getStatus() {
83 public void setStatus(Status status) {
88 public Set<String> getLoadErrors() {
89 return Collections.unmodifiableSet(this.loadErrors);
92 public void setLoadErrors(Set<String> errors) {
93 this.loadErrors = errors;
96 public void addLoadError(String error) {
97 this.loadErrors.add(error);
101 public Set<String> getLoadWarnings() {
102 return Collections.unmodifiableSet(this.loadWarnings);
105 public void setLoadWarnings(Set<String> warnings) {
106 this.loadWarnings = warnings;
109 public void addLoadWarning(String warning) {
110 this.loadWarnings.add(warning);
114 public Set<PDPPolicy> getLoadedPolicies() {
115 return Collections.unmodifiableSet(this.loadedPolicies);
118 public void setLoadedPolicies(Set<PDPPolicy> policies) {
119 this.loadedPolicies = policies;
122 public void addLoadedPolicy(PDPPolicy policy) {
123 this.loadedPolicies.add(policy);
127 public Set<PDPPolicy> getLoadedRootPolicies() {
128 return Collections.unmodifiableSet(this.loadedRootPolicies);
131 public void setLoadedRootPolicies(Set<PDPPolicy> policies) {
132 this.loadedRootPolicies = policies;
135 public void addRootPolicy(PDPPolicy policy) {
136 this.loadedRootPolicies.add(policy);
139 public void addAllLoadedRootPolicies(Set<PDPPolicy> policies) {
140 this.loadedRootPolicies.addAll(policies);
144 public Set<PDPPolicy> getFailedPolicies() {
145 return Collections.unmodifiableSet(this.failedPolicies);
148 public void setFailedPolicies(Set<PDPPolicy> policies) {
149 this.failedPolicies = policies;
152 public void addFailedPolicy(PDPPolicy policy) {
153 this.failedPolicies.add(policy);
157 public boolean policiesOK() {
158 return this.failedPolicies.isEmpty();
162 public Set<PDPPIPConfig> getLoadedPipConfigs() {
163 return Collections.unmodifiableSet(this.loadedPIPConfigs);
166 public void setLoadedPipConfigs(Set<PDPPIPConfig> configs) {
167 this.loadedPIPConfigs = configs;
170 public void addLoadedPipConfig(PDPPIPConfig config) {
171 this.loadedPIPConfigs.add(config);
175 public Set<PDPPIPConfig> getFailedPipConfigs() {
176 return Collections.unmodifiableSet(this.failedPIPConfigs);
179 public void setFailedPipConfigs(Set<PDPPIPConfig> configs) {
180 this.failedPIPConfigs = configs;
183 public void addFailedPipConfig(PDPPIPConfig config) {
184 this.failedPIPConfigs.add(config);
188 public boolean pipConfigOK() {
189 return this.failedPIPConfigs.isEmpty();
193 public int hashCode() {
194 final int prime = 31;
196 result = prime * result + (failedPIPConfigs.hashCode());
197 result = prime * result + (failedPolicies.hashCode());
198 result = prime * result + (loadErrors.hashCode());
199 result = prime * result + (loadWarnings.hashCode());
200 result = prime * result + (loadedPIPConfigs.hashCode());
201 result = prime * result + (loadedPolicies.hashCode());
202 result = prime * result + (status.hashCode());
207 public boolean equals(Object obj) {
214 if (getClass() != obj.getClass()) {
217 StdPDPStatus other = (StdPDPStatus) obj;
218 if (!failedPIPConfigs.equals(other.failedPIPConfigs)) {
221 if (!failedPolicies.equals(other.failedPolicies)) {
224 if (!loadErrors.equals(other.loadErrors)) {
227 if (!loadWarnings.equals(other.loadWarnings)) {
230 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs)) {
233 if (!loadedPolicies.equals(other.loadedPolicies)) {
236 if (!loadedRootPolicies.equals(other.loadedRootPolicies)) {
239 if (status != other.status) {
247 public boolean isOk() {
248 if (!this.policiesOK()) {
251 if (!this.pipConfigOK()) {
254 return this.status == Status.UP_TO_DATE;