View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * An enumeration representing valid workflow document statuses.
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * When invoked, RECALL & CANCEL action will perform the RECALL and set the route status of the document to the new, terminal status of RECALLED
48       * @since 2.1
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  }