2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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;
29 import java.util.HashMap;
32 import org.apache.commons.lang3.builder.EqualsBuilder;
33 import org.apache.commons.lang3.builder.HashCodeBuilder;
34 import org.apache.commons.lang3.builder.ToStringBuilder;
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 * Drools Related Information.
45 @JsonInclude(JsonInclude.Include.NON_NULL)
46 public class ControllerConfiguration {
48 public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
49 public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
50 public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
51 public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
58 @GsonJsonProperty("name")
61 * Set of operations that can be applied to a controller: create, lock
65 @JsonProperty("operation")
66 @GsonJsonProperty("operation")
67 private String operation;
69 * Maven Related Information.
72 @JsonProperty("drools")
73 @GsonJsonProperty("drools")
74 private DroolsConfiguration drools;
78 private Map<String, Object> additionalProperties = new HashMap<>();
80 protected static final Object NOT_FOUND_VALUE = new Object();
83 * No args constructor for use in serialization.
86 public ControllerConfiguration() {
94 * @param operation operation
95 * @param drools drools
97 public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
99 this.operation = operation;
100 this.drools = drools;
109 @JsonProperty("name")
110 @GsonJsonProperty("name")
111 public String getName() {
121 @JsonProperty("name")
122 @GsonJsonProperty("name")
123 public void setName(String name) {
127 public ControllerConfiguration withName(String name) {
133 * Set of operations that can be applied to a controller: create, lock
139 @JsonProperty("operation")
140 @GsonJsonProperty("operation")
141 public String getOperation() {
146 * Set of operations that can be applied to a controller: create, lock
152 @JsonProperty("operation")
153 @GsonJsonProperty("operation")
154 public void setOperation(String operation) {
155 this.operation = operation;
158 public ControllerConfiguration withOperation(String operation) {
159 this.operation = operation;
164 * Maven Related Information.
169 @JsonProperty("drools")
170 @GsonJsonProperty("drools")
171 public DroolsConfiguration getDrools() {
176 * Maven Related Information.
181 @JsonProperty("drools")
182 @GsonJsonProperty("drools")
183 public void setDrools(DroolsConfiguration drools) {
184 this.drools = drools;
187 public ControllerConfiguration withDrools(DroolsConfiguration drools) {
188 this.drools = drools;
193 public String toString() {
194 return ToStringBuilder.reflectionToString(this);
199 public Map<String, Object> getAdditionalProperties() {
200 return this.additionalProperties;
205 public void setAdditionalProperty(String name, Object value) {
206 this.additionalProperties.put(name, value);
209 public ControllerConfiguration withAdditionalProperty(String name, Object value) {
210 this.additionalProperties.put(name, value);
214 protected boolean declaredProperty(String name, Object value) {
220 callSetOperation(value);
223 callSetDrools(value);
230 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
235 return getOperation();
239 return notFoundValue;
252 public <T> T get(String name) {
253 Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
254 if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
257 return ((T) getAdditionalProperties().get(name));
264 * @param name property name
265 * @param value property value
267 public void set(String name, Object value) {
268 if (!declaredProperty(name, value)) {
269 getAdditionalProperties().put(name, (Object) value);
274 * With - sets the property and additionally returns the object.
276 * @param name property name
277 * @param value property value
280 public ControllerConfiguration with(String name, Object value) {
281 if (!declaredProperty(name, value)) {
282 getAdditionalProperties().put(name, (Object) value);
288 public int hashCode() {
289 return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
294 public boolean equals(Object other) {
298 if (!(other instanceof ControllerConfiguration)) {
301 ControllerConfiguration rhs = ((ControllerConfiguration) other);
302 return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
303 .append(additionalProperties, rhs.additionalProperties).isEquals();
311 public void callSetName(Object value) {
312 if (value instanceof String) {
313 setName((String) value);
315 throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
316 + value.getClass().toString());
321 * Call set operation.
325 public void callSetOperation(Object value) {
326 if (value instanceof String) {
327 setOperation((String) value);
329 throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
330 + value.getClass().toString());
339 public void callSetDrools(Object value) {
340 if (value instanceof DroolsConfiguration) {
341 setDrools((DroolsConfiguration) value);
343 throw new IllegalArgumentException("property \"drools\" is of type"
344 + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
345 + value.getClass().toString());