001 /** 002 * Copyright 2004-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.dept.lunch.service; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 import java.util.Properties; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.hr.time.authorization.DepartmentalRule; 024 import org.kuali.hr.time.authorization.DepartmentalRuleAuthorizer; 025 import org.kuali.hr.time.authorization.TkAuthorizedLookupableHelperBase; 026 import org.kuali.hr.time.department.Department; 027 import org.kuali.hr.time.dept.lunch.DeptLunchRule; 028 import org.kuali.hr.time.service.base.TkServiceLocator; 029 import org.kuali.hr.time.util.TKContext; 030 import org.kuali.hr.time.util.TKUtils; 031 import org.kuali.rice.kns.lookup.HtmlData; 032 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 033 import org.kuali.rice.krad.bo.BusinessObject; 034 import org.kuali.rice.krad.util.KRADConstants; 035 import org.kuali.rice.krad.util.UrlFactory; 036 037 public class DepartmentLunchRuleLookupableHelper extends TkAuthorizedLookupableHelperBase { 038 039 private static final long serialVersionUID = -6171434403261481651L; 040 041 @Override 042 /** 043 * Implemented method to reduce the set of Business Objects that are shown 044 * to the user based on their current roles. 045 */ 046 public boolean shouldShowBusinessObject(BusinessObject bo) { 047 return (bo instanceof DepartmentalRule) && DepartmentalRuleAuthorizer.hasAccessToRead((DepartmentalRule)bo); 048 } 049 050 @Override 051 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 052 List<HtmlData> customActionUrls = new ArrayList<HtmlData>(); 053 054 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames); 055 056 DeptLunchRule deptLunchRule = (DeptLunchRule) businessObject; 057 String tkDeptLunchRuleId = deptLunchRule.getTkDeptLunchRuleId(); 058 String department = deptLunchRule.getDept(); 059 String workArea = String.valueOf(deptLunchRule.getWorkArea()); 060 Department dept = TkServiceLocator.getDepartmentService().getDepartment(deptLunchRule.getDept(), TKUtils.getCurrentDate()); 061 String location = dept == null ? null : dept.getLocation(); 062 063 boolean systemAdmin = TKContext.getUser().isSystemAdmin(); 064 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location); 065 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department); 066 067 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){ 068 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) { 069 if (systemAdmin || locationAdmin || departmentAdmin) { 070 customActionUrls.add(defaultCustomActionUrl); 071 } 072 } else { 073 customActionUrls.add(defaultCustomActionUrl); 074 } 075 } 076 077 Properties params = new Properties(); 078 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName()); 079 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL); 080 params.put("tkDeptLunchRuleId", tkDeptLunchRuleId); 081 params.put("dept", department); 082 params.put("workArea", workArea); 083 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view"); 084 viewUrl.setDisplayText("view"); 085 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK); 086 customActionUrls.add(viewUrl); 087 088 return customActionUrls; 089 } 090 091 @Override 092 protected void validateSearchParameterWildcardAndOperators( 093 String attributeName, String attributeValue) { 094 if (!StringUtils.equals(attributeValue, "%")) { 095 super.validateSearchParameterWildcardAndOperators(attributeName, 096 attributeValue); 097 } 098 } 099 }