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.openecomp.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<String, Object>();
 
  71     protected final static Object NOT_FOUND_VALUE = new Object();
 
  74      * No args constructor for use in serialization
 
  77     public ControllerConfiguration() {
 
  86     public ControllerConfiguration(String name, String operation, DroolsConfiguration drools) {
 
  88         this.operation = operation;
 
 100     public String getName() {
 
 111     @JsonProperty("name")
 
 112     public void setName(String name) {
 
 116     public ControllerConfiguration withName(String name) {
 
 122      * Set of operations that can be applied to a controller: create, lock
 
 128     @JsonProperty("operation")
 
 129     public String getOperation() {
 
 134      * Set of operations that can be applied to a controller: create, lock
 
 140     @JsonProperty("operation")
 
 141     public void setOperation(String operation) {
 
 142         this.operation = operation;
 
 145     public ControllerConfiguration withOperation(String operation) {
 
 146         this.operation = operation;
 
 151      * Maven Related Information
 
 156     @JsonProperty("drools")
 
 157     public DroolsConfiguration getDrools() {
 
 162      * Maven Related Information
 
 167     @JsonProperty("drools")
 
 168     public void setDrools(DroolsConfiguration drools) {
 
 169         this.drools = drools;
 
 172     public ControllerConfiguration withDrools(DroolsConfiguration drools) {
 
 173         this.drools = drools;
 
 178     public String toString() {
 
 179         return ToStringBuilder.reflectionToString(this);
 
 183     public Map<String, Object> getAdditionalProperties() {
 
 184         return this.additionalProperties;
 
 188     public void setAdditionalProperty(String name, Object value) {
 
 189         this.additionalProperties.put(name, value);
 
 192     public ControllerConfiguration withAdditionalProperty(String name, Object value) {
 
 193         this.additionalProperties.put(name, value);
 
 197     protected boolean declaredProperty(String name, Object value) {
 
 200                 if (value instanceof String) {
 
 201                     setName(((String) value));
 
 203                     throw new IllegalArgumentException(("property \"name\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
 
 207                 if (value instanceof String) {
 
 208                     setOperation(((String) value));
 
 210                     throw new IllegalArgumentException(("property \"operation\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
 
 214                 if (value instanceof DroolsConfiguration) {
 
 215                     setDrools(((DroolsConfiguration) value));
 
 217                     throw new IllegalArgumentException(("property \"drools\" is of type \"org.openecomp.policy.drools.protocol.configuration.Drools\", but got "+ value.getClass().toString()));
 
 225     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
 
 230                 return getOperation();
 
 234                 return notFoundValue;
 
 241     public<T >T get(String name) {
 
 242         Object value = declaredPropertyOrNotFound(name, ControllerConfiguration.NOT_FOUND_VALUE);
 
 243         if (ControllerConfiguration.NOT_FOUND_VALUE!= value) {
 
 246             return ((T) getAdditionalProperties().get(name));
 
 250     public void set(String name, Object value) {
 
 251         if (!declaredProperty(name, value)) {
 
 252             getAdditionalProperties().put(name, ((Object) value));
 
 256     public ControllerConfiguration with(String name, Object value) {
 
 257         if (!declaredProperty(name, value)) {
 
 258             getAdditionalProperties().put(name, ((Object) value));
 
 264     public int hashCode() {
 
 265         return new HashCodeBuilder().append(name).append(operation).append(drools).append(additionalProperties).toHashCode();
 
 269     public boolean equals(Object other) {
 
 273         if ((other instanceof ControllerConfiguration) == false) {
 
 276         ControllerConfiguration rhs = ((ControllerConfiguration) other);
 
 277         return new EqualsBuilder().append(name, rhs.name).append(operation, rhs.operation).append(drools, rhs.drools).append(additionalProperties, rhs.additionalProperties).isEquals();