2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.drools.protocol.configuration;
23 import com.fasterxml.jackson.annotation.JsonAnyGetter;
24 import com.fasterxml.jackson.annotation.JsonAnySetter;
25 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
32 import org.apache.commons.lang3.builder.EqualsBuilder;
33 import org.apache.commons.lang3.builder.HashCodeBuilder;
34 import org.apache.commons.lang3.builder.ToStringBuilder;
38 * ENGINE-CONFIGURATION.
40 @JsonInclude(JsonInclude.Include.NON_NULL)
41 public class PdpdConfiguration {
43 /** Controller Entity ID. */
44 public static final String CONFIG_ENTITY_CONTROLLER = "controller";
46 /** Unique Transaction ID. This is an UUID. (Required) */
47 @JsonProperty("requestID")
48 private String requestID;
49 /* Set of entities on which configuration can be performed: controller (Required) */
50 @JsonProperty("entity")
51 private String entity;
52 /* Controller Information, only applicable when the entity is set to controller */
53 @JsonProperty("controllers")
54 private List<ControllerConfiguration> controllers = new ArrayList<>();
56 @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
57 protected static final Object NOT_FOUND_VALUE = new Object();
59 /** No args constructor for use in serialization. */
60 public PdpdConfiguration() {
67 * @param requestID request id
68 * @param entity entity
69 * @param controllers controllers
71 public PdpdConfiguration(
72 String requestID, String entity, List<ControllerConfiguration> controllers) {
73 this.requestID = requestID;
75 this.controllers = controllers;
79 * Unique Transaction ID. This is an UUID. (Required)
81 * @return The requestID
83 @JsonProperty("requestID")
84 public String getRequestID() {
89 * Unique Transaction ID. This is an UUID. (Required)
91 * @param requestID The requestID
93 @JsonProperty("requestID")
94 public void setRequestID(String requestID) {
95 this.requestID = requestID;
98 public PdpdConfiguration withRequestID(String requestID) {
99 this.requestID = requestID;
104 * Set of entities on which configuration can be performed: controller (Required).
108 @JsonProperty("entity")
109 public String getEntity() {
114 * Set of entities on which configuration can be performed: controller (Required).
116 * @param entity The entity
118 @JsonProperty("entity")
119 public void setEntity(String entity) {
120 this.entity = entity;
123 public PdpdConfiguration withEntity(String entity) {
124 this.entity = entity;
129 * Controller Information, only applicable when the entity is set to controller.
131 * @return The controller
133 @JsonProperty("controller")
134 public List<ControllerConfiguration> getControllers() {
139 * Controller Information, only applicable when the entity is set to controller.
141 * @param controllers controllers
143 @JsonProperty("controller")
144 public void setControllers(List<ControllerConfiguration> controllers) {
145 this.controllers = controllers;
148 public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
149 this.controllers = controllers;
154 public String toString() {
155 return ToStringBuilder.reflectionToString(this);
159 public Map<String, Object> getAdditionalProperties() {
160 return this.additionalProperties;
164 public void setAdditionalProperty(String name, Object value) {
165 this.additionalProperties.put(name, value);
168 public PdpdConfiguration withAdditionalProperty(String name, Object value) {
169 this.additionalProperties.put(name, value);
173 protected boolean declaredProperty(String name, Object value) {
176 callSetRequestId(value);
179 callSetEntity(value);
182 callSetControllers(value);
189 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
192 return getRequestID();
196 return getControllers();
198 return notFoundValue;
208 @SuppressWarnings({"unchecked"})
209 public <T> T get(String name) {
210 Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
211 if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
214 return (T) getAdditionalProperties().get(name);
224 public void set(String name, Object value) {
225 if (!declaredProperty(name, value)) {
226 getAdditionalProperties().put(name, value);
231 * With - sets and returns the object.
233 public PdpdConfiguration with(String name, Object value) {
234 if (!declaredProperty(name, value)) {
235 getAdditionalProperties().put(name, value);
241 public int hashCode() {
242 return new HashCodeBuilder()
246 .append(additionalProperties)
251 public boolean equals(Object other) {
255 if (!(other instanceof PdpdConfiguration)) {
258 PdpdConfiguration rhs = (PdpdConfiguration) other;
259 return new EqualsBuilder()
260 .append(requestID, rhs.requestID)
261 .append(entity, rhs.entity)
262 .append(controllers, rhs.controllers)
263 .append(additionalProperties, rhs.additionalProperties)
268 * Call set request id.
272 public void callSetRequestId(Object value) {
273 if (value instanceof String) {
274 setRequestID((String) value);
276 throw new IllegalArgumentException(
277 "property \"requestID\" is of type \"java.lang.String\", but got "
278 + value.getClass().toString());
287 public void callSetEntity(Object value) {
288 if (value instanceof String) {
289 setEntity((String) value);
291 throw new IllegalArgumentException(
292 "property \"entity\" is of type \"java.lang.String\", but got "
293 + value.getClass().toString());
298 * Call set controllers.
302 @SuppressWarnings("unchecked")
303 public void callSetControllers(Object value) {
304 if (value instanceof List) {
305 setControllers((List<ControllerConfiguration>) value);
307 throw new IllegalArgumentException(
308 "property \"controllers\" is of type "
309 + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
311 + value.getClass().toString());