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.inquiry; 017 018 import java.text.SimpleDateFormat; 019 import java.util.ArrayList; 020 import java.util.Calendar; 021 import java.util.Date; 022 import java.util.HashMap; 023 import java.util.List; 024 import java.util.Map; 025 import java.util.Properties; 026 027 import org.kuali.kfs.module.ld.LaborPropertyConstants; 028 import org.kuali.kfs.module.ld.businessobject.PositionData; 029 import org.kuali.kfs.sys.KFSConstants; 030 import org.kuali.kfs.sys.KFSPropertyConstants; 031 import org.kuali.rice.kns.bo.BusinessObject; 032 033 /** 034 * This class is used to generate the URL for the user-defined attributes for the Position Inquiry screen. It is entended the 035 * KualiInquirableImpl class, so it covers both the default implementation and customized implemetnation. 036 */ 037 public class PositionDataDetailsInquirableImpl extends AbstractLaborInquirableImpl { 038 039 /** 040 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#addMoreParameters(java.util.Properties, 041 * java.lang.String) 042 */ 043 @Override 044 protected void addMoreParameters(Properties parameter, String attributeName) { 045 parameter.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.START_METHOD); 046 } 047 048 /** 049 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#buildUserDefinedAttributeKeyList() 050 */ 051 protected List buildUserDefinedAttributeKeyList() { 052 List keys = new ArrayList(); 053 keys.add(KFSPropertyConstants.POSITION_NUMBER); 054 keys.add(LaborPropertyConstants.EFFECTIVE_DATE); 055 return keys; 056 } 057 058 /** 059 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getAttributeName(java.lang.String) 060 */ 061 protected String getAttributeName(String attributeName) { 062 return KFSPropertyConstants.POSITION_NUMBER; 063 } 064 065 /** 066 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getBaseUrl() 067 */ 068 protected String getBaseUrl() { 069 return KFSConstants.INQUIRY_ACTION; 070 } 071 072 /** 073 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getInquiryBusinessObjectClass(java.lang.String) 074 */ 075 protected Class getInquiryBusinessObjectClass(String attributeName) { 076 return PositionData.class; 077 } 078 079 /** 080 * Returns the position value with the greatest effective date 081 * 082 * @see org.kuali.rice.kns.inquiry.Inquirable#getBusinessObject(java.util.Map) 083 */ 084 @Override 085 public BusinessObject getBusinessObject(Map fieldValues) { 086 List<PositionData> positionList = new ArrayList<PositionData>(getLookupService().findCollectionBySearch(PositionData.class, fieldValues)); 087 SimpleDateFormat formatter = new SimpleDateFormat("MMddyyyy"); 088 089 Date today = Calendar.getInstance().getTime(); 090 Date maxEffectiveDate = null; 091 092 PositionData lookupValue = null; 093 for (PositionData position : positionList) { 094 Date effectiveDate = position.getEffectiveDate(); 095 if (effectiveDate.compareTo(today) <= 0 && (maxEffectiveDate == null || effectiveDate.compareTo(maxEffectiveDate) > 0)) { 096 maxEffectiveDate = effectiveDate; 097 lookupValue = position; 098 } 099 } 100 101 return lookupValue; 102 } 103 104 /** 105 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getKeyName(java.lang.String) 106 */ 107 protected String getKeyName(String keyName) { 108 return keyName; 109 } 110 111 /** 112 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getKeyValue(java.lang.String, java.lang.Object) 113 */ 114 protected Object getKeyValue(String keyName, Object keyValue) { 115 return keyValue; 116 } 117 118 /** 119 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getLookupableImplAttributeName() 120 */ 121 protected String getLookupableImplAttributeName() { 122 return null; 123 } 124 125 /** 126 * @see org.kuali.kfs.module.ld.businessobject.inquiry.AbstractLaborInquirableImpl#getUserDefinedAttributeMap() 127 */ 128 protected Map getUserDefinedAttributeMap() { 129 Map userDefinedAttributeMap = new HashMap(); 130 userDefinedAttributeMap.put(KFSPropertyConstants.POSITION_NUMBER, KFSPropertyConstants.POSITION_NUMBER); 131 132 return userDefinedAttributeMap; 133 } 134 }