001 /** 002 * Copyright 2004-2012 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.hr.time.calendar.service; 017 018 import java.sql.Time; 019 import java.text.ParseException; 020 import java.text.SimpleDateFormat; 021 import java.util.Iterator; 022 import java.util.List; 023 import java.util.Map; 024 import java.util.Properties; 025 026 import org.apache.commons.lang.StringUtils; 027 import org.kuali.hr.time.calendar.Calendar; 028 import org.kuali.rice.kns.lookup.HtmlData; 029 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 030 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 031 import org.kuali.rice.krad.bo.BusinessObject; 032 import org.kuali.rice.krad.util.KRADConstants; 033 import org.kuali.rice.krad.util.UrlFactory; 034 035 public class CalendarLookupableHelper extends KualiLookupableHelperServiceImpl { 036 037 private static final long serialVersionUID = 2324703412211619217L; 038 039 @Override 040 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 041 List<HtmlData> customActionUrls = super.getCustomActionUrls(businessObject, pkNames); 042 043 Calendar calendar = (Calendar) businessObject; 044 String hrCalendarId = calendar.getHrCalendarId(); 045 046 Properties params = new Properties(); 047 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName()); 048 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL); 049 params.put("hrCalendarId", hrCalendarId); 050 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view"); 051 viewUrl.setDisplayText("view"); 052 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK); 053 customActionUrls.add(viewUrl); 054 055 return customActionUrls; 056 } 057 058 @Override 059 public List<? extends BusinessObject> getSearchResults( 060 Map<String, String> fieldValues) { 061 String flsaTime = null; 062 if(fieldValues.containsKey("flsaBeginTime")){ 063 flsaTime = fieldValues.get("flsaBeginTime"); 064 fieldValues.remove("flsaBeginTime"); 065 } 066 List<? extends BusinessObject> objectList = super.getSearchResults(fieldValues); 067 if(!objectList.isEmpty() && flsaTime != null && StringUtils.isNotBlank(flsaTime)){ 068 SimpleDateFormat sdFormat = new SimpleDateFormat("hh:mm aa"); 069 Time flsaBeginTime = null; 070 try { 071 flsaBeginTime = new Time(sdFormat.parse(flsaTime).getTime()); 072 Iterator itr = objectList.iterator(); 073 while(itr.hasNext()){ 074 Calendar pc = (Calendar)itr.next(); 075 if(pc.getFlsaBeginTime()!= null && !pc.getFlsaBeginTime().equals(flsaBeginTime)){ 076 itr.remove(); 077 } 078 } 079 } catch (ParseException e) { 080 } 081 } 082 return objectList; 083 } 084 085 }