f3a422e7c4302dbbf7671d56e05a53b1ab22506f
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
4  * ================================================================================
5  * Copyright (C) 2017-2021 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.drools.protocol.configuration;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import lombok.EqualsAndHashCode;
28 import lombok.NoArgsConstructor;
29 import lombok.ToString;
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;
34
35
36 /**
37  * ENGINE-CONFIGURATION.
38  */
39 @ToString
40 @EqualsAndHashCode
41 @NoArgsConstructor
42 public class PdpdConfiguration {
43
44     /** Controller Entity ID. */
45     public static final String CONFIG_ENTITY_CONTROLLER = "controller";
46
47     protected static final Object NOT_FOUND_VALUE = new Object();
48
49     /** Unique Transaction ID. This is an UUID. (Required) */
50     @GsonJsonProperty("requestID")
51     private String requestId;
52     /* Set of entities on which configuration can be performed: controller (Required) */
53     @GsonJsonProperty("entity")
54     private String entity;
55     /* Controller Information, only applicable when the entity is set to controller */
56     @GsonJsonProperty("controllers")
57     private List<ControllerConfiguration> controllers = new ArrayList<>();
58
59     @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>();
60
61     /**
62      * Constructor.
63      *
64      * @param requestId request id
65      * @param entity entity
66      * @param controllers controllers
67      */
68     public PdpdConfiguration(
69             String requestId, String entity, List<ControllerConfiguration> controllers) {
70         this.requestId = requestId;
71         this.entity = entity;
72         this.controllers = controllers;
73     }
74
75     /**
76      * Unique Transaction ID. This is an UUID. (Required)
77      *
78      * @return The requestID
79      */
80     @GsonJsonProperty("requestID")
81     public String getRequestId() {
82         return requestId;
83     }
84
85     /**
86      * Unique Transaction ID. This is an UUID. (Required)
87      *
88      * @param requestId The requestID
89      */
90     @GsonJsonProperty("requestID")
91     public void setRequestId(String requestId) {
92         this.requestId = requestId;
93     }
94
95     public PdpdConfiguration withRequestId(String requestId) {
96         this.requestId = requestId;
97         return this;
98     }
99
100     /**
101      * Set of entities on which configuration can be performed: controller (Required).
102      *
103      * @return The entity
104      */
105     @GsonJsonProperty("entity")
106     public String getEntity() {
107         return entity;
108     }
109
110     /**
111      * Set of entities on which configuration can be performed: controller (Required).
112      *
113      * @param entity The entity
114      */
115     @GsonJsonProperty("entity")
116     public void setEntity(String entity) {
117         this.entity = entity;
118     }
119
120     public PdpdConfiguration withEntity(String entity) {
121         this.entity = entity;
122         return this;
123     }
124
125     /**
126      * Controller Information, only applicable when the entity is set to controller.
127      *
128      * @return The controller
129      */
130     @GsonJsonProperty("controllers")
131     public List<ControllerConfiguration> getControllers() {
132         return controllers;
133     }
134
135     /**
136      * Controller Information, only applicable when the entity is set to controller.
137      *
138      * @param controllers controllers
139      */
140     @GsonJsonProperty("controllers")
141     public void setControllers(List<ControllerConfiguration> controllers) {
142         this.controllers = controllers;
143     }
144
145     public PdpdConfiguration withController(List<ControllerConfiguration> controllers) {
146         this.controllers = controllers;
147         return this;
148     }
149
150     @GsonJsonAnyGetter
151     public Map<String, Object> getAdditionalProperties() {
152         return this.additionalProperties;
153     }
154
155     @GsonJsonAnySetter
156     public void setAdditionalProperty(String name, Object value) {
157         this.additionalProperties.put(name, value);
158     }
159
160     public PdpdConfiguration withAdditionalProperty(String name, Object value) {
161         this.additionalProperties.put(name, value);
162         return this;
163     }
164
165     protected boolean declaredProperty(String name, Object value) {
166         switch (name) {
167             case "requestID":
168                 callSetRequestId(value);
169                 return true;
170             case "entity":
171                 callSetEntity(value);
172                 return true;
173             case "controllers":
174                 callSetControllers(value);
175                 return true;
176             default:
177                 return false;
178         }
179     }
180
181     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
182         switch (name) {
183             case "requestID":
184                 return getRequestId();
185             case "entity":
186                 return getEntity();
187             case "controllers":
188                 return getControllers();
189             default:
190                 return 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().toString());
277         }
278     }
279 }