View Javadoc

1   /**
2    * Copyright 2005-2012 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   * TODO...
29   * 
30   * @author ewestfal
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  	private final String code;
48      private final DocumentStatusCategory category;
49  	
50  	private DocumentStatus(String code, DocumentStatusCategory category) {
51  		this.code = code;
52          this.category = category;
53  	}
54  	
55  	@Override
56  	public String getCode() {
57  		return code;
58  	}
59  
60      public DocumentStatusCategory getCategory() {
61          return category;
62      }
63  	
64  	public String getLabel() {
65  	    return name();
66  	}
67  	
68  	public static DocumentStatus fromCode(String code) {
69  		if (code == null) {
70  			return null;
71  		}
72  		for (DocumentStatus status : values()) {
73  			if (status.code.equals(code)) {
74  				return status;
75  			}
76  		}
77  		throw new IllegalArgumentException("Failed to locate the DocumentStatus with the given code: " + code);
78  	}
79  
80      public static EnumSet<DocumentStatus> getStatusesForCategory(DocumentStatusCategory category) {
81          if (category == null) {
82              throw new IllegalArgumentException("category was null");
83          }
84          EnumSet<DocumentStatus> categoryStatuses = EnumSet.noneOf(DocumentStatus.class);
85          for (DocumentStatus status : values()) {
86  			if (status.category == category) {
87  				categoryStatuses.add(status);
88  			}
89  		}
90          return categoryStatuses;
91      }
92  	
93  }