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.HashMap;
021 import java.util.List;
022 import java.util.Map;
023
024 import org.kuali.kfs.module.ld.businessobject.July1PositionFunding;
025 import org.kuali.kfs.module.ld.businessobject.LedgerBalance;
026 import org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl;
027 import org.kuali.kfs.module.ld.businessobject.inquiry.July1PositionFundingInquirableImpl;
028 import org.kuali.kfs.module.ld.businessobject.inquiry.PositionDataDetailsInquirableImpl;
029 import org.kuali.kfs.module.ld.dataaccess.LaborDao;
030 import org.kuali.kfs.sys.KFSConstants;
031 import org.kuali.kfs.sys.KFSPropertyConstants;
032 import org.kuali.rice.kns.bo.BusinessObject;
033 import org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl;
034 import org.kuali.rice.kns.lookup.CollectionIncomplete;
035 import org.kuali.rice.kns.lookup.HtmlData;
036 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
037 import org.kuali.rice.kns.util.BeanPropertyComparator;
038
039 /**
040 * The July1PositionFundingLookupableHelperServiceImpl class is the front-end for all July 1 funds balance inquiry processing.
041 */
042 public class July1PositionFundingLookupableHelperServiceImpl extends AbstractLookupableHelperServiceImpl {
043 private static org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(July1PositionFundingLookupableHelperServiceImpl.class);
044
045 private LaborDao laborDao;
046
047 /**
048 * @see org.kuali.rice.kns.lookup.Lookupable#getInquiryUrl(org.kuali.rice.kns.bo.BusinessObject, java.lang.String)
049 */
050 @Override
051 public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
052 if (KFSPropertyConstants.POSITION_NUMBER.equals(propertyName)) {
053 LedgerBalance balance = (LedgerBalance) bo;
054 AbstractLaborInquirableImpl positionDataDetailsInquirable = new PositionDataDetailsInquirableImpl();
055
056 Map<String, String> fieldValues = new HashMap<String, String>();
057 fieldValues.put(propertyName, balance.getPositionNumber());
058
059 BusinessObject positionData = positionDataDetailsInquirable.getBusinessObject(fieldValues);
060
061 return positionData == null ? new AnchorHtmlData(KFSConstants.EMPTY_STRING, KFSConstants.EMPTY_STRING) : positionDataDetailsInquirable.getInquiryUrl(positionData, propertyName);
062 }
063 return (new July1PositionFundingInquirableImpl()).getInquiryUrl(bo, propertyName);
064 }
065
066 /**
067 * @see org.kuali.rice.kns.lookup.Lookupable#getSearchResults(java.util.Map)
068 */
069 @Override
070 public List getSearchResults(Map<String, String> fieldValues) {
071 setBackLocation((String) fieldValues.get(KFSConstants.BACK_LOCATION));
072 setDocFormKey((String) fieldValues.get(KFSConstants.DOC_FORM_KEY));
073
074 Collection<July1PositionFunding> searchResultsCollection = getLaborDao().getJuly1PositionFunding(fieldValues);
075
076 // sort list if default sort column given
077 List searchResults = (List) searchResultsCollection;
078 List defaultSortColumns = getDefaultSortColumns();
079 if (defaultSortColumns.size() > 0) {
080 Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true));
081 }
082
083 return new CollectionIncomplete(searchResults, new Long(0));
084 }
085
086 /**
087 * Gets the laborDao attribute.
088 * @return Returns the laborDao.
089 */
090 public LaborDao getLaborDao() {
091 return laborDao;
092 }
093
094 /**
095 * Sets the laborDao attribute value.
096 * @param laborDao The laborDao to set.
097 */
098 public void setLaborDao(LaborDao laborDao) {
099 this.laborDao = laborDao;
100 }
101 }