/**
 * Copyright 2005-2014 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package edu.sampleu.travel;

import org.kuali.rice.core.api.util.RiceKeyConstants;
import org.kuali.rice.core.api.util.type.KualiDecimal;
import org.kuali.rice.krad.demo.travel.dataobject.TravelAccount;
import org.kuali.rice.krad.lookup.LookupForm;
import org.kuali.rice.krad.lookup.LookupableImpl;
import org.kuali.rice.krad.uif.UifConstants;
import org.kuali.rice.krad.util.GlobalVariables;
import org.kuali.rice.krad.util.MessageMap;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

/**
 * @author Kuali Rice Team (rice.collab@kuali.org)
 */
public class TravelLookupableImpl extends LookupableImpl {

    /**
     * Override the performSearch method so that we can perform any additional filtering of results from the standard query.
     * Here we are getting the additional parameters being passed in and filtering on minSubsidized value.
     *
     * @{inheritDoc}
     */
    @Override
    public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) {
        Collection<org.kuali.rice.krad.demo.travel.dataobject.TravelAccount> results =
                (Collection<org.kuali.rice.krad.demo.travel.dataobject.TravelAccount>) super.performSearch(form,
                        searchCriteria, bounded);

        // get additional parameter
        String minSubsidized = form.getInitialRequestParameters().get("minSubsidized")[0];

        // filter results
        Collection<TravelAccount> finalResults = new ArrayList();
        for (TravelAccount travelAccount : results) {
            if (travelAccount.getSubsidizedPercent() != null && travelAccount.getSubsidizedPercent().isGreaterEqual(
                    new KualiDecimal(minSubsidized))) {
                finalResults.add(travelAccount);
            }
        }

        // over write the default search message that was set
        MessageMap messageMap = GlobalVariables.getMessageMap();
        messageMap.getInfoMessages().remove(UifConstants.MessageKeys.LOOKUP_RESULT_MESSAGES);
        messageMap.putInfoForSectionId(UifConstants.MessageKeys.LOOKUP_RESULT_MESSAGES,
                RiceKeyConstants.INFO_LOOKUP_RESULTS_DISPLAY_ALL, finalResults.size() + "");

        // NOTE: an alternative to the above is to add the new value as a part of the searchCriteria passed in
        // then database can filter results and would not have to over write default search message
        // however KualiPercent is broke at time of this example
        //searchCriteria.put("subsidizedPercent", ">=" + minSubsidized);

        return finalResults;
    }

}

@@ -670,421 +670,80 @@
 ice.
-core.api.util.RiceKeyConstants;%0Aimport org.kuali.rice.core.api.util.type.KualiDecimal;%0Aimport org.kuali.rice.krad.demo.travel.dataobject.TravelAccount;%0Aimport org.kuali.rice.krad.lookup.LookupForm;%0Aimport org.kuali.rice.krad.lookup.LookupableImpl;%0Aimport org.kuali.rice.krad.uif.UifConstants;%0Aimport org.kuali.rice.krad.util.GlobalVariables;%0Aimport org.kuali.rice.krad.util.MessageMap;%0A%0Aimport java.util.ArrayList
+krad.lookup.LookupForm;%0Aimport org.kuali.rice.krad.lookup.LookupableImpl
 ;%0Aim
@@ -1324,1552 +1324,264 @@
     
-Collection%3Corg.kuali.rice.krad.demo.travel.dataobject.TravelAccount%3E results =%0A                (Collection%3Corg.kuali.rice.krad.demo.travel.dataobject.TravelAccount%3E) super.performSearch(form,%0A                        searchCriteria, bounded);%0A%0A        // get additional parameter%0A        String minSubsidized = form.getInitialRequestParameters().get(%22minSubsidized%22)%5B0%5D;%0A%0A        // filter results%0A        Collection%3CTravelAccount%3E finalResults = new ArrayList();%0A        for (TravelAccount travelAccount : results) %7B%0A            if (travelAccount.getSubsidizedPercent() != null && travelAccount.getSubsidizedPercent().isGreaterEqual(%0A                    new KualiDecimal(minSubsidized))) %7B%0A                finalResults.add(travelAccount);%0A            %7D%0A        %7D%0A%0A        // over write the default search message that was set%0A        MessageMap messageMap = GlobalVariables.getMessageMap();%0A        messageMap.getInfoMessages().remove(UifConstants.MessageKeys.LOOKUP_RESULT_MESSAGES);%0A        messageMap.putInfoForSectionId(UifConstants.MessageKeys.LOOKUP_RESULT_MESSAGES,%0A                RiceKeyConstants.INFO_LOOKUP_RESULTS_DISPLAY_ALL, finalResults.size() + %22%22);%0A%0A        // NOTE: an alternative to the above is to add the new value as a part of the searchCriteria passed in%0A        // then database can filter results and would not have to over write default search message%0A        // however KualiPercent is broke at time of this example%0A        //searchCriteria.put(%22subsidizedPercent%22, %22%3E=%22 + minSubsidized);%0A%0A        return finalResults
+// get additional parameter%0A        String minSubsidized = form.getInitialRequestParameters().get(%22minSubsidized%22)%5B0%5D;%0A%0A        searchCriteria.put(%22subsidizedPercent%22, %22%3E=%22 + minSubsidized);%0A%0A        return super.performSearch(form, searchCriteria,bounded)
 ;%0A  

Simplified the code since KualiPercent is fixed.