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.document.OLEAccountingDocument;
28  import org.kuali.ole.sys.identity.OleKimAttributes;
29  import org.kuali.rice.kim.api.identity.Person;
30  import org.kuali.rice.krad.document.Document;
31  
32  /**
33   * DocumentAuthorizer containing common, reusable document-level authorization code for financial (i.e. Transactional) documents
34   */
35  public class AccountingDocumentAuthorizerBase extends FinancialSystemTransactionalDocumentAuthorizerBase {
36      private static final Log LOG = LogFactory.getLog(AccountingDocumentAuthorizerBase.class);
37  
38      /**
39       * Determines if the line is editable; if so, it adds the line to the editableAccounts map
40       * @param line the line to determine editability of
41       * @param currentUser the current session user to check permissions for
42       * @param accountService the accountService
43       * @return true if the line is editable, false otherwise 
44       */
45      protected boolean determineLineEditability(AccountingLine line, Person currentUser, AccountService accountService) {
46          Account acct = accountService.getByPrimaryId(line.getChartOfAccountsCode(), line.getAccountNumber());
47          if (acct == null) return true;
48          return accountService.hasResponsibilityOnAccount(currentUser, acct);
49      }
50      
51      @Override
52      protected void addRoleQualification(Object dataObject, Map<String,String> attributes) {
53          super.addRoleQualification(dataObject, attributes);
54          Document document = (Document)dataObject;
55          // add the document amount
56  /*        if ( ((AccountingDocument)document).getSourceTotal() != null && ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount() != null ) {
57              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, ((FinancialSystemDocumentHeader)document.getDocumentHeader()).getFinancialDocumentTotalAmount().toString());
58          } else {
59              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, "0" );
60          }*/
61          if ( ((OLEAccountingDocument)document).getSourceTotal() != null && (((OLEAccountingDocument) document).getFinancialSystemDocumentHeader()).getFinancialDocumentTotalAmount() != null ) {
62              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, ((FinancialSystemDocumentHeader)document).getFinancialDocumentTotalAmount().toString());
63          } else {
64              attributes.put(OleKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, "0" );
65          }
66      }
67  }
68