4c672e7b96e8cc54ea87498fa3264f30bdd9f217
[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                 if (value instanceof String) {
200                     setArtifactId((String) value);
201                 } else {
202                     throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
203                 }
204                 return true;
205             case "groupId":
206                 if (value instanceof String) {
207                     setGroupId((String) value);
208                 } else {
209                     throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
210                 }
211                 return true;
212             case "version":
213                 if (value instanceof String) {
214                     setVersion((String) value);
215                 } else {
216                     throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
217                 }
218                 return true;
219             default:
220                 return false;
221         }
222     }
223
224     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
225         switch (name) {
226             case "artifactId":
227                 return getArtifactId();
228             case "groupId":
229                 return getGroupId();
230             case "version":
231                 return getVersion();
232             default:
233                 return notFoundValue;
234         }
235     }
236
237     @SuppressWarnings({
238         "unchecked"
239     })
240     public<T >T get(String name) {
241         Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
242         if (DroolsConfiguration.NOT_FOUND_VALUE!= value) {
243             return (T) value;
244         } else {
245             return (T) getAdditionalProperties().get(name);
246         }
247     }
248
249     public void set(String name, Object value) {
250         if (!declaredProperty(name, value)) {
251             getAdditionalProperties().put(name, value);
252         }
253     }
254
255     public DroolsConfiguration with(String name, Object value) {
256         if (!declaredProperty(name, value)) {
257             getAdditionalProperties().put(name, value);
258         }
259         return this;
260     }
261
262     @Override
263     public int hashCode() {
264         return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode();
265     }
266
267     @Override
268     public boolean equals(Object other) {
269         if (other == this) {
270             return true;
271         }
272         if ((other instanceof DroolsConfiguration) == false) {
273             return false;
274         }
275         DroolsConfiguration rhs = ((DroolsConfiguration) other);
276         return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals();
277     }
278
279 }