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.kpme.pm.position.web; 017 018 import java.util.List; 019 import java.util.Map; 020 import java.util.Properties; 021 022 import org.apache.commons.lang.StringUtils; 023 import org.kuali.kpme.core.lookup.KPMELookupableImpl; 024 import org.kuali.kpme.core.util.TKUtils; 025 import org.kuali.kpme.pm.position.Position; 026 import org.kuali.kpme.pm.service.base.PmServiceLocator; 027 import org.kuali.rice.core.api.config.property.ConfigContext; 028 import org.kuali.rice.krad.uif.UifConstants; 029 import org.kuali.rice.krad.uif.UifParameters; 030 import org.kuali.rice.krad.uif.element.Action; 031 import org.kuali.rice.krad.uif.util.LookupInquiryUtils; 032 import org.kuali.rice.krad.uif.view.LookupView; 033 import org.kuali.rice.krad.util.KRADConstants; 034 import org.kuali.rice.krad.util.KRADUtils; 035 import org.kuali.rice.krad.util.UrlFactory; 036 import org.kuali.rice.krad.web.form.LookupForm; 037 038 public class PositionLookupableImpl extends KPMELookupableImpl { 039 040 private static final long serialVersionUID = 8658536323175048980L; 041 042 @Override 043 protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) { 044 String positionNum = searchCriteria.get("positionNumber"); 045 String description = searchCriteria.get("description"); 046 String workingPositionTitle = searchCriteria.get("workingPositionTitle"); 047 String campus = searchCriteria.get("campus"); 048 String institution = searchCriteria.get("institution"); 049 String classificationTitle = searchCriteria.get("classificationTitle"); 050 String positionType = searchCriteria.get("positionType"); 051 String poolEligible = searchCriteria.get("poolEligible"); 052 String fromEffdt = TKUtils.getFromDateString(searchCriteria.get("effectiveDate")); 053 String toEffdt = TKUtils.getToDateString(searchCriteria.get("effectiveDate")); 054 String active = searchCriteria.get("active"); 055 String showHist = searchCriteria.get("history"); 056 057 if (StringUtils.equals(positionNum, "%")) { 058 positionNum = ""; 059 } 060 061 return PmServiceLocator.getPositionService().getPositions(positionNum, description, workingPositionTitle, campus, 062 institution, classificationTitle, positionType, poolEligible, TKUtils.formatDateString(fromEffdt), 063 TKUtils.formatDateString(toEffdt), active, showHist); 064 } 065 066 @Override 067 protected String getActionUrlHref(LookupForm lookupForm, Object dataObject, String methodToCall, List<String> pkNames) { 068 if (!StringUtils.equals(methodToCall, "maintenanceEdit")) { 069 return super.getActionUrlHref(lookupForm, dataObject, methodToCall, pkNames); 070 } else { 071 Properties urlParameters = new Properties(); 072 073 urlParameters.setProperty(UifParameters.DATA_OBJECT_CLASS_NAME, dataObject.getClass().getName()); 074 urlParameters.setProperty(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.START); 075 076 Map<String, String> primaryKeyValues = KRADUtils.getPropertyKeyValuesFromDataObject(pkNames, dataObject); 077 for (String primaryKey : primaryKeyValues.keySet()) { 078 String primaryKeyValue = primaryKeyValues.get(primaryKey); 079 080 urlParameters.put(primaryKey, primaryKeyValue); 081 } 082 083 String path = ConfigContext.getCurrentContextConfig().getProperty("application.url"); 084 String hrefPrefix = path + "/portal.do?channelTitle=ProcessMaint&channelUrl=" + path + "/ProcessMaint.do"; 085 Position aPosition = (Position) dataObject; 086 String paramString = "?positionId=" + aPosition.getHrPositionId(); 087 return (hrefPrefix + paramString); 088 } 089 } 090 091 @Override 092 public void initSuppressAction(LookupForm lookupForm) { 093 /* 094 * lookupAuthorizer.canInitiateDocument(lookupForm, user) returns false in this instance, because no 095 * documentTypeName can be obtained within LookupViewAuthorizeBase.canInitiateDocument(LookupForm, Person). 096 */ 097 ((LookupView) lookupForm.getView()).setSuppressActions(false); 098 } 099 }