b0b8b50465686491209f8cd2f81306c04943a8cc
[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                 if (value instanceof String) {
202                     setName(((String) value));
203                 } else {
204                     throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
205                 }
206                 return true;
207             case "operation":
208                 if (value instanceof String) {
209                     setOperation(((String) value));
210                 } else {
211                     throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
212                 }
213                 return true;
214             case "drools":
215                 if (value instanceof DroolsConfiguration) {
216                     setDrools(((DroolsConfiguration) value));
217                 } else {
218                     throw new IllegalArgumentException(("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString()));
219                 }
220                 return true;
221             default:
222                 return false;
223         }
224     }
225
226     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
227         switch (name) {
228             case "name":
229                 return getName();
230             case "operation":
231                 return getOperation();
232             case "drools":
233                 return getDrools();
234             default:
235                 return notFoundValue;
236         }
237     }
238
239     @SuppressWarnings({
240         "unchecked"
241     })
242     public<T >T get(String name) {
243         Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
244         if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
245             return ((T) value);
246         } else {
247             return ((T) getAdditionalProperties().get(name));
248         }
249     }
250
251     public void set(String name, Object value) {
252         if (!declaredProperty(name, value)) {
253             getAdditionalProperties().put(name, ((Object) value));
254         }
255     }
256
257     public ControllerConfiguration with(String name, Object value) {
258         if (!declaredProperty(name, value)) {
259             getAdditionalProperties().put(name, ((Object) value));
260         }
261         return this;
262     }
263
264     @Override
265     public int hashCode() {
266         return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode();
267     }
268
269     @Override
270     public boolean equals(Object other) {
271         if (other == this) {
272             return true;
273         }
274         if ((other instanceof ControllerConfiguration) == false) {
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).append(additionalProperties, rhs.additionalProperties).isEquals();
279     }
280
281 }