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