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;
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;
39 * Maven Related Information.
42 @JsonInclude(JsonInclude.Include.NON_NULL)
44 public class DroolsConfiguration {
51 @JsonProperty("artifactId")
52 @GsonJsonProperty("artifactId")
53 private String artifactId;
60 @JsonProperty("groupId")
61 @GsonJsonProperty("groupId")
62 private String groupId;
69 @JsonProperty("version")
70 @GsonJsonProperty("version")
71 private String version;
75 private Map<String, Object> additionalProperties = new HashMap<>();
77 protected static final Object NOT_FOUND_VALUE = new Object();
80 * No args constructor for use in serialization.
83 public DroolsConfiguration() {
90 * @param groupId group id
91 * @param artifactId artifact id
92 * @param version version
94 public DroolsConfiguration(String artifactId, String groupId, String version) {
95 this.artifactId = artifactId;
96 this.groupId = groupId;
97 this.version = version;
107 @JsonProperty("artifactId")
108 @GsonJsonProperty("artifactId")
109 public String getArtifactId() {
120 @JsonProperty("artifactId")
121 @GsonJsonProperty("artifactId")
122 public void setArtifactId(String artifactId) {
123 this.artifactId = artifactId;
126 public DroolsConfiguration withArtifactId(String artifactId) {
127 this.artifactId = artifactId;
138 @JsonProperty("groupId")
139 @GsonJsonProperty("groupId")
140 public String getGroupId() {
151 @JsonProperty("groupId")
152 @GsonJsonProperty("groupId")
153 public void setGroupId(String groupId) {
154 this.groupId = groupId;
157 public DroolsConfiguration withGroupId(String groupId) {
158 this.groupId = groupId;
169 @JsonProperty("version")
170 @GsonJsonProperty("version")
171 public String getVersion() {
182 @JsonProperty("version")
183 @GsonJsonProperty("version")
184 public void setVersion(String version) {
185 this.version = version;
188 public DroolsConfiguration withVersion(String version) {
189 this.version = version;
195 public Map<String, Object> getAdditionalProperties() {
196 return this.additionalProperties;
201 public void setAdditionalProperty(String name, Object value) {
202 this.additionalProperties.put(name, value);
205 public DroolsConfiguration withAdditionalProperty(String name, Object value) {
206 this.additionalProperties.put(name, value);
210 protected boolean declaredProperty(String name, Object value) {
213 callSetArtifactId(value);
216 callSetGroupId(value);
219 callSetVersion(value);
226 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
229 return getArtifactId();
235 return notFoundValue;
240 * Get declared property.
242 * @param name property name
243 * @return the property object
248 public <T> T get(String name) {
249 Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
250 if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
253 return (T) getAdditionalProperties().get(name);
258 * Set property value.
260 * @param name property name
261 * @param value property value
263 public void set(String name, Object value) {
264 if (!declaredProperty(name, value)) {
265 getAdditionalProperties().put(name, value);
270 * Set property value and return object.
272 * @param name property name
273 * @param value property value
276 public DroolsConfiguration with(String name, Object value) {
277 if (!declaredProperty(name, value)) {
278 getAdditionalProperties().put(name, value);
284 public int hashCode() {
285 return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
290 public boolean equals(Object other) {
294 if (!(other instanceof DroolsConfiguration)) {
297 DroolsConfiguration rhs = ((DroolsConfiguration) other);
298 return new EqualsBuilder().append(artifactId, rhs.artifactId)
299 .append(groupId, rhs.groupId).append(version, rhs.version)
300 .append(additionalProperties, rhs.additionalProperties).isEquals();
304 * Call set artifact id.
308 public void callSetArtifactId(Object value) {
309 if (value instanceof String) {
310 setArtifactId((String) value);
312 throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
313 + value.getClass().toString());
322 public void callSetGroupId(Object value) {
323 if (value instanceof String) {
324 setGroupId((String) value);
326 throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
327 + value.getClass().toString());
334 * @param value version
336 public void callSetVersion(Object value) {
337 if (value instanceof String) {
338 setVersion((String) value);
340 throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
341 + value.getClass().toString());