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