2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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 java.util.HashMap;
25 import lombok.ToString;
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
29 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
30 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
31 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
35 * Drools Related Information.
39 public class ControllerConfiguration {
41 public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
42 public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
43 public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
44 public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
50 @GsonJsonProperty("name")
53 * Set of operations that can be applied to a controller: create, lock
57 @GsonJsonProperty("operation")
58 private String operation;
60 * Maven Related Information.
63 @GsonJsonProperty("drools")
64 private DroolsConfiguration drools;
67 private Map<String, Object> additionalProperties = new HashMap<>();
69 protected static final Object NOT_FOUND_VALUE = new Object();
72 * No args constructor for use in serialization.
75 public ControllerConfiguration() {
83 * @param operation operation
84 * @param drools drools
86 public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
88 this.operation = operation;
98 @GsonJsonProperty("name")
99 public String getName() {
109 @GsonJsonProperty("name")
110 public void setName(String name) {
114 public ControllerConfiguration withName(String name) {
120 * Set of operations that can be applied to a controller: create, lock
126 @GsonJsonProperty("operation")
127 public String getOperation() {
132 * Set of operations that can be applied to a controller: create, lock
138 @GsonJsonProperty("operation")
139 public void setOperation(String operation) {
140 this.operation = operation;
143 public ControllerConfiguration withOperation(String operation) {
144 this.operation = operation;
149 * Maven Related Information.
154 @GsonJsonProperty("drools")
155 public DroolsConfiguration getDrools() {
160 * Maven Related Information.
165 @GsonJsonProperty("drools")
166 public void setDrools(DroolsConfiguration drools) {
167 this.drools = drools;
170 public ControllerConfiguration withDrools(DroolsConfiguration drools) {
171 this.drools = drools;
176 public Map<String, Object> getAdditionalProperties() {
177 return this.additionalProperties;
181 public void setAdditionalProperty(String name, Object value) {
182 this.additionalProperties.put(name, value);
185 public ControllerConfiguration withAdditionalProperty(String name, Object value) {
186 this.additionalProperties.put(name, value);
190 protected boolean declaredProperty(String name, Object value) {
196 callSetOperation(value);
199 callSetDrools(value);
206 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
211 return getOperation();
215 return notFoundValue;
228 public <T> T get(String name) {
229 Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
230 if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
233 return ((T) getAdditionalProperties().get(name));
240 * @param name property name
241 * @param value property value
243 public void set(String name, Object value) {
244 if (!declaredProperty(name, value)) {
245 getAdditionalProperties().put(name, value);
250 * With - sets the property and additionally returns the object.
252 * @param name property name
253 * @param value property value
256 public ControllerConfiguration with(String name, Object value) {
257 if (!declaredProperty(name, value)) {
258 getAdditionalProperties().put(name, value);
264 public int hashCode() {
265 return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
270 public boolean equals(Object other) {
274 if (!(other instanceof ControllerConfiguration)) {
277 ControllerConfiguration rhs = ((ControllerConfiguration) other);
278 return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
279 .append(additionalProperties, rhs.additionalProperties).isEquals();
287 public void callSetName(Object value) {
288 if (value instanceof String) {
289 setName((String) value);
291 throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
292 + value.getClass().toString());
297 * Call set operation.
301 public void callSetOperation(Object value) {
302 if (value instanceof String) {
303 setOperation((String) value);
305 throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
306 + value.getClass().toString());
315 public void callSetDrools(Object value) {
316 if (value instanceof DroolsConfiguration) {
317 setDrools((DroolsConfiguration) value);
319 throw new IllegalArgumentException("property \"drools\" is of type"
320 + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
321 + value.getClass().toString());