001: /*
002: * Copyright 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.labor.web.lookupable;
017:
018: import static org.kuali.module.labor.LaborConstants.BalanceInquiries.BALANCE_TYPE_AC_AND_A21;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.apache.commons.lang.StringUtils;
026: import org.kuali.core.bo.BusinessObject;
027: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
028: import org.kuali.core.lookup.CollectionIncomplete;
029: import org.kuali.core.util.BeanPropertyComparator;
030: import org.kuali.kfs.KFSConstants;
031: import org.kuali.kfs.KFSPropertyConstants;
032: import org.kuali.module.gl.web.inquirable.EntryInquirableImpl;
033: import org.kuali.module.gl.web.inquirable.InquirableFinancialDocument;
034: import org.kuali.module.labor.bo.LedgerEntry;
035: import org.kuali.module.labor.service.LaborInquiryOptionsService;
036: import org.springframework.transaction.annotation.Transactional;
037:
038: /**
039: * The class is the front-end for all Ledger Entry inquiry processing.
040: *
041: * @see org.kuali.module.labor.bo.LedgerEntry
042: */
043: @Transactional
044: public class LedgerEntryLookupableHelperServiceImpl extends
045: AbstractLookupableHelperServiceImpl {
046: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
047: .getLogger(LedgerEntryLookupableHelperServiceImpl.class);
048:
049: private LaborInquiryOptionsService laborInquiryOptionsService;
050:
051: /**
052: * @see org.kuali.core.lookup.Lookupable#getInquiryUrl(org.kuali.core.bo.BusinessObject, java.lang.String)
053: */
054: @Override
055: public String getInquiryUrl(BusinessObject businessObject,
056: String propertyName) {
057: if (KFSPropertyConstants.DOCUMENT_NUMBER.equals(propertyName)) {
058: if (businessObject instanceof LedgerEntry) {
059: LedgerEntry entry = (LedgerEntry) businessObject;
060: return new InquirableFinancialDocument()
061: .getInquirableDocumentUrl(entry);
062: }
063: }
064: return (new EntryInquirableImpl()).getInquiryUrl(
065: businessObject, propertyName);
066: }
067:
068: /**
069: * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#getSearchResults(java.util.Map)
070: */
071: @Override
072: public List<? extends BusinessObject> getSearchResults(
073: Map<String, String> fieldValues) {
074: setBackLocation((String) fieldValues
075: .get(KFSConstants.BACK_LOCATION));
076: setDocFormKey((String) fieldValues
077: .get(KFSConstants.DOC_FORM_KEY));
078:
079: // get the pending entry option. This method must be prior to the get search results
080: String pendingEntryOption = laborInquiryOptionsService
081: .getSelectedPendingEntryOption(fieldValues);
082:
083: // get the input balance type code
084: String balanceTypeCode = fieldValues
085: .get(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE);
086: boolean isA21Balance = StringUtils.isNotEmpty(balanceTypeCode)
087: && BALANCE_TYPE_AC_AND_A21.equals(balanceTypeCode
088: .trim());
089:
090: if (isA21Balance) {
091: fieldValues.put(
092: KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
093: KFSConstants.BALANCE_TYPE_ACTUAL);
094: }
095:
096: Collection<LedgerEntry> ledgerEntries = getLookupService()
097: .findCollectionBySearch(LedgerEntry.class, fieldValues);
098: laborInquiryOptionsService
099: .updateLedgerEntryByPendingLedgerEntry(ledgerEntries,
100: fieldValues, pendingEntryOption);
101:
102: // add the ledger entries into the search results if the searching balance type code is A21
103: if (isA21Balance) {
104: fieldValues.put(
105: KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
106: KFSConstants.BALANCE_TYPE_A21);
107: Collection<LedgerEntry> effortLedgerEntries = getLookupService()
108: .findCollectionBySearch(LedgerEntry.class,
109: fieldValues);
110: laborInquiryOptionsService
111: .updateLedgerEntryByPendingLedgerEntry(
112: effortLedgerEntries, fieldValues,
113: pendingEntryOption);
114:
115: ledgerEntries.addAll(effortLedgerEntries);
116: }
117:
118: // get the actual size of all qualified search results
119: Long actualSize = new Long(ledgerEntries.size());
120: return this .buildSearchResultList(ledgerEntries, actualSize);
121: }
122:
123: /**
124: * build the serach result list from the given collection and the number of all qualified search results
125: *
126: * @param searchResultsCollection the given search results, which may be a subset of the qualified search results
127: * @param actualSize the number of all qualified search results
128: * @return the serach result list with the given results and actual size
129: */
130: protected List buildSearchResultList(
131: Collection searchResultsCollection, Long actualSize) {
132: CollectionIncomplete results = new CollectionIncomplete(
133: searchResultsCollection, actualSize);
134:
135: // sort list if default sort column given
136: List searchResults = (List) results;
137: List defaultSortColumns = getDefaultSortColumns();
138: if (defaultSortColumns.size() > 0) {
139: Collections.sort(results, new BeanPropertyComparator(
140: defaultSortColumns, true));
141: }
142: return searchResults;
143: }
144:
145: /**
146: * Sets the laborInquiryOptionsService attribute value.
147: *
148: * @param laborInquiryOptionsService The laborInquiryOptionsService to set.
149: */
150: public void setLaborInquiryOptionsService(
151: LaborInquiryOptionsService laborInquiryOptionsService) {
152: this.laborInquiryOptionsService = laborInquiryOptionsService;
153: }
154: }
|