View Javadoc

1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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       * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String,
40       *      boolean)
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      // get inquiry url to a person if the payee is a non-vendor employee
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      // get inquiry url to a vendor if the payee is a vendor
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  }