001 /**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.api.document;
017
018 import javax.xml.bind.annotation.XmlEnum;
019 import javax.xml.bind.annotation.XmlEnumValue;
020 import javax.xml.bind.annotation.XmlRootElement;
021 import javax.xml.bind.annotation.XmlType;
022
023 import org.kuali.rice.core.api.mo.common.Coded;
024
025 import java.util.EnumSet;
026
027 /**
028 * An enumeration representing valid workflow document statuses.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 *
032 */
033 @XmlRootElement(name = "documentStatus")
034 @XmlType(name = "DocumentStatusType")
035 @XmlEnum
036 public enum DocumentStatus implements Coded {
037
038 @XmlEnumValue("I") INITIATED("I", DocumentStatusCategory.PENDING),
039 @XmlEnumValue("S") SAVED("S", DocumentStatusCategory.PENDING),
040 @XmlEnumValue("R") ENROUTE("R", DocumentStatusCategory.PENDING),
041 @XmlEnumValue("E") EXCEPTION("E", DocumentStatusCategory.PENDING),
042 @XmlEnumValue("P") PROCESSED("P", DocumentStatusCategory.SUCCESSFUL),
043 @XmlEnumValue("F") FINAL("F", DocumentStatusCategory.SUCCESSFUL),
044 @XmlEnumValue("X") CANCELED("X", DocumentStatusCategory.UNSUCCESSFUL),
045 @XmlEnumValue("D") DISAPPROVED("D", DocumentStatusCategory.UNSUCCESSFUL),
046 /**
047 * When invoked, RECALL & CANCEL action will perform the RECALL and set the route status of the document to the new, terminal status of RECALLED
048 * @since 2.1
049 */
050 @XmlEnumValue("L") RECALLED("L", DocumentStatusCategory.UNSUCCESSFUL);
051
052 private final String code;
053 private final DocumentStatusCategory category;
054
055 private DocumentStatus(String code, DocumentStatusCategory category) {
056 this.code = code;
057 this.category = category;
058 }
059
060 @Override
061 public String getCode() {
062 return code;
063 }
064
065 public DocumentStatusCategory getCategory() {
066 return category;
067 }
068
069 public String getLabel() {
070 return name();
071 }
072
073 public static DocumentStatus fromCode(String code) {
074 if (code == null) {
075 return null;
076 }
077 for (DocumentStatus status : values()) {
078 if (status.code.equals(code)) {
079 return status;
080 }
081 }
082 throw new IllegalArgumentException("Failed to locate the DocumentStatus with the given code: " + code);
083 }
084
085 public static EnumSet<DocumentStatus> getStatusesForCategory(DocumentStatusCategory category) {
086 if (category == null) {
087 throw new IllegalArgumentException("category was null");
088 }
089 EnumSet<DocumentStatus> categoryStatuses = EnumSet.noneOf(DocumentStatus.class);
090 for (DocumentStatus status : values()) {
091 if (status.category == category) {
092 categoryStatuses.add(status);
093 }
094 }
095 return categoryStatuses;
096 }
097
098 }