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.earncode.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.earncode.EarnCode;
26  import org.kuali.hr.time.service.base.TkServiceLocator;
27  import org.kuali.hr.time.util.TKContext;
28  import org.kuali.hr.time.util.TKUser;
29  import org.kuali.hr.time.util.TKUtils;
30  import org.kuali.rice.kns.lookup.HtmlData;
31  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
32  import org.kuali.rice.krad.bo.BusinessObject;
33  import org.kuali.rice.krad.util.KRADConstants;
34  import org.kuali.rice.krad.util.UrlFactory;
35  
36  public class EarnCodeLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
37  
38  	private static final long serialVersionUID = -4558119049003795647L;
39  
40  	@Override
41  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
42  		List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
43  		
44  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
45  		
46  		EarnCode earnCodeObj = (EarnCode) businessObject;
47  		String hrEarnCodeId = earnCodeObj.getHrEarnCodeId();
48  		String earnCode = earnCodeObj.getEarnCode();
49  		
50  		boolean systemAdmin = TKUser.isSystemAdmin();
51  		boolean locationAdmin = TKUser.isLocationAdmin();
52  
53  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
54  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
55  				if (systemAdmin || locationAdmin) {
56  					customActionUrls.add(defaultCustomActionUrl);
57  				}
58  			} else {
59  				customActionUrls.add(defaultCustomActionUrl);
60  			}
61  		}
62  		
63  		Properties params = new Properties();
64  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
65  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
66  		params.put("hrEarnCodeId", hrEarnCodeId);
67  		params.put("earnCode", earnCode);
68  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
69  		viewUrl.setDisplayText("view");
70  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
71  		customActionUrls.add(viewUrl);
72  		
73  		return customActionUrls;
74  	}
75  
76      @Override
77      public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
78          String earnCode = fieldValues.get("earnCode");
79          String ovtEarnCode = fieldValues.get("ovtEarnCode");
80          String descr = fieldValues.get("description");
81          String leavePlan = fieldValues.get("leavePlan");
82  		String accrualCategory = fieldValues.get("accrualCategory");
83          String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate"));
84          String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate"));
85          String active = fieldValues.get("active");
86          String showHist = fieldValues.get("history");
87  
88          return TkServiceLocator.getEarnCodeService().getEarnCodes(earnCode, ovtEarnCode, descr, leavePlan, accrualCategory, TKUtils.formatDateString(fromEffdt),
89                  TKUtils.formatDateString(toEffdt), active, showHist);
90      }
91  }