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