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