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 java.util.Collection;
019: import java.util.Collections;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.bo.BusinessObject;
024: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
025: import org.kuali.core.lookup.CollectionIncomplete;
026: import org.kuali.core.util.BeanPropertyComparator;
027: import org.kuali.kfs.KFSConstants;
028: import org.kuali.kfs.KFSPropertyConstants;
029: import org.kuali.module.gl.web.Constant;
030: import org.kuali.module.gl.web.inquirable.InquirableFinancialDocument;
031: import org.kuali.module.labor.bo.LaborLedgerPendingEntry;
032: import org.kuali.module.labor.service.LaborInquiryOptionsService;
033: import org.kuali.module.labor.service.LaborLedgerPendingEntryService;
034: import org.kuali.module.labor.web.inquirable.LedgerPendingEntryInquirableImpl;
035:
036: /**
037: * Helper Service for looking up instances of <code>{@link LaborLedgerPendingEntry}</code>
038: */
039: public class LaborPendingEntryLookupableHelperServiceImpl extends
040: AbstractLookupableHelperServiceImpl {
041: private static org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
042: .getLog(LaborPendingEntryLookupableHelperServiceImpl.class);
043:
044: private LaborLedgerPendingEntryService laborLedgerPendingEntryService;
045: private LaborInquiryOptionsService laborInquiryOptionsService;
046:
047: /**
048: * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#getInquiryUrl(org.kuali.core.bo.BusinessObject,
049: * java.lang.String)
050: */
051: @Override
052: public String getInquiryUrl(BusinessObject businessObject,
053: String propertyName) {
054: if (KFSPropertyConstants.DOCUMENT_NUMBER.equals(propertyName)
055: && businessObject instanceof LaborLedgerPendingEntry) {
056: LaborLedgerPendingEntry pendingEntry = (LaborLedgerPendingEntry) businessObject;
057: return new InquirableFinancialDocument()
058: .getInquirableDocumentUrl(pendingEntry);
059: }
060: return (new LedgerPendingEntryInquirableImpl()).getInquiryUrl(
061: businessObject, propertyName);
062: }
063:
064: /**
065: * @see org.kuali.core.lookup.AbstractLookupableHelperServiceImpl#getSearchResults(java.util.Map)
066: */
067: @Override
068: public List getSearchResults(Map fieldValues) {
069: setBackLocation((String) fieldValues
070: .get(KFSConstants.BACK_LOCATION));
071: setDocFormKey((String) fieldValues
072: .get(KFSConstants.DOC_FORM_KEY));
073:
074: // determine if only approved pending entries need to be returned
075: String pendingEntryOption = laborInquiryOptionsService
076: .getSelectedPendingEntryOption(fieldValues);
077: boolean isApprovedPendingSelected = Constant.APPROVED_PENDING_ENTRY
078: .equals(pendingEntryOption) ? true : false;
079:
080: Collection<LaborLedgerPendingEntry> searchResults = laborLedgerPendingEntryService
081: .findPendingEntries(fieldValues,
082: isApprovedPendingSelected);
083: Long resultSize = searchResults == null ? 0 : new Long(
084: searchResults.size());
085:
086: return this .buildSearchResultList(searchResults, resultSize);
087: }
088:
089: /**
090: * build the serach result list from the given collection and the number of all qualified search results
091: *
092: * @param searchResultsCollection the given search results, which may be a subset of the qualified search results
093: * @param actualSize the number of all qualified search results
094: * @return the serach result list with the given results and actual size
095: */
096: protected List buildSearchResultList(
097: Collection searchResultsCollection, Long actualSize) {
098: CollectionIncomplete results = new CollectionIncomplete(
099: searchResultsCollection, actualSize);
100:
101: // sort list if default sort column given
102: List searchResults = (List) results;
103: List defaultSortColumns = getDefaultSortColumns();
104: if (defaultSortColumns.size() > 0) {
105: Collections.sort(results, new BeanPropertyComparator(
106: defaultSortColumns, true));
107: }
108: return searchResults;
109: }
110:
111: /**
112: * Sets the laborLedgerPendingEntryService attribute value.
113: *
114: * @param laborLedgerPendingEntryService The laborLedgerPendingEntryService to set.
115: */
116: public void setLaborLedgerPendingEntryService(
117: LaborLedgerPendingEntryService laborLedgerPendingEntryService) {
118: this .laborLedgerPendingEntryService = laborLedgerPendingEntryService;
119: }
120:
121: /**
122: * Sets the laborInquiryOptionsService attribute value.
123: *
124: * @param laborInquiryOptionsService The laborInquiryOptionsService to set.
125: */
126: public void setLaborInquiryOptionsService(
127: LaborInquiryOptionsService laborInquiryOptionsService) {
128: this.laborInquiryOptionsService = laborInquiryOptionsService;
129: }
130: }
|