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.kuali.core.authorization.AuthorizationConstants;
024: import org.kuali.core.bo.user.UniversalUser;
025: import org.kuali.core.document.Document;
026: import org.kuali.core.document.authorization.DocumentActionFlags;
027: import org.kuali.core.document.authorization.TransactionalDocumentActionFlags;
028: import org.kuali.core.exceptions.DocumentTypeAuthorizationException;
029: import org.kuali.core.workflow.service.KualiWorkflowDocument;
030: import org.kuali.kfs.KFSConstants;
031: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
032: import org.kuali.workflow.KualiWorkflowUtils.RouteLevelNames;
033:
034: /**
035: * Document Authorizer for the Procurement Card document.
036: */
037: public class ProcurementCardDocumentAuthorizer extends
038: AccountingDocumentAuthorizerBase {
039:
040: /**
041: * Overrides to call super and then blanketly reset the actions not allowed on the procurment card document.
042: *
043: * @see org.kuali.core.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
044: * org.kuali.core.bo.user.KualiUser)
045: */
046: @Override
047: public DocumentActionFlags getDocumentActionFlags(
048: Document document, UniversalUser user) {
049: TransactionalDocumentActionFlags flags = new TransactionalDocumentActionFlags(
050: super .getDocumentActionFlags(document, user));
051:
052: flags.setCanErrorCorrect(false); // PCDO doesn't allow error correction
053:
054: flags.setCanCancel(false); // PCDO cannot be cancelled
055:
056: flags.setCanDisapprove(false); // PCDO cannot be disapproved
057:
058: flags.setCanCopy(false); // PCDO cannot be copied
059:
060: return flags;
061: }
062:
063: /**
064: * Override to set the editMode to fullEntry if the routing is at the first account review node (PCDO has 2), second account
065: * review functions as normal.
066: *
067: * @see org.kuali.core.authorization.DocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
068: * org.kuali.core.bo.user.KualiUser)
069: */
070: @Override
071: public Map getEditMode(Document document, UniversalUser user,
072: List sourceLines, List targetLines) {
073: KualiWorkflowDocument workflowDocument = document
074: .getDocumentHeader().getWorkflowDocument();
075: List activeNodes = getCurrentRouteLevels(workflowDocument);
076:
077: List lineList = new ArrayList();
078: lineList.addAll(sourceLines);
079: lineList.addAll(targetLines);
080:
081: Map editModeMap = new HashMap();
082: // FULL_ENTRY only if: a) person has an approval request, b) we are at the correct level, c) it's not a correction
083: // document, d) it is not an ADHOC request (important so that ADHOC don't get full entry).
084: if (workflowDocument.isApprovalRequested()
085: && activeNodes
086: .contains(RouteLevelNames.ACCOUNT_REVIEW_FULL_EDIT)
087: && (document.getDocumentHeader()
088: .getFinancialDocumentInErrorNumber() == null)
089: && !document.getDocumentHeader().getWorkflowDocument()
090: .isAdHocRequested()) {
091: editModeMap
092: .put(
093: AuthorizationConstants.TransactionalEditMode.FULL_ENTRY,
094: "TRUE");
095: } else {
096: editModeMap = super .getEditMode(document, user,
097: sourceLines, targetLines);
098: }
099:
100: return editModeMap;
101: }
102:
103: /**
104: * Override to only allow the SYSTEM user to initiate a PCDO document
105: *
106: * @see org.kuali.core.authorization.DocumentAuthorizer#canInitiate(java.lang.String, org.kuali.core.bo.user.KualiUser)
107: */
108: @Override
109: public void canInitiate(String documentTypeName, UniversalUser user) {
110: if (!KFSConstants.SYSTEM_USER.equalsIgnoreCase(user
111: .getPersonUserIdentifier())) {
112: throw new DocumentTypeAuthorizationException(user
113: .getPersonUserIdentifier(), "initiate",
114: documentTypeName);
115: }
116: }
117:
118: }
|