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 java.util.Iterator;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
23 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
24 import org.kuali.ole.fp.document.ProcurementCardDocument;
25 import org.kuali.ole.sys.OLEKeyConstants;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.businessobject.AccountingLine;
28 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.validation.GenericValidation;
31 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
32 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
33 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.MessageMap;
36 import org.kuali.rice.krad.util.ObjectUtils;
37
38
39
40
41 public class ProcurementCardObjectCodeValidation extends GenericValidation {
42 private AccountingLine accountingLineForValidation;
43
44
45
46
47
48
49 public boolean validate(AttributedDocumentEvent event) {
50 ProcurementCardDocument pcDocument = (ProcurementCardDocument) event.getDocument();
51 AccountingLine accountingLine = getAccountingLineForValidation();
52 if (!accountingLine.isTargetAccountingLine()) return true;
53
54 MessageMap errors = GlobalVariables.getMessageMap();
55 String errorKey = OLEPropertyConstants.FINANCIAL_OBJECT_CODE;
56 boolean objectCodeAllowed = true;
57
58
59 if (ObjectUtils.isNull(accountingLine.getObjectCode())) {
60 return false;
61 }
62
63
64 if (!accountingLine.getObjectCode().isFinancialObjectActiveCode()) {
65 errors.putError(errorKey, OLEKeyConstants.ERROR_INACTIVE, "object code");
66 objectCodeAllowed = false;
67 }
68
69
70 String mccRestriction = "";
71 ProcurementCardTargetAccountingLine line = (ProcurementCardTargetAccountingLine) accountingLine;
72 List pcTransactions = pcDocument.getTransactionEntries();
73 for (Iterator iter = pcTransactions.iterator(); iter.hasNext();) {
74 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iter.next();
75 if (transactionEntry.getFinancialDocumentTransactionLineNumber().equals(line.getFinancialDocumentTransactionLineNumber())) {
76 mccRestriction = transactionEntry.getProcurementCardVendor().getTransactionMerchantCategoryCode();
77 }
78 }
79
80 if (StringUtils.isBlank(mccRestriction)) {
81 return objectCodeAllowed;
82 }
83
84
85 if (objectCodeAllowed) {
86 ParameterEvaluator evaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(ProcurementCardDocument.class, ProcurementCardDocumentRuleConstants.VALID_OBJECTS_BY_MCC_CODE_PARM_NM, ProcurementCardDocumentRuleConstants.INVALID_OBJECTS_BY_MCC_CODE_PARM_NM, mccRestriction, accountingLine.getFinancialObjectCode());
87 objectCodeAllowed = evaluator.evaluateAndAddError(SourceAccountingLine.class, OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
88 }
89
90
91 if (objectCodeAllowed) {
92 ParameterEvaluator evaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(ProcurementCardDocument.class, ProcurementCardDocumentRuleConstants.VALID_OBJ_SUB_TYPE_BY_MCC_CODE_PARM_NM, ProcurementCardDocumentRuleConstants.INVALID_OBJ_SUB_TYPE_BY_MCC_CODE_PARM_NM, mccRestriction, accountingLine.getObjectCode().getFinancialObjectSubTypeCode());
93 objectCodeAllowed = evaluator.evaluateAndAddError(SourceAccountingLine.class, "objectCode.financialObjectSubTypeCode", OLEPropertyConstants.FINANCIAL_OBJECT_CODE);
94 }
95 return objectCodeAllowed;
96 }
97
98
99
100
101
102
103 public AccountingLine getAccountingLineForValidation() {
104 return accountingLineForValidation;
105 }
106
107
108
109
110
111 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) {
112 this.accountingLineForValidation = accountingLineForValidation;
113 }
114 }