View Javadoc

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.util;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.kuali.rice.kew.api.KewApiConstants;
22  import org.kuali.rice.kew.api.action.ActionRequestPolicy;
23  import org.kuali.rice.kew.api.action.ActionRequestStatus;
24  
25  
26  /**
27   * Utility class to translate the various codes into labels and vice versa.
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class CodeTranslator {
32      public static final Map<String, String> arLabels = getArLabels();
33      public static final Map<String, String> atLabels = getAtLabels();
34      public static final Map<String, String> arStatusLabels = getArStatusLabels();
35      public static final Map<String, String> routeStatusLabels = getRouteStatusLabels();
36      public static final Map<Boolean, String> activeIndicatorLabels = getActiveIndicatorLabels();
37      public static final Map<String, String> activationPolicyLabels = getActivationPolicyLabels();
38      public static final Map<String, String> policyLabels = getPolicyLabels();
39      public static final Map<String, String> approvePolicyLabels = getApprovePolicyLabels();
40  
41      private static Map<String, String> getAtLabels() {
42      	Map<String, String> newAtLabels = new HashMap<String, String>();
43          newAtLabels.put(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED);
44          newAtLabels.put(KewApiConstants.ACTION_TAKEN_ADHOC_CD, KewApiConstants.ACTION_TAKEN_ADHOC);
45          newAtLabels.put(KewApiConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, KewApiConstants.ACTION_TAKEN_ADHOC_REVOKED);
46          newAtLabels.put(KewApiConstants.ACTION_TAKEN_APPROVED_CD, KewApiConstants.ACTION_TAKEN_APPROVED);
47          newAtLabels.put(KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD, KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE);
48          newAtLabels.put(KewApiConstants.ACTION_TAKEN_CANCELED_CD, KewApiConstants.ACTION_TAKEN_CANCELED);
49          newAtLabels.put(KewApiConstants.ACTION_TAKEN_COMPLETED_CD, KewApiConstants.ACTION_TAKEN_COMPLETED);
50          newAtLabels.put(KewApiConstants.ACTION_TAKEN_ROUTED_CD, KewApiConstants.ACTION_TAKEN_ROUTED);
51          newAtLabels.put(KewApiConstants.ACTION_TAKEN_DENIED_CD, KewApiConstants.ACTION_TAKEN_DENIED);
52          newAtLabels.put(KewApiConstants.ACTION_TAKEN_FYI_CD, KewApiConstants.ACTION_TAKEN_FYI);
53          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SAVED_CD, KewApiConstants.ACTION_TAKEN_SAVED);
54          newAtLabels.put(KewApiConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD, KewApiConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS);
55          newAtLabels.put(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION);
56          newAtLabels.put(KewApiConstants.ACTION_TAKEN_MOVE_CD, KewApiConstants.ACTION_TAKEN_MOVE);
57          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_APPROVED);
58          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD, KewApiConstants.ACTION_TAKEN_SU_CANCELED);
59          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_DISAPPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_DISAPPROVED);
60          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED);
61          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED);
62          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD, KewApiConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS);
63          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED);
64          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI);
65          newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED);
66          newAtLabels.put(KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY);
67          newAtLabels.put(KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY);
68          return newAtLabels;
69      }
70  
71      private static Map<String, String> getArLabels() {
72      	Map<String, String> newArLabels = new HashMap<String, String>();
73          newArLabels.put(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
74          newArLabels.put(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, KewApiConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
75          newArLabels.put(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ, KewApiConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL);
76          newArLabels.put(KewApiConstants.ACTION_REQUEST_FYI_REQ, KewApiConstants.ACTION_REQUEST_FYI_REQ_LABEL);
77          return newArLabels;
78      }
79  
80      private static Map<String, String> getArStatusLabels() {
81          Map<String, String> newArStatusLabels = new HashMap<String, String>();
82          newArStatusLabels.put(ActionRequestStatus.ACTIVATED.getCode(), KewApiConstants.ACTIVE_LABEL);
83          newArStatusLabels.put(ActionRequestStatus.INITIALIZED.getCode(), ActionRequestStatus.INITIALIZED.getLabel());
84          newArStatusLabels.put(ActionRequestStatus.DONE.getCode(), ActionRequestStatus.DONE.getLabel());
85          return newArStatusLabels;
86      }
87  
88      private static Map<String, String> getRouteStatusLabels() {
89      	Map<String, String> newRouteStatusLabels = new HashMap<String, String>();
90          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_CANCEL_CD, KewApiConstants.ROUTE_HEADER_CANCEL_LABEL);
91          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_DISAPPROVED_CD, KewApiConstants.ROUTE_HEADER_DISAPPROVED_LABEL);
92          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_ENROUTE_CD, KewApiConstants.ROUTE_HEADER_ENROUTE_LABEL);
93          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_EXCEPTION_CD, KewApiConstants.ROUTE_HEADER_EXCEPTION_LABEL);
94          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_FINAL_CD, KewApiConstants.ROUTE_HEADER_FINAL_LABEL);
95          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_INITIATED_CD, KewApiConstants.ROUTE_HEADER_INITIATED_LABEL);
96          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_PROCESSED_CD, KewApiConstants.ROUTE_HEADER_PROCESSED_LABEL);
97          newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_SAVED_CD, KewApiConstants.ROUTE_HEADER_SAVED_LABEL);
98          return newRouteStatusLabels;
99      }
100 
101     private static Map<Boolean, String> getActiveIndicatorLabels() {
102     	Map<Boolean, String> newActiveIndicatorLabels = new HashMap<Boolean, String>();
103         newActiveIndicatorLabels.put(Boolean.TRUE, KewApiConstants.ACTIVE_LABEL_LOWER);
104         newActiveIndicatorLabels.put(Boolean.FALSE, KewApiConstants.INACTIVE_LABEL_LOWER);
105         return newActiveIndicatorLabels;
106     }
107 
108     private static Map<String, String> getPolicyLabels() {
109     	Map<String, String> newDocTypeActiveIndicatorLabels = new HashMap<String, String>();
110         newDocTypeActiveIndicatorLabels.put(KewApiConstants.TRUE_CD, KewApiConstants.YES_LABEL);
111         newDocTypeActiveIndicatorLabels.put(KewApiConstants.FALSE_CD, KewApiConstants.NO_LABEL);
112         newDocTypeActiveIndicatorLabels.put(KewApiConstants.INHERITED_CD, KewApiConstants.INHERITED_LABEL);
113         return newDocTypeActiveIndicatorLabels;
114     }
115 
116     private static Map<String, String> getActivationPolicyLabels() {
117     	Map<String, String> newActivationPolicyLabels = new HashMap<String, String>();
118         newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_PARALLEL, KewApiConstants.ROUTE_LEVEL_PARALLEL_LABEL);
119         newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_SEQUENCE, KewApiConstants.ROUTE_LEVEL_SEQUENCE_LABEL);
120         newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL, KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL_LABEL);
121         return newActivationPolicyLabels;
122     }
123 
124     private static Map<String, String> getApprovePolicyLabels() {
125         Map<String, String> approvePolicyLabels = new HashMap<String, String>();
126         approvePolicyLabels.put(ActionRequestPolicy.ALL.getCode(), ActionRequestPolicy.ALL.getLabel());
127         approvePolicyLabels.put(ActionRequestPolicy.FIRST.getCode(), ActionRequestPolicy.FIRST.getLabel());
128         return approvePolicyLabels;
129     }
130 
131     /**
132      * Given an actionRequest code return the appropriate label.
133      *
134      * @param actionRequestCode
135      *            The actionRequestCode to be translated.
136      * @return action request label
137      */
138     static public String getActionRequestLabel(String actionRequestCode) {
139         return (String) arLabels.get(actionRequestCode);
140     }
141 
142     /**
143      * Given an action taken code return the appropriate label for it.
144      *
145      * @param actionTakenCode
146      *            action taken code to use to find the label.
147      * @return action taken label
148      */
149     static public String getActionTakenLabel(String actionTakenCode) {
150         return (String) atLabels.get(actionTakenCode);
151     }
152 
153     /**
154      * Return the label for the given request status level.
155      *
156      * @param status
157      *            code of the request status
158      * @return label for the corresponding code.
159      */
160     static public String getActionRequestStatusLabel(String status) {
161         return (String) arStatusLabels.get(status);
162     }
163 
164     static public String getRouteStatusLabel(String status) {
165         return (String) routeStatusLabels.get(status);
166     }
167 
168     static public String getActiveIndicatorLabel(Boolean indicator) {
169         return (String) activeIndicatorLabels.get(indicator);
170     }
171 
172     static public String getActivationPolicyLabel(String code) {
173         return (String) activationPolicyLabels.get(code);
174     }
175 
176     static public String getPolicyLabel(String code) {
177         return (String) policyLabels.get(code);
178     }
179 
180 }