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.ec.businessobject.lookup; 017 018 import java.util.Collections; 019 import java.util.HashMap; 020 import java.util.List; 021 import java.util.Map; 022 023 import org.kuali.kfs.integration.ld.LaborLedgerBalance; 024 import org.kuali.kfs.integration.ld.LaborLedgerBalanceForEffortCertification; 025 import org.kuali.kfs.module.ec.EffortPropertyConstants; 026 import org.kuali.kfs.module.ec.businessobject.EffortCertificationReportDefinition; 027 import org.kuali.kfs.module.ec.service.EffortCertificationReportDefinitionService; 028 import org.kuali.kfs.sys.KFSConstants; 029 import org.kuali.kfs.sys.KFSPropertyConstants; 030 import org.kuali.kfs.sys.service.OptionsService; 031 import org.kuali.rice.kns.bo.BusinessObject; 032 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 033 import org.kuali.rice.kns.service.BusinessObjectService; 034 import org.kuali.rice.kns.service.KualiModuleService; 035 import org.kuali.rice.kns.util.BeanPropertyComparator; 036 import org.kuali.rice.kns.util.KNSConstants; 037 038 public class EffortLedgerBalanceLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { 039 040 private KualiModuleService kualiModuleService; 041 private BusinessObjectService businessObjectService; 042 private OptionsService optionsService; 043 private EffortCertificationReportDefinitionService effortCertificationReportDefinitionService; 044 045 /** 046 * @see org.kuali.rice.kns.lookup.LookupableHelperService#getSearchResults(java.util.Map) 047 */ 048 @Override 049 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { 050 Map<String, Object> searchFieldValues = this.getSearchFieldValues(fieldValues); 051 List<String> defaultSortColumns = this.getDefaultSortColumns(); 052 053 List<? extends BusinessObject> searchResults = (List<? extends BusinessObject>) getLookupService().findCollectionBySearch(getBusinessObjectClass(), searchFieldValues); 054 055 if (defaultSortColumns.size() > 0) { 056 Collections.sort(searchResults, new BeanPropertyComparator(defaultSortColumns, true)); 057 } 058 059 return searchResults; 060 } 061 062 /** 063 * build the real search field value map from the given field values 064 * 065 * @param fieldValues the given field values 066 * @return the real search field value map built from the given field values 067 */ 068 private Map<String, Object> getSearchFieldValues(Map<String, String> fieldValues) { 069 String reportYear = fieldValues.get(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR); 070 String reportNumber = fieldValues.get(EffortPropertyConstants.EFFORT_CERTIFICATION_REPORT_NUMBER); 071 072 Map<String, String> primaryKeys = new HashMap<String, String>(); 073 primaryKeys.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, reportYear); 074 primaryKeys.put(EffortPropertyConstants.EFFORT_CERTIFICATION_REPORT_NUMBER, reportNumber); 075 076 EffortCertificationReportDefinition reportDefiniton = effortCertificationReportDefinitionService.findReportDefinitionByPrimaryKey(primaryKeys); 077 078 Map<String, Object> searchFieldValues = new HashMap<String, Object>(); 079 searchFieldValues.putAll(fieldValues); 080 searchFieldValues.remove(EffortPropertyConstants.EFFORT_CERTIFICATION_REPORT_NUMBER); 081 082 String fiscalYears = KFSConstants.EMPTY_STRING; 083 String expenseObjectTypeCodes = KFSConstants.EMPTY_STRING; 084 for (Integer fiscalYear : reportDefiniton.getReportPeriods().keySet()) { 085 fiscalYears += fiscalYear + KNSConstants.OR_LOGICAL_OPERATOR; 086 expenseObjectTypeCodes += optionsService.getOptions(fiscalYear).getFinObjTypeExpenditureexpCd() + KNSConstants.OR_LOGICAL_OPERATOR; 087 } 088 searchFieldValues.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, fiscalYears); 089 searchFieldValues.put(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, expenseObjectTypeCodes); 090 091 String balanceTypeCodes = KFSConstants.BALANCE_TYPE_ACTUAL + KNSConstants.OR_LOGICAL_OPERATOR + KFSConstants.BALANCE_TYPE_A21; 092 searchFieldValues.put(KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, balanceTypeCodes); 093 094 return searchFieldValues; 095 } 096 097 /** 098 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getBusinessObjectClass() 099 */ 100 @Override 101 public Class<? extends LaborLedgerBalance> getBusinessObjectClass() { 102 return kualiModuleService.getResponsibleModuleService(LaborLedgerBalanceForEffortCertification.class).createNewObjectFromExternalizableClass(LaborLedgerBalanceForEffortCertification.class).getClass(); 103 } 104 105 /** 106 * Sets the businessObjectService attribute value. 107 * 108 * @param businessObjectService The businessObjectService to set. 109 */ 110 public void setBusinessObjectService(BusinessObjectService businessObjectService) { 111 this.businessObjectService = businessObjectService; 112 } 113 114 /** 115 * Sets the effortCertificationReportDefinitionService attribute value. 116 * 117 * @param effortCertificationReportDefinitionService The effortCertificationReportDefinitionService to set. 118 */ 119 public void setEffortCertificationReportDefinitionService(EffortCertificationReportDefinitionService effortCertificationReportDefinitionService) { 120 this.effortCertificationReportDefinitionService = effortCertificationReportDefinitionService; 121 } 122 123 /** 124 * Sets the optionsService attribute value. 125 * 126 * @param optionsService The optionsService to set. 127 */ 128 public void setOptionsService(OptionsService optionsService) { 129 this.optionsService = optionsService; 130 } 131 132 /** 133 * Sets the kualiModuleService attribute value. 134 * 135 * @param kualiModuleService The kualiModuleService to set. 136 */ 137 public void setKualiModuleService(KualiModuleService kualiModuleService) { 138 this.kualiModuleService = kualiModuleService; 139 } 140 141 }