2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.protocol.configuration;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
28 import lombok.EqualsAndHashCode;
29 import lombok.NoArgsConstructor;
30 import lombok.ToString;
31 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
32 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
33 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
34 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
38 * ENGINE-CONFIGURATION.
43 public class PdpdConfiguration {
45 /** Controller Entity ID. */
46 public static final String CONFIG_ENTITY_CONTROLLER = "controller";
48 protected static final Object NOT_FOUND_VALUE = new Object();
50 /** Unique Transaction ID. This is an UUID. (Required) */
51 @GsonJsonProperty("requestID")
52 private String requestId;
53 /* Set of entities on which configuration can be performed: controller (Required) */
54 @GsonJsonProperty("entity")
55 private String entity;
56 /* Controller Information, only applicable when the entity is set to controller */
57 @GsonJsonProperty("controllers")
58 private List<ControllerConfiguration> controllers = new ArrayList<>();
61 private final Map<String, Object> additionalProperties = new HashMap<>();
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) {
168 return switch (name) {
169 case "requestID" -> {
170 callSetRequestId(value);
174 callSetEntity(value);
177 case "controllers" -> {
178 callSetControllers(value);
185 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
186 return switch (name) {
187 case "requestID" -> getRequestId();
188 case "entity" -> getEntity();
189 case "controllers" -> getControllers();
190 default -> notFoundValue;
200 @SuppressWarnings({"unchecked"})
201 public <T> T get(String name) {
202 Object value = declaredPropertyOrNotFound(name, PdpdConfiguration.NOT_FOUND_VALUE);
203 if (PdpdConfiguration.NOT_FOUND_VALUE != value) {
206 return (T) getAdditionalProperties().get(name);
216 public void set(String name, Object value) {
217 if (!declaredProperty(name, value)) {
218 getAdditionalProperties().put(name, value);
223 * With - sets and returns the object.
225 public PdpdConfiguration with(String name, Object value) {
226 if (!declaredProperty(name, value)) {
227 getAdditionalProperties().put(name, value);
233 * Call set request id.
237 public void callSetRequestId(Object value) {
238 if (value instanceof String) {
239 setRequestId((String) value);
241 throw new IllegalArgumentException(
242 "property \"requestID\" is of type \"java.lang.String\", but got "
243 + value.getClass().toString());
252 public void callSetEntity(Object value) {
253 if (value instanceof String) {
254 setEntity((String) value);
256 throw new IllegalArgumentException(
257 "property \"entity\" is of type \"java.lang.String\", but got "
258 + value.getClass().toString());
263 * Call set controllers.
267 @SuppressWarnings("unchecked")
268 public void callSetControllers(Object value) {
269 if (value instanceof List) {
270 setControllers((List<ControllerConfiguration>) value);
272 throw new IllegalArgumentException(
273 "property \"controllers\" is of type "
274 + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "