d6df0e422680240a490a944ed3f3c7aa081d78bc
[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.HashMap;
29 import java.util.Map;
30 import lombok.ToString;
31 import org.apache.commons.lang3.builder.EqualsBuilder;
32 import org.apache.commons.lang3.builder.HashCodeBuilder;
33 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
34 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
35 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
36 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
37
38
39 /**
40  * Drools Related Information.
41  *
42  */
43 @JsonInclude(JsonInclude.Include.NON_NULL)
44 @ToString
45 public class ControllerConfiguration {
46
47     public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
48     public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
49     public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
50     public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
51
52     /**
53      * (Required).
54      *
55      */
56     @JsonProperty("name")
57     @GsonJsonProperty("name")
58     private String name;
59     /**
60      * Set of operations that can be applied to a controller: create, lock
61      * (Required).
62      *
63      */
64     @JsonProperty("operation")
65     @GsonJsonProperty("operation")
66     private String operation;
67     /**
68      * Maven Related Information.
69      *
70      */
71     @JsonProperty("drools")
72     @GsonJsonProperty("drools")
73     private DroolsConfiguration drools;
74
75     @JsonIgnore
76     @GsonJsonIgnore
77     private Map<String, Object> additionalProperties = new HashMap<>();
78
79     protected static final Object NOT_FOUND_VALUE = new Object();
80
81     /**
82      * No args constructor for use in serialization.
83      *
84      */
85     public ControllerConfiguration() {
86         // Empty
87     }
88
89     /**
90      * Constructor.
91      *
92      * @param name name
93      * @param operation operation
94      * @param drools drools
95      */
96     public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
97         this.name = name;
98         this.operation = operation;
99         this.drools = drools;
100     }
101
102     /**
103      * (Required).
104      *
105      * @return
106      *     The name
107      */
108     @JsonProperty("name")
109     @GsonJsonProperty("name")
110     public String getName() {
111         return name;
112     }
113
114     /**
115      * (Required).
116      *
117      * @param name
118      *     The name
119      */
120     @JsonProperty("name")
121     @GsonJsonProperty("name")
122     public void setName(String name) {
123         this.name = name;
124     }
125
126     public ControllerConfiguration withName(String name) {
127         this.name = name;
128         return this;
129     }
130
131     /**
132      * Set of operations that can be applied to a controller: create, lock
133      * (Required).
134      *
135      * @return
136      *     The operation
137      */
138     @JsonProperty("operation")
139     @GsonJsonProperty("operation")
140     public String getOperation() {
141         return operation;
142     }
143
144     /**
145      * Set of operations that can be applied to a controller: create, lock
146      * (Required).
147      *
148      * @param operation
149      *     The operation
150      */
151     @JsonProperty("operation")
152     @GsonJsonProperty("operation")
153     public void setOperation(String operation) {
154         this.operation = operation;
155     }
156
157     public ControllerConfiguration withOperation(String operation) {
158         this.operation = operation;
159         return this;
160     }
161
162     /**
163      * Maven Related Information.
164      *
165      * @return
166      *     The drools
167      */
168     @JsonProperty("drools")
169     @GsonJsonProperty("drools")
170     public DroolsConfiguration getDrools() {
171         return drools;
172     }
173
174     /**
175      * Maven Related Information.
176      *
177      * @param drools
178      *     The drools
179      */
180     @JsonProperty("drools")
181     @GsonJsonProperty("drools")
182     public void setDrools(DroolsConfiguration drools) {
183         this.drools = drools;
184     }
185
186     public ControllerConfiguration withDrools(DroolsConfiguration drools) {
187         this.drools = drools;
188         return this;
189     }
190
191     @JsonAnyGetter
192     @GsonJsonAnyGetter
193     public Map<String, Object> getAdditionalProperties() {
194         return this.additionalProperties;
195     }
196
197     @JsonAnySetter
198     @GsonJsonAnySetter
199     public void setAdditionalProperty(String name, Object value) {
200         this.additionalProperties.put(name, value);
201     }
202
203     public ControllerConfiguration withAdditionalProperty(String name, Object value) {
204         this.additionalProperties.put(name, value);
205         return this;
206     }
207
208     protected boolean declaredProperty(String name, Object value) {
209         switch (name) {
210             case "name":
211                 callSetName(value);
212                 return true;
213             case "operation":
214                 callSetOperation(value);
215                 return true;
216             case "drools":
217                 callSetDrools(value);
218                 return true;
219             default:
220                 return false;
221         }
222     }
223
224     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
225         switch (name) {
226             case "name":
227                 return getName();
228             case "operation":
229                 return getOperation();
230             case "drools":
231                 return getDrools();
232             default:
233                 return notFoundValue;
234         }
235     }
236
237     /**
238      * Get.
239      *
240      * @param name name
241      * @return the object
242      */
243     @SuppressWarnings({
244         "unchecked"
245         })
246     public <T> T get(String name) {
247         Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
248         if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
249             return ((T) value);
250         } else {
251             return ((T) getAdditionalProperties().get(name));
252         }
253     }
254
255     /**
256      * Set the property.
257      *
258      * @param name property name
259      * @param value property value
260      */
261     public void set(String name, Object value) {
262         if (!declaredProperty(name, value)) {
263             getAdditionalProperties().put(name, (Object) value);
264         }
265     }
266
267     /**
268      * With - sets the property and additionally returns the object.
269      *
270      * @param name property name
271      * @param value property value
272      * @return this
273      */
274     public ControllerConfiguration with(String name, Object value) {
275         if (!declaredProperty(name, value)) {
276             getAdditionalProperties().put(name, (Object) value);
277         }
278         return this;
279     }
280
281     @Override
282     public int hashCode() {
283         return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
284                 .toHashCode();
285     }
286
287     @Override
288     public boolean equals(Object other) {
289         if (other == this) {
290             return true;
291         }
292         if (!(other instanceof ControllerConfiguration)) {
293             return false;
294         }
295         ControllerConfiguration rhs = ((ControllerConfiguration) other);
296         return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
297                 .append(additionalProperties, rhs.additionalProperties).isEquals();
298     }
299
300     /**
301      * Call set name.
302      *
303      * @param value value
304      */
305     public void callSetName(Object value) {
306         if (value instanceof String) {
307             setName((String) value);
308         } else {
309             throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
310                     + value.getClass().toString());
311         }
312     }
313
314     /**
315      * Call set operation.
316      *
317      * @param value value
318      */
319     public void callSetOperation(Object value) {
320         if (value instanceof String) {
321             setOperation((String) value);
322         } else {
323             throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
324                     + value.getClass().toString());
325         }
326     }
327
328     /**
329      * Call set drools.
330      *
331      * @param value value
332      */
333     public void callSetDrools(Object value) {
334         if (value instanceof DroolsConfiguration) {
335             setDrools((DroolsConfiguration) value);
336         } else {
337             throw new IllegalArgumentException("property \"drools\" is of type"
338                     + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
339                     + value.getClass().toString());
340         }
341     }
342
343 }