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.module.ar.businessobject.inquiry;
017    
018    import java.util.Properties;
019    
020    import org.kuali.kfs.module.ar.ArConstants;
021    import org.kuali.kfs.module.ar.ArKeyConstants;
022    import org.kuali.kfs.module.ar.ArPropertyConstants;
023    import org.kuali.kfs.module.ar.businessobject.Customer;
024    import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceWriteoffLookupResult;
025    import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
026    import org.kuali.kfs.sys.KFSConstants;
027    import org.kuali.kfs.sys.businessobject.inquiry.KfsInquirableImpl;
028    import org.kuali.kfs.sys.context.SpringContext;
029    import org.kuali.rice.kns.bo.BusinessObject;
030    import org.kuali.rice.kns.lookup.HtmlData;
031    import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
032    import org.kuali.rice.kns.service.KualiConfigurationService;
033    import org.kuali.rice.kns.util.KNSConstants;
034    import org.kuali.rice.kns.util.ObjectUtils;
035    import org.kuali.rice.kns.util.UrlFactory;
036    
037    public class CustomerInvoiceWriteoffLookupResultInquirableImpl extends KfsInquirableImpl {
038    
039        /**
040         * Helper method to build an inquiry URLs for Customer Invoice Writeoff Lookup Results
041         * 
042         * @param businessObject the business object instance to build the urls for
043         * @param attributeName the attribute name which links to an inquirable
044         * @return String url to inquiry
045         */
046        public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName) {
047    
048            AnchorHtmlData inquiryHref = new AnchorHtmlData(KNSConstants.EMPTY_STRING, KNSConstants.EMPTY_STRING);
049            if (ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER.equals(attributeName)) {
050                String baseUrl = KFSConstants.INQUIRY_ACTION;
051                Properties parameters = new Properties();
052                parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD);
053                parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, Customer.class.getName());
054                parameters.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, ObjectUtils.getPropertyValue((CustomerInvoiceWriteoffLookupResult) businessObject, attributeName));
055    
056                inquiryHref.setHref(UrlFactory.parameterizeUrl(baseUrl, parameters));
057            } else if (ArPropertyConstants.CustomerInvoiceDocumentFields.DOCUMENT_NUMBER.equals(attributeName) ){
058                
059                String documentNumber = ObjectUtils.getPropertyValue((CustomerInvoiceDocument)businessObject, attributeName).toString();
060                inquiryHref.setHref(SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.WORKFLOW_URL_KEY) + "/DocHandler.do?docId=" + documentNumber + "&command=displayDocSearchView");
061            }
062            return inquiryHref;
063        }
064    }