Coverage Report - org.kuali.rice.kew.api.document.DocumentStatus
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentStatus
0%
0/29
0%
0/12
2.667
 
 1  
 /**
 2  
  * Copyright 2005-2011 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  0
 @XmlRootElement(name = "documentStatus")
 34  
 @XmlType(name = "DocumentStatusType")
 35  
 @XmlEnum
 36  
 public enum DocumentStatus implements Coded {
 37  
 
 38  0
         @XmlEnumValue("I") INITIATED("I", DocumentStatusCategory.PENDING),
 39  0
         @XmlEnumValue("S") SAVED("S", DocumentStatusCategory.PENDING),
 40  0
         @XmlEnumValue("R") ENROUTE("R", DocumentStatusCategory.PENDING),
 41  0
     @XmlEnumValue("E") EXCEPTION("E", DocumentStatusCategory.PENDING),
 42  0
         @XmlEnumValue("P") PROCESSED("P", DocumentStatusCategory.SUCCESSFUL),
 43  0
         @XmlEnumValue("F") FINAL("F", DocumentStatusCategory.SUCCESSFUL),
 44  0
         @XmlEnumValue("X") CANCELED("X", DocumentStatusCategory.UNSUCCESSFUL),
 45  0
         @XmlEnumValue("D") DISAPPROVED("D", DocumentStatusCategory.UNSUCCESSFUL);
 46  
 
 47  
         private final String code;
 48  
     private final DocumentStatusCategory category;
 49  
         
 50  0
         private DocumentStatus(String code, DocumentStatusCategory category) {
 51  0
                 this.code = code;
 52  0
         this.category = category;
 53  0
         }
 54  
         
 55  
         @Override
 56  
         public String getCode() {
 57  0
                 return code;
 58  
         }
 59  
 
 60  
     public DocumentStatusCategory getCategory() {
 61  0
         return category;
 62  
     }
 63  
         
 64  
         public String getLabel() {
 65  0
             return name();
 66  
         }
 67  
         
 68  
         public static DocumentStatus fromCode(String code) {
 69  0
                 if (code == null) {
 70  0
                         return null;
 71  
                 }
 72  0
                 for (DocumentStatus status : values()) {
 73  0
                         if (status.code.equals(code)) {
 74  0
                                 return status;
 75  
                         }
 76  
                 }
 77  0
                 throw new IllegalArgumentException("Failed to locate the DocumentStatus with the given code: " + code);
 78  
         }
 79  
 
 80  
     public static EnumSet<DocumentStatus> getStatusesForCategory(DocumentStatusCategory category) {
 81  0
         if (category == null) {
 82  0
             throw new IllegalArgumentException("category was null");
 83  
         }
 84  0
         EnumSet<DocumentStatus> categoryStatuses = EnumSet.noneOf(DocumentStatus.class);
 85  0
         for (DocumentStatus status : values()) {
 86  0
                         if (status.category == category) {
 87  0
                                 categoryStatuses.add(status);
 88  
                         }
 89  
                 }
 90  0
         return categoryStatuses;
 91  
     }
 92  
         
 93  
 }