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.DisbursementVoucherDocument;
20 import org.kuali.ole.sys.OLEConstants;
21 import org.kuali.ole.sys.OLEKeyConstants;
22 import org.kuali.ole.sys.OLEPropertyConstants;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.ole.sys.document.AccountingDocument;
25 import org.kuali.ole.sys.document.validation.GenericValidation;
26 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
27 import org.kuali.rice.kim.api.identity.Person;
28 import org.kuali.rice.kim.api.identity.PersonService;
29 import org.kuali.rice.kns.service.DataDictionaryService;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.MessageMap;
32
33 public class DisbursementVoucherEmployeeInformationValidation extends GenericValidation {
34 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherEmployeeInformationValidation.class);
35
36 private AccountingDocument accountingDocumentForValidation;
37
38 public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
39
40
41
42
43 public boolean validate(AttributedDocumentEvent event) {
44 LOG.debug("validate start");
45 boolean isValid = true;
46
47 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
48 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
49
50 if(!payeeDetail.isEmployee() || payeeDetail.isVendor()) {
51 return true;
52 }
53
54 String employeeId = payeeDetail.getDisbVchrPayeeIdNumber();
55 Person employee = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(employeeId);
56
57 MessageMap errors = GlobalVariables.getMessageMap();
58 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
59
60
61 if (employee == null) {
62 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
63 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_EXISTENCE, label);
64 isValid = false;
65 }
66 else if(!OLEConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode())) {
67
68 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
69 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_INACTIVE, label);
70 isValid = false;
71 }
72
73 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
74
75 return isValid;
76 }
77
78
79
80
81
82 public AccountingDocument getAccountingDocumentForValidation() {
83 return accountingDocumentForValidation;
84 }
85
86
87
88
89
90
91 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
92 this.accountingDocumentForValidation = accountingDocumentForValidation;
93 }
94 }
95