use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImplTest method testVehicleSort.
@Test
public void testVehicleSort() {
VehicleStatus vehicle1 = new VehicleStatus();
vehicle1.setVehicleId("1");
vehicle1.setInferredPhase("IN PROGRESS");
vehicle1.setLastUpdate("2012-07-19T13:48:20.030Z");
vehicle1.setObservedDSC("4411");
vehicle1.setPulloutTime("2012-07-18T05:51:00-04:00");
vehicle1.setPullinTime("2012-07-19T00:23:00-04:00");
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, "vehicleId", "asc");
assertEquals("1", vehicleStatusRecords.get(0).getVehicleId());
service.sort(vehicleStatusRecords, "vehicleId", "desc");
assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
service.sort(vehicleStatusRecords, "lastUpdate", "asc");
assertEquals("2012-07-19T13:48:20.030Z", vehicleStatusRecords.get(0).getLastUpdate());
service.sort(vehicleStatusRecords, "lastUpdate", "desc");
assertEquals("2012-07-19T13:50:20.030Z", vehicleStatusRecords.get(0).getLastUpdate());
service.sort(vehicleStatusRecords, "inferredPhase", "asc");
assertEquals("IN PROGRESS", vehicleStatusRecords.get(0).getInferredPhase());
service.sort(vehicleStatusRecords, "inferredPhase", "desc");
assertEquals("LAYOVER", vehicleStatusRecords.get(0).getInferredPhase());
service.sort(vehicleStatusRecords, "observedDSC", "asc");
assertEquals("4411", vehicleStatusRecords.get(0).getObservedDSC());
service.sort(vehicleStatusRecords, "observedDSC", "desc");
assertEquals("4412", vehicleStatusRecords.get(0).getObservedDSC());
service.sort(vehicleStatusRecords, "pulloutTime", "asc");
assertEquals("2012-07-18T05:51:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
service.sort(vehicleStatusRecords, "pulloutTime", "desc");
assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
service.sort(vehicleStatusRecords, "pullinTime", "asc");
assertEquals("2012-07-19T00:23:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
service.sort(vehicleStatusRecords, "pullinTime", "desc");
assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImplTest method testVehicleStatusMismatchVehicle.
@Test
public void testVehicleStatusMismatchVehicle() {
String pulloutData = "{\"pullouts\":[{\"vehicle-id\":\"5638\"," + "\"agency-id-tcip\":\"2008\",\"agency-id\":\"MTA NYCT\",\"depot\":\"OS\"," + "\"service-date\":\"2012-07-18\",\"pullout-time\":\"2012-07-18T05:51:00-04:00\"," + "\"run\":\"M15-012\",\"operator-id\":\"1663\",\"pullin-time\":\"2012-07-19T00:23:00-04:00\"" + "}],\"status\":\"OK\"}";
String lastKnownData = "{\"records\":[{" + "\"uuid\": \"67f843e0-d1a8-11e1-8614-123139243533\"," + "\"vehicle-agency-id\": 2008," + "\"time-reported\": \"2012-07-19T13:48:20.030Z\"," + "\"time-received\": \"2012-07-19T13:48:22.686Z\"," + "\"archive-time-received\": \"2012-07-19T13:48:24.657Z\"," + "\"operator-id-designator\": \"913450\"," + "\"route-id-designator\": \"61\"," + "\"run-id-designator\": \"144\"," + "\"dest-sign-code\": 4611," + "\"latitude\": 40.683021," + "\"longitude\": -74.003720," + "\"speed\": 16.0," + "\"direction-deg\": 207.72," + "\"agency-id\": \"MTA NYCT\"," + "\"vehicle-id\": 344," + "\"depot-id\": \"JG\"," + "\"service-date\": \"2012-07-19\"," + "\"inferred-run-id\": \"B61-14\"," + "\"inferred-block-id\": \"MTA NYCT_20120701CC_JG_22200_B61-14-JG_1972\"," + "\"inferred-route-id\": \"MTA NYCT_B61\"," + "\"inferred-direction-id\": \"1\"," + "\"inferred-dest-sign-code\": 4611," + "\"inferred-latitude\": 40.683001," + "\"inferred-longitude\": -74.003678," + "\"inferred-phase\": \"IN_PROGRESS\"," + "\"inferred-status\": \"default\"," + "\"inference-is-formal\": false," + "\"distance-along-block\": 30650.503480107127," + "\"distance-along-trip\": 2374.6309121986087," + "\"next-scheduled-stop-id\": \"MTA NYCT_305226\"," + "\"next-scheduled-stop-distance\": 26.791625996334915" + "}],\"status\":\"OK\"}";
when(remoteConnectionService.getContent("http://tdm.dev.obanyc.com/api/pullouts/list")).thenReturn(pulloutData);
when(configurationService.getConfigurationValueAsString("operational-api.host", "archive")).thenReturn("archive.dev.obanyc.com");
when(remoteConnectionService.getContent("http://archive.dev.obanyc.com/api/record/last-known/list")).thenReturn(lastKnownData);
List<VehicleStatus> vehicleStatusRecords = service.getVehicleStatus(true);
VehicleStatus vehicleStatus = vehicleStatusRecords.get(0);
assertEquals("Mismatched vehicle id", vehicleStatus.getVehicleId(), "344");
assertEquals("Mismatched inferred phase", vehicleStatus.getInferredPhase(), "IN PROGRESS");
assertEquals("Mismatched observed DSC", vehicleStatus.getObservedDSC(), "4611");
assertNull("No pull in time", vehicleStatus.getPullinTime());
assertNull("No pull out time", vehicleStatus.getPulloutTime());
assertEquals("Mismatched inferred destination information", vehicleStatus.getInferredDestination(), "4611:B61 Direction: 1");
assertEquals("Mismatched status image", vehicleStatus.getStatus(), "circle_red18x18.png");
}
use of org.onebusaway.admin.model.ui.VehicleStatus 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;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImpl method searchVehiclesInEmergency.
@Override
public List<VehicleStatus> searchVehiclesInEmergency(List<VehicleStatus> vehicleStatusRecords) {
Filter<VehicleStatus> emergencyFilter = new EmergencyStatusFilter();
List<VehicleStatus> vehiclesInEmergency = new ArrayList<VehicleStatus>();
for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
if (emergencyFilter.apply(vehicleStatus)) {
vehiclesInEmergency.add(vehicleStatus);
}
}
return vehiclesInEmergency;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method sort.
@Override
public void sort(List<VehicleStatus> vehiclesPerPage, String field, String order) {
VehicleSortFields sortField = VehicleSortFields.valueOf(field.toUpperCase());
Comparator<VehicleStatus> fieldComparator = null;
switch(sortField) {
case VEHICLEID:
fieldComparator = new VehicleIdComparator(order);
break;
case LASTUPDATE:
fieldComparator = new LastUpdateComparator(order);
break;
case INFERREDPHASE:
fieldComparator = new InferredPhaseComparator(order);
break;
case OBSERVEDDSC:
fieldComparator = new ObservedDSCComparator(order);
break;
case PULLOUTTIME:
fieldComparator = new PulloutTimeComparator(order);
break;
case PULLINTIME:
fieldComparator = new PullinTimeComparator(order);
break;
default:
fieldComparator = new VehicleIdComparator(order);
break;
}
Collections.sort(vehiclesPerPage, fieldComparator);
}
Aggregations