use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesTemplate method buildPredictedArrivalsTemplate.
protected void buildPredictedArrivalsTemplate(List<ArrivalAndDepartureBean> arrivals) {
if (arrivals.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
}
Collections.sort(arrivals, new ArrivalAndDepartureComparator());
long now = SystemTime.currentTimeMillis();
for (ArrivalAndDepartureBean adb : arrivals) {
TripBean trip = adb.getTrip();
RouteBean route = trip.getRoute();
addMessage(Messages.ROUTE);
String routeNumber = RoutePresenter.getNameForRoute(route);
addText(_routeNumberPronunciation.modify(routeNumber));
String headsign = trip.getTripHeadsign();
if (headsign != null) {
addMessage(Messages.TO);
String destination = _destinationPronunciation.modify(headsign);
addText(destination);
}
if (TransitDataConstants.STATUS_LEGACY_CANCELLED.equalsIgnoreCase(adb.getStatus())) {
addText("is currently not in service");
continue;
}
long t = adb.computeBestDepartureTime();
boolean isPrediction = adb.hasPredictedDepartureTime();
int min = (int) ((t - now) / 1000 / 60);
if (min < 0) {
min = -min;
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_PAST_DATE : Messages.SCHEDULED_AT_PAST_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_PAST : Messages.SCHEDULED_IN_PAST;
addMessage(message, min);
}
} else {
if (min > 60) {
String message = isPrediction ? Messages.PREDICTED_AT_FUTURE_DATE : Messages.SCHEDULED_AT_FUTURE_DATE;
addMessage(message, new Date(t));
} else {
String message = isPrediction ? Messages.PREDICTED_IN_FUTURE : Messages.SCHEDULED_IN_FUTURE;
addMessage(message, min);
}
}
if (TransitDataConstants.STATUS_REROUTE.equals(adb.getStatus()))
addText("but is currently on adverse weather re-route.");
}
addMessage(Messages.ARRIVAL_INFO_DISCLAIMER);
List<AgencyBean> agencies = AgencyPresenter.getAgenciesForArrivalAndDepartures(arrivals);
if (!agencies.isEmpty()) {
addMessage(Messages.ARRIVAL_INFO_DATA_PROVIDED_BY);
for (int i = 0; i < agencies.size(); i++) {
AgencyBean agency = agencies.get(i);
if (i == agencies.size() - 1 && agencies.size() > 1)
addText(Messages.AND);
addText(agency.getName());
addText(",");
}
}
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class StopBeanServiceImplTest method testGetStopForId.
@Test
public void testGetStopForId() {
AgencyAndId stopId = new AgencyAndId("29", "1109");
StopEntryImpl stopEntry = new StopEntryImpl(stopId, 47.1, -122.1);
Mockito.when(_transitGraphDao.getStopEntryForId(stopId)).thenReturn(stopEntry);
StopNarrative.Builder builder = StopNarrative.builder();
builder.setCode("1109-b");
builder.setDescription("stop description");
builder.setLocationType(0);
builder.setName("stop name");
builder.setUrl("http://some/url");
builder.setDirection("N");
StopNarrative stop = builder.create();
Mockito.when(_narrativeService.getStopForId(stopId)).thenReturn(stop);
AgencyAndId routeId = new AgencyAndId("1", "route");
Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
routeIds.add(routeId);
Mockito.when(_routeService.getRouteCollectionIdsForStop(stopId)).thenReturn(routeIds);
RouteBean.Builder routeBuilder = RouteBean.builder();
routeBuilder.setId(AgencyAndIdLibrary.convertToString(routeId));
RouteBean route = routeBuilder.create();
Mockito.when(_routeBeanService.getRouteForId(routeId)).thenReturn(route);
StopBean stopBean = _service.getStopForId(stopId);
assertNotNull(stopBean);
assertEquals(stopId.toString(), stopBean.getId());
assertEquals(stop.getName(), stopBean.getName());
assertEquals(stopEntry.getStopLat(), stopBean.getLat(), 0.0);
assertEquals(stopEntry.getStopLon(), stopBean.getLon(), 0.0);
assertEquals(stop.getCode(), stopBean.getCode());
assertEquals(stop.getLocationType(), stopBean.getLocationType());
List<RouteBean> routes = stopBean.getRoutes();
assertEquals(1, routes.size());
assertSame(route, routes.get(0));
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RouteForNameAction method execute.
public String execute() throws Exception {
_log.debug("in RouteForName with routeName " + _routeName);
CoordinateBounds bounds = getDefaultSearchArea();
if (bounds == null) {
return NEEDS_DEFAULT_SEARCH_LOCATION;
}
if (_routeName == null || _routeName.length() == 0) {
return INPUT;
}
SearchQueryBean routesQuery = new SearchQueryBean();
routesQuery.setBounds(bounds);
routesQuery.setMaxCount(10);
routesQuery.setQuery(_routeName);
routesQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
RoutesBean routesBean = _transitDataService.getRoutes(routesQuery);
List<RouteBean> routes = routesBean.getRoutes();
sessionMap.put("navState", new Integer(DISPLAY_DATA));
logUserInteraction("route", _routeName);
if (routes.size() == 0) {
sessionMap.put("messageFromAction", getText(Messages.NO_ROUTES_WERE_FOUND));
sessionMap.put("backAction", "search-index");
return "noRoutesFound";
} else if (routes.size() == 1) {
_route = routes.get(0);
return SUCCESS;
} else {
_routes = routes;
return "multipleRoutesFound";
}
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getAnnotatedLineStructures.
@Override
public Map<Boolean, List<AnnotatedLineStructure>> getAnnotatedLineStructures(List<String> agencyIds, List<AgencyAndId> routeIds, DetailLevel detailLevel, long currentTime, Map<Filters, String> filters) {
// Store processed StopBean as AnnotatedStopPointStructure
List<AnnotatedLineStructure> annotatedLines = new ArrayList<AnnotatedLineStructure>();
// AnnotatedStopPointStructures List with hasUpcomingScheduledService
Map<Boolean, List<AnnotatedLineStructure>> output = new HashMap<Boolean, List<AnnotatedLineStructure>>();
Boolean upcomingServiceAllStops = null;
for (AgencyAndId rteId : routeIds) {
String routeId = AgencyAndId.convertToString(rteId);
RouteBean routeBean = _transitDataService.getRouteForId(routeId);
// Filter By AgencyID
if (routeBean.getAgency() == null || !agencyIds.contains(routeBean.getAgency().getId()))
continue;
AnnotatedLineStructure annotatedLineStructure = new AnnotatedLineStructure();
RouteResult routeResult = getRouteResult(routeBean, filters);
// Skip Routes with no stops
if (routeResult.getDirections() == null || routeResult.getDirections().size() == 0)
continue;
boolean isValid = SiriSupportV2.fillAnnotatedLineStructure(annotatedLineStructure, routeResult, filters, detailLevel, currentTime);
if (isValid)
annotatedLines.add(annotatedLineStructure);
}
output.put(upcomingServiceAllStops, annotatedLines);
return output;
}
use of org.onebusaway.transit_data.model.RouteBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getStopRouteDirection.
private StopRouteDirection getStopRouteDirection(StopBean stop, List<StopsForRouteBean> stopsForRouteList, Map<Filters, String> filters) {
// Filter Values
String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
String directionIdFilter = filters.get(Filters.DIRECTION_REF);
StopRouteDirection stopRouteDirection = new StopRouteDirection(stop);
for (StopsForRouteBean stopsForRoute : stopsForRouteList) // Check to see which stop group the specified stop exists in (usually 2 stop groups)
for (StopGroupingBean stopGrouping : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroup : stopGrouping.getStopGroups()) {
NameBean name = stopGroup.getName();
String type = name.getType();
String directionId = stopGroup.getId();
RouteBean route = stopsForRoute.getRoute();
// Destination and DirectionId Filter
if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
continue;
// filter out route directions that don't stop at this stop
if (!stopGroup.getStopIds().contains(stop.getId()))
continue;
// filter hasUpcomingScheduledService
Boolean hasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((route.getAgency() != null ? route.getAgency().getId() : null), SystemTime.currentTimeMillis(), stop.getId(), stopsForRoute.getRoute().getId(), directionId);
String hasUpcomingScheduledServiceVal = String.valueOf(hasUpcomingScheduledService);
if (!hasUpcomingScheduledServiceVal.trim().equals("false")) {
hasUpcomingScheduledServiceVal = "true";
}
if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter))
continue;
stopRouteDirection.addRouteDirection(new RouteForDirection(route.getId(), directionId, hasUpcomingScheduledService));
}
}
return stopRouteDirection;
}
Aggregations