001 /** 002 * Copyright 2004-2013 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.lm.earncodesec.service; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.hr.lm.earncodesec.EarnCodeSecurity; 020 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper; 021 import org.kuali.hr.time.service.base.TkServiceLocator; 022 import org.kuali.hr.time.util.TKContext; 023 import org.kuali.hr.time.util.TKUser; 024 import org.kuali.hr.time.util.TKUtils; 025 import org.kuali.rice.kns.lookup.HtmlData; 026 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 027 import org.kuali.rice.krad.bo.BusinessObject; 028 import org.kuali.rice.krad.util.KRADConstants; 029 import org.kuali.rice.krad.util.UrlFactory; 030 031 import java.util.ArrayList; 032 import java.util.List; 033 import java.util.Map; 034 import java.util.Properties; 035 036 public class EarnCodeSecurityLookupableHelper extends HrEffectiveDateActiveLookupableHelper { 037 038 private static final long serialVersionUID = 696878785547265569L; 039 040 @Override 041 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 042 List<HtmlData> customActionUrls = new ArrayList<HtmlData>(); 043 044 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames); 045 046 EarnCodeSecurity earnCodeSecurity = (EarnCodeSecurity) businessObject; 047 String hrEarnCodeSecurityId = earnCodeSecurity.getHrEarnCodeSecurityId(); 048 String location = earnCodeSecurity.getLocation(); 049 String department = earnCodeSecurity.getDept(); 050 051 boolean systemAdmin = TKUser.isSystemAdmin(); 052 boolean locationAdmin = TKUser.getLocationAdminAreas().contains(location); 053 boolean departmentAdmin = TKUser.getDepartmentAdminAreas().contains(department); 054 055 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){ 056 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) { 057 if (systemAdmin || locationAdmin || departmentAdmin) { 058 customActionUrls.add(defaultCustomActionUrl); 059 } 060 } else { 061 customActionUrls.add(defaultCustomActionUrl); 062 } 063 } 064 065 Properties params = new Properties(); 066 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName()); 067 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL); 068 params.put("hrEarnCodeSecurityId", hrEarnCodeSecurityId); 069 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view"); 070 viewUrl.setDisplayText("view"); 071 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK); 072 customActionUrls.add(viewUrl); 073 074 return customActionUrls; 075 } 076 077 @Override 078 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { 079 String salGroup = fieldValues.get("hrSalGroup"); 080 String dept = fieldValues.get("dept"); 081 String earnCode = fieldValues.get("earnCode"); 082 String location = fieldValues.get("location"); 083 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate")); 084 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate")); 085 String active = fieldValues.get("active"); 086 String showHist = fieldValues.get("history"); 087 088 return TkServiceLocator.getEarnCodeSecurityService().searchEarnCodeSecurities(dept, salGroup, earnCode, location, TKUtils.formatDateString(fromEffdt), 089 TKUtils.formatDateString(toEffdt), active, showHist); 090 } 091 092 }