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 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;
28 import java.util.HashMap;
30 import lombok.ToString;
31 import org.apache.commons.lang3.builder.EqualsBuilder;
32 import org.apache.commons.lang3.builder.HashCodeBuilder;
33 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
34 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
35 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
36 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
40 * Drools Related Information.
43 @JsonInclude(JsonInclude.Include.NON_NULL)
45 public class ControllerConfiguration {
47 public static final String CONFIG_CONTROLLER_OPERATION_CREATE = "create";
48 public static final String CONFIG_CONTROLLER_OPERATION_UPDATE = "update";
49 public static final String CONFIG_CONTROLLER_OPERATION_LOCK = "lock";
50 public static final String CONFIG_CONTROLLER_OPERATION_UNLOCK = "unlock";
57 @GsonJsonProperty("name")
60 * Set of operations that can be applied to a controller: create, lock
64 @JsonProperty("operation")
65 @GsonJsonProperty("operation")
66 private String operation;
68 * Maven Related Information.
71 @JsonProperty("drools")
72 @GsonJsonProperty("drools")
73 private DroolsConfiguration drools;
77 private Map<String, Object> additionalProperties = new HashMap<>();
79 protected static final Object NOT_FOUND_VALUE = new Object();
82 * No args constructor for use in serialization.
85 public ControllerConfiguration() {
93 * @param operation operation
94 * @param drools drools
96 public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
98 this.operation = operation;
108 @JsonProperty("name")
109 @GsonJsonProperty("name")
110 public String getName() {
120 @JsonProperty("name")
121 @GsonJsonProperty("name")
122 public void setName(String name) {
126 public ControllerConfiguration withName(String name) {
132 * Set of operations that can be applied to a controller: create, lock
138 @JsonProperty("operation")
139 @GsonJsonProperty("operation")
140 public String getOperation() {
145 * Set of operations that can be applied to a controller: create, lock
151 @JsonProperty("operation")
152 @GsonJsonProperty("operation")
153 public void setOperation(String operation) {
154 this.operation = operation;
157 public ControllerConfiguration withOperation(String operation) {
158 this.operation = operation;
163 * Maven Related Information.
168 @JsonProperty("drools")
169 @GsonJsonProperty("drools")
170 public DroolsConfiguration getDrools() {
175 * Maven Related Information.
180 @JsonProperty("drools")
181 @GsonJsonProperty("drools")
182 public void setDrools(DroolsConfiguration drools) {
183 this.drools = drools;
186 public ControllerConfiguration withDrools(DroolsConfiguration drools) {
187 this.drools = drools;
193 public Map<String, Object> getAdditionalProperties() {
194 return this.additionalProperties;
199 public void setAdditionalProperty(String name, Object value) {
200 this.additionalProperties.put(name, value);
203 public ControllerConfiguration withAdditionalProperty(String name, Object value) {
204 this.additionalProperties.put(name, value);
208 protected boolean declaredProperty(String name, Object value) {
214 callSetOperation(value);
217 callSetDrools(value);
224 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
229 return getOperation();
233 return notFoundValue;
246 public <T> T get(String name) {
247 Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
248 if (ControllerConfiguration.NOT_FOUND_VALUE != value) {
251 return ((T) getAdditionalProperties().get(name));
258 * @param name property name
259 * @param value property value
261 public void set(String name, Object value) {
262 if (!declaredProperty(name, value)) {
263 getAdditionalProperties().put(name, value);
268 * With - sets the property and additionally returns the object.
270 * @param name property name
271 * @param value property value
274 public ControllerConfiguration with(String name, Object value) {
275 if (!declaredProperty(name, value)) {
276 getAdditionalProperties().put(name, value);
282 public int hashCode() {
283 return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties)
288 public boolean equals(Object other) {
292 if (!(other instanceof ControllerConfiguration)) {
295 ControllerConfiguration rhs = ((ControllerConfiguration) other);
296 return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools)
297 .append(additionalProperties, rhs.additionalProperties).isEquals();
305 public void callSetName(Object value) {
306 if (value instanceof String) {
307 setName((String) value);
309 throw new IllegalArgumentException("property \"name\" is of type \"java.lang.String\", but got "
310 + value.getClass().toString());
315 * Call set operation.
319 public void callSetOperation(Object value) {
320 if (value instanceof String) {
321 setOperation((String) value);
323 throw new IllegalArgumentException("property \"operation\" is of type \"java.lang.String\", but got "
324 + value.getClass().toString());
333 public void callSetDrools(Object value) {
334 if (value instanceof DroolsConfiguration) {
335 setDrools((DroolsConfiguration) value);
337 throw new IllegalArgumentException("property \"drools\" is of type"
338 + "\"org.onap.policy.drools.protocol.configuration.Drools\", but got "
339 + value.getClass().toString());