001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kew.api.action; 017 018import org.kuali.rice.core.api.mo.common.Coded; 019 020import javax.xml.bind.annotation.XmlEnum; 021import javax.xml.bind.annotation.XmlEnumValue; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlType; 024 025import java.util.HashMap; 026import java.util.Map; 027 028/** 029 * An enumeration which indicates valid actions that can be taken against workflow documents. 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 * 033 */ 034@XmlRootElement(name = "actionType") 035@XmlType(name = "ActionTypeType") 036@XmlEnum 037public enum ActionType implements Coded { 038 039 @XmlEnumValue("k") SU_ACKNOWLEDGE("k", "SUPER USER ACKNOWLEDGE"), 040 041 @XmlEnumValue("f") SU_FYI("f", "SUPER USER FYI"), 042 043 @XmlEnumValue("m") SU_COMPLETE("m", "SUPER USER COMPLETE"), 044 045 @XmlEnumValue("v") SU_APPROVE("v", "SUPER USER APPROVE"), 046 047 @XmlEnumValue("r") SU_ROUTE_NODE_APPROVE("r", "SUPER USER ROUTE NODE APPROVE"), 048 049 @XmlEnumValue("z") SU_RETURN_TO_PREVIOUS("z", "SUPER USER RETURN TO PREVIOUS"), 050 051 @XmlEnumValue("d") SU_DISAPPROVE("d", "SUPER USER DISAPPROVE"), 052 053 @XmlEnumValue("c") SU_CANCEL("c", "SUPER USER CANCEL"), 054 055 @XmlEnumValue("a") SU_BLANKET_APPROVE("a", "SUPER USER BLANKET APPROVE"), 056 057 @XmlEnumValue("B") BLANKET_APPROVE("B", "BLANKET APPROVE"), 058 059 @XmlEnumValue("F") FYI("F", "FYI"), 060 061 /** 062 * User has generated an action request to another user 063 */ 064 @XmlEnumValue("H") ADHOC_REQUEST("H", "ADHOC REQUEST"), 065 066 /** 067 * AdHoc Request has been revoked 068 */ 069 @XmlEnumValue("V") ADHOC_REQUEST_REVOKE("V", "ADHOC REQUEST_REVOKE"), 070 071 /** 072 * Document has been saved by the user for later work 073 */ 074 @XmlEnumValue("S") SAVE("S", "SAVED"), 075 076 /** 077 * Document has been canceled. 078 */ 079 @XmlEnumValue("X") CANCEL("X", "CANCEL"), 080 081 /** 082 * Document has been disapproved. 083 */ 084 @XmlEnumValue("D") DISAPPROVE("D", "DISAPPROVE"), 085 086 /** 087 * Document has been opened by the designated recipient. 088 */ 089 @XmlEnumValue("K") ACKNOWLEDGE("K", "ACKNOWLEDGE"), 090 091 /** 092 * Document has been completed as requested. 093 */ 094 @XmlEnumValue("C") COMPLETE("C", "COMPLETE"), 095 096 /** 097 * Document has been submitted to the engine for processing. 098 */ 099 @XmlEnumValue("O") ROUTE("O", "ROUTE"), 100 101 /** 102 * The document has been approved. 103 */ 104 @XmlEnumValue("A") APPROVE("A", "APPROVE"), 105 106 /** 107 * The document is being returned to a previous routelevel 108 */ 109 @XmlEnumValue("Z") RETURN_TO_PREVIOUS("Z", "RETURN TO PREVIOUS"), 110 111 /** 112 * The document is being recalled. 113 * @since 2.1 114 */ 115 @XmlEnumValue("L") RECALL("L", "RECALL"), 116 117 /** 118 * The document has non-routed activity against it that is recorded in the route log 119 */ 120 @XmlEnumValue("R") LOG_MESSAGE("R", "LOG MESSAGE"), 121 122 /** 123 * The document is routed to a group and a user in the group wants to take authority from the group 124 */ 125 @XmlEnumValue("w") TAKE_GROUP_AUTHORITY("w", "TAKE GROUP AUTHORITY"), 126 127 /** 128 * The person who took group authority is releasing it 129 */ 130 @XmlEnumValue("y") RELEASE_GROUP_AUTHORITY("y", "RELEASE GROUP AUTHORITY"), 131 132 /** 133 * The document is moved 134 */ 135 @XmlEnumValue("M") MOVE("M", "MOVED"); 136 137 /** 138 * Map of ActionTypes to their SuperUser equivalent 139 */ 140 private static final Map<ActionType, ActionType> SU_ACTION_TYPE = new HashMap<ActionType, ActionType>(); 141 static { 142 SU_ACTION_TYPE.put(APPROVE, SU_APPROVE); 143 SU_ACTION_TYPE.put(COMPLETE, SU_COMPLETE); 144 SU_ACTION_TYPE.put(FYI, SU_FYI); 145 SU_ACTION_TYPE.put(ACKNOWLEDGE, SU_ACKNOWLEDGE); 146 } 147 148 private final String code; 149 private final String label; 150 151 private ActionType(String code, String label) { 152 this.code = code; 153 this.label = label; 154 } 155 156 @Override 157 public String getCode() { 158 return code; 159 } 160 161 public String getLabel() { 162 return label; 163 } 164 165 public static ActionType fromCode(String code) { 166 return fromCode(code, false); 167 } 168 169 public static ActionType fromCode(String code, boolean allowMissing) { 170 if (code == null) { 171 return null; 172 } 173 for (ActionType status : values()) { 174 if (status.code.equals(code)) { 175 return status; 176 } 177 } 178 if (allowMissing) { 179 return null; 180 } 181 throw new IllegalArgumentException("Failed to locate the ActionType with the given code: " + code); 182 } 183 184 public static ActionType fromLabel(String label) { 185 if (label == null) { 186 return null; 187 } 188 for (ActionType status : values()) { 189 if (status.label.equals(label)) { 190 return status; 191 } 192 } 193 return null; 194 } 195 196 public static ActionType fromCodeOrLabel(String str) { 197 ActionType at = ActionType.fromCode(str, true); 198 if (at == null && str != null) { 199 at = ActionType.fromLabel(str.toUpperCase()); 200 } 201 return at; 202 } 203 204 /** 205 * Converts a non-super-user ActionType to its SuperUser equivalent 206 * @since 2.1.3 207 * @param at the ActionType 208 * @return super-user version of ActionType or null if no equivalent SU action type 209 */ 210 public static ActionType toSuperUserActionType(ActionType at) { 211 if (SU_ACTION_TYPE.containsKey(at)) return at; 212 return SU_ACTION_TYPE.get(at); 213 } 214}