2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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;
35 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
36 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
37 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
38 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
41 * Maven Related Information.
44 @JsonInclude(JsonInclude.Include.NON_NULL)
45 public class DroolsConfiguration {
52 @JsonProperty("artifactId")
53 @GsonJsonProperty("artifactId")
54 private String artifactId;
61 @JsonProperty("groupId")
62 @GsonJsonProperty("groupId")
63 private String groupId;
70 @JsonProperty("version")
71 @GsonJsonProperty("version")
72 private String version;
76 private Map<String, Object> additionalProperties = new HashMap<>();
78 protected static final Object NOT_FOUND_VALUE = new Object();
81 * No args constructor for use in serialization.
84 public DroolsConfiguration() {
91 * @param groupId group id
92 * @param artifactId artifact id
93 * @param version version
95 public DroolsConfiguration(String artifactId, String groupId, String version) {
96 this.artifactId = artifactId;
97 this.groupId = groupId;
98 this.version = version;
108 @JsonProperty("artifactId")
109 @GsonJsonProperty("artifactId")
110 public String getArtifactId() {
121 @JsonProperty("artifactId")
122 @GsonJsonProperty("artifactId")
123 public void setArtifactId(String artifactId) {
124 this.artifactId = artifactId;
127 public DroolsConfiguration withArtifactId(String artifactId) {
128 this.artifactId = artifactId;
139 @JsonProperty("groupId")
140 @GsonJsonProperty("groupId")
141 public String getGroupId() {
152 @JsonProperty("groupId")
153 @GsonJsonProperty("groupId")
154 public void setGroupId(String groupId) {
155 this.groupId = groupId;
158 public DroolsConfiguration withGroupId(String groupId) {
159 this.groupId = groupId;
170 @JsonProperty("version")
171 @GsonJsonProperty("version")
172 public String getVersion() {
183 @JsonProperty("version")
184 @GsonJsonProperty("version")
185 public void setVersion(String version) {
186 this.version = version;
189 public DroolsConfiguration withVersion(String version) {
190 this.version = version;
195 public String toString() {
196 return ToStringBuilder.reflectionToString(this);
201 public Map<String, Object> getAdditionalProperties() {
202 return this.additionalProperties;
207 public void setAdditionalProperty(String name, Object value) {
208 this.additionalProperties.put(name, value);
211 public DroolsConfiguration withAdditionalProperty(String name, Object value) {
212 this.additionalProperties.put(name, value);
216 protected boolean declaredProperty(String name, Object value) {
219 callSetArtifactId(value);
222 callSetGroupId(value);
225 callSetVersion(value);
232 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
235 return getArtifactId();
241 return notFoundValue;
246 * Get declared property.
248 * @param name property name
249 * @return the property object
254 public <T> T get(String name) {
255 Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
256 if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
259 return (T) getAdditionalProperties().get(name);
264 * Set property value.
266 * @param name property name
267 * @param value property value
269 public void set(String name, Object value) {
270 if (!declaredProperty(name, value)) {
271 getAdditionalProperties().put(name, value);
276 * Set property value and return object.
278 * @param name property name
279 * @param value property value
282 public DroolsConfiguration with(String name, Object value) {
283 if (!declaredProperty(name, value)) {
284 getAdditionalProperties().put(name, value);
290 public int hashCode() {
291 return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
296 public boolean equals(Object other) {
300 if (!(other instanceof DroolsConfiguration)) {
303 DroolsConfiguration rhs = ((DroolsConfiguration) other);
304 return new EqualsBuilder().append(artifactId, rhs.artifactId)
305 .append(groupId, rhs.groupId).append(version, rhs.version)
306 .append(additionalProperties, rhs.additionalProperties).isEquals();
310 * Call set artifact id.
314 public void callSetArtifactId(Object value) {
315 if (value instanceof String) {
316 setArtifactId((String) value);
318 throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
319 + value.getClass().toString());
328 public void callSetGroupId(Object value) {
329 if (value instanceof String) {
330 setGroupId((String) value);
332 throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
333 + value.getClass().toString());
340 * @param value version
342 public void callSetVersion(Object value) {
343 if (value instanceof String) {
344 setVersion((String) value);
346 throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
347 + value.getClass().toString());