View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.authorization;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.kuali.ole.coa.businessobject.Account;
23  import org.kuali.ole.coa.service.AccountService;
24  import org.kuali.ole.sys.businessobject.AccountingLine;
25  import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
26  import org.kuali.ole.sys.document.AccountingDocument;
27  import org.kuali.ole.sys.identity.OleKimAttributes;
28  import org.kuali.rice.kim.api.identity.Person;
29  import org.kuali.rice.krad.document.Document;
30  
31  /**
32   * DocumentAuthorizer containing common, reusable document-level authorization code for financial (i.e. Transactional) documents
33   */
34  public class AccountingDocumentAuthorizerBase extends FinancialSystemTransactionalDocumentAuthorizerBase {
35      private static final Log LOG = LogFactory.getLog(AccountingDocumentAuthorizerBase.class);
36  
37      /**
38       * Determines if the line is editable; if so, it adds the line to the editableAccounts map
39       * @param line the line to determine editability of
40       * @param currentUser the current session user to check permissions for
41       * @param accountService the accountService
42       * @return true if the line is editable, false otherwise 
43       */
44      protected boolean determineLineEditability(AccountingLine line, Person currentUser, AccountService accountService) {
45          Account acct = accountService.getByPrimaryId(line.getChartOfAccountsCode(), line.getAccountNumber());
46          if (acct == null) return true;
47          return accountService.hasResponsibilityOnAccount(currentUser, acct);
48      }
49      
50      @Override
51      protected void addRoleQualification(Object dataObject, Map<String,String> attributes) {
52          super.addRoleQualification(dataObject, attributes);
53          Document document = (Document)dataObject;
54          // add the document amount
55          if ( ((AccountingDocument)document).getSourceTotal() != null && ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount() != null ) {
56              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount().toString());
57          } else {
58              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, "0" );
59          }
60      }
61  }
62