2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 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;
25 import lombok.ToString;
26 import org.apache.commons.lang3.builder.EqualsBuilder;
27 import org.apache.commons.lang3.builder.HashCodeBuilder;
28 import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter;
29 import org.onap.policy.common.gson.annotation.GsonJsonAnySetter;
30 import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
31 import org.onap.policy.common.gson.annotation.GsonJsonProperty;
34 * Maven Related Information.
38 public class DroolsConfiguration {
45 @GsonJsonProperty("artifactId")
46 private String artifactId;
53 @GsonJsonProperty("groupId")
54 private String groupId;
61 @GsonJsonProperty("version")
62 private String version;
65 private Map<String, Object> additionalProperties = new HashMap<>();
67 protected static final Object NOT_FOUND_VALUE = new Object();
70 * No args constructor for use in serialization.
73 public DroolsConfiguration() {
80 * @param groupId group id
81 * @param artifactId artifact id
82 * @param version version
84 public DroolsConfiguration(String artifactId, String groupId, String version) {
85 this.artifactId = artifactId;
86 this.groupId = groupId;
87 this.version = version;
97 @GsonJsonProperty("artifactId")
98 public String getArtifactId() {
109 @GsonJsonProperty("artifactId")
110 public void setArtifactId(String artifactId) {
111 this.artifactId = artifactId;
114 public DroolsConfiguration withArtifactId(String artifactId) {
115 this.artifactId = artifactId;
126 @GsonJsonProperty("groupId")
127 public String getGroupId() {
138 @GsonJsonProperty("groupId")
139 public void setGroupId(String groupId) {
140 this.groupId = groupId;
143 public DroolsConfiguration withGroupId(String groupId) {
144 this.groupId = groupId;
155 @GsonJsonProperty("version")
156 public String getVersion() {
167 @GsonJsonProperty("version")
168 public void setVersion(String version) {
169 this.version = version;
172 public DroolsConfiguration withVersion(String version) {
173 this.version = version;
178 public Map<String, Object> getAdditionalProperties() {
179 return this.additionalProperties;
183 public void setAdditionalProperty(String name, Object value) {
184 this.additionalProperties.put(name, value);
187 public DroolsConfiguration withAdditionalProperty(String name, Object value) {
188 this.additionalProperties.put(name, value);
192 protected boolean declaredProperty(String name, Object value) {
195 callSetArtifactId(value);
198 callSetGroupId(value);
201 callSetVersion(value);
208 protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
211 return getArtifactId();
217 return notFoundValue;
222 * Get declared property.
224 * @param name property name
225 * @return the property object
230 public <T> T get(String name) {
231 Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
232 if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
235 return (T) getAdditionalProperties().get(name);
240 * Set property value.
242 * @param name property name
243 * @param value property value
245 public void set(String name, Object value) {
246 if (!declaredProperty(name, value)) {
247 getAdditionalProperties().put(name, value);
252 * Set property value and return object.
254 * @param name property name
255 * @param value property value
258 public DroolsConfiguration with(String name, Object value) {
259 if (!declaredProperty(name, value)) {
260 getAdditionalProperties().put(name, value);
266 public int hashCode() {
267 return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
272 public boolean equals(Object other) {
276 if (!(other instanceof DroolsConfiguration)) {
279 DroolsConfiguration rhs = ((DroolsConfiguration) other);
280 return new EqualsBuilder().append(artifactId, rhs.artifactId)
281 .append(groupId, rhs.groupId).append(version, rhs.version)
282 .append(additionalProperties, rhs.additionalProperties).isEquals();
286 * Call set artifact id.
290 public void callSetArtifactId(Object value) {
291 if (value instanceof String) {
292 setArtifactId((String) value);
294 throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
295 + value.getClass().toString());
304 public void callSetGroupId(Object value) {
305 if (value instanceof String) {
306 setGroupId((String) value);
308 throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
309 + value.getClass().toString());
316 * @param value version
318 public void callSetVersion(Object value) {
319 if (value instanceof String) {
320 setVersion((String) value);
322 throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
323 + value.getClass().toString());