1 | |
package org.kuali.rice.krms.api.repository.proposition; |
2 | |
|
3 | |
import java.io.Serializable; |
4 | |
import java.util.Collection; |
5 | |
|
6 | |
import javax.xml.bind.annotation.XmlAccessType; |
7 | |
import javax.xml.bind.annotation.XmlAccessorType; |
8 | |
import javax.xml.bind.annotation.XmlAnyElement; |
9 | |
import javax.xml.bind.annotation.XmlElement; |
10 | |
import javax.xml.bind.annotation.XmlRootElement; |
11 | |
import javax.xml.bind.annotation.XmlType; |
12 | |
|
13 | |
import org.apache.commons.lang.StringUtils; |
14 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
15 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
16 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
17 | |
import org.kuali.rice.core.api.CoreConstants; |
18 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
19 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
@XmlRootElement(name = PropositionParameter.Constants.ROOT_ELEMENT_NAME) |
29 | |
@XmlAccessorType(XmlAccessType.NONE) |
30 | |
@XmlType(name = PropositionParameter.Constants.TYPE_NAME, propOrder = { |
31 | |
PropositionParameter.Elements.ID, |
32 | |
PropositionParameter.Elements.PROP_ID, |
33 | |
PropositionParameter.Elements.VALUE, |
34 | |
PropositionParameter.Elements.PARM_TYPE, |
35 | |
PropositionParameter.Elements.SEQUENCE, |
36 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
37 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
38 | |
}) |
39 | 41 | public final class PropositionParameter implements PropositionParameterContract, ModelObjectComplete{ |
40 | |
private static final long serialVersionUID = 2783959459503209577L; |
41 | |
|
42 | |
@XmlElement(name = Elements.ID, required=true) |
43 | |
private String id; |
44 | |
@XmlElement(name = Elements.PROP_ID, required=true) |
45 | |
private String propId; |
46 | |
@XmlElement(name = Elements.VALUE, required=true) |
47 | |
private String value; |
48 | |
@XmlElement(name = Elements.PARM_TYPE, required=true) |
49 | |
private String parameterType; |
50 | |
@XmlElement(name = Elements.SEQUENCE, required=true) |
51 | |
private Integer sequenceNumber; |
52 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
53 | |
private final Long versionNumber; |
54 | |
|
55 | 98 | @SuppressWarnings("unused") |
56 | |
@XmlAnyElement |
57 | |
private final Collection<org.w3c.dom.Element> _futureElements = null; |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 57 | private PropositionParameter() { |
64 | 57 | this.id = null; |
65 | 57 | this.propId = null; |
66 | 57 | this.value = null; |
67 | 57 | this.parameterType = null; |
68 | 57 | this.sequenceNumber = null; |
69 | 57 | this.versionNumber = null; |
70 | 57 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | 41 | private PropositionParameter(Builder builder) { |
79 | 41 | this.id = builder.getId(); |
80 | 41 | this.propId = builder.getPropId(); |
81 | 41 | this.value = builder.getValue(); |
82 | 41 | this.parameterType = builder.getParameterType(); |
83 | 41 | this.sequenceNumber = builder.getSequenceNumber(); |
84 | 41 | this.versionNumber = builder.getVersionNumber(); |
85 | 41 | } |
86 | |
|
87 | |
@Override |
88 | |
public String getId() { |
89 | 1 | return this.id; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public String getPropId() { |
94 | 1 | return this.propId; |
95 | |
} |
96 | |
|
97 | |
@Override |
98 | |
public String getValue() { |
99 | 1 | return this.value; |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
public String getParameterType() { |
104 | 1 | return this.parameterType; |
105 | |
} |
106 | |
@Override |
107 | |
public Integer getSequenceNumber() { |
108 | 1 | return this.sequenceNumber; |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public Long getVersionNumber() { |
113 | 0 | return versionNumber; |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | 5 | public static class Builder implements PropositionParameterContract, ModelBuilder, Serializable { |
121 | |
private static final long serialVersionUID = -6889320709850568900L; |
122 | |
|
123 | |
private String id; |
124 | |
private String propId; |
125 | |
private String value; |
126 | |
private String parameterType; |
127 | |
private Integer sequenceNumber; |
128 | |
private Long versionNumber; |
129 | |
private PropositionDefinition.Builder proposition; |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | 54 | private Builder(String id, String propId, String value, String parameterType, Integer sequenceNumber) { |
135 | 54 | setId(id); |
136 | 52 | setPropId(propId); |
137 | 50 | setValue(value); |
138 | 46 | setParameterType(parameterType); |
139 | 42 | setSequenceNumber(sequenceNumber); |
140 | 41 | } |
141 | |
|
142 | |
public static Builder create(String id, String propId, String value, String parameterType, Integer sequenceNumber) { |
143 | 18 | return new Builder(id, propId, value, parameterType, sequenceNumber); |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public static Builder create(PropositionParameterContract contract) { |
153 | 36 | if (contract == null) { |
154 | 0 | throw new IllegalArgumentException("contract is null"); |
155 | |
} |
156 | 36 | Builder builder = new Builder(contract.getId(), contract.getPropId(), contract.getValue(), contract.getParameterType(), contract.getSequenceNumber()); |
157 | 36 | builder.setVersionNumber(contract.getVersionNumber()); |
158 | 36 | return builder; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public void setId(String id) { |
168 | 54 | if (id != null && StringUtils.isBlank(id)) { |
169 | 2 | throw new IllegalArgumentException("id is blank"); |
170 | |
} |
171 | 52 | this.id = id; |
172 | 52 | } |
173 | |
|
174 | |
public void setPropId(String propId) { |
175 | |
|
176 | 52 | if (null != propId && StringUtils.isBlank(propId)) { |
177 | 2 | throw new IllegalArgumentException("propId must be null or non-blank"); |
178 | |
} |
179 | 50 | this.propId = propId; |
180 | 50 | } |
181 | |
|
182 | |
public void setValue(String value) { |
183 | |
|
184 | 50 | if (StringUtils.isBlank(value)) { |
185 | 4 | throw new IllegalArgumentException("value is blank"); |
186 | |
} |
187 | 46 | this.value = value; |
188 | 46 | } |
189 | |
|
190 | |
public void setParameterType(String parameterType) { |
191 | 46 | if (StringUtils.isBlank(parameterType)){ |
192 | 3 | throw new IllegalArgumentException("parameter type is null or blank"); |
193 | |
} |
194 | 43 | if (!PropositionParameterType.VALID_TYPE_CODES.contains(parameterType)){ |
195 | 1 | throw new IllegalArgumentException("parameter type is invalid"); |
196 | |
} |
197 | |
|
198 | 42 | this.parameterType = parameterType; |
199 | 42 | } |
200 | |
|
201 | |
public void setSequenceNumber(Integer sequenceNumber) { |
202 | 42 | if (sequenceNumber == null) { |
203 | 1 | throw new IllegalArgumentException("parameter type is blank"); |
204 | |
} |
205 | 41 | this.sequenceNumber = sequenceNumber; |
206 | 41 | } |
207 | |
|
208 | |
public void setProposition(PropositionDefinition.Builder proposition) { |
209 | 0 | if (proposition != null && !StringUtils.isBlank(proposition.getId())) { |
210 | 0 | setPropId(proposition.getId()); |
211 | |
} |
212 | 0 | this.proposition = proposition; |
213 | 0 | } |
214 | |
|
215 | |
public void setVersionNumber(Long versionNumber){ |
216 | 36 | this.versionNumber = versionNumber; |
217 | 36 | } |
218 | |
|
219 | |
@Override |
220 | |
public String getId() { |
221 | 65 | return id; |
222 | |
} |
223 | |
|
224 | |
@Override |
225 | |
public String getPropId() { |
226 | 65 | return propId; |
227 | |
} |
228 | |
|
229 | |
@Override |
230 | |
public String getValue() { |
231 | 65 | return value; |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public String getParameterType() { |
236 | 65 | return parameterType; |
237 | |
} |
238 | |
|
239 | |
@Override |
240 | |
public Integer getSequenceNumber() { |
241 | 65 | return sequenceNumber; |
242 | |
} |
243 | |
|
244 | |
@Override |
245 | |
public Long getVersionNumber() { |
246 | 65 | return versionNumber; |
247 | |
} |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
@Override |
255 | |
public PropositionParameter build() { |
256 | 41 | if (proposition == null && StringUtils.isBlank(propId)) { |
257 | 0 | throw new IllegalStateException("either proposition must be non-null or propId must be non-blank"); |
258 | |
} |
259 | 41 | return new PropositionParameter(this); |
260 | |
} |
261 | |
|
262 | |
} |
263 | |
@Override |
264 | |
public int hashCode() { |
265 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
266 | |
} |
267 | |
|
268 | |
@Override |
269 | |
public boolean equals(Object obj) { |
270 | 28 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
271 | |
} |
272 | |
|
273 | |
@Override |
274 | |
public String toString() { |
275 | 0 | return ToStringBuilder.reflectionToString(this); |
276 | |
} |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | 0 | static class Constants { |
282 | |
final static String ROOT_ELEMENT_NAME = "PropositionParameter"; |
283 | |
final static String TYPE_NAME = "PropositionParameterType"; |
284 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
285 | |
} |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | 0 | public static class Elements { |
292 | |
final static String ID = "id"; |
293 | |
final static String PROP_ID = "propId"; |
294 | |
final static String VALUE = "value"; |
295 | |
final static String PARM_TYPE = "parameterType"; |
296 | |
final static String SEQUENCE = "sequenceNumber"; |
297 | |
} |
298 | |
|
299 | |
} |