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.time.principal.service; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 import java.util.Map; 021 import java.util.Properties; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.kuali.hr.time.HrEffectiveDateActiveLookupableHelper; 025 import org.kuali.hr.time.principal.PrincipalHRAttributes; 026 import org.kuali.hr.time.service.base.TkServiceLocator; 027 import org.kuali.hr.time.util.TKContext; 028 import org.kuali.hr.time.util.TKUtils; 029 import org.kuali.rice.kns.lookup.HtmlData; 030 import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; 031 import org.kuali.rice.krad.bo.BusinessObject; 032 import org.kuali.rice.krad.util.KRADConstants; 033 import org.kuali.rice.krad.util.UrlFactory; 034 035 public class PrincipalHRAttributesLookupableHelper extends HrEffectiveDateActiveLookupableHelper { 036 037 private static final long serialVersionUID = 6198072858175242923L; 038 039 @Override 040 public List<HtmlData> getCustomActionUrls(BusinessObject businessObject, List pkNames) { 041 List<HtmlData> customActionUrls = new ArrayList<HtmlData>(); 042 043 List<HtmlData> defaultCustomActionUrls = super.getCustomActionUrls(businessObject, pkNames); 044 045 PrincipalHRAttributes principalHRAttributes = (PrincipalHRAttributes) businessObject; 046 String hrPrincipalAttributeId = principalHRAttributes.getHrPrincipalAttributeId(); 047 048 boolean systemAdmin = TKContext.getUser().isSystemAdmin(); 049 boolean locationAdmin = TKContext.getUser().isLocationAdmin(); 050 051 for (HtmlData defaultCustomActionUrl : defaultCustomActionUrls){ 052 if (StringUtils.equals(defaultCustomActionUrl.getMethodToCall(), "edit")) { 053 if (systemAdmin || locationAdmin) { 054 customActionUrls.add(defaultCustomActionUrl); 055 } 056 } else { 057 customActionUrls.add(defaultCustomActionUrl); 058 } 059 } 060 061 Properties params = new Properties(); 062 params.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, getBusinessObjectClass().getName()); 063 params.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL); 064 params.put("hrPrincipalAttributeId", hrPrincipalAttributeId); 065 AnchorHtmlData viewUrl = new AnchorHtmlData(UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, params), "view"); 066 viewUrl.setDisplayText("view"); 067 viewUrl.setTarget(AnchorHtmlData.TARGET_BLANK); 068 customActionUrls.add(viewUrl); 069 070 return customActionUrls; 071 } 072 073 @Override 074 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) { 075 String principalId = fieldValues.get("principalId"); 076 String fromEffdt = TKUtils.getFromDateString(fieldValues.get("effectiveDate")); 077 String toEffdt = TKUtils.getToDateString(fieldValues.get("effectiveDate")); 078 String active = fieldValues.get("active"); 079 String showHist = fieldValues.get("history"); 080 081 return TkServiceLocator.getPrincipalHRAttributeService().getPrincipalHrAtributes(principalId, TKUtils.formatDateString(fromEffdt), 082 TKUtils.formatDateString(toEffdt), active, showHist); 083 } 084 }