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