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