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