1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.api.document; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
import java.util.Collection; |
20 | |
import java.util.Collections; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.xml.bind.annotation.XmlAccessType; |
25 | |
import javax.xml.bind.annotation.XmlAccessorType; |
26 | |
import javax.xml.bind.annotation.XmlAnyElement; |
27 | |
import javax.xml.bind.annotation.XmlElement; |
28 | |
import javax.xml.bind.annotation.XmlRootElement; |
29 | |
import javax.xml.bind.annotation.XmlType; |
30 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
31 | |
|
32 | |
import org.apache.commons.lang.StringUtils; |
33 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
34 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
35 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
36 | |
import org.joda.time.DateTime; |
37 | |
import org.kuali.rice.core.api.CoreConstants; |
38 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
39 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
40 | |
import org.kuali.rice.core.util.jaxb.DateTimeAdapter; |
41 | |
import org.kuali.rice.core.util.jaxb.MapStringStringAdapter; |
42 | |
import org.w3c.dom.Element; |
43 | |
|
44 | |
@XmlRootElement(name = Document.Constants.ROOT_ELEMENT_NAME) |
45 | |
@XmlAccessorType(XmlAccessType.NONE) |
46 | |
@XmlType(name = Document.Constants.TYPE_NAME, propOrder = { |
47 | |
Document.Elements.DOCUMENT_ID, |
48 | |
Document.Elements.STATUS, |
49 | |
Document.Elements.DATE_CREATED, |
50 | |
Document.Elements.DATE_LAST_MODIFIED, |
51 | |
Document.Elements.DATE_APPROVED, |
52 | |
Document.Elements.DATE_FINALIZED, |
53 | |
Document.Elements.TITLE, |
54 | |
Document.Elements.APPLICATION_DOCUMENT_ID, |
55 | |
Document.Elements.INITIATOR_PRINCIPAL_ID, |
56 | |
Document.Elements.ROUTED_BY_PRINCIPAL_ID, |
57 | |
Document.Elements.DOCUMENT_TYPE_NAME, |
58 | |
Document.Elements.DOCUMENT_TYPE_ID, |
59 | |
Document.Elements.DOCUMENT_HANDLER_URL, |
60 | |
Document.Elements.APPLICATION_DOCUMENT_STATUS, |
61 | |
Document.Elements.APPLICATION_DOCUMENT_STATUS_DATE, |
62 | |
Document.Elements.VARIABLES, |
63 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
64 | |
}) |
65 | 0 | public final class Document implements ModelObjectComplete, DocumentContract { |
66 | |
|
67 | |
private static final long serialVersionUID = -6954090887747605047L; |
68 | |
|
69 | |
@XmlElement(name = Elements.DOCUMENT_ID, required = true) |
70 | |
private final String documentId; |
71 | |
|
72 | |
@XmlElement(name = Elements.STATUS, required = true) |
73 | |
private final String status; |
74 | |
|
75 | |
@XmlElement(name = Elements.DATE_CREATED, required = true) |
76 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
77 | |
private final DateTime dateCreated; |
78 | |
|
79 | |
@XmlElement(name = Elements.DATE_LAST_MODIFIED, required = true) |
80 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
81 | |
private final DateTime dateLastModified; |
82 | |
|
83 | |
@XmlElement(name = Elements.DATE_APPROVED, required = false) |
84 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
85 | |
private final DateTime dateApproved; |
86 | |
|
87 | |
@XmlElement(name = Elements.DATE_FINALIZED, required = false) |
88 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
89 | |
private final DateTime dateFinalized; |
90 | |
|
91 | |
@XmlElement(name = Elements.TITLE, required = false) |
92 | |
private final String title; |
93 | |
|
94 | |
@XmlElement(name = Elements.APPLICATION_DOCUMENT_ID, required = false) |
95 | |
private final String applicationDocumentId; |
96 | |
|
97 | |
@XmlElement(name = Elements.INITIATOR_PRINCIPAL_ID, required = true) |
98 | |
private final String initiatorPrincipalId; |
99 | |
|
100 | |
@XmlElement(name = Elements.ROUTED_BY_PRINCIPAL_ID, required = false) |
101 | |
private final String routedByPrincipalId; |
102 | |
|
103 | |
@XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = true) |
104 | |
private final String documentTypeName; |
105 | |
|
106 | |
@XmlElement(name = Elements.DOCUMENT_TYPE_ID, required = true) |
107 | |
private final String documentTypeId; |
108 | |
|
109 | |
@XmlElement(name = Elements.DOCUMENT_HANDLER_URL, required = false) |
110 | |
private final String documentHandlerUrl; |
111 | |
|
112 | |
@XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS, required = false) |
113 | |
private final String applicationDocumentStatus; |
114 | |
|
115 | |
@XmlElement(name = Elements.APPLICATION_DOCUMENT_STATUS_DATE, required = false) |
116 | |
@XmlJavaTypeAdapter(DateTimeAdapter.class) |
117 | |
private final DateTime applicationDocumentStatusDate; |
118 | |
|
119 | |
@XmlElement(name = Elements.VARIABLES, required = false) |
120 | |
@XmlJavaTypeAdapter(MapStringStringAdapter.class) |
121 | |
private final Map<String, String> variables; |
122 | |
|
123 | 0 | @SuppressWarnings("unused") |
124 | |
@XmlAnyElement |
125 | |
private final Collection<Element> _futureElements = null; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | 0 | private Document() { |
131 | 0 | this.documentId = null; |
132 | 0 | this.status = null; |
133 | 0 | this.dateCreated = null; |
134 | 0 | this.dateLastModified = null; |
135 | 0 | this.dateApproved = null; |
136 | 0 | this.dateFinalized = null; |
137 | 0 | this.title = null; |
138 | 0 | this.applicationDocumentId = null; |
139 | 0 | this.initiatorPrincipalId = null; |
140 | 0 | this.routedByPrincipalId = null; |
141 | 0 | this.documentTypeName = null; |
142 | 0 | this.documentTypeId = null; |
143 | 0 | this.documentHandlerUrl = null; |
144 | 0 | this.applicationDocumentStatus = null; |
145 | 0 | this.applicationDocumentStatusDate = null; |
146 | 0 | this.variables = null; |
147 | 0 | } |
148 | |
|
149 | 0 | private Document(Builder builder) { |
150 | 0 | this.documentId = builder.getDocumentId(); |
151 | 0 | this.status = builder.getStatus().getCode(); |
152 | 0 | this.dateCreated = builder.getDateCreated(); |
153 | 0 | this.dateLastModified = builder.getDateLastModified(); |
154 | 0 | this.dateApproved = builder.getDateApproved(); |
155 | 0 | this.dateFinalized = builder.getDateFinalized(); |
156 | 0 | this.title = builder.getTitle(); |
157 | 0 | this.applicationDocumentId = builder.getApplicationDocumentId(); |
158 | 0 | this.initiatorPrincipalId = builder.getInitiatorPrincipalId(); |
159 | 0 | this.routedByPrincipalId = builder.getRoutedByPrincipalId(); |
160 | 0 | this.documentTypeName = builder.getDocumentTypeName(); |
161 | 0 | this.documentTypeId = builder.getDocumentTypeId(); |
162 | 0 | this.documentHandlerUrl = builder.getDocumentHandlerUrl(); |
163 | 0 | this.applicationDocumentStatus = builder.getApplicationDocumentStatus(); |
164 | 0 | this.applicationDocumentStatusDate = builder.getApplicationDocumentStatusDate(); |
165 | 0 | this.variables = new HashMap<String, String>(builder.getVariables()); |
166 | 0 | } |
167 | |
|
168 | |
@Override |
169 | |
public String getDocumentId() { |
170 | 0 | return this.documentId; |
171 | |
} |
172 | |
|
173 | |
@Override |
174 | |
public DocumentStatus getStatus() { |
175 | 0 | if (StringUtils.isBlank(this.status)) { |
176 | 0 | throw new IllegalStateException("Status should not be null"); |
177 | |
} |
178 | 0 | return DocumentStatus.fromCode(this.status); |
179 | |
} |
180 | |
|
181 | |
@Override |
182 | |
public DateTime getDateCreated() { |
183 | 0 | return this.dateCreated; |
184 | |
} |
185 | |
|
186 | |
@Override |
187 | |
public DateTime getDateLastModified() { |
188 | 0 | return this.dateLastModified; |
189 | |
} |
190 | |
|
191 | |
@Override |
192 | |
public DateTime getDateApproved() { |
193 | 0 | return this.dateApproved; |
194 | |
} |
195 | |
|
196 | |
@Override |
197 | |
public DateTime getDateFinalized() { |
198 | 0 | return this.dateFinalized; |
199 | |
} |
200 | |
|
201 | |
@Override |
202 | |
public String getTitle() { |
203 | 0 | return this.title; |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public String getApplicationDocumentId() { |
208 | 0 | return this.applicationDocumentId; |
209 | |
} |
210 | |
|
211 | |
@Override |
212 | |
public String getInitiatorPrincipalId() { |
213 | 0 | return this.initiatorPrincipalId; |
214 | |
} |
215 | |
|
216 | |
@Override |
217 | |
public String getRoutedByPrincipalId() { |
218 | 0 | return this.routedByPrincipalId; |
219 | |
} |
220 | |
|
221 | |
@Override |
222 | |
public String getDocumentTypeName() { |
223 | 0 | return this.documentTypeName; |
224 | |
} |
225 | |
|
226 | |
@Override |
227 | |
public String getDocumentTypeId() { |
228 | 0 | return this.documentTypeId; |
229 | |
} |
230 | |
|
231 | |
@Override |
232 | |
public String getDocumentHandlerUrl() { |
233 | 0 | return this.documentHandlerUrl; |
234 | |
} |
235 | |
|
236 | |
@Override |
237 | |
public String getApplicationDocumentStatus() { |
238 | 0 | return this.applicationDocumentStatus; |
239 | |
} |
240 | |
|
241 | |
@Override |
242 | |
public DateTime getApplicationDocumentStatusDate() { |
243 | 0 | return this.applicationDocumentStatusDate; |
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public Map<String, String> getVariables() { |
248 | 0 | return Collections.unmodifiableMap(this.variables); |
249 | |
} |
250 | |
|
251 | |
@Override |
252 | |
public int hashCode() { |
253 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
254 | |
} |
255 | |
|
256 | |
@Override |
257 | |
public boolean equals(Object object) { |
258 | 0 | return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
259 | |
} |
260 | |
|
261 | |
@Override |
262 | |
public String toString() { |
263 | 0 | return ToStringBuilder.reflectionToString(this); |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | 0 | public final static class Builder |
272 | |
implements Serializable, ModelBuilder, DocumentContract |
273 | |
{ |
274 | |
|
275 | |
private static final long serialVersionUID = -1584497024880308500L; |
276 | |
|
277 | |
private String documentId; |
278 | |
private DocumentStatus status; |
279 | |
private DateTime dateCreated; |
280 | |
private DateTime dateLastModified; |
281 | |
private DateTime dateApproved; |
282 | |
private DateTime dateFinalized; |
283 | |
private String title; |
284 | |
private String applicationDocumentId; |
285 | |
private String initiatorPrincipalId; |
286 | |
private String routedByPrincipalId; |
287 | |
private String documentTypeName; |
288 | |
private String documentTypeId; |
289 | |
private String documentHandlerUrl; |
290 | |
private String applicationDocumentStatus; |
291 | |
private DateTime applicationDocumentStatusDate; |
292 | |
private Map<String, String> variables; |
293 | |
|
294 | 0 | private Builder(String documentId, DocumentStatus status, DateTime dateCreated, String initiatorPrincipalId, String documentTypeName, String documentTypeId) { |
295 | 0 | setDocumentId(documentId); |
296 | 0 | setStatus(status); |
297 | 0 | setDateCreated(dateCreated); |
298 | 0 | setTitle(""); |
299 | 0 | setInitiatorPrincipalId(initiatorPrincipalId); |
300 | 0 | setDocumentTypeName(documentTypeName); |
301 | 0 | setDocumentTypeId(documentTypeId); |
302 | 0 | setVariables(new HashMap<String, String>()); |
303 | 0 | } |
304 | |
|
305 | |
public static Builder create(String documentId, DocumentStatus status, DateTime dateCreated, String initiatorPrincipalId, String documentTypeName, String documentTypeId) { |
306 | 0 | return new Builder(documentId, status, dateCreated, initiatorPrincipalId, documentTypeName, documentTypeId); |
307 | |
} |
308 | |
|
309 | |
public static Builder create(String documentId, String initiatorPrinicpalId, String documentTypeName, String documentTypeId) { |
310 | 0 | return new Builder(documentId, DocumentStatus.INITIATED, new DateTime(), initiatorPrinicpalId, documentTypeName, documentTypeId); |
311 | |
} |
312 | |
|
313 | |
public static Builder create(DocumentContract contract) { |
314 | 0 | if (contract == null) { |
315 | 0 | throw new IllegalArgumentException("contract was null"); |
316 | |
} |
317 | 0 | Builder builder = create( |
318 | |
contract.getDocumentId(), |
319 | |
contract.getStatus(), |
320 | |
contract.getDateCreated(), |
321 | |
contract.getInitiatorPrincipalId(), |
322 | |
contract.getDocumentTypeName(), |
323 | |
contract.getDocumentTypeId() |
324 | |
); |
325 | 0 | builder.setDateLastModified(contract.getDateLastModified()); |
326 | 0 | builder.setDateApproved(contract.getDateApproved()); |
327 | 0 | builder.setDateFinalized(contract.getDateFinalized()); |
328 | 0 | builder.setTitle(contract.getTitle()); |
329 | 0 | builder.setApplicationDocumentId(contract.getApplicationDocumentId()); |
330 | 0 | builder.setRoutedByPrincipalId(contract.getRoutedByPrincipalId()); |
331 | 0 | builder.setDocumentHandlerUrl(contract.getDocumentHandlerUrl()); |
332 | 0 | builder.setApplicationDocumentStatus(contract.getApplicationDocumentStatus()); |
333 | 0 | builder.setApplicationDocumentStatusDate(contract.getApplicationDocumentStatusDate()); |
334 | 0 | builder.setVariables(new HashMap<String, String>(contract.getVariables())); |
335 | 0 | return builder; |
336 | |
} |
337 | |
|
338 | |
public Document build() { |
339 | 0 | return new Document(this); |
340 | |
} |
341 | |
|
342 | |
@Override |
343 | |
public String getDocumentId() { |
344 | 0 | return this.documentId; |
345 | |
} |
346 | |
|
347 | |
@Override |
348 | |
public DocumentStatus getStatus() { |
349 | 0 | return this.status; |
350 | |
} |
351 | |
|
352 | |
@Override |
353 | |
public DateTime getDateCreated() { |
354 | 0 | return this.dateCreated; |
355 | |
} |
356 | |
|
357 | |
@Override |
358 | |
public DateTime getDateLastModified() { |
359 | 0 | return this.dateLastModified; |
360 | |
} |
361 | |
|
362 | |
@Override |
363 | |
public DateTime getDateApproved() { |
364 | 0 | return this.dateApproved; |
365 | |
} |
366 | |
|
367 | |
@Override |
368 | |
public DateTime getDateFinalized() { |
369 | 0 | return this.dateFinalized; |
370 | |
} |
371 | |
|
372 | |
@Override |
373 | |
public String getTitle() { |
374 | 0 | return this.title; |
375 | |
} |
376 | |
|
377 | |
@Override |
378 | |
public String getApplicationDocumentId() { |
379 | 0 | return this.applicationDocumentId; |
380 | |
} |
381 | |
|
382 | |
@Override |
383 | |
public String getInitiatorPrincipalId() { |
384 | 0 | return this.initiatorPrincipalId; |
385 | |
} |
386 | |
|
387 | |
@Override |
388 | |
public String getRoutedByPrincipalId() { |
389 | 0 | return this.routedByPrincipalId; |
390 | |
} |
391 | |
|
392 | |
@Override |
393 | |
public String getDocumentTypeName() { |
394 | 0 | return this.documentTypeName; |
395 | |
} |
396 | |
|
397 | |
@Override |
398 | |
public String getDocumentTypeId() { |
399 | 0 | return this.documentTypeId; |
400 | |
} |
401 | |
|
402 | |
@Override |
403 | |
public String getDocumentHandlerUrl() { |
404 | 0 | return this.documentHandlerUrl; |
405 | |
} |
406 | |
|
407 | |
@Override |
408 | |
public String getApplicationDocumentStatus() { |
409 | 0 | return this.applicationDocumentStatus; |
410 | |
} |
411 | |
|
412 | |
@Override |
413 | |
public DateTime getApplicationDocumentStatusDate() { |
414 | 0 | return this.applicationDocumentStatusDate; |
415 | |
} |
416 | |
|
417 | |
@Override |
418 | |
public Map<String, String> getVariables() { |
419 | 0 | return this.variables; |
420 | |
} |
421 | |
|
422 | |
public void setDocumentId(String documentId) { |
423 | 0 | if (StringUtils.isBlank(documentId)) { |
424 | 0 | throw new IllegalArgumentException("documentId was null or blank"); |
425 | |
} |
426 | 0 | this.documentId = documentId; |
427 | 0 | } |
428 | |
|
429 | |
public void setStatus(DocumentStatus status) { |
430 | 0 | if (status == null) { |
431 | 0 | throw new IllegalArgumentException("status was null"); |
432 | |
} |
433 | 0 | this.status = status; |
434 | 0 | } |
435 | |
|
436 | |
public void setDateCreated(DateTime dateCreated) { |
437 | 0 | if (dateCreated == null) { |
438 | 0 | throw new IllegalArgumentException("dateCreated was null"); |
439 | |
} |
440 | 0 | this.dateCreated = dateCreated; |
441 | 0 | } |
442 | |
|
443 | |
public void setDateLastModified(DateTime dateLastModified) { |
444 | 0 | this.dateLastModified = dateLastModified; |
445 | 0 | } |
446 | |
|
447 | |
public void setDateApproved(DateTime dateApproved) { |
448 | 0 | this.dateApproved = dateApproved; |
449 | 0 | } |
450 | |
|
451 | |
public void setDateFinalized(DateTime dateFinalized) { |
452 | 0 | this.dateFinalized = dateFinalized; |
453 | 0 | } |
454 | |
|
455 | |
public void setTitle(String title) { |
456 | 0 | if (title == null) { |
457 | 0 | title = ""; |
458 | |
} |
459 | 0 | this.title = title; |
460 | 0 | } |
461 | |
|
462 | |
public void setApplicationDocumentId(String applicationDocumentId) { |
463 | 0 | this.applicationDocumentId = applicationDocumentId; |
464 | 0 | } |
465 | |
|
466 | |
public void setInitiatorPrincipalId(String initiatorPrincipalId) { |
467 | 0 | if (StringUtils.isBlank(initiatorPrincipalId)) { |
468 | 0 | throw new IllegalArgumentException("initiatorPrincipalId was null or blank"); |
469 | |
} |
470 | 0 | this.initiatorPrincipalId = initiatorPrincipalId; |
471 | 0 | } |
472 | |
|
473 | |
public void setRoutedByPrincipalId(String routedByPrincipalId) { |
474 | 0 | this.routedByPrincipalId = routedByPrincipalId; |
475 | 0 | } |
476 | |
|
477 | |
public void setDocumentTypeName(String documentTypeName) { |
478 | 0 | if (StringUtils.isBlank(documentTypeName)) { |
479 | 0 | throw new IllegalArgumentException("documentTypeName was null or blank"); |
480 | |
} |
481 | 0 | this.documentTypeName = documentTypeName; |
482 | 0 | } |
483 | |
|
484 | |
public void setDocumentTypeId(String documentTypeId) { |
485 | 0 | if (StringUtils.isBlank(documentTypeId)) { |
486 | 0 | throw new IllegalArgumentException("documentTypeId was null or blank"); |
487 | |
} |
488 | 0 | this.documentTypeId = documentTypeId; |
489 | 0 | } |
490 | |
|
491 | |
public void setDocumentHandlerUrl(String documentHandlerUrl) { |
492 | 0 | this.documentHandlerUrl = documentHandlerUrl; |
493 | 0 | } |
494 | |
|
495 | |
public void setApplicationDocumentStatus(String applicationDocumentStatus) { |
496 | 0 | this.applicationDocumentStatus = applicationDocumentStatus; |
497 | 0 | } |
498 | |
|
499 | |
public void setApplicationDocumentStatusDate(DateTime applicationDocumentStatusDate) { |
500 | 0 | this.applicationDocumentStatusDate = applicationDocumentStatusDate; |
501 | 0 | } |
502 | |
|
503 | |
public void setVariables(Map<String, String> variables) { |
504 | 0 | if (variables == null) { |
505 | 0 | variables = new HashMap<String, String>(); |
506 | |
} |
507 | 0 | this.variables = variables; |
508 | 0 | } |
509 | |
|
510 | |
} |
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | 0 | static class Constants { |
516 | |
final static String ROOT_ELEMENT_NAME = "document"; |
517 | |
final static String TYPE_NAME = "DocumentType"; |
518 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
519 | |
} |
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | 0 | static class Elements { |
525 | |
final static String DOCUMENT_ID = "documentId"; |
526 | |
final static String STATUS = "status"; |
527 | |
final static String DATE_CREATED = "dateCreated"; |
528 | |
final static String DATE_LAST_MODIFIED = "dateLastModified"; |
529 | |
final static String DATE_APPROVED = "dateApproved"; |
530 | |
final static String DATE_FINALIZED = "dateFinalized"; |
531 | |
final static String TITLE = "title"; |
532 | |
final static String APPLICATION_DOCUMENT_ID = "applicationDocumentId"; |
533 | |
final static String INITIATOR_PRINCIPAL_ID = "initiatorPrincipalId"; |
534 | |
final static String ROUTED_BY_PRINCIPAL_ID = "routedByPrincipalId"; |
535 | |
final static String DOCUMENT_TYPE_NAME = "documentTypeName"; |
536 | |
final static String DOCUMENT_TYPE_ID = "documentTypeId"; |
537 | |
final static String DOCUMENT_HANDLER_URL = "documentHandlerUrl"; |
538 | |
final static String APPLICATION_DOCUMENT_STATUS = "applicationDocumentStatus"; |
539 | |
final static String APPLICATION_DOCUMENT_STATUS_DATE = "applicationDocumentStatusDate"; |
540 | |
final static String VARIABLES = "variables"; |
541 | |
} |
542 | |
|
543 | |
} |
544 | |
|