29888bbb6d77e60074307ac24db049a89473db2b
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
4  * ================================================================================
5  * Copyright (C) 2017-2018 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 static final 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     protected boolean declaredProperty(String name, Object value) {
201         switch (name) {
202             case "requestID":
203                 callSetRequestId(value);
204                 return true;
205             case "entity":
206                 callSetEntity(value);
207                 return true;
208             case "controllers":
209                 callSetControllers(value);
210                 return true;
211             default:
212                 return false;
213         }
214     }
215
216     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
217         switch (name) {
218             case "requestID":
219                 return getRequestID();
220             case "entity":
221                 return getEntity();
222             case "controllers":
223                 return getControllers();
224             default:
225                 return notFoundValue;
226         }
227     }
228
229     @SuppressWarnings({
230         "unchecked"
231     })
232     public<T >T get(String name) {
233         Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
234         if (PdpdConfiguration.NOT_FOUND_VALUE!= value) {
235             return (T) value;
236         } else {
237             return (T) getAdditionalProperties().get(name);
238         }
239     }
240
241     public void set(String name, Object value) {
242         if (!declaredProperty(name, value)) {
243             getAdditionalProperties().put(name, value);
244         }
245     }
246
247     public PdpdConfiguration with(String name, Object value) {
248         if (!declaredProperty(name, value)) {
249             getAdditionalProperties().put(name, value);
250         }
251         return this;
252     }
253
254     @Override
255     public int hashCode() {
256         return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode();
257     }
258
259     @Override
260     public boolean equals(Object other) {
261         if (other == this) {
262             return true;
263         }
264         if (!(other instanceof PdpdConfiguration)) {
265             return false;
266         }
267         PdpdConfiguration rhs = (PdpdConfiguration) other;
268         return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals();
269     }
270     
271     public void callSetRequestId(Object value) {
272         if (value instanceof String) {
273             setRequestID((String) value);
274         } else {
275             throw new IllegalArgumentException("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
276         }       
277     }
278     
279     public void callSetEntity(Object value) {
280         if (value instanceof String) {
281             setEntity((String) value);
282         } else {
283             throw new IllegalArgumentException("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString());
284         }       
285     }
286
287     @SuppressWarnings("unchecked")
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 }