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