2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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;
35 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
36 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
37 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
38 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
42 * ENGINE-CONFIGURATION.
44 @JsonInclude(JsonInclude.Include.NON_NULL)
45 public class PdpdConfiguration {
47 /** Controller Entity ID. */
48 public static final String CONFIG_ENTITY_CONTROLLER = "controller";
50 /** Unique Transaction ID. This is an UUID. (Required) */
51 @JsonProperty("requestID")
52 @GsonJsonProperty("requestID")
53 private String requestId;
54 /* Set of entities on which configuration can be performed: controller (Required) */
55 @JsonProperty("entity")
56 @GsonJsonProperty("entity")
57 private String entity;
58 /* Controller Information, only applicable when the entity is set to controller */
59 @JsonProperty("controllers")
60 @GsonJsonProperty("controllers")
61 private List<ControllerConfiguration> controllers = new ArrayList<>();
63 @JsonIgnore @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
64 protected static final Object NOT_FOUND_VALUE = new Object();
66 /** No args constructor for use in serialization. */
67 public PdpdConfiguration() {
74 * @param requestId request id
75 * @param entity entity
76 * @param controllers controllers
78 public PdpdConfiguration(
79 String requestId, String entity, List<ControllerConfiguration> controllers) {
80 this.requestId = requestId;
82 this.controllers = controllers;
86 * Unique Transaction ID. This is an UUID. (Required)
88 * @return The requestID
90 @JsonProperty("requestID")
91 @GsonJsonProperty("requestID")
92 public String getRequestId() {
97 * Unique Transaction ID. This is an UUID. (Required)
99 * @param requestId The requestID
101 @JsonProperty("requestID")
102 @GsonJsonProperty("requestID")
103 public void setRequestId(String requestId) {
104 this.requestId = requestId;
107 public PdpdConfiguration withRequestId(String requestId) {
108 this.requestId = requestId;
113 * Set of entities on which configuration can be performed: controller (Required).
117 @JsonProperty("entity")
118 @GsonJsonProperty("entity")
119 public String getEntity() {
124 * Set of entities on which configuration can be performed: controller (Required).
126 * @param entity The entity
128 @JsonProperty("entity")
129 @GsonJsonProperty("entity")
130 public void setEntity(String entity) {
131 this.entity = entity;
134 public PdpdConfiguration withEntity(String entity) {
135 this.entity = entity;
140 * Controller Information, only applicable when the entity is set to controller.
142 * @return The controller
144 @JsonProperty("controllers")
145 @GsonJsonProperty("controllers")
146 public List<ControllerConfiguration> getControllers() {
151 * Controller Information, only applicable when the entity is set to controller.
153 * @param controllers controllers
155 @JsonProperty("controllers")
156 @GsonJsonProperty("controllers")
157 public void setControllers(List<ControllerConfiguration> controllers) {
158 this.controllers = controllers;
161 public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
162 this.controllers = controllers;
167 public String toString() {
168 return ToStringBuilder.reflectionToString(this);
173 public Map<String, Object> getAdditionalProperties() {
174 return this.additionalProperties;
179 public void setAdditionalProperty(String name, Object value) {
180 this.additionalProperties.put(name, value);
183 public PdpdConfiguration withAdditionalProperty(String name, Object value) {
184 this.additionalProperties.put(name, value);
188 protected boolean declaredProperty(String name, Object value) {
191 callSetRequestId(value);
194 callSetEntity(value);
197 callSetControllers(value);
204 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
207 return getRequestId();
211 return getControllers();
213 return notFoundValue;
223 @SuppressWarnings({"unchecked"})
224 public <T> T get(String name) {
225 Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
226 if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
229 return (T) getAdditionalProperties().get(name);
239 public void set(String name, Object value) {
240 if (!declaredProperty(name, value)) {
241 getAdditionalProperties().put(name, value);
246 * With - sets and returns the object.
248 public PdpdConfiguration with(String name, Object value) {
249 if (!declaredProperty(name, value)) {
250 getAdditionalProperties().put(name, value);
256 public int hashCode() {
257 return new HashCodeBuilder()
261 .append(additionalProperties)
266 public boolean equals(Object other) {
270 if (!(other instanceof PdpdConfiguration)) {
273 PdpdConfiguration rhs = (PdpdConfiguration) other;
274 return new EqualsBuilder()
275 .append(requestId, rhs.requestId)
276 .append(entity, rhs.entity)
277 .append(controllers, rhs.controllers)
278 .append(additionalProperties, rhs.additionalProperties)
283 * Call set request id.
287 public void callSetRequestId(Object value) {
288 if (value instanceof String) {
289 setRequestId((String) value);
291 throw new IllegalArgumentException(
292 "property \"requestID\" is of type \"java.lang.String\", but got "
293 + value.getClass().toString());
302 public void callSetEntity(Object value) {
303 if (value instanceof String) {
304 setEntity((String) value);
306 throw new IllegalArgumentException(
307 "property \"entity\" is of type \"java.lang.String\", but got "
308 + value.getClass().toString());
313 * Call set controllers.
317 @SuppressWarnings("unchecked")
318 public void callSetControllers(Object value) {
319 if (value instanceof List) {
320 setControllers((List<ControllerConfiguration>) value);
322 throw new IllegalArgumentException(
323 "property \"controllers\" is of type "
324 + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
326 + value.getClass().toString());