001    /**
002     * Copyright 2005-2014 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     */
016    package org.kuali.rice.kew.api.util;
017    
018    import java.util.HashMap;
019    import java.util.Map;
020    
021    import org.kuali.rice.kew.api.KewApiConstants;
022    import org.kuali.rice.kew.api.action.ActionRequestPolicy;
023    import org.kuali.rice.kew.api.action.ActionRequestStatus;
024    import org.kuali.rice.kew.api.action.ActionType;
025    
026    /**
027     * Utility class to translate the various codes into labels and vice versa.
028     *
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     */
031    public class CodeTranslator {
032        public static final Map<String, String> arLabels = getArLabels();
033        public static final Map<String, String> atLabels = getAtLabels();
034        public static final Map<String, String> arStatusLabels = getArStatusLabels();
035        public static final Map<String, String> routeStatusLabels = getRouteStatusLabels();
036        public static final Map<Boolean, String> activeIndicatorLabels = getActiveIndicatorLabels();
037        public static final Map<String, String> activationPolicyLabels = getActivationPolicyLabels();
038        public static final Map<String, String> policyLabels = getPolicyLabels();
039        public static final Map<String, String> approvePolicyLabels = getApprovePolicyLabels();
040    
041        private static Map<String, String> getAtLabels() {
042            Map<String, String> newAtLabels = new HashMap<String, String>();
043            newAtLabels.put(KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED_CD, KewApiConstants.ACTION_TAKEN_ACKNOWLEDGED);
044            newAtLabels.put(KewApiConstants.ACTION_TAKEN_ADHOC_CD, KewApiConstants.ACTION_TAKEN_ADHOC);
045            newAtLabels.put(KewApiConstants.ACTION_TAKEN_ADHOC_REVOKED_CD, KewApiConstants.ACTION_TAKEN_ADHOC_REVOKED);
046            newAtLabels.put(KewApiConstants.ACTION_TAKEN_APPROVED_CD, KewApiConstants.ACTION_TAKEN_APPROVED);
047            newAtLabels.put(KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE_CD, KewApiConstants.ACTION_TAKEN_BLANKET_APPROVE);
048            newAtLabels.put(KewApiConstants.ACTION_TAKEN_CANCELED_CD, KewApiConstants.ACTION_TAKEN_CANCELED);
049            newAtLabels.put(ActionType.RECALL.getCode(), ActionType.RECALL.getLabel());
050            newAtLabels.put(KewApiConstants.ACTION_TAKEN_COMPLETED_CD, KewApiConstants.ACTION_TAKEN_COMPLETED);
051            newAtLabels.put(KewApiConstants.ACTION_TAKEN_ROUTED_CD, KewApiConstants.ACTION_TAKEN_ROUTED);
052            newAtLabels.put(KewApiConstants.ACTION_TAKEN_DENIED_CD, KewApiConstants.ACTION_TAKEN_DENIED);
053            newAtLabels.put(KewApiConstants.ACTION_TAKEN_FYI_CD, KewApiConstants.ACTION_TAKEN_FYI);
054            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SAVED_CD, KewApiConstants.ACTION_TAKEN_SAVED);
055            newAtLabels.put(KewApiConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS_CD, KewApiConstants.ACTION_TAKEN_RETURNED_TO_PREVIOUS);
056            newAtLabels.put(KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION_CD, KewApiConstants.ACTION_TAKEN_LOG_DOCUMENT_ACTION);
057            newAtLabels.put(KewApiConstants.ACTION_TAKEN_MOVE_CD, KewApiConstants.ACTION_TAKEN_MOVE);
058            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_APPROVED);
059            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_CANCELED_CD, KewApiConstants.ACTION_TAKEN_SU_CANCELED);
060            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_DISAPPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_DISAPPROVED);
061            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_ROUTE_LEVEL_APPROVED);
062            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_APPROVED);
063            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS_CD, KewApiConstants.ACTION_TAKEN_SU_RETURNED_TO_PREVIOUS);
064            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_ACKNOWLEDGED);
065            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_FYI);
066            newAtLabels.put(KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED_CD, KewApiConstants.ACTION_TAKEN_SU_ACTION_REQUEST_COMPLETED);
067            newAtLabels.put(KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY_CD, KewApiConstants.ACTION_TAKEN_TAKE_WORKGROUP_AUTHORITY);
068            newAtLabels.put(KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY_CD, KewApiConstants.ACTION_TAKEN_RELEASE_WORKGROUP_AUTHORITY);
069            return newAtLabels;
070        }
071    
072        private static Map<String, String> getArLabels() {
073            Map<String, String> newArLabels = new HashMap<String, String>();
074            newArLabels.put(KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ_LABEL);
075            newArLabels.put(KewApiConstants.ACTION_REQUEST_APPROVE_REQ, KewApiConstants.ACTION_REQUEST_APPROVE_REQ_LABEL);
076            newArLabels.put(KewApiConstants.ACTION_REQUEST_COMPLETE_REQ, KewApiConstants.ACTION_REQUEST_COMPLETE_REQ_LABEL);
077            newArLabels.put(KewApiConstants.ACTION_REQUEST_FYI_REQ, KewApiConstants.ACTION_REQUEST_FYI_REQ_LABEL);
078            return newArLabels;
079        }
080    
081        private static Map<String, String> getArStatusLabels() {
082            Map<String, String> newArStatusLabels = new HashMap<String, String>();
083            newArStatusLabels.put(ActionRequestStatus.ACTIVATED.getCode(), KewApiConstants.ACTIVE_LABEL);
084            newArStatusLabels.put(ActionRequestStatus.INITIALIZED.getCode(), ActionRequestStatus.INITIALIZED.getLabel());
085            newArStatusLabels.put(ActionRequestStatus.DONE.getCode(), ActionRequestStatus.DONE.getLabel());
086            return newArStatusLabels;
087        }
088    
089        private static Map<String, String> getRouteStatusLabels() {
090            Map<String, String> newRouteStatusLabels = new HashMap<String, String>();
091            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_CANCEL_CD, KewApiConstants.ROUTE_HEADER_CANCEL_LABEL);
092            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_DISAPPROVED_CD, KewApiConstants.ROUTE_HEADER_DISAPPROVED_LABEL);
093            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_ENROUTE_CD, KewApiConstants.ROUTE_HEADER_ENROUTE_LABEL);
094            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_EXCEPTION_CD, KewApiConstants.ROUTE_HEADER_EXCEPTION_LABEL);
095            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_FINAL_CD, KewApiConstants.ROUTE_HEADER_FINAL_LABEL);
096            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_INITIATED_CD, KewApiConstants.ROUTE_HEADER_INITIATED_LABEL);
097            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_PROCESSED_CD, KewApiConstants.ROUTE_HEADER_PROCESSED_LABEL);
098            newRouteStatusLabels.put(KewApiConstants.ROUTE_HEADER_SAVED_CD, KewApiConstants.ROUTE_HEADER_SAVED_LABEL);
099            return newRouteStatusLabels;
100        }
101    
102        private static Map<Boolean, String> getActiveIndicatorLabels() {
103            Map<Boolean, String> newActiveIndicatorLabels = new HashMap<Boolean, String>();
104            newActiveIndicatorLabels.put(Boolean.TRUE, KewApiConstants.ACTIVE_LABEL_LOWER);
105            newActiveIndicatorLabels.put(Boolean.FALSE, KewApiConstants.INACTIVE_LABEL_LOWER);
106            return newActiveIndicatorLabels;
107        }
108    
109        private static Map<String, String> getPolicyLabels() {
110            Map<String, String> newDocTypeActiveIndicatorLabels = new HashMap<String, String>();
111            newDocTypeActiveIndicatorLabels.put(KewApiConstants.TRUE_CD, KewApiConstants.YES_LABEL);
112            newDocTypeActiveIndicatorLabels.put(KewApiConstants.FALSE_CD, KewApiConstants.NO_LABEL);
113            newDocTypeActiveIndicatorLabels.put(KewApiConstants.INHERITED_CD, KewApiConstants.INHERITED_LABEL);
114            return newDocTypeActiveIndicatorLabels;
115        }
116    
117        private static Map<String, String> getActivationPolicyLabels() {
118            Map<String, String> newActivationPolicyLabels = new HashMap<String, String>();
119            newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_PARALLEL, KewApiConstants.ROUTE_LEVEL_PARALLEL_LABEL);
120            newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_SEQUENCE, KewApiConstants.ROUTE_LEVEL_SEQUENCE_LABEL);
121            newActivationPolicyLabels.put(KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL, KewApiConstants.ROUTE_LEVEL_PRIORITY_PARALLEL_LABEL);
122            return newActivationPolicyLabels;
123        }
124    
125        private static Map<String, String> getApprovePolicyLabels() {
126            Map<String, String> approvePolicyLabels = new HashMap<String, String>();
127            approvePolicyLabels.put(ActionRequestPolicy.ALL.getCode(), ActionRequestPolicy.ALL.getLabel());
128            approvePolicyLabels.put(ActionRequestPolicy.FIRST.getCode(), ActionRequestPolicy.FIRST.getLabel());
129            return approvePolicyLabels;
130        }
131    
132        /**
133         * Given an actionRequest code return the appropriate label.
134         *
135         * @param actionRequestCode
136         *            The actionRequestCode to be translated.
137         * @return action request label
138         */
139        static public String getActionRequestLabel(String actionRequestCode) {
140            return (String) arLabels.get(actionRequestCode);
141        }
142    
143        /**
144         * Given an action taken code return the appropriate label for it.
145         *
146         * @param actionTakenCode
147         *            action taken code to use to find the label.
148         * @return action taken label
149         */
150        static public String getActionTakenLabel(String actionTakenCode) {
151            return (String) atLabels.get(actionTakenCode);
152        }
153    
154        /**
155         * Return the label for the given request status level.
156         *
157         * @param status
158         *            code of the request status
159         * @return label for the corresponding code.
160         */
161        static public String getActionRequestStatusLabel(String status) {
162            return (String) arStatusLabels.get(status);
163        }
164    
165        static public String getRouteStatusLabel(String status) {
166            return (String) routeStatusLabels.get(status);
167        }
168    
169        static public String getActiveIndicatorLabel(Boolean indicator) {
170            return (String) activeIndicatorLabels.get(indicator);
171        }
172    
173        static public String getActivationPolicyLabel(String code) {
174            return (String) activationPolicyLabels.get(code);
175        }
176    
177        static public String getPolicyLabel(String code) {
178            return (String) policyLabels.get(code);
179        }
180    
181    }