eec4df56025b2a7ba3939c75376e83471056ce89
[policy/drools-pdp.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-management
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.drools.protocol.configuration;
22
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;
29 import java.util.Map;
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;
37
38 /**
39  * Maven Related Information.
40  *
41  */
42 @JsonInclude(JsonInclude.Include.NON_NULL)
43 @ToString
44 public class DroolsConfiguration {
45
46     /**
47      * Maven Artifact ID
48      * (Required).
49      *
50      */
51     @JsonProperty("artifactId")
52     @GsonJsonProperty("artifactId")
53     private String artifactId;
54
55     /**
56      * Maven Group ID
57      * (Required).
58      *
59      */
60     @JsonProperty("groupId")
61     @GsonJsonProperty("groupId")
62     private String groupId;
63
64     /**
65      * Maven Version
66      * (Required).
67      *
68      */
69     @JsonProperty("version")
70     @GsonJsonProperty("version")
71     private String version;
72
73     @JsonIgnore
74     @GsonJsonIgnore
75     private Map<String, Object> additionalProperties = new HashMap<>();
76
77     protected static final Object NOT_FOUND_VALUE = new Object();
78
79     /**
80      * No args constructor for use in serialization.
81      *
82      */
83     public DroolsConfiguration() {
84         // Empty
85     }
86
87     /**
88      * Constructor.
89      *
90      * @param groupId group id
91      * @param artifactId artifact id
92      * @param version version
93      */
94     public DroolsConfiguration(String artifactId, String groupId, String version) {
95         this.artifactId = artifactId;
96         this.groupId = groupId;
97         this.version = version;
98     }
99
100     /**
101      * Maven Artifact ID
102      * (Required).
103      *
104      * @return
105      *     The artifactId
106      */
107     @JsonProperty("artifactId")
108     @GsonJsonProperty("artifactId")
109     public String getArtifactId() {
110         return artifactId;
111     }
112
113     /**
114      * Maven Artifact ID
115      * (Required).
116      *
117      * @param artifactId
118      *     The artifactId
119      */
120     @JsonProperty("artifactId")
121     @GsonJsonProperty("artifactId")
122     public void setArtifactId(String artifactId) {
123         this.artifactId = artifactId;
124     }
125
126     public DroolsConfiguration withArtifactId(String artifactId) {
127         this.artifactId = artifactId;
128         return this;
129     }
130
131     /**
132      * Maven Group ID
133      * (Required).
134      *
135      * @return
136      *     The groupId
137      */
138     @JsonProperty("groupId")
139     @GsonJsonProperty("groupId")
140     public String getGroupId() {
141         return groupId;
142     }
143
144     /**
145      * Maven Group ID
146      * (Required).
147      *
148      * @param groupId
149      *     The groupId
150      */
151     @JsonProperty("groupId")
152     @GsonJsonProperty("groupId")
153     public void setGroupId(String groupId) {
154         this.groupId = groupId;
155     }
156
157     public DroolsConfiguration withGroupId(String groupId) {
158         this.groupId = groupId;
159         return this;
160     }
161
162     /**
163      * Maven Version
164      * (Required).
165      *
166      * @return
167      *     The version
168      */
169     @JsonProperty("version")
170     @GsonJsonProperty("version")
171     public String getVersion() {
172         return version;
173     }
174
175     /**
176      * Maven Version
177      * (Required).
178      *
179      * @param version
180      *     The version
181      */
182     @JsonProperty("version")
183     @GsonJsonProperty("version")
184     public void setVersion(String version) {
185         this.version = version;
186     }
187
188     public DroolsConfiguration withVersion(String version) {
189         this.version = version;
190         return this;
191     }
192
193     @JsonAnyGetter
194     @GsonJsonAnyGetter
195     public Map<String, Object> getAdditionalProperties() {
196         return this.additionalProperties;
197     }
198
199     @JsonAnySetter
200     @GsonJsonAnySetter
201     public void setAdditionalProperty(String name, Object value) {
202         this.additionalProperties.put(name, value);
203     }
204
205     public DroolsConfiguration withAdditionalProperty(String name, Object value) {
206         this.additionalProperties.put(name, value);
207         return this;
208     }
209
210     protected boolean declaredProperty(String name, Object value) {
211         switch (name) {
212             case "artifactId":
213                 callSetArtifactId(value);
214                 return true;
215             case "groupId":
216                 callSetGroupId(value);
217                 return true;
218             case "version":
219                 callSetVersion(value);
220                 return true;
221             default:
222                 return false;
223         }
224     }
225
226     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
227         switch (name) {
228             case "artifactId":
229                 return getArtifactId();
230             case "groupId":
231                 return getGroupId();
232             case "version":
233                 return getVersion();
234             default:
235                 return notFoundValue;
236         }
237     }
238
239     /**
240      * Get declared property.
241      *
242      * @param name property name
243      * @return the property object
244      */
245     @SuppressWarnings({
246         "unchecked"
247         })
248     public <T> T get(String name) {
249         Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
250         if (DroolsConfiguration.NOT_FOUND_VALUE != value) {
251             return (T) value;
252         } else {
253             return (T) getAdditionalProperties().get(name);
254         }
255     }
256
257     /**
258      * Set property value.
259      *
260      * @param name property name
261      * @param value property value
262      */
263     public void set(String name, Object value) {
264         if (!declaredProperty(name, value)) {
265             getAdditionalProperties().put(name, value);
266         }
267     }
268
269     /**
270      * Set property value and return object.
271      *
272      * @param name property name
273      * @param value property value
274      * @return this
275      */
276     public DroolsConfiguration with(String name, Object value) {
277         if (!declaredProperty(name, value)) {
278             getAdditionalProperties().put(name, value);
279         }
280         return this;
281     }
282
283     @Override
284     public int hashCode() {
285         return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties)
286                 .toHashCode();
287     }
288
289     @Override
290     public boolean equals(Object other) {
291         if (other == this) {
292             return true;
293         }
294         if (!(other instanceof DroolsConfiguration)) {
295             return false;
296         }
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();
301     }
302
303     /**
304      * Call set artifact id.
305      *
306      * @param value id
307      */
308     public void callSetArtifactId(Object value) {
309         if (value instanceof String) {
310             setArtifactId((String) value);
311         } else {
312             throw new IllegalArgumentException("property \"artifactId\" is of type \"java.lang.String\", but got "
313         + value.getClass().toString());
314         }
315     }
316
317     /**
318      * Call set group id.
319      *
320      * @param value id
321      */
322     public void callSetGroupId(Object value) {
323         if (value instanceof String) {
324             setGroupId((String) value);
325         } else {
326             throw new IllegalArgumentException("property \"groupId\" is of type \"java.lang.String\", but got "
327                     + value.getClass().toString());
328         }
329     }
330
331     /**
332      * Call set version.
333      *
334      * @param value version
335      */
336     public void callSetVersion(Object value) {
337         if (value instanceof String) {
338             setVersion((String) value);
339         } else {
340             throw new IllegalArgumentException("property \"version\" is of type \"java.lang.String\", but got "
341                     + value.getClass().toString());
342         }
343     }
344 }