View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.fp.document.authorization;
20  
21  import java.util.Map;
22  import java.util.Set;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.sys.KFSConstants;
26  import org.kuali.kfs.sys.KFSKeyConstants;
27  import org.kuali.kfs.sys.businessobject.AccountingLine;
28  import org.kuali.kfs.sys.context.SpringContext;
29  import org.kuali.kfs.sys.document.AccountingDocument;
30  import org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase;
31  import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER;
32  import org.kuali.kfs.sys.document.web.AccountingLineRenderingContext;
33  import org.kuali.kfs.sys.document.web.AccountingLineViewAction;
34  import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
35  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
36  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
37  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
38  import org.kuali.rice.kim.api.identity.Person;
39  import org.kuali.rice.kns.service.DataDictionaryService;
40  
41  /**
42   * Authorizer which deals with financial processing document issues, specifically sales tax lines on documents
43   */
44  public class FinancialProcessingAccountingLineAuthorizer extends AccountingLineAuthorizerBase {
45      private final static String SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_DOCUMENT_TYPES";
46      private final static String SALES_TAX_LINE_ACCOUNT_OBJECT_CODES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES";
47  
48      /**
49       * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getUnviewableBlocks(org.kuali.kfs.sys.document.AccountingDocument, org.kuali.kfs.sys.businessobject.AccountingLine, boolean, org.kuali.rice.kim.api.identity.Person)
50       */
51      @Override
52      public Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser) {
53          Set unviewableBlocks = super.getUnviewableBlocks(accountingDocument, accountingLine, newLine, currentUser);
54          if (salesTaxUnviewable(accountingDocument, accountingLine)) {
55              unviewableBlocks.add(KFSConstants.AccountingLineViewStandardBlockNames.SALES_TAX_BLOCK);
56          }
57          return unviewableBlocks;
58      }
59  
60      /**
61       * Determines if the given line on the given document should not show any sales tax block it has
62       * @param document the document the line lives on (or will live on)
63       * @param line the accounting line which perhaps should be hiding any sales tax information
64       * @return true if sales tax should not be seen for the line, false otherwise
65       */
66      protected boolean salesTaxUnviewable(AccountingDocument document, AccountingLine line) {
67          ParameterService parameterService = SpringContext.getBean(ParameterService.class);
68          String docTypeCode = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(document.getClass());
69          ParameterEvaluator docTypeEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, FinancialProcessingAccountingLineAuthorizer.SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME, docTypeCode);
70          if (!docTypeEvaluator.evaluationSucceeds()) return true;
71          if (!StringUtils.isEmpty(line.getFinancialObjectCode()) && !StringUtils.isEmpty(line.getAccountNumber())) {
72              String compare = line.getAccountNumber() + ":" + line.getFinancialObjectCode();
73              ParameterEvaluator salesTaxApplicableAccountAndObjectEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(KfsParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES, compare);
74              if (!salesTaxApplicableAccountAndObjectEvaluator.evaluationSucceeds()) return true;
75              return false;
76          }
77          return true;
78      }
79      
80      /**
81       * adds refresh method to the action map.
82       * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getActionMap(org.kuali.kfs.sys.document.web.AccountingLineRenderingContext, java.lang.String, java.lang.Integer, java.lang.String)
83       */
84      @Override
85      protected Map<String, AccountingLineViewAction> getActionMap(AccountingLineRenderingContext accountingLineRenderingContext, String accountingLinePropertyName, Integer accountingLineIndex, String groupTitle) {
86      
87          Map<String, AccountingLineViewAction> actionMap = super.getActionMap(accountingLineRenderingContext, accountingLinePropertyName, accountingLineIndex, groupTitle);
88  
89          if (accountingLineIndex != null) {
90              AccountingLineViewAction refreshAction = this.getRefreshAction(accountingLineRenderingContext.getAccountingLine(), accountingLinePropertyName, accountingLineIndex, groupTitle);
91              actionMap.put(KFSConstants.RETURN_METHOD_TO_CALL, refreshAction);
92          }
93          
94          return actionMap;
95      }
96      
97      /**
98       * constructs a refresh action image and action
99       * 
100      * @param accountingLine
101      * @param accountingLinePropertyName
102      * @param accountingLineIndex
103      * @param groupTitle
104      * @return
105      */
106     protected AccountingLineViewAction getRefreshAction(AccountingLine accountingLine, String accountingLinePropertyName, Integer accountingLineIndex, String groupTitle) {
107         String actionMethod = this.getRefreshLineMethod(accountingLine, accountingLinePropertyName, accountingLineIndex);
108         String actionLabel = getActionLabel(KFSKeyConstants.AccountingLineViewRendering.ACCOUNTING_LINE_REFRESH_ACTION_LABEL, groupTitle, accountingLineIndex + 1);
109 
110         String actionImageName = getRiceImagePath() + "tinybutton-refresh.gif";
111 
112         return new AccountingLineViewAction(actionMethod, actionLabel, actionImageName);
113     }
114     
115     /**
116      * constructs a refresh line method
117      * 
118      * @param accountingLine
119      * @param accountingLineProperty
120      * @param accountingLineIndex
121      * @return
122      */
123     protected String getRefreshLineMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
124         final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
125         return "refresh.line" + accountingLineIndex + ".anchoraccounting" + infix + "Anchor";
126     }
127 }
128