View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.util;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  
23  /**
24   * Utility class to translate the various codes into labels and vice versa.
25   *
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class CodeTranslator {
29      public static final Map arLabels = getArLabels();
30      public static final Map atLabels = getAtLabels();
31      public static final Map arStatusLabels = getArStatusLabels();
32      public static final Map routeStatusLabels = getRouteStatusLabels();
33      public static final Map activeIndicatorLabels = getActiveIndicatorLabels();
34      public static final Map activationPolicyLabels = getActivationPolicyLabels();
35      public static final Map policyLabels = getPolicyLabels();
36      public static final Map approvePolicyLabels = getApprovePolicyLabels();
37  
38      private static Map getAtLabels() {
39          Map newAtLabels = new HashMap();
40          newAtLabels.put(KEWConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KEWConstants.ACTION_TAKEN_ACKNOWLEDGED);
41          newAtLabels.put(KEWConstants.ACTION_TAKEN_ADHOC_CD, KEWConstants.ACTION_TAKEN_ADHOC);
42          newAtLabels.put(KEWConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, KEWConstants.ACTION_TAKEN_ADHOC_REVOKED);
43          newAtLabels.put(KEWConstants.ACTION_TAKEN_APPROVED_CD, KEWConstants.ACTION_TAKEN_APPROVED);
44          newAtLabels.put(KEWConstants.ACTION_TAKEN_BLANKET_APPROVE_CD, KEWConstants.ACTION_TAKEN_BLANKET_APPROVE);
45          newAtLabels.put(KEWConstants.ACTION_TAKEN_CANCELED_CD, KEWConstants.ACTION_TAKEN_CANCELED);
46          newAtLabels.put(KEWConstants.ACTION_TAKEN_COMPLETED_CD, KEWConstants.ACTION_TAKEN_COMPLETED);
47          newAtLabels.put(KEWConstants.ACTION_TAKEN_ROUTED_CD, KEWConstants.ACTION_TAKEN_ROUTED);
48          newAtLabels.put(KEWConstants.ACTION_TAKEN_DENIED_CD, KEWConstants.ACTION_TAKEN_DENIED);
49          newAtLabels.put(KEWConstants.ACTION_TAKEN_FYI_CD, KEWConstants.ACTION_TAKEN_FYI);
50          newAtLabels.put(KEWConstants.ACTION_TAKEN_SAVED_CD, KEWConstants.ACTION_TAKEN_SAVED);
51          newAtLabels.put(KEWConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD, KEWConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS);
52          newAtLabels.put(KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, KEWConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION);
53          newAtLabels.put(KEWConstants.ACTION_TAKEN_MOVE_CD, KEWConstants.ACTION_TAKEN_MOVE);
54          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_APPROVED);
55          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_CANCELED_CD, KEWConstants.ACTION_TAKEN_SU_CANCELED);
56          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_DISAPPROVED_CD, KEWConstants.ACTION_TAKEN_SU_DISAPPROVED);
57          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED);
58          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED);
59          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD, KEWConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS);
60          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED);
61          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI);
62          newAtLabels.put(KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, KEWConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED);
63          newAtLabels.put(KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, KEWConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY);
64          newAtLabels.put(KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, KEWConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY);
65          return newAtLabels;
66      }
67  
68      private static Map getArLabels() {
69          Map newArLabels = new HashMap();
70          newArLabels.put(KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
71          newArLabels.put(KEWConstants.ACTION_REQUEST_APPROVE_REQ, KEWConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
72          newArLabels.put(KEWConstants.ACTION_REQUEST_COMPLETE_REQ, KEWConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL);
73          newArLabels.put(KEWConstants.ACTION_REQUEST_FYI_REQ, KEWConstants.ACTION_REQUEST_FYI_REQ_LABEL);
74          return newArLabels;
75      }
76  
77      private static Map getArStatusLabels() {
78          Map newArStatusLabels = new HashMap();
79          newArStatusLabels.put(KEWConstants.ACTION_REQUEST_ACTIVATED, KEWConstants.ACTIVE_LABEL);
80          newArStatusLabels.put(KEWConstants.ACTION_REQUEST_INITIALIZED, KEWConstants.ACTION_REQUEST_INITIALIZED_LABEL);
81          newArStatusLabels.put(KEWConstants.ACTION_REQUEST_DONE_STATE, KEWConstants.ACTION_REQUEST_DONE_STATE_LABEL);
82          return newArStatusLabels;
83      }
84  
85      private static Map getRouteStatusLabels() {
86          Map newRouteStatusLabels = new HashMap();
87          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_APPROVED_CD, KEWConstants.ROUTE_HEADER_APPROVED_LABEL);
88          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_CANCEL_CD, KEWConstants.ROUTE_HEADER_CANCEL_LABEL);
89          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_DISAPPROVED_CD, KEWConstants.ROUTE_HEADER_DISAPPROVED_LABEL);
90          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_ENROUTE_CD, KEWConstants.ROUTE_HEADER_ENROUTE_LABEL);
91          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_EXCEPTION_CD, KEWConstants.ROUTE_HEADER_EXCEPTION_LABEL);
92          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_FINAL_CD, KEWConstants.ROUTE_HEADER_FINAL_LABEL);
93          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_INITIATED_CD, KEWConstants.ROUTE_HEADER_INITIATED_LABEL);
94          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_PROCESSED_CD, KEWConstants.ROUTE_HEADER_PROCESSED_LABEL);
95          newRouteStatusLabels.put(KEWConstants.ROUTE_HEADER_SAVED_CD, KEWConstants.ROUTE_HEADER_SAVED_LABEL);
96          return newRouteStatusLabels;
97      }
98  
99      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 }