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