001/* 002 * Copyright 2007 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 */ 016package org.kuali.ole.sys.document.authorization; 017 018import java.util.Map; 019 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.kuali.ole.coa.businessobject.Account; 023import org.kuali.ole.coa.service.AccountService; 024import org.kuali.ole.sys.businessobject.AccountingLine; 025import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader; 026import org.kuali.ole.sys.document.AccountingDocument; 027import org.kuali.ole.sys.identity.OleKimAttributes; 028import org.kuali.rice.kim.api.identity.Person; 029import org.kuali.rice.krad.document.Document; 030 031/** 032 * DocumentAuthorizer containing common, reusable document-level authorization code for financial (i.e. Transactional) documents 033 */ 034public class AccountingDocumentAuthorizerBase extends FinancialSystemTransactionalDocumentAuthorizerBase { 035 private static final Log LOG = LogFactory.getLog(AccountingDocumentAuthorizerBase.class); 036 037 /** 038 * Determines if the line is editable; if so, it adds the line to the editableAccounts map 039 * @param line the line to determine editability of 040 * @param currentUser the current session user to check permissions for 041 * @param accountService the accountService 042 * @return true if the line is editable, false otherwise 043 */ 044 protected boolean determineLineEditability(AccountingLine line, Person currentUser, AccountService accountService) { 045 Account acct = accountService.getByPrimaryId(line.getChartOfAccountsCode(), line.getAccountNumber()); 046 if (acct == null) return true; 047 return accountService.hasResponsibilityOnAccount(currentUser, acct); 048 } 049 050 @Override 051 protected void addRoleQualification(Object dataObject, Map<String,String> attributes) { 052 super.addRoleQualification(dataObject, attributes); 053 Document document = (Document)dataObject; 054 // add the document amount 055 if ( ((AccountingDocument)document).getSourceTotal() != null && ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount() != null ) { 056 attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount().toString()); 057 } else { 058 attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, "0" ); 059 } 060 } 061} 062