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.validation.impl;
17  
18  import static org.kuali.ole.sys.OLEKeyConstants.ERROR_DOCUMENT_ACCOUNTING_LINE_INVALID_ACCT_OBJ_CD;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.sys.businessobject.AccountingLine;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.APPLICATION_PARAMETER;
26  import org.kuali.ole.sys.service.impl.OleParameterConstants;
27  import org.kuali.rice.core.api.parameter.ParameterEvaluator;
28  import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
29  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  
32  /**
33   * Validation that checks the sales tax account/object code combination on accounting lines of the cash receipt
34   */
35  public class CashReceiptAccountAndObjectCodeValidation extends GenericValidation {
36      private AccountingLine accountingLineForValidation;
37      private ParameterService parameterService;
38  
39      /**
40       * This method processes the accounting line to make sure if a sales tax account is used the right object code is used with it
41       * @see org.kuali.ole.sys.document.validation.Validation#validate(org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent)
42       */
43      public boolean validate(AttributedDocumentEvent event) {
44          boolean isValid = true;
45          // not evaluating, just want to retrieve the evaluator to get the values of the parameter
46          // get the object code and account
47          String objCd = getAccountingLineForValidation().getFinancialObjectCode();
48          String account = getAccountingLineForValidation().getAccountNumber();
49          if (!StringUtils.isEmpty(objCd) && !StringUtils.isEmpty(account)) {
50              String[] params = getParameterService().getParameterValuesAsString(OleParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES).toArray(new String[] {});
51              boolean acctsMatched = false;
52              for (int i = 0; i < params.length; i++) {
53                  String paramAcct = params[i].split(":")[0];
54                  if (account.equalsIgnoreCase(paramAcct)) {
55                      acctsMatched = true;
56                  }
57              }
58              if (acctsMatched) {
59                  String compare = account + ":" + objCd;
60                  ParameterEvaluator evaluator = /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(OleParameterConstants.FINANCIAL_PROCESSING_DOCUMENT.class, APPLICATION_PARAMETER.SALES_TAX_APPLICABLE_ACCOUNTS_AND_OBJECT_CODES, compare);
61                  if (!evaluator.evaluationSucceeds()) {
62                      isValid = false;
63                  }
64              }
65  
66          }
67          if (!isValid) {
68              GlobalVariables.getMessageMap().putError("accountNumber", ERROR_DOCUMENT_ACCOUNTING_LINE_INVALID_ACCT_OBJ_CD, account, objCd);
69          }
70          return isValid;
71      }
72  
73      /**
74       * Gets the accountingLineForValidation attribute. 
75       * @return Returns the accountingLineForValidation.
76       */
77      public AccountingLine getAccountingLineForValidation() {
78          return accountingLineForValidation;
79      }
80  
81      /**
82       * Sets the accountingLineForValidation attribute value.
83       * @param accountingLineForValidation The accountingLineForValidation to set.
84       */
85      public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
86          this.accountingLineForValidation = accountingLineForValidation;
87      }
88  
89      /**
90       * Gets the parameterService attribute. 
91       * @return Returns the parameterService.
92       */
93      public ParameterService getParameterService() {
94          return parameterService;
95      }
96  
97      /**
98       * Sets the parameterService attribute value.
99       * @param parameterService The parameterService to set.
100      */
101     public void setParameterService(ParameterService parameterService) {
102         this.parameterService = parameterService;
103     }
104 }