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;
38 * Drools Related Information.
41 @JsonInclude(JsonInclude.Include.NON_NULL)
42 public class ControllerConfiguration {
44 public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
45 public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
46 public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
47 public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
56 * Set of operations that can be applied to a controller: create, lock
60 @JsonProperty("operation")
61 private String operation;
63 * Maven Related Information.
66 @JsonProperty("drools")
67 private DroolsConfiguration drools;
69 private Map<String, Object> additionalProperties = new HashMap<>();
70 protected static final Object NOT_FOUND_VALUE = new Object();
73 * No args constructor for use in serialization.
76 public ControllerConfiguration() {
84 * @param operation operation
85 * @param drools drools
87 public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
89 this.operation = operation;
100 public String getName() {
110 @JsonProperty("name")
111 public void setName(String name) {
115 public ControllerConfiguration withName(String name) {
121 * Set of operations that can be applied to a controller: create, lock
127 @JsonProperty("operation")
128 public String getOperation() {
133 * Set of operations that can be applied to a controller: create, lock
139 @JsonProperty("operation")
140 public void setOperation(String operation) {
141 this.operation = operation;
144 public ControllerConfiguration withOperation(String operation) {
145 this.operation = operation;
150 * Maven Related Information.
155 @JsonProperty("drools")
156 public DroolsConfiguration getDrools() {
161 * Maven Related Information.
166 @JsonProperty("drools")
167 public void setDrools(DroolsConfiguration drools) {
168 this.drools = drools;
171 public ControllerConfiguration withDrools(DroolsConfiguration drools) {
172 this.drools = drools;
177 public String toString() {
178 return ToStringBuilder.reflectionToString(this);
182 public Map<String, Object> getAdditionalProperties() {
183 return this.additionalProperties;
187 public void setAdditionalProperty(String name, Object value) {
188 this.additionalProperties.put(name, value);
191 public ControllerConfiguration withAdditionalProperty(String name, Object value) {
192 this.additionalProperties.put(name, value);
196 protected boolean declaredProperty(String name, Object value) {
202 callSetOperation(value);
205 callSetDrools(value);
212 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
217 return getOperation();
221 return notFoundValue;
234 public <T> T get(String name) {
235 Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
236 if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
239 return ((T) getAdditionalProperties().get(name));
246 * @param name property name
247 * @param value property value
249 public void set(String name, Object value) {
250 if (!declaredProperty(name, value)) {
251 getAdditionalProperties().put(name, (Object) value);
256 * With - sets the property and additionally returns the object.
258 * @param name property name
259 * @param value property value
262 public ControllerConfiguration with(String name, Object value) {
263 if (!declaredProperty(name, value)) {
264 getAdditionalProperties().put(name, (Object) value);
270 public int hashCode() {
271 return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
276 public boolean equals(Object other) {
280 if (!(other instanceof ControllerConfiguration)) {
283 ControllerConfiguration rhs = ((ControllerConfiguration) other);
284 return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
285 .append(additionalProperties, rhs.additionalProperties).isEquals();
293 public void callSetName(Object value) {
294 if (value instanceof String) {
295 setName((String) value);
297 throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
298 + value.getClass().toString());
303 * Call set operation.
307 public void callSetOperation(Object value) {
308 if (value instanceof String) {
309 setOperation((String) value);
311 throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
312 + value.getClass().toString());
321 public void callSetDrools(Object value) {
322 if (value instanceof DroolsConfiguration) {
323 setDrools((DroolsConfiguration) value);
325 throw new IllegalArgumentException("property \"drools\" is of type"
326 + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
327 + value.getClass().toString());