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.openecomp.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<String>();
39 private Set<String> loadWarnings = new HashSet<String>();
41 private Set<PDPPolicy> loadedPolicies = new HashSet<PDPPolicy>();
43 private Set<PDPPolicy> loadedRootPolicies = new HashSet<PDPPolicy>();
45 private Set<PDPPolicy> failedPolicies = new HashSet<PDPPolicy>();
47 private Set<PDPPIPConfig> loadedPIPConfigs = new HashSet<PDPPIPConfig>();
49 private Set<PDPPIPConfig> failedPIPConfigs = new HashSet<PDPPIPConfig>();
51 public StdPDPStatus() {
54 public void set(StdPDPStatus newStatus) {
55 this.status = newStatus.status;
56 this.loadErrors.clear();
57 this.loadErrors.addAll(newStatus.getLoadErrors());
58 this.loadWarnings.clear();
59 this.loadWarnings.addAll(newStatus.getLoadWarnings());
60 this.loadedPolicies.clear();
61 this.loadedPolicies.addAll(newStatus.getLoadedPolicies());
62 this.loadedRootPolicies.clear();
63 this.loadedRootPolicies.addAll(newStatus.getLoadedRootPolicies());
64 this.failedPolicies.clear();
65 this.failedPolicies.addAll(newStatus.getFailedPolicies());
66 this.loadedPIPConfigs.clear();
67 this.loadedPIPConfigs.addAll(newStatus.getLoadedPipConfigs());
68 this.failedPIPConfigs.clear();
69 this.failedPIPConfigs.addAll(newStatus.getFailedPipConfigs());
75 public Status getStatus() {
79 public void setStatus(Status status) {
84 public Set<String> getLoadErrors() {
85 return Collections.unmodifiableSet(this.loadErrors);
88 public void setLoadErrors(Set<String> errors) {
89 this.loadErrors = errors;
92 public void addLoadError(String error) {
93 this.loadErrors.add(error);
97 public Set<String> getLoadWarnings() {
98 return Collections.unmodifiableSet(this.loadWarnings);
101 public void setLoadWarnings(Set<String> warnings) {
102 this.loadWarnings = warnings;
105 public void addLoadWarning(String warning) {
106 this.loadWarnings.add(warning);
110 public Set<PDPPolicy> getLoadedPolicies() {
111 return Collections.unmodifiableSet(this.loadedPolicies);
114 public void setLoadedPolicies(Set<PDPPolicy> policies) {
115 this.loadedPolicies = policies;
118 public void addLoadedPolicy(PDPPolicy policy) {
119 this.loadedPolicies.add(policy);
123 public Set<PDPPolicy> getLoadedRootPolicies() {
124 return Collections.unmodifiableSet(this.loadedRootPolicies);
127 public void setLoadedRootPolicies(Set<PDPPolicy> policies) {
128 this.loadedRootPolicies = policies;
131 public void addRootPolicy(PDPPolicy policy) {
132 this.loadedRootPolicies.add(policy);
135 public void addAllLoadedRootPolicies(Set<PDPPolicy> policies) {
136 this.loadedRootPolicies.addAll(policies);
140 public Set<PDPPolicy> getFailedPolicies() {
141 return Collections.unmodifiableSet(this.failedPolicies);
144 public void setFailedPolicies(Set<PDPPolicy> policies) {
145 this.failedPolicies = policies;
148 public void addFailedPolicy(PDPPolicy policy) {
149 this.failedPolicies.add(policy);
153 public boolean policiesOK() {
154 if (this.failedPolicies.size() > 0) {
161 public Set<PDPPIPConfig> getLoadedPipConfigs() {
162 return Collections.unmodifiableSet(this.loadedPIPConfigs);
165 public void setLoadedPipConfigs(Set<PDPPIPConfig> configs) {
166 this.loadedPIPConfigs = configs;
169 public void addLoadedPipConfig(PDPPIPConfig config) {
170 this.loadedPIPConfigs.add(config);
174 public Set<PDPPIPConfig> getFailedPipConfigs() {
175 return Collections.unmodifiableSet(this.failedPIPConfigs);
178 public void setFailedPipConfigs(Set<PDPPIPConfig> configs) {
179 this.failedPIPConfigs = configs;
182 public void addFailedPipConfig(PDPPIPConfig config) {
183 this.failedPIPConfigs.add(config);
187 public boolean pipConfigOK() {
188 if (this.failedPIPConfigs.size() > 0) {
196 public boolean isOk() {
197 if (this.policiesOK() == false) {
200 if (this.pipConfigOK() == false) {
203 return (this.status == Status.UP_TO_DATE);
207 public int hashCode() {
208 final int prime = 31;
212 + (failedPIPConfigs.hashCode());
213 result = prime * result
214 + (failedPolicies.hashCode());
215 result = prime * result
216 + (loadErrors.hashCode());
217 result = prime * result
218 + (loadWarnings.hashCode());
221 + (loadedPIPConfigs.hashCode());
222 result = prime * result
223 + (loadedPolicies.hashCode());
224 result = prime * result + (status.hashCode());
229 public boolean equals(Object obj) {
234 if (getClass() != obj.getClass())
236 StdPDPStatus other = (StdPDPStatus) obj;
237 if (!failedPIPConfigs.equals(other.failedPIPConfigs))
239 if (!failedPolicies.equals(other.failedPolicies))
241 if (!loadErrors.equals(other.loadErrors))
243 if (!loadWarnings.equals(other.loadWarnings))
245 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs))
247 if (!loadedPolicies.equals(other.loadedPolicies))
249 if (status != other.status)
255 public String toString() {
256 return "StdPDPStatus [status=" + status + ", loadErrors=" + loadErrors
257 + ", loadWarnings=" + loadWarnings + ", loadedPolicies="
258 + loadedPolicies + ", loadedRootPolicies=" + loadedRootPolicies
259 + ", failedPolicies=" + failedPolicies
260 + ", loadedPIPConfigs=" + loadedPIPConfigs
261 + ", failedPIPConfigs=" + failedPIPConfigs + "]";