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.purap.document.authorization;
017:
018: import java.util.ArrayList;
019: import java.util.Iterator;
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.util.ObjectUtils;
028: import org.kuali.core.workflow.service.KualiWorkflowDocument;
029: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
030: import org.kuali.module.chart.bo.ChartUser;
031: import org.kuali.module.purap.PurapAuthorizationConstants;
032: import org.kuali.module.purap.PurapWorkflowConstants.RequisitionDocument.NodeDetailEnum;
033: import org.kuali.module.purap.bo.RequisitionItem;
034: import org.kuali.module.purap.document.RequisitionDocument;
035:
036: /**
037: * Document Authorizer for the Requisition document.
038: */
039: public class RequisitionDocumentAuthorizer extends
040: AccountingDocumentAuthorizerBase {
041:
042: /**
043: * @see org.kuali.core.document.authorization.DocumentAuthorizerBase#hasInitiateAuthorization(org.kuali.core.document.Document,
044: * org.kuali.core.bo.user.UniversalUser)
045: */
046: @Override
047: public boolean hasInitiateAuthorization(Document document,
048: UniversalUser user) {
049: // anyone with access to the system can complete a REQ document
050: return true;
051: }
052:
053: /**
054: * @see org.kuali.kfs.document.authorization.AccountingDocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
055: * org.kuali.core.bo.user.UniversalUser, java.util.List, java.util.List)
056: */
057: @Override
058: public Map getEditMode(Document document, UniversalUser user,
059: List sourceAccountingLines, List targetAccountingLines) {
060: Map editModeMap = super .getEditMode(document, user);
061: KualiWorkflowDocument workflowDocument = document
062: .getDocumentHeader().getWorkflowDocument();
063: RequisitionDocument reqDocument = (RequisitionDocument) document;
064:
065: if (workflowDocument.stateIsInitiated()
066: || workflowDocument.stateIsSaved()
067: || workflowDocument.stateIsEnroute()) {
068: if (ObjectUtils.isNotNull(reqDocument
069: .getVendorHeaderGeneratedIdentifier())) {
070: editModeMap
071: .put(
072: PurapAuthorizationConstants.RequisitionEditMode.LOCK_VENDOR_ENTRY,
073: "TRUE");
074: }
075: }
076:
077: if (workflowDocument.stateIsEnroute()) {
078: List<String> currentRouteLevels = getCurrentRouteLevels(workflowDocument);
079: String editMode = AuthorizationConstants.TransactionalEditMode.VIEW_ONLY;
080:
081: /**
082: * CONTENT ROUTE LEVEL - Approvers can edit full detail on Requisition except they cannot change the CHART/ORG.
083: */
084: if (reqDocument
085: .isDocumentStoppedInRouteNode(NodeDetailEnum.CONTENT_REVIEW)) {
086: // FULL_ENTRY will be set by super which is fine; also set content lock
087: editMode = PurapAuthorizationConstants.RequisitionEditMode.LOCK_CONTENT_ENTRY;
088: }
089:
090: /**
091: * FISCAL OFFICER ROUTE LEVEL - Approvers can edit only the accounting lines that they own and no other detail on REQ.
092: */
093: else if (reqDocument
094: .isDocumentStoppedInRouteNode(NodeDetailEnum.ACCOUNT_REVIEW)) {
095: List lineList = new ArrayList();
096: for (Iterator iter = reqDocument.getItems().iterator(); iter
097: .hasNext();) {
098: RequisitionItem item = (RequisitionItem) iter
099: .next();
100: lineList.addAll(item.getSourceAccountingLines());
101: // If FO has deleted the last accounting line for an item, set entry mode to full so they can add another one
102: if (item.getItemType()
103: .isItemTypeAboveTheLineIndicator()
104: && item.getSourceAccountingLines().size() == 0) {
105: editModeMap
106: .remove(AuthorizationConstants.EditMode.FULL_ENTRY);
107: editModeMap
108: .put(
109: PurapAuthorizationConstants.RequisitionEditMode.ALLOW_ITEM_ENTRY,
110: item.getItemIdentifier());
111: }
112: }
113:
114: if (userOwnsAnyAccountingLine((ChartUser) user
115: .getModuleUser(ChartUser.MODULE_ID), lineList)) {
116: // remove FULL_ENTRY because FO cannot edit rest of doc; only their own acct lines
117: editModeMap
118: .remove(AuthorizationConstants.EditMode.FULL_ENTRY);
119: editMode = AuthorizationConstants.TransactionalEditMode.EXPENSE_ENTRY;
120: }
121: }
122:
123: /**
124: * SEP of DUTIES ROUTE LEVEL - Approvers can only approve or disapprove.
125: */
126: else if (reqDocument
127: .isDocumentStoppedInRouteNode(NodeDetailEnum.SEPARATION_OF_DUTIES_REVIEW)) {
128: editModeMap
129: .remove(AuthorizationConstants.EditMode.FULL_ENTRY);
130: editMode = AuthorizationConstants.TransactionalEditMode.VIEW_ONLY;
131: }
132:
133: /**
134: * SUB-ACCOUNT ROUTE LEVEL - Approvers cannot edit any detail on REQ. BASE ORG REVIEW ROUTE LEVEL - Approvers cannot
135: * edit any detail on REQ. SEPARATION OF DUTIES ROUTE LEVEL - Approvers cannot edit any detail on REQ.
136: */
137: else {
138: // VIEW_ENTRY that is already being set is sufficient.
139: }
140:
141: editModeMap.put(editMode, "TRUE");
142: }
143:
144: return editModeMap;
145: }
146:
147: /**
148: * @see org.kuali.core.document.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
149: * org.kuali.core.bo.user.UniversalUser)
150: */
151: @Override
152: public DocumentActionFlags getDocumentActionFlags(
153: Document document, UniversalUser user) {
154: DocumentActionFlags flags = super .getDocumentActionFlags(
155: document, user);
156: KualiWorkflowDocument workflowDocument = document
157: .getDocumentHeader().getWorkflowDocument();
158:
159: RequisitionDocument requisitionDocument = (RequisitionDocument) document;
160: if (requisitionDocument
161: .isDocumentStoppedInRouteNode(NodeDetailEnum.CONTENT_REVIEW)) {
162: flags.setCanSave(true);
163: // NEED TO REDO ANNOTATE CHECK SINCE CHANGED THE VALUE OF FLAGS
164: this.setAnnotateFlag(flags);
165: }
166:
167: return flags;
168: }
169:
170: }
|