001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.financial.document.authorization;
017:
018: import java.util.ArrayList;
019: import java.util.HashMap;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.apache.commons.collections.CollectionUtils;
024: import org.kuali.core.authorization.AuthorizationConstants;
025: import org.kuali.core.bo.user.UniversalUser;
026: import org.kuali.core.document.Document;
027: import org.kuali.core.document.authorization.DocumentActionFlags;
028: import org.kuali.core.document.authorization.TransactionalDocumentActionFlags;
029: import org.kuali.core.workflow.service.KualiWorkflowDocument;
030: import org.kuali.kfs.KFSConstants;
031: import org.kuali.kfs.KFSPropertyConstants;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
034: import org.kuali.kfs.service.ParameterService;
035: import org.kuali.module.financial.document.DisbursementVoucherDocument;
036: import org.kuali.module.financial.rules.DisbursementVoucherRuleConstants;
037: import org.kuali.workflow.KualiWorkflowUtils.RouteLevelNames;
038:
039: /**
040: * Document Authorizer for the Disbursement Voucher document.
041: */
042: public class DisbursementVoucherDocumentAuthorizer extends
043: AccountingDocumentAuthorizerBase {
044:
045: private static String taxGroupName;
046: private static String travelGroupName;
047: private static String wireTransferGroupName;
048: private static String frnGroupName;
049: private static String adminGroupName;
050:
051: /**
052: * Overrides to call super and then blanketly set the canBlanketApprove flag to false, since this is never allowed on a DV.
053: *
054: * @see org.kuali.core.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
055: * org.kuali.core.bo.user.KualiUser)
056: */
057: public DocumentActionFlags getDocumentActionFlags(
058: Document document, UniversalUser user) {
059: TransactionalDocumentActionFlags flags = new TransactionalDocumentActionFlags(
060: super .getDocumentActionFlags(document, user));
061:
062: flags.setCanBlanketApprove(false); // this is never allowed on a DV document
063:
064: flags.setCanErrorCorrect(false); // CR, DV, andd PCDO don't allow error correction
065:
066: return flags;
067: }
068:
069: /**
070: * @see org.kuali.core.authorization.DocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
071: * org.kuali.core.bo.user.KualiUser)
072: */
073: public Map getEditMode(Document document, UniversalUser user,
074: List sourceLines, List targetLines) {
075: KualiWorkflowDocument workflowDocument = document
076: .getDocumentHeader().getWorkflowDocument();
077:
078: Map editModeMap = super .getEditMode(document, user,
079: sourceLines, targetLines);
080: if (((workflowDocument.stateIsInitiated() || workflowDocument
081: .stateIsSaved()) && workflowDocument
082: .userIsInitiator(user))
083: || (workflowDocument.stateIsEnroute()
084: && workflowDocument.isApprovalRequested() && isSpecialRouting(
085: document, user))) {
086: setDVWorkgroupEditModes(editModeMap, document, user);
087: }
088:
089: return editModeMap;
090: }
091:
092: /**
093: * Sets additional edit modes based on the user's workgroups.
094: *
095: * @param editModeMap
096: * @param document
097: * @param user
098: */
099: private void setDVWorkgroupEditModes(Map editModeMap,
100: Document document, UniversalUser user) {
101: if (isUserInTaxGroup(user)) {
102: editModeMap
103: .put(
104: AuthorizationConstants.DisbursementVoucherEditMode.TAX_ENTRY,
105: "TRUE");
106: editModeMap
107: .put(
108: AuthorizationConstants.DisbursementVoucherEditMode.EXPENSE_SPECIAL_ENTRY,
109: "TRUE");
110: }
111: if (isUserInFRNGroup(user)) {
112: editModeMap
113: .put(
114: AuthorizationConstants.DisbursementVoucherEditMode.FRN_ENTRY,
115: "TRUE");
116: editModeMap
117: .put(
118: AuthorizationConstants.DisbursementVoucherEditMode.EXPENSE_SPECIAL_ENTRY,
119: "TRUE");
120: }
121: if (isUserInTravelGroup(user)) {
122: editModeMap
123: .put(
124: AuthorizationConstants.DisbursementVoucherEditMode.TRAVEL_ENTRY,
125: "TRUE");
126: editModeMap
127: .put(
128: AuthorizationConstants.DisbursementVoucherEditMode.EXPENSE_SPECIAL_ENTRY,
129: "TRUE");
130: }
131: if (isUserInWireGroup(user)) {
132: editModeMap
133: .put(
134: AuthorizationConstants.DisbursementVoucherEditMode.WIRE_ENTRY,
135: "TRUE");
136: editModeMap
137: .put(
138: AuthorizationConstants.DisbursementVoucherEditMode.EXPENSE_SPECIAL_ENTRY,
139: "TRUE");
140: }
141: if (isUserInDvAdminGroup(user)) {
142: editModeMap
143: .put(
144: AuthorizationConstants.DisbursementVoucherEditMode.ADMIN_ENTRY,
145: "TRUE");
146: editModeMap
147: .put(
148: AuthorizationConstants.DisbursementVoucherEditMode.EXPENSE_SPECIAL_ENTRY,
149: "TRUE");
150: }
151: }
152:
153: /**
154: * Checks if the current user is a member of the dv tax workgroup.
155: *
156: * @return true if user is in group
157: */
158: private boolean isUserInTaxGroup(UniversalUser user) {
159: if (taxGroupName == null) {
160: taxGroupName = SpringContext
161: .getBean(ParameterService.class)
162: .getParameterValue(
163: DisbursementVoucherDocument.class,
164: KFSConstants.FinancialApcParms.DV_TAX_WORKGROUP);
165: }
166: return user.isMember(taxGroupName);
167: }
168:
169: /**
170: * Checks if the current user is a member of the dv travel workgroup.
171: *
172: * @return true if user is in group
173: */
174: private boolean isUserInTravelGroup(UniversalUser user) {
175: if (travelGroupName == null) {
176: travelGroupName = SpringContext.getBean(
177: ParameterService.class).getParameterValue(
178: DisbursementVoucherDocument.class,
179: KFSConstants.FinancialApcParms.DV_TRAVEL_WORKGROUP);
180: }
181: return user.isMember(travelGroupName);
182: }
183:
184: /**
185: * Checks if the current user is a member of the dv frn workgroup.
186: *
187: * @return true if user is in group
188: */
189: private boolean isUserInFRNGroup(UniversalUser user) {
190: if (frnGroupName == null) {
191: frnGroupName = SpringContext
192: .getBean(ParameterService.class)
193: .getParameterValue(
194: DisbursementVoucherDocument.class,
195: KFSConstants.FinancialApcParms.DV_FOREIGNDRAFT_WORKGROUP);
196: }
197: return user.isMember(frnGroupName);
198: }
199:
200: /**
201: * Checks if the current user is a member of the dv wire workgroup.
202: *
203: * @return true if user is in group
204: */
205: private boolean isUserInWireGroup(UniversalUser user) {
206: if (wireTransferGroupName == null) {
207: wireTransferGroupName = SpringContext
208: .getBean(ParameterService.class)
209: .getParameterValue(
210: DisbursementVoucherDocument.class,
211: KFSConstants.FinancialApcParms.DV_WIRETRANSFER_WORKGROUP);
212: }
213: return user.isMember(wireTransferGroupName);
214: }
215:
216: /**
217: * This method checks to see whether the user is in the dv admin group or not.
218: *
219: * @return true if user is in group, false otherwise
220: */
221: private boolean isUserInDvAdminGroup(UniversalUser user) {
222: if (adminGroupName == null) {
223: adminGroupName = SpringContext.getBean(
224: ParameterService.class).getParameterValue(
225: DisbursementVoucherDocument.class,
226: KFSConstants.FinancialApcParms.DV_ADMIN_WORKGROUP);
227: }
228: return user.isMember(adminGroupName);
229: }
230:
231: /**
232: * @see org.kuali.core.authorization.DocumentAuthorizer#getAccountingLineEditableFields(org.kuali.core.document.Document,
233: * org.kuali.core.bo.user.KualiUser)
234: */
235: public Map getAccountingLineEditableFields(Document document,
236: UniversalUser user) {
237: Map editableFields = new HashMap();
238: KualiWorkflowDocument workflowDocument = document
239: .getDocumentHeader().getWorkflowDocument();
240:
241: // only check special expense edits if we are in special routing
242: if (!workflowDocument.stateIsEnroute()
243: || !workflowDocument.isApprovalRequested()
244: || !isSpecialRouting(document, user)) {
245: return editableFields;
246: }
247:
248: if (isUserInDvAdminGroup(user) || isUserInTravelGroup(user)) {
249: // retrieve allow object code edit indicator
250: boolean allowObjectEdits = SpringContext
251: .getBean(ParameterService.class)
252: .getIndicatorParameter(
253: DisbursementVoucherDocument.class,
254: DisbursementVoucherRuleConstants.ALLOW_OBJECT_CODE_EDITS);
255: if (allowObjectEdits) {
256: editableFields.put(
257: KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
258: "TRUE");
259: }
260: }
261:
262: if (isUserInTaxGroup(user) || isUserInFRNGroup(user)
263: || isUserInWireGroup(user) || isUserInTravelGroup(user)) {
264: editableFields.put(KFSPropertyConstants.AMOUNT, "TRUE");
265: }
266:
267: return editableFields;
268: }
269:
270: /**
271: * Determines if the current active routing nodes are one of the disbursement voucher special routing nodes.
272: *
273: * @param document
274: * @param user
275: * @return boolean
276: */
277: public boolean isSpecialRouting(Document document,
278: UniversalUser user) {
279: boolean isSpecialRouteNode = false;
280:
281: KualiWorkflowDocument workflowDocument = document
282: .getDocumentHeader().getWorkflowDocument();
283: List activeNodes = getCurrentRouteLevels(workflowDocument);
284:
285: List dvSpecialNodes = new ArrayList();
286: dvSpecialNodes.add(RouteLevelNames.ALIEN_INDICATOR);
287: dvSpecialNodes
288: .add(RouteLevelNames.ALIEN_INDICATOR_PAYMENT_REASON);
289: dvSpecialNodes.add(RouteLevelNames.CAMPUS_CODE);
290: dvSpecialNodes.add(RouteLevelNames.EMPLOYEE_INDICATOR);
291: dvSpecialNodes.add(RouteLevelNames.PAYMENT_METHOD);
292: dvSpecialNodes.add(RouteLevelNames.PAYMENT_REASON);
293: dvSpecialNodes.add(RouteLevelNames.PAYMENT_REASON_CAMPUS);
294: dvSpecialNodes.add(RouteLevelNames.TAX_CONTROL_CODE);
295:
296: if (CollectionUtils.containsAny(activeNodes, dvSpecialNodes)) {
297: isSpecialRouteNode = true;
298: }
299:
300: return isSpecialRouteNode;
301: }
302: }
|