c7a227b1d95904e4773340d8415386ae029c5dde
[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.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import com.fasterxml.jackson.annotation.JsonAnyGetter;
28 import com.fasterxml.jackson.annotation.JsonAnySetter;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import com.fasterxml.jackson.annotation.JsonInclude;
31 import com.fasterxml.jackson.annotation.JsonProperty;
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  * ENGINE-CONFIGURATION
39  * <p>
40  * 
41  * 
42  */
43 @JsonInclude(JsonInclude.Include.NON_NULL)
44 public class PdpdConfiguration {
45         
46         /**
47          * Controller Entity ID
48          */
49         public static final String CONFIG_ENTITY_CONTROLLER = "controller";
50
51     /**
52      * Unique Transaction ID.   This is an UUID.
53      * (Required)
54      * 
55      */
56     @JsonProperty("requestID")
57     private String requestID;
58     /**
59      * Set of entities on which configuration can be performed: controller
60      * (Required)
61      * 
62      */
63     @JsonProperty("entity")
64     private String entity;
65     /**
66      * Controller Information, only applicable when the entity is set to controller
67      * 
68      */
69     @JsonProperty("controllers")
70     private List<ControllerConfiguration> controllers = new ArrayList<>();
71     @JsonIgnore
72     private Map<String, Object> additionalProperties = new HashMap<>();
73     protected final static Object NOT_FOUND_VALUE = new Object();
74
75     /**
76      * No args constructor for use in serialization
77      * 
78      */
79     public PdpdConfiguration() {
80         // Empty
81     }
82
83     /**
84      * 
85      * @param controller
86      * @param requestID
87      * @param entity
88      */
89     public PdpdConfiguration(String requestID, String entity, List<ControllerConfiguration> controllers) {
90         this.requestID = requestID;
91         this.entity = entity;
92         this.controllers = controllers;
93     }
94
95     /**
96      * Unique Transaction ID.   This is an UUID.
97      * (Required)
98      * 
99      * @return
100      *     The requestID
101      */
102     @JsonProperty("requestID")
103     public String getRequestID() {
104         return requestID;
105     }
106
107     /**
108      * Unique Transaction ID.   This is an UUID.
109      * (Required)
110      * 
111      * @param requestID
112      *     The requestID
113      */
114     @JsonProperty("requestID")
115     public void setRequestID(String requestID) {
116         this.requestID = requestID;
117     }
118
119     public PdpdConfiguration withRequestID(String requestID) {
120         this.requestID = requestID;
121         return this;
122     }
123
124     /**
125      * Set of entities on which configuration can be performed: controller
126      * (Required)
127      * 
128      * @return
129      *     The entity
130      */
131     @JsonProperty("entity")
132     public String getEntity() {
133         return entity;
134     }
135
136     /**
137      * Set of entities on which configuration can be performed: controller
138      * (Required)
139      * 
140      * @param entity
141      *     The entity
142      */
143     @JsonProperty("entity")
144     public void setEntity(String entity) {
145         this.entity = entity;
146     }
147
148     public PdpdConfiguration withEntity(String entity) {
149         this.entity = entity;
150         return this;
151     }
152
153     /**
154      * Controller Information, only applicable when the entity is set to controller
155      * 
156      * @return
157      *     The controller
158      */
159     @JsonProperty("controller")
160     public List<ControllerConfiguration> getControllers() {
161         return controllers;
162     }
163
164     /**
165      * Controller Information, only applicable when the entity is set to controller
166      * 
167      * @param controller
168      *     The controller
169      */
170     @JsonProperty("controller")
171     public void setControllers(List<ControllerConfiguration> controllers) {
172         this.controllers = controllers;
173     }
174
175     public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
176         this.controllers = controllers;
177         return this;
178     }
179
180     @Override
181     public String toString() {
182         return ToStringBuilder.reflectionToString(this);
183     }
184
185     @JsonAnyGetter
186     public Map<String, Object> getAdditionalProperties() {
187         return this.additionalProperties;
188     }
189
190     @JsonAnySetter
191     public void setAdditionalProperty(String name, Object value) {
192         this.additionalProperties.put(name, value);
193     }
194
195     public PdpdConfiguration withAdditionalProperty(String name, Object value) {
196         this.additionalProperties.put(name, value);
197         return this;
198     }
199
200     @SuppressWarnings("unchecked")
201         protected boolean declaredProperty(String name, Object value) {
202         switch (name) {
203             case "requestID":
204                 callSetRequestId(value);
205                 return true;
206             case "entity":
207                 callSetEntity(value);
208                 return true;
209             case "controllers":
210                 callSetControllers(value);
211                 return true;
212             default:
213                 return false;
214         }
215     }
216
217     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
218         switch (name) {
219             case "requestID":
220                 return getRequestID();
221             case "entity":
222                 return getEntity();
223             case "controllers":
224                 return getControllers();
225             default:
226                 return notFoundValue;
227         }
228     }
229
230     @SuppressWarnings({
231         "unchecked"
232     })
233     public<T >T get(String name) {
234         Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
235         if (PdpdConfiguration.NOT_FOUND_VALUE!= value) {
236             return (T) value;
237         } else {
238             return (T) getAdditionalProperties().get(name);
239         }
240     }
241
242     public void set(String name, Object value) {
243         if (!declaredProperty(name, value)) {
244             getAdditionalProperties().put(name, value);
245         }
246     }
247
248     public PdpdConfiguration with(String name, Object value) {
249         if (!declaredProperty(name, value)) {
250             getAdditionalProperties().put(name, value);
251         }
252         return this;
253     }
254
255     @Override
256     public int hashCode() {
257         return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode();
258     }
259
260     @Override
261     public boolean equals(Object other) {
262         if (other == this) {
263             return true;
264         }
265         if ((other instanceof PdpdConfiguration) == false) {
266             return false;
267         }
268         PdpdConfiguration rhs = (PdpdConfiguration) other;
269         return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals();
270     }
271     
272     public void callSetRequestId(Object value) {
273         if (value instanceof String) {
274             setRequestID((String) value);
275         } else {
276             throw new IllegalArgumentException("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
277         }       
278     }
279     
280     public void callSetEntity(Object value) {
281         if (value instanceof String) {
282             setEntity((String) value);
283         } else {
284             throw new IllegalArgumentException("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
285         }       
286     }
287
288     public void callSetControllers(Object value) {
289         if (value instanceof List) {
290             setControllers((List<ControllerConfiguration> ) value);
291         } else {
292             throw new IllegalArgumentException("property \"controllers\" is of type \"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", but got "+ value.getClass().toString());
293         }        
294     }
295 }