use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImplTest method testGetRouteForId.
@Test
public void testGetRouteForId() {
AgencyAndId routeId = new AgencyAndId("1", "route");
RouteCollectionNarrative.Builder routeBuilder = RouteCollectionNarrative.builder();
routeBuilder.setColor("blue");
routeBuilder.setDescription("route desc");
routeBuilder.setLongName("route long name");
routeBuilder.setShortName("route short name");
routeBuilder.setTextColor("red");
routeBuilder.setType(3);
routeBuilder.setUrl("http://wwww.route.com");
RouteCollectionNarrative route = routeBuilder.create();
AgencyBean agency = new AgencyBean();
Mockito.when(_agencyBeanService.getAgencyForId("1")).thenReturn(agency);
Mockito.when(_narrativeService.getRouteCollectionForId(routeId)).thenReturn(route);
RouteBean bean = _service.getRouteForId(routeId);
assertEquals(route.getColor(), bean.getColor());
assertEquals(route.getDescription(), bean.getDescription());
assertEquals(AgencyAndIdLibrary.convertToString(routeId), bean.getId());
assertEquals(route.getLongName(), bean.getLongName());
assertEquals(route.getShortName(), bean.getShortName());
assertEquals(route.getTextColor(), bean.getTextColor());
assertEquals(route.getType(), bean.getType());
assertEquals(route.getUrl(), bean.getUrl());
}
use of org.onebusaway.transit_data.model.AgencyBean 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.AgencyBean in project onebusaway-application-modules by camsys.
the class PreCacheTask method run.
@Override
public void run() {
// Clear all existing cache elements
for (String cacheName : _cacheManager.getCacheNames()) {
Cache cache = _cacheManager.getCache(cacheName);
cache.removeAll();
}
try {
List<AgencyWithCoverageBean> agenciesWithCoverage = _service.getAgenciesWithCoverage();
for (AgencyWithCoverageBean agencyWithCoverage : agenciesWithCoverage) {
AgencyBean agency = agencyWithCoverage.getAgency();
System.out.println("agency=" + agency.getId());
ListBean<String> stopIds = _service.getStopIdsForAgencyId(agency.getId());
for (String stopId : stopIds.getList()) {
System.out.println(" stop=" + stopId);
_service.getStop(stopId);
}
ListBean<String> routeIds = _service.getRouteIdsForAgencyId(agency.getId());
for (String routeId : routeIds.getList()) {
System.out.println(" route=" + routeId);
_service.getStopsForRoute(routeId);
}
}
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
for (TripEntry trip : _transitGraphDao.getAllTrips()) {
AgencyAndId shapeId = trip.getShapeId();
if (shapeId != null && shapeId.hasValues())
shapeIds.add(shapeId);
}
for (AgencyAndId shapeId : shapeIds) {
System.out.println("shape=" + shapeId);
_service.getShapeForId(AgencyAndIdLibrary.convertToString(shapeId));
}
} catch (ServiceException ex) {
_log.error("service exception", ex);
}
}
use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.
the class ScheduleAction method getModel.
@Override
public Body<ScheduleRoute> getModel() {
Body<ScheduleRoute> body = new Body<ScheduleRoute>();
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
if (this.isValid(body, routeIds)) {
AgencyBean agency = _transitDataService.getAgency(agencyId);
List<HashMap<String, HashSet<ScheduleStop>>> blockStopsMapList = new ArrayList<HashMap<String, HashSet<ScheduleStop>>>();
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
blockStopsMapList.add(new HashMap<String, HashSet<ScheduleStop>>());
// Get All the Stops for a specific route
for (AgencyAndId routeId : routeIds) {
String route = AgencyAndId.convertToString(routeId);
StopsForRouteBean stopsForRoute = _service.getStopsForRoute(route);
for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
// Weekday Trips
for (Long weekdayTime : DateUtil.getWeekdayDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekdayTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(0), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(1), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
// Weekend Trips
for (Long weekendTime : DateUtil.getWeekendDateTimes(agency.getTimezone())) {
ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
query.setTime(weekendTime);
query.setMinutesBefore(0);
query.setMinutesAfter(MINUTES_IN_DAY);
StopsWithArrivalsAndDeparturesBean stopsWithArrivals = _service.getStopsWithArrivalsAndDepartures(stopGroupBean.getStopIds(), query);
for (ArrivalAndDepartureBean arrivalsAndDeparture : stopsWithArrivals.getArrivalsAndDepartures()) {
// Filter Arrivals and Departures By Route
if (arrivalsAndDeparture.getTrip().getRoute().getId().equals(route)) {
ScheduleStop scheduleStop = new ScheduleStop();
scheduleStop.setTag(getIdNoAgency(arrivalsAndDeparture.getStop().getId()));
scheduleStop.setEpochTime(arrivalsAndDeparture.getScheduledArrivalTime());
scheduleStop.setStopName(arrivalsAndDeparture.getStop().getName());
if (arrivalsAndDeparture.getTrip().getDirectionId().equals("0")) {
addStopByBlockId(blockStopsMapList.get(2), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
} else if (arrivalsAndDeparture.getTrip().getDirectionId().equals("1")) {
addStopByBlockId(blockStopsMapList.get(3), arrivalsAndDeparture.getTrip().getBlockId(), scheduleStop);
}
}
}
}
}
}
// Routes
for (int n = 0; n < blockStopsMapList.size(); n++) {
HashMap<String, HashSet<ScheduleStop>> blockStopsMap = blockStopsMapList.get(n);
ScheduleRoute scheduleRoute = new ScheduleRoute();
scheduleRoute.setTitle(stopsForRoute.getRoute().getLongName());
scheduleRoute.setDirection(Integer.toString(n % 2));
scheduleRoute.setTag(getIdNoAgency(stopsForRoute.getRoute().getId()));
scheduleRoute.setServiceClass(n < 3 ? "wkd" : "wkend");
// Blocks
for (Entry<String, HashSet<ScheduleStop>> entry : blockStopsMap.entrySet()) {
int tripStopTimeCounter = 0;
String blockId = entry.getKey();
HashSet<ScheduleStop> blockStops = entry.getValue();
ScheduleTableRow scheduleTr = new ScheduleTableRow(getIdNoAgency(blockId));
// Stop Times
for (ScheduleStop stop : blockStops) {
if (tripStopTimeCounter == 0) {
DisplayStop displayStop = new DisplayStop();
displayStop.setTag(stop.getTag());
displayStop.setValue(stop.getStopName());
scheduleRoute.getStops().add(displayStop);
}
// scheduleStop.setValue(value);
scheduleTr.getStops().add(stop);
}
scheduleRoute.getScheduleTableRow().add(scheduleTr);
}
body.getResponse().add(scheduleRoute);
}
}
}
return body;
}
use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.
the class StopScheduleServiceImpl method getAllServiceIdsForStop.
private Set<ServiceIdActivation> getAllServiceIdsForStop(StopEntry stop, boolean includePrivateService) {
Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
for (BlockStopTimeIndex index : indices) allServiceIds.add(index.getServiceIds());
List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
for (FrequencyBlockStopTimeIndex index : frequencyIndices) allServiceIds.add(index.getServiceIds());
for (Iterator<ServiceIdActivation> it = allServiceIds.iterator(); it.hasNext(); ) {
ServiceIdActivation activation = it.next();
LocalizedServiceId lsid = activation.getActiveServiceIds().get(0);
String agencyId = lsid.getId().getAgencyId();
AgencyBean bean = _agencyBeanService.getAgencyForId(agencyId);
if (bean.isPrivateService() && !includePrivateService)
it.remove();
}
return allServiceIds;
}
Aggregations