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