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 javax.xml.bind.annotation.XmlEnum;
19 import javax.xml.bind.annotation.XmlEnumValue;
20 import javax.xml.bind.annotation.XmlRootElement;
21 import javax.xml.bind.annotation.XmlType;
22
23 import org.kuali.rice.core.api.mo.common.Coded;
24
25 import java.util.EnumSet;
26
27
28
29
30
31
32
33 @XmlRootElement(name = "documentStatus")
34 @XmlType(name = "DocumentStatusType")
35 @XmlEnum
36 public enum DocumentStatus implements Coded {
37
38 @XmlEnumValue("I") INITIATED("I", DocumentStatusCategory.PENDING),
39 @XmlEnumValue("S") SAVED("S", DocumentStatusCategory.PENDING),
40 @XmlEnumValue("R") ENROUTE("R", DocumentStatusCategory.PENDING),
41 @XmlEnumValue("E") EXCEPTION("E", DocumentStatusCategory.PENDING),
42 @XmlEnumValue("P") PROCESSED("P", DocumentStatusCategory.SUCCESSFUL),
43 @XmlEnumValue("F") FINAL("F", DocumentStatusCategory.SUCCESSFUL),
44 @XmlEnumValue("X") CANCELED("X", DocumentStatusCategory.UNSUCCESSFUL),
45 @XmlEnumValue("D") DISAPPROVED("D", DocumentStatusCategory.UNSUCCESSFUL),
46
47
48
49
50 @XmlEnumValue("L") RECALLED("L", DocumentStatusCategory.UNSUCCESSFUL);
51
52 private final String code;
53 private final DocumentStatusCategory category;
54
55 private DocumentStatus(String code, DocumentStatusCategory category) {
56 this.code = code;
57 this.category = category;
58 }
59
60 @Override
61 public String getCode() {
62 return code;
63 }
64
65 public DocumentStatusCategory getCategory() {
66 return category;
67 }
68
69 public String getLabel() {
70 return name();
71 }
72
73 public static DocumentStatus fromCode(String code) {
74 if (code == null) {
75 return null;
76 }
77 for (DocumentStatus status : values()) {
78 if (status.code.equals(code)) {
79 return status;
80 }
81 }
82 throw new IllegalArgumentException("Failed to locate the DocumentStatus with the given code: " + code);
83 }
84
85 public static EnumSet<DocumentStatus> getStatusesForCategory(DocumentStatusCategory category) {
86 if (category == null) {
87 throw new IllegalArgumentException("category was null");
88 }
89 EnumSet<DocumentStatus> categoryStatuses = EnumSet.noneOf(DocumentStatus.class);
90 for (DocumentStatus status : values()) {
91 if (status.category == category) {
92 categoryStatuses.add(status);
93 }
94 }
95 return categoryStatuses;
96 }
97
98 }