View Javadoc
1   /*
2    * Copyright 2008 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.fp.document.authorization;
17  
18  import java.util.Map;
19  import java.util.Set;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.businessobject.AccountingLine;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.sys.document.AccountingDocument;
27  import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase;
28  import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER;
29  import org.kuali.ole.sys.document.web.AccountingLineRenderingContext;
30  import org.kuali.ole.sys.document.web.AccountingLineViewAction;
31  import org.kuali.ole.sys.service.impl.OleParameterConstants;
32  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
33  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
34  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35  import org.kuali.rice.kim.api.identity.Person;
36  import org.kuali.rice.kns.service.DataDictionaryService;
37  
38  /**
39   * Authorizer which deals with financial processing document issues, specifically sales tax lines on documents
40   */
41  public class FinancialProcessingAccountingLineAuthorizer extends AccountingLineAuthorizerBase {
42      private final static String SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_DOCUMENT_TYPES";
43      private final static String SALES_TAX_LINE_ACCOUNT_OBJECT_CODES_PARAMETER_NAME = "SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES";
44  
45      /**
46       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getUnviewableBlocks(org.kuali.ole.sys.document.AccountingDocument, org.kuali.ole.sys.businessobject.AccountingLine, boolean, org.kuali.rice.kim.api.identity.Person)
47       */
48      @Override
49      public Set<String> getUnviewableBlocks(AccountingDocument accountingDocument, AccountingLine accountingLine, boolean newLine, Person currentUser) {
50          Set unviewableBlocks = super.getUnviewableBlocks(accountingDocument, accountingLine, newLine, currentUser);
51          if (salesTaxUnviewable(accountingDocument, accountingLine)) {
52              unviewableBlocks.add(OLEConstants.AccountingLineViewStandardBlockNames.SALES_TAX_BLOCK);
53          }
54          return unviewableBlocks;
55      }
56  
57      /**
58       * Determines if the given line on the given document should not show any sales tax block it has
59       * @param document the document the line lives on (or will live on)
60       * @param line the accounting line which perhaps should be hiding any sales tax information
61       * @return true if sales tax should not be seen for the line, false otherwise
62       */
63      protected boolean salesTaxUnviewable(AccountingDocument document, AccountingLine line) {
64          ParameterService parameterService = SpringContext.getBean(ParameterService.class);
65          String docTypeCode = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(document.getClass());
66          ParameterEvaluator docTypeEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(OleParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, FinancialProcessingAccountingLineAuthorizer.SALES_TAX_DOCUMENT_TYPES_PARAMETER_NAME, docTypeCode);
67          if (!docTypeEvaluator.evaluationSucceeds()) return true;
68          if (!StringUtils.isEmpty(line.getFinancialObjectCode()) && !StringUtils.isEmpty(line.getAccountNumber())) {
69              String compare = line.getAccountNumber() + ":" + line.getFinancialObjectCode();
70              ParameterEvaluator salesTaxApplicableAccountAndObjectEvaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(OleParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES, compare);
71              if (!salesTaxApplicableAccountAndObjectEvaluator.evaluationSucceeds()) return true;
72              return false;
73          }
74          return true;
75      }
76      
77      /**
78       * adds refresh method to the action map.
79       * @see org.kuali.ole.sys.document.authorization.AccountingLineAuthorizerBase#getActionMap(org.kuali.ole.sys.document.web.AccountingLineRenderingContext, java.lang.String, java.lang.Integer, java.lang.String)
80       */
81      @Override
82      protected Map<String, AccountingLineViewAction> getActionMap(AccountingLineRenderingContext accountingLineRenderingContext, String accountingLinePropertyName, Integer accountingLineIndex, String groupTitle) {
83      
84          Map<String, AccountingLineViewAction> actionMap = super.getActionMap(accountingLineRenderingContext, accountingLinePropertyName, accountingLineIndex, groupTitle);
85  
86          if (accountingLineIndex != null) {
87              AccountingLineViewAction refreshAction = this.getRefreshAction(accountingLineRenderingContext.getAccountingLine(), accountingLinePropertyName, accountingLineIndex, groupTitle);
88              actionMap.put(OLEConstants.RETURN_METHOD_TO_CALL, refreshAction);
89          }
90          
91          return actionMap;
92      }
93      
94      /**
95       * constructs a refresh action image and action
96       * 
97       * @param accountingLine
98       * @param accountingLinePropertyName
99       * @param accountingLineIndex
100      * @param groupTitle
101      * @return
102      */
103     protected AccountingLineViewAction getRefreshAction(AccountingLine accountingLine, String accountingLinePropertyName, Integer accountingLineIndex, String groupTitle) {
104         String actionMethod = this.getRefreshLineMethod(accountingLine, accountingLinePropertyName, accountingLineIndex);
105         String actionLabel = getActionLabel(OLEKeyConstants.AccountingLineViewRendering.ACCOUNTING_LINE_REFRESH_ACTION_LABEL, groupTitle, accountingLineIndex + 1);
106 
107         String actionImageName = getRiceImagePath() + "tinybutton-refresh.gif";
108 
109         return new AccountingLineViewAction(actionMethod, actionLabel, actionImageName);
110     }
111     
112     /**
113      * constructs a refresh line method
114      * 
115      * @param accountingLine
116      * @param accountingLineProperty
117      * @param accountingLineIndex
118      * @return
119      */
120     protected String getRefreshLineMethod(AccountingLine accountingLine, String accountingLineProperty, Integer accountingLineIndex) {
121         final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
122         return "refresh.line" + accountingLineIndex + ".anchoraccounting" + infix + "Anchor";
123     }
124 }
125