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 lombok.ToString;
33 import org.apache.commons.lang3.builder.EqualsBuilder;
34 import org.apache.commons.lang3.builder.HashCodeBuilder;
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)
46 public class PdpdConfiguration {
48 /** Controller Entity ID. */
49 public static final String CONFIG_ENTITY_CONTROLLER = "controller";
51 /** Unique Transaction ID. This is an UUID. (Required) */
52 @JsonProperty("requestID")
53 @GsonJsonProperty("requestID")
54 private String requestId;
55 /* Set of entities on which configuration can be performed: controller (Required) */
56 @JsonProperty("entity")
57 @GsonJsonProperty("entity")
58 private String entity;
59 /* Controller Information, only applicable when the entity is set to controller */
60 @JsonProperty("controllers")
61 @GsonJsonProperty("controllers")
62 private List<ControllerConfiguration> controllers = new ArrayList<>();
64 @JsonIgnore @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
65 protected static final Object NOT_FOUND_VALUE = new Object();
67 /** No args constructor for use in serialization. */
68 public PdpdConfiguration() {
75 * @param requestId request id
76 * @param entity entity
77 * @param controllers controllers
79 public PdpdConfiguration(
80 String requestId, String entity, List<ControllerConfiguration> controllers) {
81 this.requestId = requestId;
83 this.controllers = controllers;
87 * Unique Transaction ID. This is an UUID. (Required)
89 * @return The requestID
91 @JsonProperty("requestID")
92 @GsonJsonProperty("requestID")
93 public String getRequestId() {
98 * Unique Transaction ID. This is an UUID. (Required)
100 * @param requestId The requestID
102 @JsonProperty("requestID")
103 @GsonJsonProperty("requestID")
104 public void setRequestId(String requestId) {
105 this.requestId = requestId;
108 public PdpdConfiguration withRequestId(String requestId) {
109 this.requestId = requestId;
114 * Set of entities on which configuration can be performed: controller (Required).
118 @JsonProperty("entity")
119 @GsonJsonProperty("entity")
120 public String getEntity() {
125 * Set of entities on which configuration can be performed: controller (Required).
127 * @param entity The entity
129 @JsonProperty("entity")
130 @GsonJsonProperty("entity")
131 public void setEntity(String entity) {
132 this.entity = entity;
135 public PdpdConfiguration withEntity(String entity) {
136 this.entity = entity;
141 * Controller Information, only applicable when the entity is set to controller.
143 * @return The controller
145 @JsonProperty("controllers")
146 @GsonJsonProperty("controllers")
147 public List<ControllerConfiguration> getControllers() {
152 * Controller Information, only applicable when the entity is set to controller.
154 * @param controllers controllers
156 @JsonProperty("controllers")
157 @GsonJsonProperty("controllers")
158 public void setControllers(List<ControllerConfiguration> controllers) {
159 this.controllers = controllers;
162 public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
163 this.controllers = controllers;
169 public Map<String, Object> getAdditionalProperties() {
170 return this.additionalProperties;
175 public void setAdditionalProperty(String name, Object value) {
176 this.additionalProperties.put(name, value);
179 public PdpdConfiguration withAdditionalProperty(String name, Object value) {
180 this.additionalProperties.put(name, value);
184 protected boolean declaredProperty(String name, Object value) {
187 callSetRequestId(value);
190 callSetEntity(value);
193 callSetControllers(value);
200 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
203 return getRequestId();
207 return getControllers();
209 return notFoundValue;
219 @SuppressWarnings({"unchecked"})
220 public <T> T get(String name) {
221 Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
222 if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
225 return (T) getAdditionalProperties().get(name);
235 public void set(String name, Object value) {
236 if (!declaredProperty(name, value)) {
237 getAdditionalProperties().put(name, value);
242 * With - sets and returns the object.
244 public PdpdConfiguration with(String name, Object value) {
245 if (!declaredProperty(name, value)) {
246 getAdditionalProperties().put(name, value);
252 public int hashCode() {
253 return new HashCodeBuilder()
257 .append(additionalProperties)
262 public boolean equals(Object other) {
266 if (!(other instanceof PdpdConfiguration)) {
269 PdpdConfiguration rhs = (PdpdConfiguration) other;
270 return new EqualsBuilder()
271 .append(requestId, rhs.requestId)
272 .append(entity, rhs.entity)
273 .append(controllers, rhs.controllers)
274 .append(additionalProperties, rhs.additionalProperties)
279 * Call set request id.
283 public void callSetRequestId(Object value) {
284 if (value instanceof String) {
285 setRequestId((String) value);
287 throw new IllegalArgumentException(
288 "property \"requestID\" is of type \"java.lang.String\", but got "
289 + value.getClass().toString());
298 public void callSetEntity(Object value) {
299 if (value instanceof String) {
300 setEntity((String) value);
302 throw new IllegalArgumentException(
303 "property \"entity\" is of type \"java.lang.String\", but got "
304 + value.getClass().toString());
309 * Call set controllers.
313 @SuppressWarnings("unchecked")
314 public void callSetControllers(Object value) {
315 if (value instanceof List) {
316 setControllers((List<ControllerConfiguration>) value);
318 throw new IllegalArgumentException(
319 "property \"controllers\" is of type "
320 + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
322 + value.getClass().toString());