View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.lm.timeoff.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.hr.lm.timeoff.SystemScheduledTimeOff;
25  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.hr.time.util.TKUtils;
29  import org.kuali.rice.kns.lookup.HtmlData;
30  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
31  import org.kuali.rice.krad.bo.BusinessObject;
32  import org.kuali.rice.krad.util.KRADConstants;
33  import org.kuali.rice.krad.util.UrlFactory;
34  
35  public class SystemScheduledTimeOffLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
36  
37  	private static final long serialVersionUID = -1285064132683716221L;
38  
39  	@Override
40  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
41  		List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
42  		
43  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
44  
45  		SystemScheduledTimeOff systemScheduledTimeOff = (SystemScheduledTimeOff) businessObject;
46  		String lmSystemScheduledTimeOffId = systemScheduledTimeOff.getLmSystemScheduledTimeOffId();
47  		String location = systemScheduledTimeOff.getLocation();
48  		
49  		boolean systemAdmin = TKContext.getUser().isSystemAdmin();
50  		boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
51  
52  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
53  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
54  				if (systemAdmin || locationAdmin) {
55  					customActionUrls.add(defaultCustomActionUrl);
56  				}
57  			} else {
58  				customActionUrls.add(defaultCustomActionUrl);
59  			}
60  		}
61  		
62  		Properties params = new Properties();
63  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
64  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
65  		params.put("lmSystemScheduledTimeOffId", lmSystemScheduledTimeOffId);
66  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
67  		viewUrl.setDisplayText("view");
68  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
69  		customActionUrls.add(viewUrl);
70  		
71  		return customActionUrls;
72  	}
73  
74      @Override
75      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
76          String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
77          String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
78          String earnCode = fieldValues.get("earnCode");
79          String fromAccruedDate = TKUtils.getFromDateString(fieldValues.get("accruedDate"));
80          String toAccruedDate = TKUtils.getToDateString(fieldValues.get("accruedDate"));
81          String fromSchTimeOffDate = TKUtils.getFromDateString(fieldValues.get("scheduledTimeOffDate"));
82          String toSchTimeOffDate = TKUtils.getToDateString(fieldValues.get("scheduledTimeOffDate"));
83          String active = fieldValues.get("active");
84          String showHist = fieldValues.get("history");
85  
86          return TkServiceLocator.getSysSchTimeOffService().getSystemScheduledTimeOffs(TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), 
87          		earnCode, TKUtils.formatDateString(fromAccruedDate), TKUtils.formatDateString(toAccruedDate), TKUtils.formatDateString(fromSchTimeOffDate), 
88          		TKUtils.formatDateString(toSchTimeOffDate), active, showHist);
89      }
90      
91  }