1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34
35 public class CashReceiptAccountAndObjectCodeValidation extends GenericValidation {
36 private AccountingLine accountingLineForValidation;
37 private ParameterService parameterService;
38
39
40
41
42
43 public boolean validate(AttributedDocumentEvent event) {
44 boolean isValid = true;
45
46
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 = 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
75
76
77 public AccountingLine getAccountingLineForValidation() {
78 return accountingLineForValidation;
79 }
80
81
82
83
84
85 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
86 this.accountingLineForValidation = accountingLineForValidation;
87 }
88
89
90
91
92
93 public ParameterService getParameterService() {
94 return parameterService;
95 }
96
97
98
99
100
101 public void setParameterService(ParameterService parameterService) {
102 this.parameterService = parameterService;
103 }
104 }