001    /**
002     * Copyright 2005-2012 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.rice.kim.impl.identity;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.core.api.criteria.Predicate;
020    import org.kuali.rice.core.api.criteria.PredicateUtils;
021    import org.kuali.rice.core.api.criteria.QueryByCriteria;
022    import org.kuali.rice.kim.api.KimConstants;
023    import org.kuali.rice.kim.api.group.Group;
024    import org.kuali.rice.kim.api.group.GroupQueryResults;
025    import org.kuali.rice.kim.api.group.GroupService;
026    import org.kuali.rice.kim.api.identity.PersonService;
027    import org.kuali.rice.kim.api.services.KimApiServiceLocator;
028    import org.kuali.rice.kim.impl.KIMPropertyConstants;
029    import org.kuali.rice.kim.impl.group.GroupBo;
030    import org.kuali.rice.krad.lookup.LookupableImpl;
031    import org.kuali.rice.krad.web.form.LookupForm;
032    
033    import java.sql.Timestamp;
034    import java.util.ArrayList;
035    import java.util.Calendar;
036    import java.util.HashMap;
037    import java.util.List;
038    import java.util.Map;
039    
040    import 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     */
047    public 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    }