Search in sources :

Example 1 with Filter

use of org.onebusaway.admin.search.Filter in project onebusaway-application-modules by camsys.

the class VehicleSearchServiceImpl method buildFilters.

private List<Filter<VehicleStatus>> buildFilters(Map<VehicleSearchParameters, String> searchParameters) {
    List<Filter<VehicleStatus>> filters = new ArrayList<Filter<VehicleStatus>>();
    // Since all parameters are optional we have to look for each one
    // To-do: there might be a better way of doing this
    String vehicleId = searchParameters.get(VehicleSearchParameters.VEHICLE_ID);
    if (StringUtils.isNotBlank(vehicleId)) {
        filters.add(new VehicleIdFilter(vehicleId));
    }
    String route = searchParameters.get(VehicleSearchParameters.ROUTE);
    if (StringUtils.isNotBlank(route)) {
        filters.add(new RouteFilter(route));
    }
    String inferredPhase = searchParameters.get(VehicleSearchParameters.INFERRED_PHASE);
    if (!inferredPhase.equalsIgnoreCase("All")) {
        filters.add(new InferredPhaseFilter(inferredPhase));
    }
    String dsc = searchParameters.get(VehicleSearchParameters.DSC);
    if (StringUtils.isNotBlank(dsc)) {
        filters.add(new DSCFilter(dsc));
    }
    String depot = searchParameters.get(VehicleSearchParameters.DEPOT);
    if (!depot.equalsIgnoreCase("All")) {
        filters.add(new DepotFilter(depot));
    }
    String pulloutStatus = searchParameters.get(VehicleSearchParameters.PULLOUT_STATUS);
    if (!pulloutStatus.equalsIgnoreCase("All")) {
        filters.add(new PulloutStatusFilter());
    }
    String emergencyStatus = searchParameters.get(VehicleSearchParameters.EMERGENCY_STATUS);
    if (emergencyStatus.equalsIgnoreCase("true")) {
        filters.add(new EmergencyStatusFilter());
    }
    String formalInferrence = searchParameters.get(VehicleSearchParameters.FORMAL_INFERRENCE);
    if (formalInferrence.equalsIgnoreCase("true")) {
        filters.add(new FormalInferrenceFilter());
    }
    return filters;
}
Also used : DepotFilter(org.onebusaway.admin.search.impl.DepotFilter) PulloutStatusFilter(org.onebusaway.admin.search.impl.PulloutStatusFilter) InferredPhaseFilter(org.onebusaway.admin.search.impl.InferredPhaseFilter) ArrayList(java.util.ArrayList) RouteFilter(org.onebusaway.admin.search.impl.RouteFilter) VehicleIdFilter(org.onebusaway.admin.search.impl.VehicleIdFilter) DSCFilter(org.onebusaway.admin.search.impl.DSCFilter) PulloutStatusFilter(org.onebusaway.admin.search.impl.PulloutStatusFilter) Filter(org.onebusaway.admin.search.Filter) DepotFilter(org.onebusaway.admin.search.impl.DepotFilter) FormalInferrenceFilter(org.onebusaway.admin.search.impl.FormalInferrenceFilter) RouteFilter(org.onebusaway.admin.search.impl.RouteFilter) InferredPhaseFilter(org.onebusaway.admin.search.impl.InferredPhaseFilter) RevenueServiceFilter(org.onebusaway.admin.search.impl.RevenueServiceFilter) TimeWindowFilter(org.onebusaway.admin.search.impl.TimeWindowFilter) DSCFilter(org.onebusaway.admin.search.impl.DSCFilter) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter) VehicleIdFilter(org.onebusaway.admin.search.impl.VehicleIdFilter) FormalInferrenceFilter(org.onebusaway.admin.search.impl.FormalInferrenceFilter) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter)

Example 2 with Filter

use of org.onebusaway.admin.search.Filter in project onebusaway-application-modules by camsys.

the class VehicleSearchServiceImpl method search.

@Override
public List<VehicleStatus> search(List<VehicleStatus> vehicleStatusRecords, Map<VehicleSearchParameters, String> searchParameters) {
    List<VehicleStatus> matchingRecords = new ArrayList<VehicleStatus>();
    // Build filters corresponding to the search parameters
    List<Filter<VehicleStatus>> filters = buildFilters(searchParameters);
    // Since there are no filters specified, return all the records as matched records
    if (filters.isEmpty()) {
        matchingRecords.addAll(vehicleStatusRecords);
    } else {
        // Apply each filter to each record
        for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
            boolean matches = applyFilters(vehicleStatus, filters);
            if (matches) {
                matchingRecords.add(vehicleStatus);
            }
        }
    }
    return matchingRecords;
}
Also used : PulloutStatusFilter(org.onebusaway.admin.search.impl.PulloutStatusFilter) Filter(org.onebusaway.admin.search.Filter) DepotFilter(org.onebusaway.admin.search.impl.DepotFilter) FormalInferrenceFilter(org.onebusaway.admin.search.impl.FormalInferrenceFilter) RouteFilter(org.onebusaway.admin.search.impl.RouteFilter) InferredPhaseFilter(org.onebusaway.admin.search.impl.InferredPhaseFilter) RevenueServiceFilter(org.onebusaway.admin.search.impl.RevenueServiceFilter) TimeWindowFilter(org.onebusaway.admin.search.impl.TimeWindowFilter) DSCFilter(org.onebusaway.admin.search.impl.DSCFilter) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter) VehicleIdFilter(org.onebusaway.admin.search.impl.VehicleIdFilter) ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus)

Aggregations

ArrayList (java.util.ArrayList)2 VehicleStatus (org.onebusaway.admin.model.ui.VehicleStatus)2 Filter (org.onebusaway.admin.search.Filter)2 DSCFilter (org.onebusaway.admin.search.impl.DSCFilter)2 DepotFilter (org.onebusaway.admin.search.impl.DepotFilter)2 EmergencyStatusFilter (org.onebusaway.admin.search.impl.EmergencyStatusFilter)2 FormalInferrenceFilter (org.onebusaway.admin.search.impl.FormalInferrenceFilter)2 InferredPhaseFilter (org.onebusaway.admin.search.impl.InferredPhaseFilter)2 PulloutStatusFilter (org.onebusaway.admin.search.impl.PulloutStatusFilter)2 RevenueServiceFilter (org.onebusaway.admin.search.impl.RevenueServiceFilter)2 RouteFilter (org.onebusaway.admin.search.impl.RouteFilter)2 TimeWindowFilter (org.onebusaway.admin.search.impl.TimeWindowFilter)2 VehicleIdFilter (org.onebusaway.admin.search.impl.VehicleIdFilter)2