use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class BeanFactoryV2 method getTripStatus.
public TripStatusV2Bean getTripStatus(TripStatusBean tripStatus) {
TripStatusV2Bean bean = new TripStatusV2Bean();
TripBean activeTrip = tripStatus.getActiveTrip();
if (activeTrip != null) {
bean.setActiveTripId(activeTrip.getId());
bean.setBlockTripSequence(tripStatus.getBlockTripSequence());
addToReferences(activeTrip);
}
bean.setServiceDate(tripStatus.getServiceDate());
FrequencyBean frequency = tripStatus.getFrequency();
if (frequency != null)
bean.setFrequency(getFrequency(frequency));
bean.setScheduledDistanceAlongTrip(tripStatus.getScheduledDistanceAlongTrip());
bean.setTotalDistanceAlongTrip(tripStatus.getTotalDistanceAlongTrip());
bean.setPosition(tripStatus.getLocation());
if (tripStatus.isOrientationSet())
bean.setOrientation(tripStatus.getOrientation());
StopBean closestStop = tripStatus.getClosestStop();
if (closestStop != null) {
bean.setClosestStop(closestStop.getId());
addToReferences(closestStop);
bean.setClosestStopTimeOffset(tripStatus.getClosestStopTimeOffset());
}
StopBean nextStop = tripStatus.getNextStop();
if (nextStop != null) {
bean.setNextStop(nextStop.getId());
addToReferences(nextStop);
bean.setNextStopTimeOffset(tripStatus.getNextStopTimeOffset());
}
bean.setPhase(tripStatus.getPhase());
bean.setStatus(tripStatus.getStatus());
bean.setPredicted(tripStatus.isPredicted());
if (tripStatus.getLastUpdateTime() > 0)
bean.setLastUpdateTime(tripStatus.getLastUpdateTime());
if (tripStatus.getLastLocationUpdateTime() > 0)
bean.setLastLocationUpdateTime(tripStatus.getLastLocationUpdateTime());
if (tripStatus.isLastKnownDistanceAlongTripSet())
bean.setLastKnownDistanceAlongTrip(tripStatus.getLastKnownDistanceAlongTrip());
bean.setLastKnownLocation(tripStatus.getLastKnownLocation());
if (tripStatus.isLastKnownOrientationSet())
bean.setLastKnownOrientation(tripStatus.getLastKnownOrientation());
if (tripStatus.isScheduleDeviationSet())
bean.setScheduleDeviation((int) tripStatus.getScheduleDeviation());
if (tripStatus.isDistanceAlongTripSet())
bean.setDistanceAlongTrip(tripStatus.getDistanceAlongTrip());
bean.setVehicleId(tripStatus.getVehicleId());
List<ServiceAlertBean> situations = tripStatus.getSituations();
if (situations != null && !situations.isEmpty()) {
List<String> situationIds = new ArrayList<String>();
for (ServiceAlertBean situation : situations) {
situationIds.add(situation.getId());
addToReferences(situation);
}
bean.setSituationIds(situationIds);
}
return bean;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class StopByNumberAction method execute.
@Override
public String execute() throws ServiceException {
if (_text != null)
_text.trim();
if (_text == null || _text.length() == 0)
return INPUT;
String[] tokens = _text.trim().split("\\s+");
if (tokens.length == 0)
return INPUT;
CoordinateBounds serviceArea = _serviceAreaService.getServiceArea();
if (serviceArea == null) {
pushNextAction("stop-by-number", "text", _text);
return "query-default-search-location";
}
_stopQuery = tokens[0];
SearchQueryBean searchQuery = new SearchQueryBean();
searchQuery.setBounds(serviceArea);
searchQuery.setMaxCount(5);
searchQuery.setType(EQueryType.BOUNDS_OR_CLOSEST);
searchQuery.setQuery(_stopQuery);
StopsBean results = _transitDataService.getStops(searchQuery);
_stops = results.getStops();
int stopIndex = 0;
if (_stops.isEmpty()) {
return "noStopsFound";
} else if (_stops.size() > 1) {
if (0 <= _selectedIndex && _selectedIndex < _stops.size()) {
stopIndex = _selectedIndex;
} else {
pushNextAction("stop-by-number", "text", _text);
pushNextAction("handle-multi-selection");
return "multipleStopsFound";
}
}
StopBean stop = _stops.get(stopIndex);
_stopId = stop.getId();
_args = new String[tokens.length - 1];
System.arraycopy(tokens, 1, _args, 0, _args.length);
return "arrivals-and-departures";
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method isValid.
private boolean isValid(Body<Predictions> body) {
if (!isValidAgency(body, agencyId)) {
return false;
}
if (stops == null) {
body.getErrors().add(new BodyError(ErrorMsg.STOP_STOPS_NULL.getDescription()));
return false;
}
for (String stop : stops) {
String[] stopArray = stop.split("\\|");
if (stopArray.length < 2) {
String error = "The stop " + stop + " is invalid because it did not contain a route, optional dir, and stop tag";
body.getErrors().add(new BodyError(error));
return false;
}
try {
String stopId = _tdsMappingService.getStopIdFromStopCode(stopArray[1]);
StopBean stopBean;
try {
stopBean = _transitDataService.getStop(stopId);
} catch (ServiceException se) {
// The user didn't provide an agency id in stopId, so use provided
// agency
String stopIdVal = new AgencyAndId(agencyId, stopId).toString();
stopBean = _transitDataService.getStop(stopIdVal);
}
boolean routeExists = false;
for (RouteBean routeBean : stopBean.getRoutes()) {
if (routeBean.getId().equals(_tdsMappingService.getRouteIdFromShortName(stopArray[0]))) {
routeExists = true;
break;
}
}
if (!routeExists) {
String error = "For agency=" + getA() + " route r=" + stopArray[0] + " is not currently available. It might be initializing still.";
body.getErrors().add(new BodyError(error));
return false;
}
String routeTag = getIdNoAgency(_tdsMappingService.getRouteIdFromShortName(stopArray[0]));
String routeStop = getIdNoAgency(_tdsMappingService.getStopIdFromStopCode(stopArray[1]));
mappedStops.add(routeTag + "|" + routeStop);
} catch (ServiceException se) {
String error = "For agency=" + getA() + " stop s=" + stopArray[1] + " is on none of the directions for r=" + stopArray[0] + " so cannot determine which stop to provide data for.";
body.getErrors().add(new BodyError(error));
return false;
}
}
return true;
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class PredictionsForMultiStopsAction method getStopIdParams.
private String getStopIdParams() {
StringBuilder sb = new StringBuilder();
for (String stopId : stops) {
StopBean stopBean = _transitDataService.getStop(stopId);
for (RouteBean routeBean : stopBean.getRoutes()) {
sb.append("rs=");
sb.append(routeBean.getId());
sb.append("|");
sb.append(stopId);
sb.append("&");
}
}
return sb.toString();
}
use of org.onebusaway.transit_data.model.StopBean in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.
/**
**
* {@link ArrivalsAndDeparturesBeanService} Interface
***
*/
@Override
public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(AgencyAndId stopId, ArrivalsAndDeparturesQueryBean query) {
StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
long time = query.getTime();
int minutesBefore = Math.max(query.getMinutesBefore(), query.getFrequencyMinutesBefore());
int minutesAfter = Math.max(query.getMinutesAfter(), query.getFrequencyMinutesAfter());
long fromTime = time - minutesBefore * 60 * 1000;
long toTime = time + minutesAfter * 60 * 1000;
long nonFrequencyFromTime = time - query.getMinutesBefore() * 60 * 1000;
long nonFrequencyToTime = time + query.getMinutesAfter() * 60 * 1000;
long frequencyFromTime = time - query.getFrequencyMinutesBefore() * 60 * 1000;
long frequencyToTime = time + query.getFrequencyMinutesAfter() * 60 * 1000;
TargetTime target = new TargetTime(time, time);
List<ArrivalAndDepartureInstance> instances = _arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stop, target, fromTime, toTime);
List<ArrivalAndDepartureBean> beans = new ArrayList<ArrivalAndDepartureBean>();
Map<AgencyAndId, StopBean> stopBeanCache = new HashMap<AgencyAndId, StopBean>();
for (ArrivalAndDepartureInstance instance : instances) {
FrequencyEntry frequency = instance.getFrequency();
long from = frequency != null ? frequencyFromTime : nonFrequencyFromTime;
long to = frequency != null ? frequencyToTime : nonFrequencyToTime;
if (!isArrivalAndDepartureInRange(instance, from, to))
continue;
ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, stopBeanCache);
applyBlockLocationToBean(instance, bean, time);
Boolean isNegativeScheduledArrivalsEnabled = _gtfsRealtimeNegativeArrivals.getShowNegativeScheduledArrivalByAgencyId(instance.getBlockTrip().getTrip().getId().getAgencyId());
if (isNegativeScheduledArrivalsEnabled != null && !isNegativeScheduledArrivalsEnabled && bean.getNumberOfStopsAway() < 0 && bean.getPredictedArrivalTime() <= 0)
continue;
applySituationsToBean(time, instance, bean);
beans.add(bean);
}
Collections.sort(beans, new ArrivalAndDepartureComparator());
return beans;
}
Aggregations