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