001/* 002 * Copyright 2008 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.fp.businessobject.inquirable; 017 018import java.util.HashMap; 019import java.util.Map; 020import java.util.Properties; 021 022import org.apache.commons.lang.StringUtils; 023import org.kuali.ole.fp.businessobject.DisbursementPayee; 024import org.kuali.ole.fp.document.service.DisbursementVoucherPayeeService; 025import org.kuali.ole.sys.OLEConstants; 026import org.kuali.ole.sys.OLEPropertyConstants; 027import org.kuali.ole.sys.context.SpringContext; 028import org.kuali.ole.vnd.businessobject.VendorDetail; 029import org.kuali.rice.kim.api.identity.Person; 030import org.kuali.rice.kns.inquiry.KualiInquirableImpl; 031import org.kuali.rice.kns.lookup.HtmlData; 032import org.kuali.rice.krad.bo.BusinessObject; 033import org.kuali.rice.krad.util.KRADConstants; 034import org.kuali.rice.krad.util.UrlFactory; 035 036public class DisbursementPayeeInquirableImpl extends KualiInquirableImpl { 037 038 /** 039 * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String, 040 * boolean) 041 */ 042 @Override 043 public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { 044 if (businessObject instanceof DisbursementPayee && OLEPropertyConstants.PAYEE_NAME.equals(attributeName)) { 045 DisbursementPayee payee = (DisbursementPayee) businessObject; 046 047 boolean isVendor = SpringContext.getBean(DisbursementVoucherPayeeService.class).isVendor(payee); 048 if (isVendor) { 049 return this.getVendorInquiryUrl(payee); 050 } 051 052 boolean isEmployee = SpringContext.getBean(DisbursementVoucherPayeeService.class).isEmployee(payee); 053 if (isEmployee) { 054 return this.getPersonInquiryUrl(payee); 055 } 056 } 057 058 return super.getInquiryUrl(businessObject, attributeName, forceInquiry); 059 } 060 061 // get inquiry url to a person if the payee is a non-vendor employee 062 private HtmlData getPersonInquiryUrl(DisbursementPayee payee) { 063 Properties params = new Properties(); 064 params.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD); 065 params.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Person.class.getName()); 066 params.put(OLEPropertyConstants.PRINCIPAL_ID, payee.getPrincipalId()); 067 068 String url = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params); 069 070 Map<String, String> fieldList = new HashMap<String, String>(); 071 fieldList.put(OLEPropertyConstants.PRINCIPAL_ID, payee.getPrincipalId()); 072 073 return this.getHyperLink(Person.class, fieldList, url); 074 } 075 076 // get inquiry url to a vendor if the payee is a vendor 077 private HtmlData getVendorInquiryUrl(DisbursementPayee payee) { 078 String payeeIdNumber = payee.getPayeeIdNumber(); 079 String vendorHeaderGeneratedIdentifier = StringUtils.substringBefore(payeeIdNumber, "-"); 080 String vendorDetailAssignedIdentifier = StringUtils.substringAfter(payeeIdNumber, "-"); 081 082 Properties params = new Properties(); 083 params.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD); 084 params.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName()); 085 params.put(OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier); 086 params.put(OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier); 087 088 String url = UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params); 089 090 Map<String, String> fieldList = new HashMap<String, String>(); 091 fieldList.put(OLEPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier); 092 fieldList.put(OLEPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier); 093 094 return this.getHyperLink(VendorDetail.class, fieldList, url); 095 } 096 097}