001    /**
002     * Copyright 2005-2012 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     * TODO...
029     * 
030     * @author ewestfal
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            private final String code;
048        private final DocumentStatusCategory category;
049            
050            private DocumentStatus(String code, DocumentStatusCategory category) {
051                    this.code = code;
052            this.category = category;
053            }
054            
055            @Override
056            public String getCode() {
057                    return code;
058            }
059    
060        public DocumentStatusCategory getCategory() {
061            return category;
062        }
063            
064            public String getLabel() {
065                return name();
066            }
067            
068            public static DocumentStatus fromCode(String code) {
069                    if (code == null) {
070                            return null;
071                    }
072                    for (DocumentStatus status : values()) {
073                            if (status.code.equals(code)) {
074                                    return status;
075                            }
076                    }
077                    throw new IllegalArgumentException("Failed to locate the DocumentStatus with the given code: " + code);
078            }
079    
080        public static EnumSet<DocumentStatus> getStatusesForCategory(DocumentStatusCategory category) {
081            if (category == null) {
082                throw new IllegalArgumentException("category was null");
083            }
084            EnumSet<DocumentStatus> categoryStatuses = EnumSet.noneOf(DocumentStatus.class);
085            for (DocumentStatus status : values()) {
086                            if (status.category == category) {
087                                    categoryStatuses.add(status);
088                            }
089                    }
090            return categoryStatuses;
091        }
092            
093    }