001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.opensource.org/licenses/ecl2.php
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.kuali.rice.kew.util;
018
019 import java.util.HashMap;
020 import java.util.Map;
021
022
023 /**
024 * Utility class to translate the various codes into labels and vice versa.
025 *
026 * @author Kuali Rice Team (rice.collab@kuali.org)
027 */
028 public class CodeTranslator {
029 public static final Map arLabels = getArLabels();
030 public static final Map atLabels = getAtLabels();
031 public static final Map arStatusLabels = getArStatusLabels();
032 public static final Map routeStatusLabels = getRouteStatusLabels();
033 public static final Map activeIndicatorLabels = getActiveIndicatorLabels();
034 public static final Map activationPolicyLabels = getActivationPolicyLabels();
035 public static final Map policyLabels = getPolicyLabels();
036 public static final Map approvePolicyLabels = getApprovePolicyLabels();
037
038 private static Map getAtLabels() {
039 Map newAtLabels = new HashMap();
040 newAtLabels.put(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KEWConstants.ACTION_TAKEN_ACKNOWLEDGED);
041 newAtLabels.put(KEWConstants.ACTION_TAKEN_ADHOC_CD, KEWConstants.ACTION_TAKEN_ADHOC);
042 newAtLabels.put(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, KEWConstants.ACTION_TAKEN_ADHOC_REVOKED);
043 newAtLabels.put(KEWConstants.ACTION_TAKEN_APPROVED_CD, KEWConstants.ACTION_TAKEN_APPROVED);
044 newAtLabels.put(KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD, KEWConstants.ACTION_TAKEN_BLANKET_APPROVE);
045 newAtLabels.put(KEWConstants.ACTION_TAKEN_CANCELED_CD, KEWConstants.ACTION_TAKEN_CANCELED);
046 newAtLabels.put(KEWConstants.ACTION_TAKEN_COMPLETED_CD, KEWConstants.ACTION_TAKEN_COMPLETED);
047 newAtLabels.put(KEWConstants.ACTION_TAKEN_ROUTED_CD, KEWConstants.ACTION_TAKEN_ROUTED);
048 newAtLabels.put(KEWConstants.ACTION_TAKEN_DENIED_CD, KEWConstants.ACTION_TAKEN_DENIED);
049 newAtLabels.put(KEWConstants.ACTION_TAKEN_FYI_CD, KEWConstants.ACTION_TAKEN_FYI);
050 newAtLabels.put(KEWConstants.ACTION_TAKEN_SAVED_CD, KEWConstants.ACTION_TAKEN_SAVED);
051 newAtLabels.put(KEWConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD, KEWConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS);
052 newAtLabels.put(KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION);
053 newAtLabels.put(KEWConstants.ACTION_TAKEN_MOVE_CD, KEWConstants.ACTION_TAKEN_MOVE);
054 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_APPROVED);
055 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_CANCELED_CD, KEWConstants.ACTION_TAKEN_SU_CANCELED);
056 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_DISAPPROVED_CD, KEWConstants.ACTION_TAKEN_SU_DISAPPROVED);
057 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED);
058 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED);
059 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD, KEWConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS);
060 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED);
061 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI);
062 newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED);
063 newAtLabels.put(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY);
064 newAtLabels.put(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY);
065 return newAtLabels;
066 }
067
068 private static Map getArLabels() {
069 Map newArLabels = new HashMap();
070 newArLabels.put(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
071 newArLabels.put(KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
072 newArLabels.put(KEWConstants.ACTION_REQUEST_COMPLETE_REQ, KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL);
073 newArLabels.put(KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
074 return newArLabels;
075 }
076
077 private static Map getArStatusLabels() {
078 Map newArStatusLabels = new HashMap();
079 newArStatusLabels.put(KEWConstants.ACTION_REQUEST_ACTIVATED, KEWConstants.ACTIVE_LABEL);
080 newArStatusLabels.put(KEWConstants.ACTION_REQUEST_INITIALIZED, KEWConstants.ACTION_REQUEST_INITIALIZED_LABEL);
081 newArStatusLabels.put(KEWConstants.ACTION_REQUEST_DONE_STATE, KEWConstants.ACTION_REQUEST_DONE_STATE_LABEL);
082 return newArStatusLabels;
083 }
084
085 private static Map getRouteStatusLabels() {
086 Map newRouteStatusLabels = new HashMap();
087 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_APPROVED_CD, KEWConstants.ROUTE_HEADER_APPROVED_LABEL);
088 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_CANCEL_CD, KEWConstants.ROUTE_HEADER_CANCEL_LABEL);
089 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_DISAPPROVED_CD, KEWConstants.ROUTE_HEADER_DISAPPROVED_LABEL);
090 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_ENROUTE_CD, KEWConstants.ROUTE_HEADER_ENROUTE_LABEL);
091 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_EXCEPTION_CD, KEWConstants.ROUTE_HEADER_EXCEPTION_LABEL);
092 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_FINAL_CD, KEWConstants.ROUTE_HEADER_FINAL_LABEL);
093 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_INITIATED_CD, KEWConstants.ROUTE_HEADER_INITIATED_LABEL);
094 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_PROCESSED_CD, KEWConstants.ROUTE_HEADER_PROCESSED_LABEL);
095 newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_SAVED_CD, KEWConstants.ROUTE_HEADER_SAVED_LABEL);
096 return newRouteStatusLabels;
097 }
098
099 private static Map getActiveIndicatorLabels() {
100 Map newActiveIndicatorLabels = new HashMap();
101 newActiveIndicatorLabels.put(Boolean.TRUE, KEWConstants.ACTIVE_LABEL_LOWER);
102 newActiveIndicatorLabels.put(Boolean.FALSE, KEWConstants.INACTIVE_LABEL_LOWER);
103 return newActiveIndicatorLabels;
104 }
105
106 private static Map getPolicyLabels() {
107 Map newDocTypeActiveIndicatorLabels = new HashMap();
108 newDocTypeActiveIndicatorLabels.put(KEWConstants.TRUE_CD, KEWConstants.YES_LABEL);
109 newDocTypeActiveIndicatorLabels.put(KEWConstants.FALSE_CD, KEWConstants.NO_LABEL);
110 newDocTypeActiveIndicatorLabels.put(KEWConstants.INHERITED_CD, KEWConstants.INHERITED_LABEL);
111 return newDocTypeActiveIndicatorLabels;
112 }
113
114 private static Map getActivationPolicyLabels() {
115 Map newActivationPolicyLabels = new HashMap();
116 newActivationPolicyLabels.put(KEWConstants.ROUTE_LEVEL_PARALLEL, KEWConstants.ROUTE_LEVEL_PARALLEL_LABEL);
117 newActivationPolicyLabels.put(KEWConstants.ROUTE_LEVEL_SEQUENCE, KEWConstants.ROUTE_LEVEL_SEQUENCE_LABEL);
118 return newActivationPolicyLabels;
119 }
120
121 private static Map getApprovePolicyLabels() {
122 Map approvePolicyLabels = new HashMap();
123 approvePolicyLabels.put(KEWConstants.APPROVE_POLICY_ALL_APPROVE, KEWConstants.APPROVE_POLICY_ALL_APPROVE_LABEL);
124 approvePolicyLabels.put(KEWConstants.APPROVE_POLICY_FIRST_APPROVE, KEWConstants.APPROVE_POLICY_FIRST_APPROVE_LABEL);
125 return approvePolicyLabels;
126 }
127
128 /**
129 * Given an actionRequest code return the appropriate label.
130 *
131 * @param actionRequestCode
132 * The actionRequestCode to be translated.
133 * @return action request label
134 */
135 static public String getActionRequestLabel(String actionRequestCode) {
136 return (String) arLabels.get(actionRequestCode);
137 }
138
139 /**
140 * Given an action taken code return the appropriate label for it.
141 *
142 * @param actionTakenCode
143 * action taken code to use to find the label.
144 * @return action taken label
145 */
146 static public String getActionTakenLabel(String actionTakenCode) {
147 return (String) atLabels.get(actionTakenCode);
148 }
149
150 /**
151 * Return the label for the given request status level.
152 *
153 * @param status
154 * code of the request status
155 * @return label for the corresponding code.
156 */
157 static public String getActionRequestStatusLabel(String status) {
158 return (String) arStatusLabels.get(status);
159 }
160
161 static public String getRouteStatusLabel(String status) {
162 return (String) routeStatusLabels.get(status);
163 }
164
165 static public String getActiveIndicatorLabel(Boolean indicator) {
166 return (String) activeIndicatorLabels.get(indicator);
167 }
168
169 static public String getActivationPolicyLabel(String code) {
170 return (String) activationPolicyLabels.get(code);
171 }
172
173 static public String getPolicyLabel(String code) {
174 return (String) policyLabels.get(code);
175 }
176
177 }