845c494473f32e93cdcfd2a96b0dadb80862719b
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-management
4  * ================================================================================
5  * Copyright (C) 2017 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
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28 import org.apache.commons.lang3.builder.ToStringBuilder;
29
30 import com.fasterxml.jackson.annotation.JsonAnyGetter;
31 import com.fasterxml.jackson.annotation.JsonAnySetter;
32 import com.fasterxml.jackson.annotation.JsonIgnore;
33 import com.fasterxml.jackson.annotation.JsonInclude;
34 import com.fasterxml.jackson.annotation.JsonProperty;
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      * 
51      * (Required)
52      * 
53      */
54     @JsonProperty("name")
55     private String name;
56     /**
57      * Set of operations that can be applied to a controller: create, lock
58      * (Required)
59      * 
60      */
61     @JsonProperty("operation")
62     private String operation;
63     /**
64      * Maven Related Information
65      * 
66      */
67     @JsonProperty("drools")
68     private DroolsConfiguration drools;
69     @JsonIgnore
70     private Map<String, Object> additionalProperties = new HashMap<>();
71     protected final static Object NOT_FOUND_VALUE = new Object();
72
73     /**
74      * No args constructor for use in serialization
75      * 
76      */
77     public ControllerConfiguration() {
78         // Empty
79     }
80
81     /**
82      * 
83      * @param name
84      * @param drools
85      * @param operation
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      * 
95      * (Required)
96      * 
97      * @return
98      *     The name
99      */
100     @JsonProperty("name")
101     public String getName() {
102         return name;
103     }
104
105     /**
106      * 
107      * (Required)
108      * 
109      * @param name
110      *     The name
111      */
112     @JsonProperty("name")
113     public void setName(String name) {
114         this.name = name;
115     }
116
117     public ControllerConfiguration withName(String name) {
118         this.name = name;
119         return this;
120     }
121
122     /**
123      * Set of operations that can be applied to a controller: create, lock
124      * (Required)
125      * 
126      * @return
127      *     The operation
128      */
129     @JsonProperty("operation")
130     public String getOperation() {
131         return operation;
132     }
133
134     /**
135      * Set of operations that can be applied to a controller: create, lock
136      * (Required)
137      * 
138      * @param operation
139      *     The operation
140      */
141     @JsonProperty("operation")
142     public void setOperation(String operation) {
143         this.operation = operation;
144     }
145
146     public ControllerConfiguration withOperation(String operation) {
147         this.operation = operation;
148         return this;
149     }
150
151     /**
152      * Maven Related Information
153      * 
154      * @return
155      *     The drools
156      */
157     @JsonProperty("drools")
158     public DroolsConfiguration getDrools() {
159         return drools;
160     }
161
162     /**
163      * Maven Related Information
164      * 
165      * @param drools
166      *     The drools
167      */
168     @JsonProperty("drools")
169     public void setDrools(DroolsConfiguration drools) {
170         this.drools = drools;
171     }
172
173     public ControllerConfiguration withDrools(DroolsConfiguration drools) {
174         this.drools = drools;
175         return this;
176     }
177
178     @Override
179     public String toString() {
180         return ToStringBuilder.reflectionToString(this);
181     }
182
183     @JsonAnyGetter
184     public Map<String, Object> getAdditionalProperties() {
185         return this.additionalProperties;
186     }
187
188     @JsonAnySetter
189     public void setAdditionalProperty(String name, Object value) {
190         this.additionalProperties.put(name, value);
191     }
192
193     public ControllerConfiguration withAdditionalProperty(String name, Object value) {
194         this.additionalProperties.put(name, value);
195         return this;
196     }
197
198     protected boolean declaredProperty(String name, Object value) {
199         switch (name) {
200             case "name":
201                 callSetName(value);
202                 return true;
203             case "operation":
204                 callSetOperation(value);
205                 return true;
206             case "drools":
207                 callSetDrools(value);
208                 return true;
209             default:
210                 return false;
211         }
212     }
213
214     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
215         switch (name) {
216             case "name":
217                 return getName();
218             case "operation":
219                 return getOperation();
220             case "drools":
221                 return getDrools();
222             default:
223                 return notFoundValue;
224         }
225     }
226
227     @SuppressWarnings({
228         "unchecked"
229     })
230     public<T >T get(String name) {
231         Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
232         if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
233             return ((T) value);
234         } else {
235             return ((T) getAdditionalProperties().get(name));
236         }
237     }
238
239     public void set(String name, Object value) {
240         if (!declaredProperty(name, value)) {
241             getAdditionalProperties().put(name, (Object) value);
242         }
243     }
244
245     public ControllerConfiguration with(String name, Object value) {
246         if (!declaredProperty(name, value)) {
247             getAdditionalProperties().put(name, (Object) value);
248         }
249         return this;
250     }
251
252     @Override
253     public int hashCode() {
254         return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode();
255     }
256
257     @Override
258     public boolean equals(Object other) {
259         if (other == this) {
260             return true;
261         }
262         if ((other instanceof ControllerConfiguration) == false) {
263             return false;
264         }
265         ControllerConfiguration rhs = ((ControllerConfiguration) other);
266         return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals();
267     }
268     
269     public void callSetName(Object value) {
270         if (value instanceof String) {
271             setName((String) value);
272         } else {
273             throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
274         }
275     }
276     
277     public void callSetOperation(Object value) {
278         if (value instanceof String) {
279             setOperation((String) value);
280         } else {
281             throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
282         }
283     }
284     
285     public void callSetDrools(Object value) {
286         if (value instanceof DroolsConfiguration) {
287             setDrools((DroolsConfiguration) value);
288         } else {
289             throw new IllegalArgumentException("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString());
290         }
291     }
292
293 }