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.core.api.criteria.Predicate;
020import org.kuali.rice.core.api.criteria.PredicateUtils;
021import org.kuali.rice.core.api.criteria.QueryByCriteria;
022import org.kuali.rice.kim.api.KimConstants;
023import org.kuali.rice.kim.api.group.Group;
024import org.kuali.rice.kim.api.group.GroupQueryResults;
025import org.kuali.rice.kim.api.group.GroupService;
026import org.kuali.rice.kim.api.identity.PersonService;
027import org.kuali.rice.kim.api.services.KimApiServiceLocator;
028import org.kuali.rice.kim.impl.KIMPropertyConstants;
029import org.kuali.rice.kim.impl.group.GroupBo;
030import org.kuali.rice.krad.lookup.LookupableImpl;
031import org.kuali.rice.krad.web.form.LookupForm;
032
033import java.sql.Timestamp;
034import java.util.ArrayList;
035import java.util.Calendar;
036import java.util.HashMap;
037import java.util.List;
038import java.util.Map;
039
040import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
041
042/**
043 * Custom lookupable for the {@link PersonImpl} lookup to call the person service for searching
044 *
045 * @author Kuali Rice Team (rice.collab@kuali.org)
046 */
047public class PersonLookupableImpl extends LookupableImpl {
048    private static final long serialVersionUID = -3149952849854425077L;
049
050    /**
051     * Lower cases criteria on principal name and calls the person service to carry out the search
052     *
053     * @return List<PersonImpl>
054     */
055    @Override
056    protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
057        // lower case principal name
058        if (searchCriteria != null && StringUtils.isNotEmpty(searchCriteria.get(
059                KIMPropertyConstants.Person.PRINCIPAL_NAME))) {
060            searchCriteria.put(KIMPropertyConstants.Person.PRINCIPAL_NAME, searchCriteria.get(
061                    KIMPropertyConstants.Person.PRINCIPAL_NAME).toLowerCase());
062        }
063
064        return getPersonService().findPeople(searchCriteria, unbounded);
065    }
066
067    public PersonService getPersonService() {
068        return KimApiServiceLocator.getPersonService();
069    }
070}