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 org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
19 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
20 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.OLEPropertyConstants;
23 import org.kuali.ole.sys.businessobject.ChartOrgHolder;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.ole.sys.document.AccountingDocument;
26 import org.kuali.ole.sys.document.validation.GenericValidation;
27 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
28 import org.kuali.ole.sys.service.FinancialSystemUserService;
29 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
30 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
31 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32 import org.kuali.rice.kim.api.identity.Person;
33 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
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 public class DisbursementVoucherDocumentLocationValidation extends GenericValidation implements DisbursementVoucherConstants {
39 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherDocumentLocationValidation.class);
40
41 private ParameterService parameterService;
42 private AccountingDocument accountingDocumentForValidation;
43
44
45
46
47 @Override
48 public boolean validate(AttributedDocumentEvent event) {
49 LOG.debug("validate start");
50 boolean isValid = true;
51
52 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
53 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
54 String documentationLocationCode = document.getDisbursementVoucherDocumentationLocationCode();
55
56 MessageMap errors = GlobalVariables.getMessageMap();
57 int initialErrorCount = errors.getErrorCount();
58 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
59
60
61 if (ObjectUtils.isNotNull(payeeDetail.getDisbVchrPaymentReasonCode())) {
62 ParameterEvaluator parameterEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_DOC_LOC_BY_PAYMENT_REASON_PARM, DisbursementVoucherConstants.INVALID_DOC_LOC_BY_PAYMENT_REASON_PARM, payeeDetail.getDisbVchrPaymentReasonCode(), documentationLocationCode);
63 parameterEvaluator.evaluateAndAddError(document.getClass(), OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE);
64 }
65
66
67
68
69
70
71
72
73 Person initiator = getInitiator(document);
74 ChartOrgHolder chartOrg = SpringContext.getBean(FinancialSystemUserService.class).getPrimaryOrganization(initiator, OLEConstants.ParameterNamespaces.FINANCIAL);
75 String locationCode = (chartOrg == null || chartOrg.getOrganization() == null) ? null : chartOrg.getOrganization().getOrganizationPhysicalCampusCode();
76
77
78 ParameterEvaluator parameterEvaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(DisbursementVoucherDocument.class, DisbursementVoucherConstants.VALID_DOC_LOC_BY_CAMPUS_PARM, DisbursementVoucherConstants.INVALID_DOC_LOC_BY_CAMPUS_PARM, locationCode, documentationLocationCode);
79 parameterEvaluator.evaluateAndAddError(document.getClass(), OLEPropertyConstants.DISBURSEMENT_VOUCHER_DOCUMENTATION_LOCATION_CODE);
80
81 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
82
83 isValid = initialErrorCount == errors.getErrorCount();
84 return isValid;
85 }
86
87
88
89
90
91
92
93 protected Person getInitiator(AccountingDocument document) {
94 Person initUser = KimApiServiceLocator.getPersonService().getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
95 if (initUser == null) {
96 throw new RuntimeException("Document Initiator not found ");
97 }
98
99 return initUser;
100 }
101
102
103
104
105
106
107 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
108 this.accountingDocumentForValidation = accountingDocumentForValidation;
109 }
110
111
112
113
114
115 public void setParameterService(ParameterService parameterService) {
116 this.parameterService = parameterService;
117 }
118
119
120
121
122
123 public AccountingDocument getAccountingDocumentForValidation() {
124 return accountingDocumentForValidation;
125 }
126 }
127