001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.module.ld.businessobject.lookup;
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.kfs.module.ld.businessobject.inquiry.BaseFundsInquirableImpl;
024 import org.kuali.kfs.module.ld.service.LaborBaseFundsService;
025 import org.kuali.kfs.module.ld.service.LaborInquiryOptionsService;
026 import org.kuali.kfs.sys.KFSConstants;
027 import org.kuali.rice.kns.bo.BusinessObject;
028 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
029 import org.kuali.rice.kns.lookup.CollectionIncomplete;
030 import org.kuali.rice.kns.lookup.HtmlData;
031 import org.kuali.rice.kns.util.BeanPropertyComparator;
032 import org.kuali.rice.kns.web.ui.Row;
033
034 /**
035 * The BaseFundsLookupableHelperServiceImpl class is the front-end for all Base Fund balance inquiry processing.
036 */
037 public class BaseFundsLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
038 private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(BaseFundsLookupableHelperServiceImpl.class);
039
040 private LaborBaseFundsService laborBaseFundsService;
041 private LaborInquiryOptionsService laborInquiryOptionsService;
042
043 /**
044 * @see org.kuali.rice.kns.lookup.Lookupable#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject, java.lang.String)
045 */
046 @Override
047 public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
048 return (new BaseFundsInquirableImpl()).getInquiryUrl(bo, propertyName);
049 }
050
051 /**
052 * @see org.kuali.rice.kns.lookup.Lookupable#getSearchResults(java.util.Map)
053 */
054 @Override
055 public List getSearchResults(Map fieldValues) {
056 setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
057 setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
058
059 // test if the consolidation option is selected or not
060 boolean isConsolidated = laborInquiryOptionsService.isConsolidationSelected(fieldValues, (Collection<Row>) getRows());
061
062 Collection searchResultsCollection = laborBaseFundsService.findAccountStatusBaseFundsWithCSFTracker(fieldValues, isConsolidated);
063
064 // get the actual size of all qualified search results
065 Long actualSize = new Long(searchResultsCollection.size());
066
067 return this.buildSearchResultList(searchResultsCollection, actualSize);
068 }
069
070 /**
071 * build the serach result list from the given collection and the number of all qualified search results
072 *
073 * @param searchResultsCollection the given search results, which may be a subset of the qualified search results
074 * @param actualSize the number of all qualified search results
075 * @return the serach result list with the given results and actual size
076 */
077 protected List buildSearchResultList(Collection searchResultsCollection, Long actualSize) {
078 CollectionIncomplete results = new CollectionIncomplete(searchResultsCollection, actualSize);
079
080 // sort list if default sort column given
081 List searchResults = (List) results;
082 List defaultSortColumns = getDefaultSortColumns();
083 if (defaultSortColumns.size() > 0) {
084 Collections.sort(results, new BeanPropertyComparator(defaultSortColumns, true));
085 }
086 return searchResults;
087 }
088
089 /**
090 * Sets the laborInquiryOptionsService attribute value.
091 *
092 * @param laborInquiryOptionsService The laborInquiryOptionsService to set.
093 */
094 public void setLaborInquiryOptionsService(LaborInquiryOptionsService laborInquiryOptionsService) {
095 this.laborInquiryOptionsService = laborInquiryOptionsService;
096 }
097
098 /**
099 * Sets the laborBaseFundsService attribute value.
100 *
101 * @param laborBaseFundsService The laborBaseFundsService to set.
102 */
103 public void setLaborBaseFundsService(LaborBaseFundsService laborBaseFundsService) {
104 this.laborBaseFundsService = laborBaseFundsService;
105 }
106 }