1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.fp.document.validation.impl;
20
21 import org.kuali.kfs.fp.businessobject.DisbursementVoucherPayeeDetail;
22 import org.kuali.kfs.fp.document.DisbursementVoucherDocument;
23 import org.kuali.kfs.sys.KFSConstants;
24 import org.kuali.kfs.sys.KFSKeyConstants;
25 import org.kuali.kfs.sys.KFSPropertyConstants;
26 import org.kuali.kfs.sys.context.SpringContext;
27 import org.kuali.kfs.sys.document.AccountingDocument;
28 import org.kuali.kfs.sys.document.validation.GenericValidation;
29 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
30 import org.kuali.rice.kim.api.identity.Person;
31 import org.kuali.rice.kim.api.identity.PersonService;
32 import org.kuali.rice.kns.service.DataDictionaryService;
33 import org.kuali.rice.krad.util.GlobalVariables;
34 import org.kuali.rice.krad.util.MessageMap;
35
36 public class DisbursementVoucherEmployeeInformationValidation extends GenericValidation {
37 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherEmployeeInformationValidation.class);
38
39 protected AccountingDocument accountingDocumentForValidation;
40
41 public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = KFSPropertyConstants.DV_PAYEE_DETAIL + "." + KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
42
43
44
45
46 @Override
47 public boolean validate(AttributedDocumentEvent event) {
48 LOG.debug("validate start");
49 boolean isValid = true;
50
51 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
52 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
53
54 if(!payeeDetail.isEmployee() || payeeDetail.isVendor() || !(document.getDocumentHeader().getWorkflowDocument().isInitiated() || document.getDocumentHeader().getWorkflowDocument().isSaved())) {
55 return true;
56 }
57
58 String employeeId = payeeDetail.getDisbVchrPayeeIdNumber();
59 Person employee = SpringContext.getBean(PersonService.class).getPersonByEmployeeId(employeeId);
60
61 MessageMap errors = GlobalVariables.getMessageMap();
62 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
63
64
65 if (employee == null) {
66 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
67 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_EXISTENCE, label);
68 isValid = false;
69 }
70 else if(!KFSConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode())) {
71
72 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, KFSPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER);
73 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, KFSKeyConstants.ERROR_INACTIVE, label);
74 isValid = false;
75 }
76
77 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
78
79 return isValid;
80 }
81
82
83
84
85
86 public AccountingDocument getAccountingDocumentForValidation() {
87 return accountingDocumentForValidation;
88 }
89
90
91
92
93
94
95 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
96 this.accountingDocumentForValidation = accountingDocumentForValidation;
97 }
98 }
99