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;
37 * Maven Related Information.
40 @JsonInclude(JsonInclude.Include.NON_NULL)
41 public class DroolsConfiguration {
48 @JsonProperty("artifactId")
49 private String artifactId;
56 @JsonProperty("groupId")
57 private String groupId;
64 @JsonProperty("version")
65 private String version;
67 private Map<String, Object> additionalProperties = new HashMap<>();
68 protected static final Object NOT_FOUND_VALUE = new Object();
71 * No args constructor for use in serialization.
74 public DroolsConfiguration() {
81 * @param groupId group id
82 * @param artifactId artifact id
83 * @param version version
85 public DroolsConfiguration(String artifactId, String groupId, String version) {
86 this.artifactId = artifactId;
87 this.groupId = groupId;
88 this.version = version;
98 @JsonProperty("artifactId")
99 public String getArtifactId() {
110 @JsonProperty("artifactId")
111 public void setArtifactId(String artifactId) {
112 this.artifactId = artifactId;
115 public DroolsConfiguration withArtifactId(String artifactId) {
116 this.artifactId = artifactId;
127 @JsonProperty("groupId")
128 public String getGroupId() {
139 @JsonProperty("groupId")
140 public void setGroupId(String groupId) {
141 this.groupId = groupId;
144 public DroolsConfiguration withGroupId(String groupId) {
145 this.groupId = groupId;
156 @JsonProperty("version")
157 public String getVersion() {
168 @JsonProperty("version")
169 public void setVersion(String version) {
170 this.version = version;
173 public DroolsConfiguration withVersion(String version) {
174 this.version = version;
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 DroolsConfiguration withAdditionalProperty(String name, Object value) {
194 this.additionalProperties.put(name, value);
198 protected boolean declaredProperty(String name, Object value) {
201 callSetArtifactId(value);
204 callSetGroupId(value);
207 callSetVersion(value);
214 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
217 return getArtifactId();
223 return notFoundValue;
228 * Get declared property.
230 * @param name property name
231 * @return the property object
236 public <T> T get(String name) {
237 Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
238 if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
241 return (T) getAdditionalProperties().get(name);
246 * Set property value.
248 * @param name property name
249 * @param value property value
251 public void set(String name, Object value) {
252 if (!declaredProperty(name, value)) {
253 getAdditionalProperties().put(name, value);
258 * Set property value and return object.
260 * @param name property name
261 * @param value property value
264 public DroolsConfiguration with(String name, Object value) {
265 if (!declaredProperty(name, value)) {
266 getAdditionalProperties().put(name, value);
272 public int hashCode() {
273 return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
278 public boolean equals(Object other) {
282 if (!(other instanceof DroolsConfiguration)) {
285 DroolsConfiguration rhs = ((DroolsConfiguration) other);
286 return new EqualsBuilder().append(artifactId, rhs.artifactId)
287 .append(groupId, rhs.groupId).append(version, rhs.version)
288 .append(additionalProperties, rhs.additionalProperties).isEquals();
292 * Call set artifact id.
296 public void callSetArtifactId(Object value) {
297 if (value instanceof String) {
298 setArtifactId((String) value);
300 throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
301 + value.getClass().toString());
310 public void callSetGroupId(Object value) {
311 if (value instanceof String) {
312 setGroupId((String) value);
314 throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
315 + value.getClass().toString());
322 * @param value version
324 public void callSetVersion(Object value) {
325 if (value instanceof String) {
326 setVersion((String) value);
328 throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
329 + value.getClass().toString());