001/* 002 * Copyright 2006 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.gl.businessobject.lookup; 017 018import java.util.Iterator; 019import java.util.List; 020import java.util.Map; 021 022import org.kuali.ole.gl.Constant; 023import org.kuali.ole.gl.GeneralLedgerConstants; 024import org.kuali.ole.gl.businessobject.AccountBalance; 025import org.kuali.ole.gl.businessobject.TransientBalanceInquiryAttributes; 026import org.kuali.ole.gl.businessobject.inquiry.AccountBalanceByObjectInquirableImpl; 027import org.kuali.ole.gl.businessobject.inquiry.AccountBalanceInquirableImpl; 028import org.kuali.ole.gl.service.AccountBalanceService; 029import org.kuali.ole.sys.OLEConstants; 030import org.kuali.ole.sys.OLEPropertyConstants; 031import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl; 032import org.kuali.rice.kns.lookup.HtmlData; 033import org.kuali.rice.krad.bo.BusinessObject; 034import org.kuali.rice.krad.lookup.CollectionIncomplete; 035 036/** 037 * An extension of KualiLookupableImpl to support the account balance by object inquiry screen 038 */ 039public class AccountBalanceByObjectLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl { 040 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountBalanceByObjectLookupableHelperServiceImpl.class); 041 042 private AccountBalanceService accountBalanceService; 043 044 public void setAccountBalanceService(AccountBalanceService abs) { 045 accountBalanceService = abs; 046 } 047 048 /** 049 * Returns the inquiry url for a result field. 050 * 051 * @param bo the business object instance to build the urls for 052 * @param propertyName the property which links to an inquirable 053 * @return String url to inquiry 054 */ 055 @Override 056 public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) { 057 if (GeneralLedgerConstants.DummyBusinessObject.LINK_BUTTON_OPTION.equals(propertyName)) { 058 return (new AccountBalanceByObjectInquirableImpl()).getInquiryUrl(bo, propertyName); 059 } 060 return (new AccountBalanceInquirableImpl()).getInquiryUrl(bo, propertyName); 061 } 062 063 /** 064 * Uses Lookup Service to provide a basic search. 065 * 066 * @param fieldValues - Map containing prop name keys and search values 067 * @return List found business objects 068 */ 069 public List getSearchResults(Map fieldValues) { 070 LOG.debug("getSearchResults() started"); 071 072 setBackLocation((String) fieldValues.get(OLEConstants.BACK_LOCATION)); 073 setDocFormKey((String) fieldValues.get(OLEConstants.DOC_FORM_KEY)); 074 075 BusinessObjectFieldConverter.escapeSingleQuote(fieldValues); 076 077 String costShareOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.COST_SHARE_OPTION); 078 String pendingEntryOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.PENDING_ENTRY_OPTION); 079 String consolidationOption = (String) fieldValues.get(GeneralLedgerConstants.DummyBusinessObject.CONSOLIDATION_OPTION); 080 boolean isCostShareExcluded = Constant.COST_SHARE_EXCLUDE.equals(costShareOption); 081 int pendingEntryCode = AccountBalanceService.PENDING_NONE; 082 if (GeneralLedgerConstants.PendingEntryOptions.APPROVED.equals(pendingEntryOption)) { 083 pendingEntryCode = AccountBalanceService.PENDING_APPROVED; 084 } 085 else if (GeneralLedgerConstants.PendingEntryOptions.ALL.equals(pendingEntryOption)) { 086 pendingEntryCode = AccountBalanceService.PENDING_ALL; 087 } 088 boolean isConsolidated = Constant.CONSOLIDATION.equals(consolidationOption); 089 090 String chartOfAccountsCode = (String) fieldValues.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE); 091 String accountNumber = (String) fieldValues.get(OLEPropertyConstants.ACCOUNT_NUMBER); 092 String subAccountNumber = (String) fieldValues.get(OLEPropertyConstants.SUB_ACCOUNT_NUMBER); 093 String financialObjectLevelCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.OBJECT_LEVEL_CODE); 094 String financialReportingSortCode = (String) fieldValues.get(GeneralLedgerConstants.BalanceInquiryDrillDowns.REPORTING_SORT_CODE); 095 096 // Dashes means no sub account number 097 if (OLEConstants.getDashSubAccountNumber().equals(subAccountNumber)) { 098 subAccountNumber = ""; 099 } 100 101 String ufy = (String) fieldValues.get(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR); 102 103 // TODO Deal with invalid numbers 104 Integer universityFiscalYear = new Integer(Integer.parseInt(ufy)); 105 106 List results = accountBalanceService.findAccountBalanceByObject(universityFiscalYear, chartOfAccountsCode, accountNumber, subAccountNumber, financialObjectLevelCode, financialReportingSortCode, isCostShareExcluded, isConsolidated, pendingEntryCode); 107 108 // Put the search related stuff in the objects 109 for (Iterator iter = results.iterator(); iter.hasNext();) { 110 AccountBalance ab = (AccountBalance) iter.next(); 111 112 TransientBalanceInquiryAttributes dbo = ab.getDummyBusinessObject(); 113 dbo.setConsolidationOption(consolidationOption); 114 dbo.setCostShareOption(costShareOption); 115 dbo.setPendingEntryOption(pendingEntryOption); 116 dbo.setLinkButtonOption(Constant.LOOKUP_BUTTON_VALUE); 117 } 118 return new CollectionIncomplete(results, new Long(results.size())); 119 } 120}