Removing deprecated DMAAP library
[policy/drools-pdp.git] / policy-management / src / main / java / org / onap / policy / drools / protocol / configuration / PdpdConfiguration.java
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.drools.protocol.configuration;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
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;
35
36
37 /**
38  * ENGINE-CONFIGURATION.
39  */
40 @ToString
41 @EqualsAndHashCode
42 @NoArgsConstructor
43 public class PdpdConfiguration {
44
45     /** Controller Entity ID. */
46     public static final String CONFIG_ENTITY_CONTROLLER = "controller";
47
48     protected static final Object NOT_FOUND_VALUE = new Object();
49
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<>();
59
60     @GsonJsonIgnore
61     private final Map<String, Object> additionalProperties = new HashMap<>();
62
63     /**
64      * Constructor.
65      *
66      * @param requestId request id
67      * @param entity entity
68      * @param controllers controllers
69      */
70     public PdpdConfiguration(
71             String requestId, String entity, List<ControllerConfiguration> controllers) {
72         this.requestId = requestId;
73         this.entity = entity;
74         this.controllers = controllers;
75     }
76
77     /**
78      * Unique Transaction ID. This is an UUID. (Required)
79      *
80      * @return The requestID
81      */
82     @GsonJsonProperty("requestID")
83     public String getRequestId() {
84         return requestId;
85     }
86
87     /**
88      * Unique Transaction ID. This is an UUID. (Required)
89      *
90      * @param requestId The requestID
91      */
92     @GsonJsonProperty("requestID")
93     public void setRequestId(String requestId) {
94         this.requestId = requestId;
95     }
96
97     public PdpdConfiguration withRequestId(String requestId) {
98         this.requestId = requestId;
99         return this;
100     }
101
102     /**
103      * Set of entities on which configuration can be performed: controller (Required).
104      *
105      * @return The entity
106      */
107     @GsonJsonProperty("entity")
108     public String getEntity() {
109         return entity;
110     }
111
112     /**
113      * Set of entities on which configuration can be performed: controller (Required).
114      *
115      * @param entity The entity
116      */
117     @GsonJsonProperty("entity")
118     public void setEntity(String entity) {
119         this.entity = entity;
120     }
121
122     public PdpdConfiguration withEntity(String entity) {
123         this.entity = entity;
124         return this;
125     }
126
127     /**
128      * Controller Information, only applicable when the entity is set to controller.
129      *
130      * @return The controller
131      */
132     @GsonJsonProperty("controllers")
133     public List<ControllerConfiguration> getControllers() {
134         return controllers;
135     }
136
137     /**
138      * Controller Information, only applicable when the entity is set to controller.
139      *
140      * @param controllers controllers
141      */
142     @GsonJsonProperty("controllers")
143     public void setControllers(List<ControllerConfiguration> controllers) {
144         this.controllers = controllers;
145     }
146
147     public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
148         this.controllers = controllers;
149         return this;
150     }
151
152     @GsonJsonAnyGetter
153     public Map<String, Object> getAdditionalProperties() {
154         return this.additionalProperties;
155     }
156
157     @GsonJsonAnySetter
158     public void setAdditionalProperty(String name, Object value) {
159         this.additionalProperties.put(name, value);
160     }
161
162     public PdpdConfiguration withAdditionalProperty(String name, Object value) {
163         this.additionalProperties.put(name, value);
164         return this;
165     }
166
167     protected boolean declaredProperty(String name, Object value) {
168         return switch (name) {
169             case "requestID" -> {
170                 callSetRequestId(value);
171                 yield true;
172             }
173             case "entity" -> {
174                 callSetEntity(value);
175                 yield true;
176             }
177             case "controllers" -> {
178                 callSetControllers(value);
179                 yield true;
180             }
181             default -> false;
182         };
183     }
184
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;
191         };
192     }
193
194     /**
195      * Get.
196      *
197      * @param name name
198      * @return object
199      */
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) {
204             return (T) value;
205         } else {
206             return (T) getAdditionalProperties().get(name);
207         }
208     }
209
210     /**
211      * Set property.
212      *
213      * @param name name
214      * @param value value
215      */
216     public void set(String name, Object value) {
217         if (!declaredProperty(name, value)) {
218             getAdditionalProperties().put(name, value);
219         }
220     }
221
222     /**
223      * With - sets and returns the object.
224      */
225     public PdpdConfiguration with(String name, Object value) {
226         if (!declaredProperty(name, value)) {
227             getAdditionalProperties().put(name, value);
228         }
229         return this;
230     }
231
232     /**
233      * Call set request id.
234      *
235      * @param value value
236      */
237     public void callSetRequestId(Object value) {
238         if (value instanceof String) {
239             setRequestId((String) value);
240         } else {
241             throw new IllegalArgumentException(
242                     "property \"requestID\" is of type \"java.lang.String\", but got "
243                             + value.getClass().toString());
244         }
245     }
246
247     /**
248      * Call set entity.
249      *
250      * @param value value
251      */
252     public void callSetEntity(Object value) {
253         if (value instanceof String) {
254             setEntity((String) value);
255         } else {
256             throw new IllegalArgumentException(
257                     "property \"entity\" is of type \"java.lang.String\", but got "
258                             + value.getClass().toString());
259         }
260     }
261
262     /**
263      * Call set controllers.
264      *
265      * @param value value
266      */
267     @SuppressWarnings("unchecked")
268     public void callSetControllers(Object value) {
269         if (value instanceof List) {
270             setControllers((List<ControllerConfiguration>) value);
271         } else {
272             throw new IllegalArgumentException(
273                     "property \"controllers\" is of type "
274                             + "\"java.util.List<org.onap.policy.drools.protocol.configuration.Controller>\", "
275                             + "but got "
276                             + value.getClass());
277         }
278     }
279 }