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