87cf2348c92c726d073e7f1efce90cae81480b0f
[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.openecomp.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<String, Object>();
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     }
75
76     /**
77      * 
78      * @param groupId
79      * @param artifactId
80      * @param version
81      */
82     public DroolsConfiguration(String artifactId, String groupId, String version) {
83         this.artifactId = artifactId;
84         this.groupId = groupId;
85         this.version = version;
86     }
87
88     /**
89      * Maven Artifact ID
90      * (Required)
91      * 
92      * @return
93      *     The artifactId
94      */
95     @JsonProperty("artifactId")
96     public String getArtifactId() {
97         return artifactId;
98     }
99
100     /**
101      * Maven Artifact ID
102      * (Required)
103      * 
104      * @param artifactId
105      *     The artifactId
106      */
107     @JsonProperty("artifactId")
108     public void setArtifactId(String artifactId) {
109         this.artifactId = artifactId;
110     }
111
112     public DroolsConfiguration withArtifactId(String artifactId) {
113         this.artifactId = artifactId;
114         return this;
115     }
116
117     /**
118      * Maven Group ID
119      * (Required)
120      * 
121      * @return
122      *     The groupId
123      */
124     @JsonProperty("groupId")
125     public String getGroupId() {
126         return groupId;
127     }
128
129     /**
130      * Maven Group ID
131      * (Required)
132      * 
133      * @param groupId
134      *     The groupId
135      */
136     @JsonProperty("groupId")
137     public void setGroupId(String groupId) {
138         this.groupId = groupId;
139     }
140
141     public DroolsConfiguration withGroupId(String groupId) {
142         this.groupId = groupId;
143         return this;
144     }
145
146     /**
147      * Maven Version
148      * (Required)
149      * 
150      * @return
151      *     The version
152      */
153     @JsonProperty("version")
154     public String getVersion() {
155         return version;
156     }
157
158     /**
159      * Maven Version
160      * (Required)
161      * 
162      * @param version
163      *     The version
164      */
165     @JsonProperty("version")
166     public void setVersion(String version) {
167         this.version = version;
168     }
169
170     public DroolsConfiguration withVersion(String version) {
171         this.version = version;
172         return this;
173     }
174
175     @Override
176     public String toString() {
177         return ToStringBuilder.reflectionToString(this);
178     }
179
180     @JsonAnyGetter
181     public Map<String, Object> getAdditionalProperties() {
182         return this.additionalProperties;
183     }
184
185     @JsonAnySetter
186     public void setAdditionalProperty(String name, Object value) {
187         this.additionalProperties.put(name, value);
188     }
189
190     public DroolsConfiguration withAdditionalProperty(String name, Object value) {
191         this.additionalProperties.put(name, value);
192         return this;
193     }
194
195     protected boolean declaredProperty(String name, Object value) {
196         switch (name) {
197             case "artifactId":
198                 if (value instanceof String) {
199                     setArtifactId(((String) value));
200                 } else {
201                     throw new IllegalArgumentException(("property \"artifactId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
202                 }
203                 return true;
204             case "groupId":
205                 if (value instanceof String) {
206                     setGroupId(((String) value));
207                 } else {
208                     throw new IllegalArgumentException(("property \"groupId\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
209                 }
210                 return true;
211             case "version":
212                 if (value instanceof String) {
213                     setVersion(((String) value));
214                 } else {
215                     throw new IllegalArgumentException(("property \"version\" is of type \"java.lang.String\", but got "+ value.getClass().toString()));
216                 }
217                 return true;
218             default:
219                 return false;
220         }
221     }
222
223     protected Object declaredPropertyOrNotFound(String name, Object notFoundValue) {
224         switch (name) {
225             case "artifactId":
226                 return getArtifactId();
227             case "groupId":
228                 return getGroupId();
229             case "version":
230                 return getVersion();
231             default:
232                 return notFoundValue;
233         }
234     }
235
236     @SuppressWarnings({
237         "unchecked"
238     })
239     public<T >T get(String name) {
240         Object value = declaredPropertyOrNotFound(name, DroolsConfiguration.NOT_FOUND_VALUE);
241         if (DroolsConfiguration.NOT_FOUND_VALUE!= value) {
242             return ((T) value);
243         } else {
244             return ((T) getAdditionalProperties().get(name));
245         }
246     }
247
248     public void set(String name, Object value) {
249         if (!declaredProperty(name, value)) {
250             getAdditionalProperties().put(name, ((Object) value));
251         }
252     }
253
254     public DroolsConfiguration with(String name, Object value) {
255         if (!declaredProperty(name, value)) {
256             getAdditionalProperties().put(name, ((Object) value));
257         }
258         return this;
259     }
260
261     @Override
262     public int hashCode() {
263         return new HashCodeBuilder().append(artifactId).append(groupId).append(version).append(additionalProperties).toHashCode();
264     }
265
266     @Override
267     public boolean equals(Object other) {
268         if (other == this) {
269             return true;
270         }
271         if ((other instanceof DroolsConfiguration) == false) {
272             return false;
273         }
274         DroolsConfiguration rhs = ((DroolsConfiguration) other);
275         return new EqualsBuilder().append(artifactId, rhs.artifactId).append(groupId, rhs.groupId).append(version, rhs.version).append(additionalProperties, rhs.additionalProperties).isEquals();
276     }
277
278 }