[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-XACML / src / main / java / org / onap / policy / xacml / std / pap / StdPDPStatus.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-XACML
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.policy.xacml.std.pap;
21
22 import java.io.Serializable;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.Set;
26
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;
31
32 public class StdPDPStatus implements Serializable, PDPStatus {
33         private static final long serialVersionUID = 1L;
34         
35         private Status status = Status.UNKNOWN;
36
37         private Set<String>     loadErrors = new HashSet<>();
38         
39         private Set<String> loadWarnings = new HashSet<>();
40         
41         private Set<PDPPolicy> loadedPolicies = new HashSet<>();
42         
43         private Set<PDPPolicy> loadedRootPolicies = new HashSet<>();
44         
45         private Set<PDPPolicy> failedPolicies = new HashSet<>();
46         
47         private Set<PDPPIPConfig>       loadedPIPConfigs = new HashSet<>();
48         
49         private Set<PDPPIPConfig>       failedPIPConfigs = new HashSet<>();
50         
51         public StdPDPStatus() {
52         }
53
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());
70         }
71         
72         
73
74         @Override
75         public Status getStatus() {
76                 return this.status;
77         }
78         
79         public void setStatus(Status status) {
80                 this.status = status;
81         }
82         
83         @Override
84         public Set<String> getLoadErrors() {
85                 return Collections.unmodifiableSet(this.loadErrors);
86         }
87
88         public void setLoadErrors(Set<String> errors) {
89                 this.loadErrors = errors;
90         }
91         
92         public void addLoadError(String error) {
93                 this.loadErrors.add(error);
94         }
95
96         @Override
97         public Set<String> getLoadWarnings() {
98                 return Collections.unmodifiableSet(this.loadWarnings);
99         }
100
101         public void setLoadWarnings(Set<String> warnings) {
102                 this.loadWarnings = warnings;
103         }
104         
105         public void addLoadWarning(String warning) {
106                 this.loadWarnings.add(warning);
107         }
108
109         @Override
110         public Set<PDPPolicy> getLoadedPolicies() {
111                 return Collections.unmodifiableSet(this.loadedPolicies);
112         }
113         
114         public void setLoadedPolicies(Set<PDPPolicy> policies) {
115                 this.loadedPolicies = policies;
116         }
117         
118         public void addLoadedPolicy(PDPPolicy policy) {
119                 this.loadedPolicies.add(policy);
120         }
121         
122         @Override
123         public Set<PDPPolicy> getLoadedRootPolicies() {
124                 return Collections.unmodifiableSet(this.loadedRootPolicies);
125         }
126         
127         public void setLoadedRootPolicies(Set<PDPPolicy> policies) {
128                 this.loadedRootPolicies = policies;
129         }
130         
131         public void addRootPolicy(PDPPolicy policy) {
132                 this.loadedRootPolicies.add(policy);
133         }
134         
135         public void addAllLoadedRootPolicies(Set<PDPPolicy> policies) {
136                 this.loadedRootPolicies.addAll(policies);
137         }
138         
139         @Override
140         public Set<PDPPolicy> getFailedPolicies() {
141                 return Collections.unmodifiableSet(this.failedPolicies);
142         }
143         
144         public void     setFailedPolicies(Set<PDPPolicy> policies) {
145                 this.failedPolicies = policies;
146         }
147         
148         public void addFailedPolicy(PDPPolicy policy) {
149                 this.failedPolicies.add(policy);
150         }
151
152         @Override
153         public boolean policiesOK() {
154                 if (this.failedPolicies.size() > 0) {
155                         return false;
156                 }
157                 return true;
158         }
159
160         @Override
161         public Set<PDPPIPConfig> getLoadedPipConfigs() {
162                 return Collections.unmodifiableSet(this.loadedPIPConfigs);
163         }
164         
165         public void setLoadedPipConfigs(Set<PDPPIPConfig> configs) {
166                 this.loadedPIPConfigs = configs;
167         }
168         
169         public void addLoadedPipConfig(PDPPIPConfig config) {
170                 this.loadedPIPConfigs.add(config);
171         }
172
173         @Override
174         public Set<PDPPIPConfig> getFailedPipConfigs() {
175                 return Collections.unmodifiableSet(this.failedPIPConfigs);
176         }
177
178         public void setFailedPipConfigs(Set<PDPPIPConfig> configs) {
179                 this.failedPIPConfigs = configs;
180         }
181         
182         public void addFailedPipConfig(PDPPIPConfig config) {
183                 this.failedPIPConfigs.add(config);
184         }
185
186         @Override
187         public boolean pipConfigOK() {
188                 if (this.failedPIPConfigs.size() > 0) {
189                         return false;
190                 }
191                 return true;
192         }
193
194         @Override
195         @JsonIgnore
196         public boolean isOk() {
197                 if (this.policiesOK() == false) {
198                         return false;
199                 }
200                 if (this.pipConfigOK() == false) {
201                         return false;
202                 }
203                 return (this.status == Status.UP_TO_DATE);
204         }
205
206         @Override
207         public int hashCode() {
208                 final int prime = 31;
209                 int result = 1;
210                 result = prime
211                                 * result
212                                 + (failedPIPConfigs.hashCode());
213                 result = prime * result
214                                 + (failedPolicies.hashCode());
215                 result = prime * result
216                                 + (loadErrors.hashCode());
217                 result = prime * result
218                                 + (loadWarnings.hashCode());
219                 result = prime
220                                 * result
221                                 + (loadedPIPConfigs.hashCode());
222                 result = prime * result
223                                 + (loadedPolicies.hashCode());
224                 result = prime * result + (status.hashCode());
225                 return result;
226         }
227
228         @Override
229         public boolean equals(Object obj) {
230                 if (this == obj)
231                         return true;
232                 if (obj == null)
233                         return false;
234                 if (getClass() != obj.getClass())
235                         return false;
236                 StdPDPStatus other = (StdPDPStatus) obj;
237                 if (!failedPIPConfigs.equals(other.failedPIPConfigs))
238                         return false;
239                 if (!failedPolicies.equals(other.failedPolicies))
240                         return false;
241                 if (!loadErrors.equals(other.loadErrors))
242                         return false;
243                 if (!loadWarnings.equals(other.loadWarnings))
244                         return false;
245                 if (!loadedPIPConfigs.equals(other.loadedPIPConfigs))
246                         return false;
247                 if (!loadedPolicies.equals(other.loadedPolicies))
248                         return false;
249                 if (status != other.status)
250                         return false;
251                 return true;
252         }
253
254         @Override
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 + "]";
262         }
263
264
265 }