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.vendor.lookup;
017:
018: import java.sql.Date;
019: import java.util.ArrayList;
020: import java.util.Collections;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.ojb.broker.query.Criteria;
025: import org.kuali.core.bo.PersistableBusinessObject;
026: import org.kuali.core.dao.LookupDao;
027: import org.kuali.core.lookup.AbstractLookupableHelperServiceImpl;
028: import org.kuali.core.service.DateTimeService;
029: import org.kuali.core.util.BeanPropertyComparator;
030: import org.kuali.kfs.KFSConstants;
031: import org.kuali.module.vendor.bo.VendorContract;
032: import org.springframework.transaction.annotation.Transactional;
033:
034: @Transactional
035: public class VendorContractLookupableHelperServiceImpl extends
036: AbstractLookupableHelperServiceImpl {
037: private LookupDao lookupDao;
038: private DateTimeService dateTimeService;
039:
040: public void setLookupDao(LookupDao lookupDao) {
041: this .lookupDao = lookupDao;
042: }
043:
044: public void setDateTimeService(DateTimeService dateTimeService) {
045: this .dateTimeService = dateTimeService;
046: }
047:
048: /**
049: * Overrides the getSearchResults in the super class so that we can do some customization in our vendor contract lookup.
050: *
051: * @see org.kuali.core.lookup.Lookupable#getSearchResults(java.util.Map)
052: */
053: @Override
054: public List<PersistableBusinessObject> getSearchResults(
055: Map<String, String> fieldValues) {
056:
057: boolean unbounded = false;
058: super .setBackLocation((String) fieldValues
059: .get(KFSConstants.BACK_LOCATION));
060: super .setDocFormKey((String) fieldValues
061: .get(KFSConstants.DOC_FORM_KEY));
062:
063: Date now = dateTimeService.getCurrentSqlDate();
064: Criteria additionalCriteria = new Criteria();
065: additionalCriteria.addLessOrEqualThan(
066: "vendorContractBeginningDate", now);
067: additionalCriteria.addGreaterOrEqualThan(
068: "vendorContractEndDate", now);
069:
070: // We ought to call the findCollectionBySearchHelper that would accept the additionalCriteria
071: boolean usePrimaryKeyValuesOnly = getLookupService()
072: .allPrimaryKeyValuesPresentAndNotWildcard(
073: getBusinessObjectClass(), fieldValues);
074: List<PersistableBusinessObject> searchResults = (List) lookupDao
075: .findCollectionBySearchHelper(getBusinessObjectClass(),
076: fieldValues, unbounded,
077: usePrimaryKeyValuesOnly, additionalCriteria);
078:
079: List<PersistableBusinessObject> finalSearchResults = new ArrayList();
080: // loop through results to eliminate inactive or debarred vendors
081: for (PersistableBusinessObject object : searchResults) {
082: VendorContract vendorContract = (VendorContract) object;
083: if (vendorContract.getVendorDetail().isActiveIndicator()
084: && !vendorContract.getVendorDetail()
085: .isVendorDebarred()) {
086: finalSearchResults.add(vendorContract);
087: }
088: }
089:
090: // sort list if default sort column given
091: List<String> defaultSortColumns = getDefaultSortColumns();
092: if (defaultSortColumns.size() > 0) {
093: Collections.sort(finalSearchResults,
094: new BeanPropertyComparator(getDefaultSortColumns(),
095: true));
096: }
097:
098: return finalSearchResults;
099: }
100:
101: }
|