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.time.graceperiod.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.time.HrEffectiveDateActiveLookupableHelper;
25  import org.kuali.hr.time.graceperiod.rule.GracePeriodRule;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.rice.kns.lookup.HtmlData;
29  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
30  import org.kuali.rice.krad.bo.BusinessObject;
31  import org.kuali.rice.krad.util.KRADConstants;
32  import org.kuali.rice.krad.util.UrlFactory;
33  
34  public class GracePeriodRuleLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
35  
36  	private static final long serialVersionUID = -1656060180428314707L;
37  
38  	@Override
39  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
40  		List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
41  		
42  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
43  		
44  		GracePeriodRule gracePeriodRule = (GracePeriodRule) businessObject;
45  		String tkGracePeriodRuleId = gracePeriodRule.getTkGracePeriodRuleId();
46  		
47  		boolean systemAdmin = TKContext.getUser().isSystemAdmin();
48  
49  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
50  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
51  				if (systemAdmin) {
52  					customActionUrls.add(defaultCustomActionUrl);
53  				}
54  			} else {
55  				customActionUrls.add(defaultCustomActionUrl);
56  			}
57  		}
58  		
59  		Properties params = new Properties();
60  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
61  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
62  		params.put("tkGracePeriodRuleId", tkGracePeriodRuleId);
63  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
64  		viewUrl.setDisplayText("view");
65  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
66  		customActionUrls.add(viewUrl);
67  		
68  		return customActionUrls;
69  	}
70  
71      @Override
72      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues){
73  
74          String hourFactor = fieldValues.get("hourFactor");
75          String active = fieldValues.get("active");
76  
77          return TkServiceLocator.getGracePeriodService().getGracePeriodRules(hourFactor,active);
78      }
79  }