001/** 002 * Copyright 2005-2017 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 */ 016package org.kuali.rice.krad.labs.lookup; 017 018import org.apache.commons.collections.MapUtils; 019import org.apache.commons.lang3.StringUtils; 020import org.kuali.rice.kim.api.identity.IdentityService; 021import org.kuali.rice.kim.api.services.KimApiServiceLocator; 022import org.kuali.rice.krad.lookup.LookupForm; 023import org.kuali.rice.krad.lookup.LookupableImpl; 024import org.kuali.rice.krad.service.KRADServiceLocator; 025 026import java.util.Collection; 027import java.util.Map; 028 029/** 030 * Silly example for demonstrating Spring instantiation of certain services used in KRAD. 031 * 032 * <pre> 033 * {@code <property name="viewHelperService" value="#{#getService('labsTravelAccountLookupable')}"/>} 034 * </pre> 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038public class LabsTravelAccountLookupableImpl extends LookupableImpl { 039 040 private static final long serialVersionUID = -8463531661189633011L; 041 042 private transient IdentityService identityService; 043 044 /** 045 * {@inheritDoc} 046 * 047 * <p> 048 * This lookupable modifies the lookup results so that any search for 'fred' actually searches for 'admin'. 049 * </p> 050 */ 051 @Override 052 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) { 053 if (StringUtils.equals(MapUtils.getString(searchCriteria, "fiscalOfficer.principalName"), "fred")) { 054 String principalName = getIdentityService().getPrincipal("admin").getPrincipalName(); 055 searchCriteria.put("fiscalOfficer.principalName", principalName); 056 } 057 058 return super.performSearch(form, searchCriteria, bounded); 059 } 060 061 /** 062 * Returns the {@link IdentityService}. 063 * 064 * @return the {@link IdentityService} 065 */ 066 public IdentityService getIdentityService() { 067 return identityService; 068 } 069 070 /** 071 * Sets the {@link IdentityService}. 072 * 073 * @param identityService the {@link IdentityService} to set 074 */ 075 public void setIdentityService(IdentityService identityService) { 076 this.identityService = identityService; 077 } 078 079}