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