[POLICY-72] replace openecomp for drools-pdp
[policy/drools-pdp.git] / policy-management / src / main / java / org / onap / policy / drools / protocol / configuration / ControllerConfiguration.java
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<String, Object>();
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     }
79
80     /**
81      * 
82      * @param name
83      * @param drools
84      * @param operation
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      * 
94      * (Required)
95      * 
96      * @return
97      *     The name
98      */
99     @JsonProperty("name")
100     public String getName() {
101         return name;
102     }
103
104     /**
105      * 
106      * (Required)
107      * 
108      * @param name
109      *     The name
110      */
111     @JsonProperty("name")
112     public void setName(String name) {
113         this.name = name;
114     }
115
116     public ControllerConfiguration withName(String name) {
117         this.name = name;
118         return this;
119     }
120
121     /**
122      * Set of operations that can be applied to a controller: create, lock
123      * (Required)
124      * 
125      * @return
126      *     The operation
127      */
128     @JsonProperty("operation")
129     public String getOperation() {
130         return operation;
131     }
132
133     /**
134      * Set of operations that can be applied to a controller: create, lock
135      * (Required)
136      * 
137      * @param operation
138      *     The operation
139      */
140     @JsonProperty("operation")
141     public void setOperation(String operation) {
142         this.operation = operation;
143     }
144
145     public ControllerConfiguration withOperation(String operation) {
146         this.operation = operation;
147         return this;
148     }
149
150     /**
151      * Maven Related Information
152      * 
153      * @return
154      *     The drools
155      */
156     @JsonProperty("drools")
157     public DroolsConfiguration getDrools() {
158         return drools;
159     }
160
161     /**
162      * Maven Related Information
163      * 
164      * @param drools
165      *     The drools
166      */
167     @JsonProperty("drools")
168     public void setDrools(DroolsConfiguration drools) {
169         this.drools = drools;
170     }
171
172     public ControllerConfiguration withDrools(DroolsConfiguration drools) {
173         this.drools = drools;
174         return this;
175     }
176
177     @Override
178     public String toString() {
179         return ToStringBuilder.reflectionToString(this);
180     }
181
182     @JsonAnyGetter
183     public Map<String, Object> getAdditionalProperties() {
184         return this.additionalProperties;
185     }
186
187     @JsonAnySetter
188     public void setAdditionalProperty(String name, Object value) {
189         this.additionalProperties.put(name, value);
190     }
191
192     public ControllerConfiguration withAdditionalProperty(String name, Object value) {
193         this.additionalProperties.put(name, value);
194         return this;
195     }
196
197     protected boolean declaredProperty(String name, Object value) {
198         switch (name) {
199             case "name":
200                 if (value instanceof String) {
201                     setName(((String) value));
202                 } else {
203                     throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
204                 }
205                 return true;
206             case "operation":
207                 if (value instanceof String) {
208                     setOperation(((String) value));
209                 } else {
210                     throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
211                 }
212                 return true;
213             case "drools":
214                 if (value instanceof DroolsConfiguration) {
215                     setDrools(((DroolsConfiguration) value));
216                 } else {
217                     throw new IllegalArgumentException(("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString()));
218                 }
219                 return true;
220             default:
221                 return false;
222         }
223     }
224
225     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
226         switch (name) {
227             case "name":
228                 return getName();
229             case "operation":
230                 return getOperation();
231             case "drools":
232                 return getDrools();
233             default:
234                 return notFoundValue;
235         }
236     }
237
238     @SuppressWarnings({
239         "unchecked"
240     })
241     public<T >T get(String name) {
242         Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
243         if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
244             return ((T) value);
245         } else {
246             return ((T) getAdditionalProperties().get(name));
247         }
248     }
249
250     public void set(String name, Object value) {
251         if (!declaredProperty(name, value)) {
252             getAdditionalProperties().put(name, ((Object) value));
253         }
254     }
255
256     public ControllerConfiguration with(String name, Object value) {
257         if (!declaredProperty(name, value)) {
258             getAdditionalProperties().put(name, ((Object) 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).toHashCode();
266     }
267
268     @Override
269     public boolean equals(Object other) {
270         if (other == this) {
271             return true;
272         }
273         if ((other instanceof ControllerConfiguration) == false) {
274             return false;
275         }
276         ControllerConfiguration rhs = ((ControllerConfiguration) other);
277         return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals();
278     }
279
280 }