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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.fp.businessobject.DisbursementVoucherPayeeDetail;
20 import org.kuali.ole.fp.document.DisbursementVoucherConstants;
21 import org.kuali.ole.fp.document.DisbursementVoucherDocument;
22 import org.kuali.ole.sys.OLEKeyConstants;
23 import org.kuali.ole.sys.OLEPropertyConstants;
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.vnd.businessobject.VendorDetail;
29 import org.kuali.ole.vnd.document.service.VendorService;
30 import org.kuali.rice.kim.api.KimConstants;
31 import org.kuali.rice.kim.api.identity.Person;
32 import org.kuali.rice.kim.api.identity.PersonService;
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
37 public class DisbursementVoucherPayeeInitiatorValidation extends GenericValidation implements DisbursementVoucherConstants{
38 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPayeeInitiatorValidation.class);
39
40 private AccountingDocument accountingDocumentForValidation;
41
42 public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
43
44
45
46
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 MessageMap errors = GlobalVariables.getMessageMap();
55 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
56
57 String uuid = null;
58
59 if (payeeDetail.isVendor() && StringUtils.isNotBlank(payeeDetail.getDisbVchrVendorHeaderIdNumber())) {
60 VendorDetail dvVendor = retrieveVendorDetail(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger(), payeeDetail.getDisbVchrVendorDetailAssignedIdNumberAsInteger());
61
62 if (dvVendor != null && TAX_TYPE_SSN.equals(dvVendor.getVendorHeader().getVendorTaxTypeCode())) {
63
64 Person user = retrieveEmployeeBySSN(dvVendor.getVendorHeader().getVendorTaxNumber());
65 if (user != null) {
66 uuid = user.getPrincipalId();
67 }
68 }
69 }
70
71 else if(payeeDetail.isEmployee()) {
72 uuid = payeeDetail.getDisbVchrEmployeeIdNumber();
73 }
74
75
76 if (StringUtils.isNotBlank(uuid)) {
77 Person initUser = getInitiator(document);
78 if (uuid.equals(initUser.getPrincipalId())) {
79 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_PAYEE_INITIATOR);
80 isValid = false;
81 }
82 }
83
84 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
85
86 return isValid;
87 }
88
89
90
91
92
93
94
95
96 protected VendorDetail retrieveVendorDetail(Integer vendorIdNumber, Integer vendorDetailIdNumber) {
97 return SpringContext.getBean(VendorService.class).getVendorDetail(vendorIdNumber, vendorDetailIdNumber);
98 }
99
100
101
102
103
104
105
106 protected Person retrieveEmployeeBySSN(String ssnNumber) {
107 Person person = (Person) SpringContext.getBean(PersonService.class).getPersonByExternalIdentifier(KimConstants.PersonExternalIdentifierTypes.TAX, ssnNumber).get(0);
108 if (person == null) {
109 LOG.error("User Not Found");
110 }
111 return person;
112 }
113
114
115
116
117
118
119
120 protected Person getInitiator(AccountingDocument document) {
121 Person initUser = KimApiServiceLocator.getPersonService().getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId());
122 if (initUser == null) {
123 throw new RuntimeException("Document Initiator not found");
124 }
125
126 return initUser;
127 }
128
129
130
131
132
133 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
134 this.accountingDocumentForValidation = accountingDocumentForValidation;
135 }
136
137
138
139
140
141 public AccountingDocument getAccountingDocumentForValidation() {
142 return accountingDocumentForValidation;
143 }
144
145 }
146