2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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 java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import lombok.ToString;
28 import org.apache.commons.lang3.builder.EqualsBuilder;
29 import org.apache.commons.lang3.builder.HashCodeBuilder;
30 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
31 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
32 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
33 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
37 * ENGINE-CONFIGURATION.
40 public class PdpdConfiguration {
42 /** Controller Entity ID. */
43 public static final String CONFIG_ENTITY_CONTROLLER = "controller";
45 /** Unique Transaction ID. This is an UUID. (Required) */
46 @GsonJsonProperty("requestID")
47 private String requestId;
48 /* Set of entities on which configuration can be performed: controller (Required) */
49 @GsonJsonProperty("entity")
50 private String entity;
51 /* Controller Information, only applicable when the entity is set to controller */
52 @GsonJsonProperty("controllers")
53 private List<ControllerConfiguration> controllers = new ArrayList<>();
55 @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
56 protected static final Object NOT_FOUND_VALUE = new Object();
58 /** No args constructor for use in serialization. */
59 public PdpdConfiguration() {
66 * @param requestId request id
67 * @param entity entity
68 * @param controllers controllers
70 public PdpdConfiguration(
71 String requestId, String entity, List<ControllerConfiguration> controllers) {
72 this.requestId = requestId;
74 this.controllers = controllers;
78 * Unique Transaction ID. This is an UUID. (Required)
80 * @return The requestID
82 @GsonJsonProperty("requestID")
83 public String getRequestId() {
88 * Unique Transaction ID. This is an UUID. (Required)
90 * @param requestId The requestID
92 @GsonJsonProperty("requestID")
93 public void setRequestId(String requestId) {
94 this.requestId = requestId;
97 public PdpdConfiguration withRequestId(String requestId) {
98 this.requestId = requestId;
103 * Set of entities on which configuration can be performed: controller (Required).
107 @GsonJsonProperty("entity")
108 public String getEntity() {
113 * Set of entities on which configuration can be performed: controller (Required).
115 * @param entity The entity
117 @GsonJsonProperty("entity")
118 public void setEntity(String entity) {
119 this.entity = entity;
122 public PdpdConfiguration withEntity(String entity) {
123 this.entity = entity;
128 * Controller Information, only applicable when the entity is set to controller.
130 * @return The controller
132 @GsonJsonProperty("controllers")
133 public List<ControllerConfiguration> getControllers() {
138 * Controller Information, only applicable when the entity is set to controller.
140 * @param controllers controllers
142 @GsonJsonProperty("controllers")
143 public void setControllers(List<ControllerConfiguration> controllers) {
144 this.controllers = controllers;
147 public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
148 this.controllers = controllers;
153 public Map<String, Object> getAdditionalProperties() {
154 return this.additionalProperties;
158 public void setAdditionalProperty(String name, Object value) {
159 this.additionalProperties.put(name, value);
162 public PdpdConfiguration withAdditionalProperty(String name, Object value) {
163 this.additionalProperties.put(name, value);
167 protected boolean declaredProperty(String name, Object value) {
170 callSetRequestId(value);
173 callSetEntity(value);
176 callSetControllers(value);
183 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
186 return getRequestId();
190 return getControllers();
192 return notFoundValue;
202 @SuppressWarnings({"unchecked"})
203 public <T> T get(String name) {
204 Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
205 if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
208 return (T) getAdditionalProperties().get(name);
218 public void set(String name, Object value) {
219 if (!declaredProperty(name, value)) {
220 getAdditionalProperties().put(name, value);
225 * With - sets and returns the object.
227 public PdpdConfiguration with(String name, Object value) {
228 if (!declaredProperty(name, value)) {
229 getAdditionalProperties().put(name, value);
235 public int hashCode() {
236 return new HashCodeBuilder()
240 .append(additionalProperties)
245 public boolean equals(Object other) {
249 if (!(other instanceof PdpdConfiguration)) {
252 PdpdConfiguration rhs = (PdpdConfiguration) other;
253 return new EqualsBuilder()
254 .append(requestId, rhs.requestId)
255 .append(entity, rhs.entity)
256 .append(controllers, rhs.controllers)
257 .append(additionalProperties, rhs.additionalProperties)
262 * Call set request id.
266 public void callSetRequestId(Object value) {
267 if (value instanceof String) {
268 setRequestId((String) value);
270 throw new IllegalArgumentException(
271 "property \"requestID\" is of type \"java.lang.String\", but got "
272 + value.getClass().toString());
281 public void callSetEntity(Object value) {
282 if (value instanceof String) {
283 setEntity((String) value);
285 throw new IllegalArgumentException(
286 "property \"entity\" is of type \"java.lang.String\", but got "
287 + value.getClass().toString());
292 * Call set controllers.
296 @SuppressWarnings("unchecked")
297 public void callSetControllers(Object value) {
298 if (value instanceof List) {
299 setControllers((List<ControllerConfiguration>) value);
301 throw new IllegalArgumentException(
302 "property \"controllers\" is of type "
303 + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
305 + value.getClass().toString());