1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.hr.time.dept.lunch.service;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.hr.time.authorization.DepartmentalRule;
24  import org.kuali.hr.time.authorization.DepartmentalRuleAuthorizer;
25  import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase;
26  import org.kuali.hr.time.department.Department;
27  import org.kuali.hr.time.dept.lunch.DeptLunchRule;
28  import org.kuali.hr.time.service.base.TkServiceLocator;
29  import org.kuali.hr.time.util.TKContext;
30  import org.kuali.hr.time.util.TKUtils;
31  import org.kuali.rice.kns.lookup.HtmlData;
32  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
33  import org.kuali.rice.krad.bo.BusinessObject;
34  import org.kuali.rice.krad.util.KRADConstants;
35  import org.kuali.rice.krad.util.UrlFactory;
36  
37  public class DepartmentLunchRuleLookupableHelper extends TkAuthorizedLookupableHelperBase {
38  	
39  	private static final long serialVersionUID = -6171434403261481651L;
40  
41  	@Override
42      
43  
44  
45  
46      public boolean shouldShowBusinessObject(BusinessObject bo) {
47          return (bo instanceof DepartmentalRule) && DepartmentalRuleAuthorizer.hasAccessToRead((DepartmentalRule)bo);
48      }
49  
50  	@Override
51  	public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) {
52  		List<HtmlData> customActionUrls = new ArrayList<HtmlData>();
53  		
54  		List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames);
55  		
56  		DeptLunchRule deptLunchRule = (DeptLunchRule) businessObject;
57  		String tkDeptLunchRuleId = deptLunchRule.getTkDeptLunchRuleId();
58  		String department = deptLunchRule.getDept();
59  		String workArea = String.valueOf(deptLunchRule.getWorkArea());
60          Department dept = TkServiceLocator.getDepartmentService().getDepartment(deptLunchRule.getDept(), TKUtils.getCurrentDate());
61          String location = dept == null ? null : dept.getLocation();
62  		
63  		boolean systemAdmin = TKContext.getUser().isSystemAdmin();
64  		boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location);
65  		boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department);
66  		
67  		for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){
68  			if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) {
69  				if (systemAdmin || locationAdmin || departmentAdmin) {
70  					customActionUrls.add(defaultCustomActionUrl);
71  				}
72  			} else {
73  				customActionUrls.add(defaultCustomActionUrl);
74  			}
75  		}
76  		
77  		Properties params = new Properties();
78  		params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName());
79  		params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL);
80  		params.put("tkDeptLunchRuleId", tkDeptLunchRuleId);
81  		params.put("dept", department);
82  		params.put("workArea", workArea);
83  		AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view");
84  		viewUrl.setDisplayText("view");
85  		viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK);
86  		customActionUrls.add(viewUrl);
87  		
88  		return customActionUrls;
89  	}
90  
91  	@Override
92  	protected void validateSearchParameterWildcardAndOperators(
93  			String attributeName, String attributeValue) {
94  		if (!StringUtils.equals(attributeValue, "%")) {
95  			super.validateSearchParameterWildcardAndOperators(attributeName,
96  					attributeValue);
97  		}
98  	}
99  }