001/**
002 * Copyright 2005-2016 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.kim.impl.identity;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.kim.api.identity.PersonService;
020import org.kuali.rice.kim.api.services.KimApiServiceLocator;
021import org.kuali.rice.kim.impl.KIMPropertyConstants;
022import org.kuali.rice.krad.lookup.LookupableImpl;
023import org.kuali.rice.krad.lookup.LookupForm;
024
025import java.util.Collection;
026import java.util.List;
027import java.util.Map;
028
029/**
030 * Custom lookupable for the {@link PersonImpl} lookup to call the person service for searching
031 *
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034public class PersonLookupableImpl extends LookupableImpl {
035    private static final long serialVersionUID = -3149952849854425077L;
036
037    /**
038     * Lower cases criteria on principal name and calls the person service to carry out the search
039     *
040     * @return List<PersonImpl>
041     */
042    @Override
043    protected Collection<?> executeSearch(Map<String, String> adjustedSearchCriteria,
044                List<String> wildcardAsLiteralSearchCriteria, boolean bounded, Integer searchResultsLimit) {
045        // lower case principal name
046        if (adjustedSearchCriteria != null && StringUtils.isNotEmpty(adjustedSearchCriteria.get(
047                KIMPropertyConstants.Person.PRINCIPAL_NAME))) {
048            adjustedSearchCriteria.put(KIMPropertyConstants.Person.PRINCIPAL_NAME, adjustedSearchCriteria.get(
049                    KIMPropertyConstants.Person.PRINCIPAL_NAME).toLowerCase());
050        }
051
052        return getPersonService().findPeople(adjustedSearchCriteria, !bounded);
053    }
054
055    public PersonService getPersonService() {
056        return KimApiServiceLocator.getPersonService();
057    }
058}