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.OLEConstants;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.document.AccountingDocument;
27 import org.kuali.ole.sys.document.validation.GenericValidation;
28 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29 import org.kuali.ole.vnd.businessobject.VendorDetail;
30 import org.kuali.ole.vnd.document.service.VendorService;
31 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
32 import org.kuali.rice.kim.api.KimConstants.PersonExternalIdentifierTypes;
33 import org.kuali.rice.kim.api.identity.Person;
34 import org.kuali.rice.kim.api.identity.PersonService;
35 import org.kuali.rice.kim.api.identity.entity.Entity;
36 import org.kuali.rice.kim.api.services.IdentityManagementService;
37 import org.kuali.rice.kns.service.DataDictionaryService;
38 import org.kuali.rice.krad.util.GlobalVariables;
39 import org.kuali.rice.krad.util.MessageMap;
40
41 public class DisbursementVoucherVendorInformationValidation extends GenericValidation implements DisbursementVoucherConstants {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DisbursementVoucherPaymentReasonValidation.class);
43
44 private ParameterService parameterService;
45 private AccountingDocument accountingDocumentForValidation;
46
47 public static final String DV_PAYEE_ID_NUMBER_PROPERTY_PATH = OLEPropertyConstants.DV_PAYEE_DETAIL + "." + OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER;
48
49
50
51
52 @Override
53 public boolean validate(AttributedDocumentEvent event) {
54 LOG.debug("validate start");
55 boolean isValid = true;
56
57 DisbursementVoucherDocument document = (DisbursementVoucherDocument) accountingDocumentForValidation;
58 DisbursementVoucherPayeeDetail payeeDetail = document.getDvPayeeDetail();
59
60 if (!payeeDetail.isVendor()) {
61
62 String initiator = document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
63 final Entity entity= SpringContext.getBean(IdentityManagementService.class).getEntityByPrincipalId(initiator);
64 String originatorId = entity.getEmploymentInformation().get(0).getEmployeeId();
65 String employeeId = payeeDetail.getDisbVchrEmployeeIdNumber();
66
67 if (originatorId.equals(employeeId)) {
68 isValid = false;
69 MessageMap errors = GlobalVariables.getMessageMap();
70 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
71 String[] errorName = { "Payee ID " + employeeId ," Originator has the same ID ", "name" };
72 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_DV_VENDOR_NAME_PERSON_NAME_CONFUSION, errorName);
73 }
74 return isValid;
75 }
76
77 if (StringUtils.isBlank(payeeDetail.getDisbVchrPayeeIdNumber())) {
78 return false;
79 }
80
81 VendorDetail vendor = retrieveVendorDetail(payeeDetail.getDisbVchrVendorHeaderIdNumberAsInteger(), payeeDetail.getDisbVchrVendorDetailAssignedIdNumberAsInteger());
82
83 MessageMap errors = GlobalVariables.getMessageMap();
84 errors.addToErrorPath(OLEPropertyConstants.DOCUMENT);
85
86
87 if (vendor == null) {
88 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_EXISTENCE, SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER));
89 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
90 return false;
91 }
92
93
94 if (!vendor.isActiveIndicator()) {
95 errors.putError(DV_PAYEE_ID_NUMBER_PROPERTY_PATH, OLEKeyConstants.ERROR_INACTIVE, SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(DisbursementVoucherPayeeDetail.class, OLEPropertyConstants.DISB_VCHR_PAYEE_ID_NUMBER));
96 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
97 return false;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136 errors.removeFromErrorPath(OLEPropertyConstants.DOCUMENT);
137
138 return isValid;
139 }
140
141
142
143
144
145
146
147
148 protected VendorDetail retrieveVendorDetail(Integer vendorIdNumber, Integer vendorDetailIdNumber) {
149 return SpringContext.getBean(VendorService.class).getVendorDetail(vendorIdNumber, vendorDetailIdNumber);
150 }
151
152
153
154
155
156
157
158 protected Person retrieveEmployeeBySSN(String ssnNumber) {
159 Person person = SpringContext.getBean(PersonService.class).getPersonByExternalIdentifier(PersonExternalIdentifierTypes.TAX, ssnNumber).get(0);
160 if (person == null) {
161 LOG.error("User Not Found");
162 }
163 return person;
164 }
165
166
167
168
169
170
171
172 protected boolean isEmployeeSSN(String ssnNumber) {
173 return retrieveEmployeeBySSN(ssnNumber) != null;
174 }
175
176
177
178
179
180
181
182 protected boolean isActiveEmployeeSSN(String ssnNumber) {
183 Person employee = retrieveEmployeeBySSN(ssnNumber);
184 return employee != null && OLEConstants.EMPLOYEE_ACTIVE_STATUS.equals(employee.getEmployeeStatusCode());
185 }
186
187
188
189
190
191
192 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
193 this.accountingDocumentForValidation = accountingDocumentForValidation;
194 }
195
196
197
198
199
200 public void setParameterService(ParameterService parameterService) {
201 this.parameterService = parameterService;
202 }
203
204
205
206
207
208 public AccountingDocument getAccountingDocumentForValidation() {
209 return accountingDocumentForValidation;
210 }
211 }
212