use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImpl method searchVehiclesInRevenueService.
@Override
public List<VehicleStatus> searchVehiclesInRevenueService(List<VehicleStatus> vehicleStatusRecords) {
Filter<VehicleStatus> revenueServiceFilter = new RevenueServiceFilter();
List<VehicleStatus> vehiclesInRevenueService = new ArrayList<VehicleStatus>();
for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
if (revenueServiceFilter.apply(vehicleStatus)) {
vehiclesInRevenueService.add(vehicleStatus);
}
}
return vehiclesInRevenueService;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImpl method searchVehiclesTracked.
@Override
public List<VehicleStatus> searchVehiclesTracked(int minutes, List<VehicleStatus> vehicleStatusRecords) {
Filter<VehicleStatus> timeWindowFilter = new TimeWindowFilter(minutes);
List<VehicleStatus> vehiclesTracked = new ArrayList<VehicleStatus>();
for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
if (timeWindowFilter.apply(vehicleStatus)) {
vehiclesTracked.add(vehicleStatus);
}
}
return vehiclesTracked;
}
use of org.onebusaway.admin.model.ui.VehicleStatus 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;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getVehicleStatus.
@Override
public List<VehicleStatus> getVehicleStatus(boolean loadNew) {
List<VehicleStatus> vehicleStatusRecords = null;
// Load new data only if asked explicitly
if (loadNew) {
VehicleStatusBuilder builder = new VehicleStatusBuilder();
// get last known record data from operational API
List<VehicleLastKnownRecord> vehicleLastKnownRecords = getLastKnownRecordData();
// get vehicle pipo data
Map<String, VehiclePullout> vehiclePullouts = getPulloutData();
vehicleStatusRecords = new ArrayList<VehicleStatus>();
// Build vehicle status objects by getting the required fields from both collections
for (VehicleLastKnownRecord lastknownRecord : vehicleLastKnownRecords) {
VehiclePullout pullout = vehiclePullouts.get(lastknownRecord.getVehicleId());
VehicleStatus vehicleStatus = builder.buildVehicleStatus(pullout, lastknownRecord);
vehicleStatusRecords.add(vehicleStatus);
}
// Add these records to the cache
cache.add(vehicleStatusRecords);
} else {
// return data from the cache to improve performance
vehicleStatusRecords = cache.fetch();
}
return vehicleStatusRecords;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImplTest method testSortBlankPulloutFields.
@Test
public void testSortBlankPulloutFields() {
VehicleStatus vehicle1 = new VehicleStatus();
vehicle1.setVehicleId("1");
vehicle1.setInferredPhase("IN PROGRESS");
vehicle1.setLastUpdate("2012-07-19T13:48:20.030Z");
vehicle1.setObservedDSC("4411");
vehicle1.setPulloutTime("");
vehicle1.setPullinTime("");
VehicleStatus vehicle2 = new VehicleStatus();
vehicle2.setVehicleId("2");
vehicle2.setInferredPhase("LAYOVER");
vehicle2.setLastUpdate("2012-07-19T13:50:20.030Z");
vehicle2.setObservedDSC("4412");
vehicle2.setPulloutTime("2012-07-18T05:54:00-04:00");
vehicle2.setPullinTime("2012-07-19T00:25:00-04:00");
List<VehicleStatus> vehicleStatusRecords = new ArrayList<VehicleStatus>();
vehicleStatusRecords.add(vehicle1);
vehicleStatusRecords.add(vehicle2);
service.sort(vehicleStatusRecords, "pulloutTime", "asc");
assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
service.sort(vehicleStatusRecords, "pulloutTime", "desc");
assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
service.sort(vehicleStatusRecords, "pullinTime", "asc");
assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
service.sort(vehicleStatusRecords, "pullinTime", "desc");
assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
}
Aggregations