1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.pdp.businessobject.lookup;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.lang.StringUtils;
24 import org.kuali.ole.fp.businessobject.DisbursementPayee;
25 import org.kuali.ole.fp.businessobject.lookup.AbstractPayeeLookupableHelperServiceImpl;
26 import org.kuali.ole.pdp.PdpConstants;
27 import org.kuali.ole.pdp.PdpKeyConstants;
28 import org.kuali.ole.pdp.businessobject.ACHPayee;
29 import org.kuali.ole.sys.OLEKeyConstants;
30 import org.kuali.ole.sys.OLEPropertyConstants;
31 import org.kuali.ole.vnd.businessobject.VendorDetail;
32 import org.kuali.rice.kim.api.identity.Person;
33 import org.kuali.rice.kim.impl.KIMPropertyConstants;
34 import org.kuali.rice.krad.bo.BusinessObject;
35 import org.kuali.rice.krad.exception.ValidationException;
36 import org.kuali.rice.krad.lookup.CollectionIncomplete;
37 import org.kuali.rice.krad.util.BeanPropertyComparator;
38 import org.kuali.rice.krad.util.GlobalVariables;
39
40
41
42
43
44 public class ACHPayeeLookupableHelperServiceImpl extends AbstractPayeeLookupableHelperServiceImpl {
45
46
47
48
49
50
51
52
53
54 @Override
55 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
56 List<DisbursementPayee> searchResults = new ArrayList<DisbursementPayee>();
57
58 String payeeTypeCode = fieldValues.get(OLEPropertyConstants.PAYEE_TYPE_CODE);
59 if (StringUtils.isBlank(payeeTypeCode)) {
60 GlobalVariables.getMessageMap().putInfo(OLEPropertyConstants.PAYEE_TYPE_CODE, PdpKeyConstants.MESSAGE_PDP_ACH_PAYEE_LOOKUP_NO_PAYEE_TYPE);
61 }
62
63 if (StringUtils.isNotBlank(fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER)) || StringUtils.isNotBlank(fieldValues.get(OLEPropertyConstants.VENDOR_NAME)) || (StringUtils.isNotBlank(payeeTypeCode) && PdpConstants.PayeeIdTypeCodes.VENDOR_ID.equals(payeeTypeCode))) {
64 searchResults.addAll(this.getVendorsAsPayees(fieldValues));
65 }
66 else if (StringUtils.isNotBlank(fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID)) || StringUtils.isNotBlank(fieldValues.get(KIMPropertyConstants.Person.ENTITY_ID)) || (StringUtils.isNotBlank(payeeTypeCode) && (PdpConstants.PayeeIdTypeCodes.EMPLOYEE.equals(payeeTypeCode) || PdpConstants.PayeeIdTypeCodes.ENTITY.equals(payeeTypeCode)))) {
67 searchResults.addAll(this.getPersonAsPayees(fieldValues));
68 }
69 else {
70 searchResults.addAll(this.getVendorsAsPayees(fieldValues));
71 searchResults.addAll(this.getPersonAsPayees(fieldValues));
72 }
73
74 CollectionIncomplete results = new CollectionIncomplete(searchResults, Long.valueOf(searchResults.size()));
75
76
77 List<String> defaultSortColumns = getDefaultSortColumns();
78 if (defaultSortColumns.size() > 0) {
79 Collections.sort(results, new BeanPropertyComparator(getDefaultSortColumns(), true));
80 }
81
82 return results;
83 }
84
85
86
87
88
89
90
91
92 @Override
93 protected DisbursementPayee getPayeeFromPerson(Person personDetail, Map<String, String> fieldValues) {
94 DisbursementPayee payee = super.getPayeeFromPerson(personDetail, fieldValues);
95
96 String payeeTypeCode = fieldValues.get(OLEPropertyConstants.PAYEE_TYPE_CODE);
97
98 ACHPayee achPayee = new ACHPayee();
99
100 if (PdpConstants.PayeeIdTypeCodes.ENTITY.equals(payeeTypeCode)) {
101 achPayee.setPayeeIdNumber(personDetail.getEntityId());
102 achPayee.setPayeeTypeCode(PdpConstants.PayeeIdTypeCodes.ENTITY);
103 }
104 else {
105 achPayee.setPayeeIdNumber(personDetail.getEmployeeId());
106 achPayee.setPayeeTypeCode(PdpConstants.PayeeIdTypeCodes.EMPLOYEE);
107 }
108
109 achPayee.setPayeeName(payee.getPayeeName());
110 achPayee.setPrincipalId(payee.getPrincipalId());
111 achPayee.setTaxNumber(payee.getTaxNumber());
112 achPayee.setAddress(payee.getAddress());
113 achPayee.setActive(payee.isActive());
114
115 return achPayee;
116 }
117
118
119
120
121
122
123 @Override
124 protected DisbursementPayee getPayeeFromVendor(VendorDetail vendorDetail, Map<String, String> fieldValues) {
125 DisbursementPayee payee = super.getPayeeFromVendor(vendorDetail, fieldValues);
126
127 ACHPayee achPayee = new ACHPayee();
128
129 achPayee.setPayeeIdNumber(payee.getPayeeIdNumber());
130 achPayee.setPayeeTypeCode(PdpConstants.PayeeIdTypeCodes.VENDOR_ID);
131 achPayee.setPayeeName(payee.getPayeeName());
132 achPayee.setPrincipalId(payee.getPrincipalId());
133 achPayee.setTaxNumber(payee.getTaxNumber());
134 achPayee.setAddress(payee.getAddress());
135 achPayee.setActive(payee.isActive());
136
137 return achPayee;
138 }
139
140
141
142
143
144 @Override
145 public void validateSearchParameters(Map fieldValues) {
146 super.validateSearchParameters(fieldValues);
147
148 String vendorName = (String) fieldValues.get(OLEPropertyConstants.VENDOR_NAME);
149 String vendorNumber = (String) fieldValues.get(OLEPropertyConstants.VENDOR_NUMBER);
150 String employeeId = (String) fieldValues.get(KIMPropertyConstants.Person.EMPLOYEE_ID);
151 String entityId = (String) fieldValues.get(KIMPropertyConstants.Person.ENTITY_ID);
152 String payeeTypeCode = (String) fieldValues.get(OLEPropertyConstants.PAYEE_TYPE_CODE);
153
154
155 boolean isVendorInfoEntered = StringUtils.isNotBlank(vendorName) || StringUtils.isNotBlank(vendorNumber);
156 if (StringUtils.isNotBlank(entityId) && isVendorInfoEntered) {
157 String messageKey = OLEKeyConstants.ERROR_DV_VENDOR_EMPLOYEE_CONFUSION;
158
159 String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
160 String vendorNumberLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NUMBER);
161 String entityIdLabel = this.getAttributeLabel(KIMPropertyConstants.Person.ENTITY_ID);
162
163 GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.ENTITY_ID, messageKey, entityIdLabel, vendorNameLabel, vendorNumberLabel);
164 }
165
166 boolean isEmployeeInfoEntered = StringUtils.isNotBlank(employeeId) || StringUtils.isNotBlank(entityId);
167 boolean payeeTypeEntered = StringUtils.isNotBlank(payeeTypeCode);
168
169 if (payeeTypeEntered && PdpConstants.PayeeIdTypeCodes.VENDOR_ID.equals(payeeTypeCode) && isEmployeeInfoEntered) {
170 String messageKey = PdpKeyConstants.ERROR_PAYEE_LOOKUP_VENDOR_EMPLOYEE_CONFUSION;
171
172 String employeeIdLabel = this.getAttributeLabel(KIMPropertyConstants.Person.EMPLOYEE_ID);
173 String entityIdLabel = this.getAttributeLabel(KIMPropertyConstants.Person.ENTITY_ID);
174 String payeeTypeLabel = this.getAttributeLabel(OLEPropertyConstants.PAYEE_TYPE_CODE);
175
176 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_TYPE_CODE, messageKey, payeeTypeLabel, payeeTypeCode, employeeIdLabel, entityIdLabel);
177 }
178 else if (payeeTypeEntered && (PdpConstants.PayeeIdTypeCodes.EMPLOYEE.equals(payeeTypeCode) || PdpConstants.PayeeIdTypeCodes.ENTITY.equals(payeeTypeCode)) && isVendorInfoEntered) {
179 String messageKey = PdpKeyConstants.ERROR_PAYEE_LOOKUP_VENDOR_EMPLOYEE_CONFUSION;
180
181 String vendorNameLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NAME);
182 String vendorNumberLabel = this.getAttributeLabel(OLEPropertyConstants.VENDOR_NUMBER);
183 String payeeTypeLabel = this.getAttributeLabel(OLEPropertyConstants.PAYEE_TYPE_CODE);
184
185 GlobalVariables.getMessageMap().putError(OLEPropertyConstants.PAYEE_TYPE_CODE, messageKey, payeeTypeLabel, payeeTypeCode, vendorNameLabel, vendorNumberLabel);
186 }
187
188 if (GlobalVariables.getMessageMap().hasErrors()) {
189 throw new ValidationException("errors in search criteria");
190 }
191 }
192
193 }