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