d7295fd423cb6533cdfd575321094c988b092558
[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<ControllerConfiguration>();
71     @JsonIgnore
72     private Map<String, Object> additionalProperties = new HashMap<String, Object>();
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     }
81
82     /**
83      * 
84      * @param controller
85      * @param requestID
86      * @param entity
87      */
88     public PdpdConfiguration(String requestID, String entity, List<ControllerConfiguration> controllers) {
89         this.requestID = requestID;
90         this.entity = entity;
91         this.controllers = controllers;
92     }
93
94     /**
95      * Unique Transaction ID.   This is an UUID.
96      * (Required)
97      * 
98      * @return
99      *     The requestID
100      */
101     @JsonProperty("requestID")
102     public String getRequestID() {
103         return requestID;
104     }
105
106     /**
107      * Unique Transaction ID.   This is an UUID.
108      * (Required)
109      * 
110      * @param requestID
111      *     The requestID
112      */
113     @JsonProperty("requestID")
114     public void setRequestID(String requestID) {
115         this.requestID = requestID;
116     }
117
118     public PdpdConfiguration withRequestID(String requestID) {
119         this.requestID = requestID;
120         return this;
121     }
122
123     /**
124      * Set of entities on which configuration can be performed: controller
125      * (Required)
126      * 
127      * @return
128      *     The entity
129      */
130     @JsonProperty("entity")
131     public String getEntity() {
132         return entity;
133     }
134
135     /**
136      * Set of entities on which configuration can be performed: controller
137      * (Required)
138      * 
139      * @param entity
140      *     The entity
141      */
142     @JsonProperty("entity")
143     public void setEntity(String entity) {
144         this.entity = entity;
145     }
146
147     public PdpdConfiguration withEntity(String entity) {
148         this.entity = entity;
149         return this;
150     }
151
152     /**
153      * Controller Information, only applicable when the entity is set to controller
154      * 
155      * @return
156      *     The controller
157      */
158     @JsonProperty("controller")
159     public List<ControllerConfiguration> getControllers() {
160         return controllers;
161     }
162
163     /**
164      * Controller Information, only applicable when the entity is set to controller
165      * 
166      * @param controller
167      *     The controller
168      */
169     @JsonProperty("controller")
170     public void setControllers(List<ControllerConfiguration> controllers) {
171         this.controllers = controllers;
172     }
173
174     public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
175         this.controllers = controllers;
176         return this;
177     }
178
179     @Override
180     public String toString() {
181         return ToStringBuilder.reflectionToString(this);
182     }
183
184     @JsonAnyGetter
185     public Map<String, Object> getAdditionalProperties() {
186         return this.additionalProperties;
187     }
188
189     @JsonAnySetter
190     public void setAdditionalProperty(String name, Object value) {
191         this.additionalProperties.put(name, value);
192     }
193
194     public PdpdConfiguration withAdditionalProperty(String name, Object value) {
195         this.additionalProperties.put(name, value);
196         return this;
197     }
198
199     @SuppressWarnings("unchecked")
200         protected boolean declaredProperty(String name, Object value) {
201         switch (name) {
202             case "requestID":
203                 if (value instanceof String) {
204                     setRequestID(((String) value));
205                 } else {
206                     throw new IllegalArgumentException(("property \"requestID\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
207                 }
208                 return true;
209             case "entity":
210                 if (value instanceof String) {
211                     setEntity(((String) value));
212                 } else {
213                     throw new IllegalArgumentException(("property \"entity\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
214                 }
215                 return true;
216             case "controllers":
217                 if (value instanceof List) {
218                     setControllers(((List<ControllerConfiguration> ) value));
219                 } else {
220                     throw new IllegalArgumentException(("property \"controllers\" is of type \"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", but got "+ value.getClass().toString()));
221                 }
222                 return true;
223             default:
224                 return false;
225         }
226     }
227
228     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
229         switch (name) {
230             case "requestID":
231                 return getRequestID();
232             case "entity":
233                 return getEntity();
234             case "controllers":
235                 return getControllers();
236             default:
237                 return notFoundValue;
238         }
239     }
240
241     @SuppressWarnings({
242         "unchecked"
243     })
244     public<T >T get(String name) {
245         Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
246         if (PdpdConfiguration.NOT_FOUND_VALUE!= value) {
247             return ((T) value);
248         } else {
249             return ((T) getAdditionalProperties().get(name));
250         }
251     }
252
253     public void set(String name, Object value) {
254         if (!declaredProperty(name, value)) {
255             getAdditionalProperties().put(name, ((Object) value));
256         }
257     }
258
259     public PdpdConfiguration with(String name, Object value) {
260         if (!declaredProperty(name, value)) {
261             getAdditionalProperties().put(name, ((Object) value));
262         }
263         return this;
264     }
265
266     @Override
267     public int hashCode() {
268         return new HashCodeBuilder().append(requestID).append(entity).append(controllers).append(additionalProperties).toHashCode();
269     }
270
271     @Override
272     public boolean equals(Object other) {
273         if (other == this) {
274             return true;
275         }
276         if ((other instanceof PdpdConfiguration) == false) {
277             return false;
278         }
279         PdpdConfiguration rhs = ((PdpdConfiguration) other);
280         return new EqualsBuilder().append(requestID, rhs.requestID).append(entity, rhs.entity).append(controllers, rhs.controllers).append(additionalProperties, rhs.additionalProperties).isEquals();
281     }
282
283 }