1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.businessobject.inquirable;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Properties;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.fp.businessobject.DisbursementPayee;
24 import org.kuali.ole.fp.document.service.DisbursementVoucherPayeeService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.context.SpringContext;
28 import org.kuali.ole.vnd.businessobject.VendorDetail;
29 import org.kuali.rice.kim.api.identity.Person;
30 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
31 import org.kuali.rice.kns.lookup.HtmlData;
32 import org.kuali.rice.krad.bo.BusinessObject;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.krad.util.UrlFactory;
35
36 public class DisbursementPayeeInquirableImpl extends KualiInquirableImpl {
37
38
39
40
41
42 @Override
43 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
44 if (businessObject instanceof DisbursementPayee && OLEPropertyConstants.PAYEE_NAME.equals(attributeName)) {
45 DisbursementPayee payee = (DisbursementPayee) businessObject;
46
47 boolean isVendor = SpringContext.getBean(DisbursementVoucherPayeeService.class).isVendor(payee);
48 if (isVendor) {
49 return this.getVendorInquiryUrl(payee);
50 }
51
52 boolean isEmployee = SpringContext.getBean(DisbursementVoucherPayeeService.class).isEmployee(payee);
53 if (isEmployee) {
54 return this.getPersonInquiryUrl(payee);
55 }
56 }
57
58 return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
59 }
60
61
62 private HtmlData getPersonInquiryUrl(DisbursementPayee payee) {
63 Properties params = new Properties();
64 params.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD);
65 params.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Person.class.getName());
66 params.put(OLEPropertyConstants.PRINCIPAL_ID, payee.getPrincipalId());
67
68 String url = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params);
69
70 Map<String, String> fieldList = new HashMap<String, String>();
71 fieldList.put(OLEPropertyConstants.PRINCIPAL_ID, payee.getPrincipalId());
72
73 return this.getHyperLink(Person.class, fieldList, url);
74 }
75
76
77 private HtmlData getVendorInquiryUrl(DisbursementPayee payee) {
78 String payeeIdNumber = payee.getPayeeIdNumber();
79 String vendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, "-");
80 String vendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, "-");
81
82 Properties params = new Properties();
83 params.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD);
84 params.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName());
85 params.put(OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
86 params.put(OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
87
88 String url = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params);
89
90 Map<String, String> fieldList = new HashMap<String, String>();
91 fieldList.put(OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
92 fieldList.put(OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
93
94 return this.getHyperLink(VendorDetail.class, fieldList, url);
95 }
96
97 }