View Javadoc

1   /**
2    * Copyright 2004-2012 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.earncodesec.service;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.hr.earncodesec.EarnCodeSecurity;
20  import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.hr.time.util.TKContext;
23  import org.kuali.hr.time.util.TKUtils;
24  import org.kuali.rice.kns.lookup.HtmlData;
25  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
26  import org.kuali.rice.krad.bo.BusinessObject;
27  import org.kuali.rice.krad.util.KRADConstants;
28  import org.kuali.rice.krad.util.UrlFactory;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  import java.util.Properties;
34  
35  public class EarnCodeSecurityLookupableHelper extends HrEffectiveDateActiveLookupableHelper {
36  
37  	private static final long serialVersionUID = 696878785547265569L;
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  		EarnCodeSecurity earnCodeSecurity = (EarnCodeSecurity) businessObject;
46  		String hrEarnCodeSecurityId = earnCodeSecurity.getHrEarnCodeSecurityId();
47  		String location = earnCodeSecurity.getLocation();
48  		String department = earnCodeSecurity.getDept();
49  		
50  		boolean systemAdmin = TKContext.getUser().isSystemAdmin();
51  		boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
52  		boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
53  		
54  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
55  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
56  				if (systemAdmin || locationAdmin || departmentAdmin) {
57  					customActionUrls.add(defaultCustomActionUrl);
58  				}
59  			} else {
60  				customActionUrls.add(defaultCustomActionUrl);
61  			}
62  		}
63  		
64  		Properties params = new Properties();
65  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
66  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
67  		params.put("hrEarnCodeSecurityId", hrEarnCodeSecurityId);
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(
78  			Map<String, String> fieldValues) {
79          String salGroup = fieldValues.get("hrSalGroup");
80          String dept = fieldValues.get("dept");
81          String earnCode = fieldValues.get("earnCode");
82          String location = fieldValues.get("location");
83          String fromEffdt = fieldValues.get("rangeLowerBoundKeyPrefix_effectiveDate");
84          String toEffdt = StringUtils.isNotBlank(fieldValues.get("effectiveDate")) ? fieldValues.get("effectiveDate").replace("<=", "") : "";
85          String active = fieldValues.get("active");
86          String showHist = fieldValues.get("history");
87          System.out.println("field value map is >>> "+fieldValues);
88          System.out.println("actual list is  "+TkServiceLocator.getEarnCodeSecurityService().searchEarnCodeSecurities(dept, salGroup, earnCode, location, 
89  				TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), active, showHist));
90  		return TkServiceLocator.getEarnCodeSecurityService().searchEarnCodeSecurities(dept, salGroup, earnCode, location, 
91  								TKUtils.formatDateString(fromEffdt), TKUtils.formatDateString(toEffdt), active, showHist);
92  	}
93  
94  }