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  * Maven Related Information
 
  41 @JsonInclude(JsonInclude.Include.NON_NULL)
 
  42 public class DroolsConfiguration {
 
  49     @JsonProperty("artifactId")
 
  50     private String artifactId;
 
  56     @JsonProperty("groupId")
 
  57     private String groupId;
 
  63     @JsonProperty("version")
 
  64     private String version;
 
  66     private Map<String, Object> additionalProperties = new HashMap<>();
 
  67     protected final static Object NOT_FOUND_VALUE = new Object();
 
  70      * No args constructor for use in serialization
 
  73     public DroolsConfiguration() {
 
  83     public DroolsConfiguration(String artifactId, String groupId, String version) {
 
  84         this.artifactId = artifactId;
 
  85         this.groupId = groupId;
 
  86         this.version = version;
 
  96     @JsonProperty("artifactId")
 
  97     public String getArtifactId() {
 
 108     @JsonProperty("artifactId")
 
 109     public void setArtifactId(String artifactId) {
 
 110         this.artifactId = artifactId;
 
 113     public DroolsConfiguration withArtifactId(String artifactId) {
 
 114         this.artifactId = artifactId;
 
 125     @JsonProperty("groupId")
 
 126     public String getGroupId() {
 
 137     @JsonProperty("groupId")
 
 138     public void setGroupId(String groupId) {
 
 139         this.groupId = groupId;
 
 142     public DroolsConfiguration withGroupId(String groupId) {
 
 143         this.groupId = groupId;
 
 154     @JsonProperty("version")
 
 155     public String getVersion() {
 
 166     @JsonProperty("version")
 
 167     public void setVersion(String version) {
 
 168         this.version = version;
 
 171     public DroolsConfiguration withVersion(String version) {
 
 172         this.version = version;
 
 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 DroolsConfiguration withAdditionalProperty(String name, Object value) {
 
 192         this.additionalProperties.put(name, value);
 
 196     protected boolean declaredProperty(String name, Object value) {
 
 199                 if (value instanceof String) {
 
 200                     setArtifactId((String) value);
 
 202                     throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
 
 206                 if (value instanceof String) {
 
 207                     setGroupId((String) value);
 
 209                     throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
 
 213                 if (value instanceof String) {
 
 214                     setVersion((String) value);
 
 216                     throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
 
 224     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
 
 227                 return getArtifactId();
 
 233                 return notFoundValue;
 
 240     public<T >T get(String name) {
 
 241         Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
 
 242         if (DroolsConfiguration.NOT_FOUND_VALUE!= value) {
 
 245             return (T) getAdditionalProperties().get(name);
 
 249     public void set(String name, Object value) {
 
 250         if (!declaredProperty(name, value)) {
 
 251             getAdditionalProperties().put(name, value);
 
 255     public DroolsConfiguration with(String name, Object value) {
 
 256         if (!declaredProperty(name, value)) {
 
 257             getAdditionalProperties().put(name, value);
 
 263     public int hashCode() {
 
 264         return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode();
 
 268     public boolean equals(Object other) {
 
 272         if ((other instanceof DroolsConfiguration) == false) {
 
 275         DroolsConfiguration rhs = ((DroolsConfiguration) other);
 
 276         return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals();