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.department.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.HrEffectiveDateActiveLookupableHelper; 024 import org.kuali.hr.time.department.Department; 025 import org.kuali.hr.time.service.base.TkServiceLocator; 026 import org.kuali.hr.time.util.TKContext; 027 import org.kuali.hr.time.util.TKUtils; 028 import org.kuali.rice.kns.lookup.HtmlData; 029 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 030 import org.kuali.rice.krad.bo.BusinessObject; 031 import org.kuali.rice.krad.util.KRADConstants; 032 import org.kuali.rice.krad.util.UrlFactory; 033 034 public class DepartmentLookupableHelper extends HrEffectiveDateActiveLookupableHelper { 035 036 private static final long serialVersionUID = 566277764259830850L; 037 038 @Override 039 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 040 List<HtmlData> customActionUrls = new ArrayList<HtmlData>(); 041 042 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames); 043 044 Department departmentObj = (Department) businessObject; 045 String hrDeptId = departmentObj.getHrDeptId(); 046 Department dept = TkServiceLocator.getDepartmentService().getDepartment(departmentObj.getDept(), TKUtils.getCurrentDate()); 047 String location = dept == null ? null : dept.getLocation(); 048 String department = departmentObj.getDept(); 049 050 boolean systemAdmin = TKContext.getUser().isSystemAdmin(); 051 boolean locationAdmin = TKContext.getUser().getLocationAdminAreas().contains(location); 052 boolean departmentAdmin = TKContext.getUser().getDepartmentAdminAreas().contains(department); 053 054 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){ 055 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) { 056 if (systemAdmin || locationAdmin || departmentAdmin) { 057 customActionUrls.add(defaultCustomActionUrl); 058 } 059 } else { 060 customActionUrls.add(defaultCustomActionUrl); 061 } 062 } 063 064 Properties params = new Properties(); 065 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName()); 066 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL); 067 params.put("hrDeptId", hrDeptId); 068 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view"); 069 viewUrl.setDisplayText("view"); 070 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK); 071 customActionUrls.add(viewUrl); 072 073 return customActionUrls; 074 } 075 076 }