2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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;
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28 import org.apache.commons.lang3.builder.ToStringBuilder;
30 import com.fasterxml.jackson.annotation.JsonAnyGetter;
31 import com.fasterxml.jackson.annotation.JsonAnySetter;
32 import com.fasterxml.jackson.annotation.JsonIgnore;
33 import com.fasterxml.jackson.annotation.JsonInclude;
34 import com.fasterxml.jackson.annotation.JsonProperty;
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";
57 * Set of operations that can be applied to a controller: create, lock
61 @JsonProperty("operation")
62 private String operation;
64 * Maven Related Information
67 @JsonProperty("drools")
68 private DroolsConfiguration drools;
70 private Map<String, Object> additionalProperties = new HashMap<>();
71 protected final static Object NOT_FOUND_VALUE = new Object();
74 * No args constructor for use in serialization
77 public ControllerConfiguration() {
87 public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
89 this.operation = operation;
100 @JsonProperty("name")
101 public String getName() {
112 @JsonProperty("name")
113 public void setName(String name) {
117 public ControllerConfiguration withName(String name) {
123 * Set of operations that can be applied to a controller: create, lock
129 @JsonProperty("operation")
130 public String getOperation() {
135 * Set of operations that can be applied to a controller: create, lock
141 @JsonProperty("operation")
142 public void setOperation(String operation) {
143 this.operation = operation;
146 public ControllerConfiguration withOperation(String operation) {
147 this.operation = operation;
152 * Maven Related Information
157 @JsonProperty("drools")
158 public DroolsConfiguration getDrools() {
163 * Maven Related Information
168 @JsonProperty("drools")
169 public void setDrools(DroolsConfiguration drools) {
170 this.drools = drools;
173 public ControllerConfiguration withDrools(DroolsConfiguration drools) {
174 this.drools = drools;
179 public String toString() {
180 return ToStringBuilder.reflectionToString(this);
184 public Map<String, Object> getAdditionalProperties() {
185 return this.additionalProperties;
189 public void setAdditionalProperty(String name, Object value) {
190 this.additionalProperties.put(name, value);
193 public ControllerConfiguration withAdditionalProperty(String name, Object value) {
194 this.additionalProperties.put(name, value);
198 protected boolean declaredProperty(String name, Object value) {
201 if (value instanceof String) {
202 setName(((String) value));
204 throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
208 if (value instanceof String) {
209 setOperation(((String) value));
211 throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
215 if (value instanceof DroolsConfiguration) {
216 setDrools(((DroolsConfiguration) value));
218 throw new IllegalArgumentException(("property \"drools\" is of type \"org.onap.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString()));
226 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
231 return getOperation();
235 return notFoundValue;
242 public<T >T get(String name) {
243 Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
244 if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
247 return ((T) getAdditionalProperties().get(name));
251 public void set(String name, Object value) {
252 if (!declaredProperty(name, value)) {
253 getAdditionalProperties().put(name, ((Object) value));
257 public ControllerConfiguration with(String name, Object value) {
258 if (!declaredProperty(name, value)) {
259 getAdditionalProperties().put(name, ((Object) value));
265 public int hashCode() {
266 return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode();
270 public boolean equals(Object other) {
274 if ((other instanceof ControllerConfiguration) == false) {
277 ControllerConfiguration rhs = ((ControllerConfiguration) other);
278 return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals();