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.HashMap;
019: import java.util.List;
020: import java.util.Map;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.kuali.core.bo.user.UniversalUser;
025: import org.kuali.core.document.Document;
026: import org.kuali.core.document.TransactionalDocument;
027: import org.kuali.core.document.authorization.DocumentActionFlags;
028: import org.kuali.core.document.authorization.TransactionalDocumentActionFlags;
029: import org.kuali.core.exceptions.DocumentTypeAuthorizationException;
030: import org.kuali.core.util.Timer;
031: import org.kuali.kfs.bo.AccountingLine;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
034: import org.kuali.module.chart.bo.ChartUser;
035: import org.kuali.module.financial.bo.CashDrawer;
036: import org.kuali.module.financial.document.CashReceiptDocument;
037: import org.kuali.module.financial.service.CashDrawerService;
038: import org.kuali.module.financial.service.CashReceiptService;
039:
040: /**
041: * Abstract base class for all TransactionalDocumentAuthorizers, since there's this one bit of common code.
042: */
043: public class CashReceiptDocumentAuthorizer extends
044: AccountingDocumentAuthorizerBase {
045: private static Log LOG = LogFactory
046: .getLog(CashReceiptDocumentAuthorizer.class);
047:
048: /**
049: * Overrides to use the parent's implementation, with the exception that if the cash drawer that is associated with this
050: * document is closed, the CR doc cannot be approved at all.
051: *
052: * @see org.kuali.core.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
053: * org.kuali.core.bo.user.KualiUser)
054: */
055: @Override
056: public DocumentActionFlags getDocumentActionFlags(
057: Document document, UniversalUser user) {
058: Timer t0 = new Timer("getDocumentActionFlags");
059: DocumentActionFlags flags = super .getDocumentActionFlags(
060: document, user);
061:
062: // if an approval is requested, check to make sure that the cash drawer is open
063: // if it's not, then they should not be able to verify the CR document
064: if (document.getDocumentHeader().getWorkflowDocument()
065: .isApprovalRequested()) {
066: CashReceiptDocument crd = (CashReceiptDocument) document;
067:
068: String unitName = SpringContext.getBean(
069: CashReceiptService.class)
070: .getCashReceiptVerificationUnitForCampusCode(
071: crd.getCampusLocationCode());
072: CashDrawer cd = SpringContext.getBean(
073: CashDrawerService.class).getByWorkgroupName(
074: unitName, false);
075: if (cd == null) {
076: throw new IllegalStateException(
077: "There is no cash drawer associated with cash receipt: "
078: + crd.getDocumentNumber());
079: } else if (cd.isClosed()) {
080: flags.setCanBlanketApprove(false);
081: flags.setCanApprove(false);
082: }
083: }
084:
085: TransactionalDocumentActionFlags tflags = (TransactionalDocumentActionFlags) flags;
086: tflags.setCanErrorCorrect(false); // CR, DV, andd PCDO don't allow error correction
087:
088: t0.log();
089: return flags;
090: }
091:
092: /**
093: * Overrides to always return false because there is never FO routing or FO approval for CR docs.
094: *
095: * @see org.kuali.module.financial.document.FinancialDocumentAuthorizer#userOwnsAnyAccountingLine(org.kuali.core.bo.user.KualiUser,
096: * java.util.List)
097: */
098: @Override
099: protected boolean userOwnsAnyAccountingLine(ChartUser user,
100: List accountingLines) {
101: return false;
102: }
103:
104: /**
105: * Overrides parent to return an empty Map since FO routing doesn't apply to the CR doc.
106: *
107: * @see org.kuali.core.authorization.TransactionalDocumentAuthorizer#getEditableAccounts(org.kuali.core.document.TransactionalDocument,
108: * org.kuali.core.bo.user.KualiUser)
109: */
110: @Override
111: public Map getEditableAccounts(TransactionalDocument document,
112: ChartUser user) {
113: return new HashMap();
114: }
115:
116: /**
117: * Overrides parent to return an empty Map since FO routing doesn't apply to the CR doc.
118: *
119: * @see org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase#getEditableAccounts(java.util.List,
120: * org.kuali.module.chart.bo.ChartUser)
121: */
122: @Override
123: public Map getEditableAccounts(List<AccountingLine> lines,
124: ChartUser user) {
125: return new HashMap();
126: }
127:
128: /**
129: * CR docs cannot be initiated by users in a verification unit that the CR is associated with. Right now, since there is a
130: * single verification unit, we only need this to check for exitence in that one.
131: *
132: * @see org.kuali.core.authorization.DocumentAuthorizer#canInitiate(java.lang.String, org.kuali.core.bo.user.KualiUser)
133: */
134: @Override
135: public void canInitiate(String documentTypeName, UniversalUser user) {
136: boolean authorized = false;
137: String unitName = SpringContext.getBean(
138: CashReceiptService.class)
139: .getCashReceiptVerificationUnitForUser(user);
140: if (unitName != null) {
141: authorized = !user.isMember(unitName);
142: }
143: if (!authorized) {
144: // TODO: customize message indicating the required unitName using DocumentInitiationAuthorizationException
145: throw new DocumentTypeAuthorizationException(user
146: .getPersonUserIdentifier(), "initiate",
147: documentTypeName);
148: }
149: }
150: }
|