58cd67fd17cee4b2ffd01a6f366584328261ae57
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
4  * ================================================================================
5  * Copyright (C) 2017-2018 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
21 package org.onap.policy.drools.protocol.configuration;
22
23 import com.fasterxml.jackson.annotation.JsonAnyGetter;
24 import com.fasterxml.jackson.annotation.JsonAnySetter;
25 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32 import org.apache.commons.lang3.builder.EqualsBuilder;
33 import org.apache.commons.lang3.builder.HashCodeBuilder;
34 import org.apache.commons.lang3.builder.ToStringBuilder;
35
36
37 /**
38  * ENGINE-CONFIGURATION.
39  */
40 @JsonInclude(JsonInclude.Include.NON_NULL)
41 public class PdpdConfiguration {
42
43     /** Controller Entity ID. */
44     public static final String CONFIG_ENTITY_CONTROLLER = "controller";
45
46     /** Unique Transaction ID. This is an UUID. (Required) */
47     @JsonProperty("requestID")
48     private String requestID;
49     /* Set of entities on which configuration can be performed: controller (Required) */
50     @JsonProperty("entity")
51     private String entity;
52     /* Controller Information, only applicable when the entity is set to controller */
53     @JsonProperty("controllers")
54     private List<ControllerConfiguration> controllers = new ArrayList<>();
55
56     @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
57     protected static final Object NOT_FOUND_VALUE = new Object();
58
59     /** No args constructor for use in serialization. */
60     public PdpdConfiguration() {
61         // Empty
62     }
63
64     /**
65      * Constructor.
66      * 
67      * @param requestID request id
68      * @param entity entity
69      * @param controllers controllers
70      */
71     public PdpdConfiguration(
72             String requestID, String entity, List<ControllerConfiguration> controllers) {
73         this.requestID = requestID;
74         this.entity = entity;
75         this.controllers = controllers;
76     }
77
78     /**
79      * Unique Transaction ID. This is an UUID. (Required)
80      *
81      * @return The requestID
82      */
83     @JsonProperty("requestID")
84     public String getRequestID() {
85         return requestID;
86     }
87
88     /**
89      * Unique Transaction ID. This is an UUID. (Required)
90      *
91      * @param requestID The requestID
92      */
93     @JsonProperty("requestID")
94     public void setRequestID(String requestID) {
95         this.requestID = requestID;
96     }
97
98     public PdpdConfiguration withRequestID(String requestID) {
99         this.requestID = requestID;
100         return this;
101     }
102
103     /**
104      * Set of entities on which configuration can be performed: controller (Required).
105      *
106      * @return The entity
107      */
108     @JsonProperty("entity")
109     public String getEntity() {
110         return entity;
111     }
112
113     /**
114      * Set of entities on which configuration can be performed: controller (Required).
115      *
116      * @param entity The entity
117      */
118     @JsonProperty("entity")
119     public void setEntity(String entity) {
120         this.entity = entity;
121     }
122
123     public PdpdConfiguration withEntity(String entity) {
124         this.entity = entity;
125         return this;
126     }
127
128     /**
129      * Controller Information, only applicable when the entity is set to controller.
130      *
131      * @return The controller
132      */
133     @JsonProperty("controller")
134     public List<ControllerConfiguration> getControllers() {
135         return controllers;
136     }
137
138     /**
139      * Controller Information, only applicable when the entity is set to controller.
140      *
141      * @param controllers controllers
142      */
143     @JsonProperty("controller")
144     public void setControllers(List<ControllerConfiguration> controllers) {
145         this.controllers = controllers;
146     }
147
148     public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
149         this.controllers = controllers;
150         return this;
151     }
152
153     @Override
154     public String toString() {
155         return ToStringBuilder.reflectionToString(this);
156     }
157
158     @JsonAnyGetter
159     public Map<String, Object> getAdditionalProperties() {
160         return this.additionalProperties;
161     }
162
163     @JsonAnySetter
164     public void setAdditionalProperty(String name, Object value) {
165         this.additionalProperties.put(name, value);
166     }
167
168     public PdpdConfiguration withAdditionalProperty(String name, Object value) {
169         this.additionalProperties.put(name, value);
170         return this;
171     }
172
173     protected boolean declaredProperty(String name, Object value) {
174         switch (name) {
175             case "requestID":
176                 callSetRequestId(value);
177                 return true;
178             case "entity":
179                 callSetEntity(value);
180                 return true;
181             case "controllers":
182                 callSetControllers(value);
183                 return true;
184             default:
185                 return false;
186         }
187     }
188
189     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
190         switch (name) {
191             case "requestID":
192                 return getRequestID();
193             case "entity":
194                 return getEntity();
195             case "controllers":
196                 return getControllers();
197             default:
198                 return notFoundValue;
199         }
200     }
201
202     /**
203      * Get.
204      * 
205      * @param name name
206      * @return object
207      */
208     @SuppressWarnings({"unchecked"})
209     public <T> T get(String name) {
210         Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
211         if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
212             return (T) value;
213         } else {
214             return (T) getAdditionalProperties().get(name);
215         }
216     }
217
218     /**
219      * Set property.
220      * 
221      * @param name name
222      * @param value value
223      */
224     public void set(String name, Object value) {
225         if (!declaredProperty(name, value)) {
226             getAdditionalProperties().put(name, value);
227         }
228     }
229
230     /**
231      * With - sets and returns the object.
232      */
233     public PdpdConfiguration with(String name, Object value) {
234         if (!declaredProperty(name, value)) {
235             getAdditionalProperties().put(name, value);
236         }
237         return this;
238     }
239
240     @Override
241     public int hashCode() {
242         return new HashCodeBuilder()
243                 .append(requestID)
244                 .append(entity)
245                 .append(controllers)
246                 .append(additionalProperties)
247                 .toHashCode();
248     }
249
250     @Override
251     public boolean equals(Object other) {
252         if (other == this) {
253             return true;
254         }
255         if (!(other instanceof PdpdConfiguration)) {
256             return false;
257         }
258         PdpdConfiguration rhs = (PdpdConfiguration) other;
259         return new EqualsBuilder()
260                 .append(requestID, rhs.requestID)
261                 .append(entity, rhs.entity)
262                 .append(controllers, rhs.controllers)
263                 .append(additionalProperties, rhs.additionalProperties)
264                 .isEquals();
265     }
266
267     /**
268      * Call set request id.
269      * 
270      * @param value value
271      */
272     public void callSetRequestId(Object value) {
273         if (value instanceof String) {
274             setRequestID((String) value);
275         } else {
276             throw new IllegalArgumentException(
277                     "property \"requestID\" is of type \"java.lang.String\", but got "
278                             + value.getClass().toString());
279         }
280     }
281
282     /**
283      * Call set entity.
284      * 
285      * @param value value
286      */
287     public void callSetEntity(Object value) {
288         if (value instanceof String) {
289             setEntity((String) value);
290         } else {
291             throw new IllegalArgumentException(
292                     "property \"entity\" is of type \"java.lang.String\", but got "
293                             + value.getClass().toString());
294         }
295     }
296
297     /**
298      * Call set controllers.
299      * 
300      * @param value value
301      */
302     @SuppressWarnings("unchecked")
303     public void callSetControllers(Object value) {
304         if (value instanceof List) {
305             setControllers((List<ControllerConfiguration>) value);
306         } else {
307             throw new IllegalArgumentException(
308                     "property \"controllers\" is of type "
309                             + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
310                             + "but got "
311                             + value.getClass().toString());
312         }
313     }
314 }