001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.fp.businessobject.inquirable;
017
018 import java.util.HashMap;
019 import java.util.Map;
020 import java.util.Properties;
021
022 import org.apache.commons.lang.StringUtils;
023 import org.kuali.kfs.fp.businessobject.DisbursementPayee;
024 import org.kuali.kfs.fp.document.service.DisbursementVoucherPayeeService;
025 import org.kuali.kfs.sys.KFSConstants;
026 import org.kuali.kfs.sys.KFSPropertyConstants;
027 import org.kuali.kfs.sys.context.SpringContext;
028 import org.kuali.kfs.vnd.businessobject.VendorDetail;
029 import org.kuali.rice.kim.bo.Person;
030 import org.kuali.rice.kns.bo.BusinessObject;
031 import org.kuali.rice.kns.inquiry.KualiInquirableImpl;
032 import org.kuali.rice.kns.lookup.HtmlData;
033 import org.kuali.rice.kns.util.KNSConstants;
034 import org.kuali.rice.kns.util.UrlFactory;
035
036 public class DisbursementPayeeInquirableImpl extends KualiInquirableImpl {
037
038 /**
039 * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getInquiryUrl(org.kuali.rice.kns.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 && KFSPropertyConstants.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(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD);
065 params.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Person.class.getName());
066 params.put(KFSPropertyConstants.PRINCIPAL_ID, payee.getPrincipalId());
067
068 String url = UrlFactory.parameterizeUrl(KNSConstants.INQUIRY_ACTION, params);
069
070 Map<String, String> fieldList = new HashMap<String, String>();
071 fieldList.put(KFSPropertyConstants.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(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD);
084 params.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, VendorDetail.class.getName());
085 params.put(KFSPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
086 params.put(KFSPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
087
088 String url = UrlFactory.parameterizeUrl(KNSConstants.INQUIRY_ACTION, params);
089
090 Map<String, String> fieldList = new HashMap<String, String>();
091 fieldList.put(KFSPropertyConstants.VENDOR_HEADER_GENERATED_ID, vendorHeaderGeneratedIdentifier);
092 fieldList.put(KFSPropertyConstants.VENDOR_DETAIL_ASSIGNED_ID, vendorDetailAssignedIdentifier);
093
094 return this.getHyperLink(VendorDetail.class, fieldList, url);
095 }
096
097 }