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