use of org.onebusaway.transit_data.model.StopGroupBean in project onebusaway-application-modules by camsys.
the class RouteConfigAction method getModel.
@Override
public Body<Route> getModel() {
Body<Route> body = new Body<Route>();
if (isValid(body)) {
List<String> agencyIds = processAgencyIds(agencyId);
List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
List<RouteBean> routeBeans = new ArrayList<RouteBean>();
int routes_count = 1;
if (processRouteIds(routeId, routeIds, agencyIds, body)) {
for (AgencyAndId routeId : routeIds) {
routeBeans.add(_transitDataService.getRouteForId(routeId.toString()));
}
} else if (routeId == null) {
routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
}
Collections.sort(routeBeans, new Comparator<RouteBean>() {
AlphanumComparator alphaComparator = new AlphanumComparator();
public int compare(RouteBean arg0, RouteBean arg1) {
return alphaComparator.compare(arg0.getId(), arg1.getId());
}
});
for (RouteBean routeBean : routeBeans) {
// Limit Number of Routes Returned
if (routes_count > MAX_ROUTES)
break;
Route route = new Route();
route.setTag(getIdNoAgency(routeBean.getId()));
route.setTitle(route.getTag() + " " + routeBean.getLongName());
route.setShortTitle(routeBean.getShortName());
route.setColor(routeBean.getColor());
route.setOppositeColor(routeBean.getTextColor());
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
// Stops
for (StopBean stopBean : stopsForRoute.getStops()) {
Stop stop = new Stop();
stop.setTag(getIdNoAgency(stopBean.getId()));
stop.setTitle(stopBean.getName());
stop.setLat(stopBean.getLat());
stop.setLon(stopBean.getLon());
stop.setStopId(stopBean.getCode());
route.getStops().add(stop);
}
// Directions
for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
Direction direction = new Direction();
direction.setTag(stopGroupBean.getId());
direction.setTitle(stopGroupBean.getName().getName());
for (String stopId : stopGroupBean.getStopIds()) {
direction.getStops().add(new DisplayStop(getIdNoAgency(stopId)));
}
route.getDirections().add(direction);
}
}
// PolyLines
for (EncodedPolylineBean polyline : stopsForRoute.getPolylines()) {
Path path = new Path();
List<CoordinatePoint> coordinatePoints = PolylineEncoder.decode(polyline);
for (CoordinatePoint coordinatePoint : coordinatePoints) {
path.getPoints().add(new Point(coordinatePoint.getLat(), coordinatePoint.getLon()));
}
route.getPaths().add(path);
}
body.getResponse().add(route);
routes_count++;
}
}
return body;
}
use of org.onebusaway.transit_data.model.StopGroupBean in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method sortResult.
private void sortResult(StopsForRouteBean result) {
Collections.sort(result.getStops(), new StopBeanIdComparator());
Collections.sort(result.getStopGroupings(), new Comparator<StopGroupingBean>() {
public int compare(StopGroupingBean o1, StopGroupingBean o2) {
return o1.getType().compareTo(o2.getType());
}
});
for (StopGroupingBean grouping : result.getStopGroupings()) {
Collections.sort(grouping.getStopGroups(), new Comparator<StopGroupBean>() {
public int compare(StopGroupBean o1, StopGroupBean o2) {
return getName(o1).compareTo(getName(o2));
}
private String getName(StopGroupBean bean) {
StringBuilder b = new StringBuilder();
for (String name : bean.getName().getNames()) b.append(name);
return b.toString();
}
});
}
}
use of org.onebusaway.transit_data.model.StopGroupBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceV2Impl method getRouteResult.
private RouteResult getRouteResult(RouteBean routeBean, Map<Filters, String> filters) {
List<RouteDirection> directions = new ArrayList<RouteDirection>();
StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
// Filter Values
String directionIdFilter = filters.get(Filters.DIRECTION_REF);
String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
// create stop ID->stop bean map
Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
for (StopBean stopBean : stopsForRoute.getStops()) {
stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
}
List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
for (StopGroupingBean stopGroupingBean : stopGroupings) {
for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
NameBean name = stopGroupBean.getName();
String type = name.getType();
String directionId = stopGroupBean.getId();
// Destination and DirectionId Filter
if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
continue;
List<String> polylines = new ArrayList<String>();
for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
polylines.add(polyline.getPoints());
}
// TODO - Re-evaluate the best method to determine upcoming scheduled service
Boolean routeHasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), directionId);
// if there are buses on route, always have "scheduled service"
Boolean routeHasVehiclesInService = getVehiclesInServiceForRoute(routeBean.getId(), directionId, SystemTime.currentTimeMillis());
if (routeHasVehiclesInService) {
routeHasUpcomingScheduledService = true;
}
String hasUpcomingScheduledServiceVal = String.valueOf(routeHasUpcomingScheduledService);
// String hasUpcomingScheduledServiceVal = String.valueOf(routeHasVehiclesInService);
if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter) || routeHasUpcomingScheduledService == null || !routeHasUpcomingScheduledService)
continue;
// stops in this direction
List<StopOnRoute> stopsOnRoute = null;
if (!stopGroupBean.getStopIds().isEmpty()) {
stopsOnRoute = new ArrayList<StopOnRoute>();
for (String stopId : stopGroupBean.getStopIds()) {
// service in this direction
StopBean stopBean = stopIdToStopBeanMap.get(stopId);
Boolean stopHasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
stopsOnRoute.add(new StopOnRoute(stopBean, stopHasUpcomingScheduledService));
}
}
directions.add(new RouteDirection(stopGroupBean, polylines, stopsOnRoute, routeHasUpcomingScheduledService));
}
}
return new RouteResult(routeBean, directions);
}
use of org.onebusaway.transit_data.model.StopGroupBean in project onebusaway-application-modules by camsys.
the class RealtimeServiceTest method initialize.
@Before
public void initialize() {
// Agency Bean
AgencyBean agency = new AgencyBean();
agency.setId("1");
// Route Bean
Builder routeBuilder = RouteBean.builder();
routeBuilder.setAgency(agency);
routeBuilder.setId("1_100194");
routeBean = routeBuilder.create();
// Route Bean List
routes = new ArrayList<RouteBean>(1);
routes.add(routeBean);
// Stop Bean
stopBean = new StopBean();
stopBean.setId("1_430");
stopBean.setName("3rd Ave & Pine St");
stopBean.setLon(-122.338662);
stopBean.setLat(47.610813);
stopBean.setRoutes(routes);
// Stop Bean List
stops = new ArrayList<StopBean>(1);
stops.add(stopBean);
// Stop Group
stopIds = new ArrayList<String>(1);
stopIds.add(stopBean.getId());
stopGroupName = new NameBean("destination", "Destination");
stopGroup = new StopGroupBean();
stopGroup.setId("0");
stopGroup.setStopIds(stopIds);
stopGroup.setName(stopGroupName);
// Stop Group List
stopGroups = new ArrayList<StopGroupBean>(1);
stopGroups.add(stopGroup);
// Stop Grouping
stopGrouping = new StopGroupingBean();
stopGrouping.setStopGroups(stopGroups);
// Stop Grouping List
List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
stopGroupings.add(stopGrouping);
// Stops For Route
stopsForRouteBean = new StopsForRouteBean();
stopsForRouteBean.setRoute(routeBean);
stopsForRouteBean.setStopGroupings(stopGroupings);
stopsForRouteBean.setStops(stops);
}
use of org.onebusaway.transit_data.model.StopGroupBean in project onebusaway-application-modules by camsys.
the class StopPointsActionTest method initialize.
@Before
public void initialize() throws Exception {
// Agencies
Map<String, List<CoordinateBounds>> agencies = new HashMap<String, List<CoordinateBounds>>();
agencies.put("1", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.410813, -122.038662, 47.810813, -122.638662))));
agencies.put("3", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(0.0, 0.0, 0.0, 0.0))));
agencies.put("40", new ArrayList<CoordinateBounds>(Arrays.asList(new CoordinateBounds(47.510813, -122.138662, 47.710813, -122.538662))));
// Route Bean
Builder routeBuilder = RouteBean.builder();
routeBuilder.setAgency(new AgencyBean());
routeBuilder.setId("1_100194");
routeBean = routeBuilder.create();
// Route Bean List
routes = new ArrayList<RouteBean>(1);
routes.add(routeBean);
// Stop Bean
stopBean = new StopBean();
stopBean.setId("1_430");
stopBean.setName("3rd Ave & Pine St");
stopBean.setLon(-122.338662);
stopBean.setLat(47.610813);
stopBean.setRoutes(routes);
// Stop Bean List
stops = new ArrayList<StopBean>(1);
stops.add(stopBean);
// Stop Group
stopIds = new ArrayList<String>(1);
stopIds.add(stopBean.getId());
stopGroupName = new NameBean("destination", "Destination");
stopGroup = new StopGroupBean();
stopGroup.setId("0");
stopGroup.setStopIds(stopIds);
stopGroup.setName(stopGroupName);
// Stop Group List
stopGroups = new ArrayList<StopGroupBean>(1);
stopGroups.add(stopGroup);
// Stop Grouping
stopGrouping = new StopGroupingBean();
stopGrouping.setStopGroups(stopGroups);
// Stop Grouping List
List<StopGroupingBean> stopGroupings = new ArrayList<StopGroupingBean>(1);
stopGroupings.add(stopGrouping);
// Stops For Route
stopsForRouteBean = new StopsForRouteBean();
stopsForRouteBean.setRoute(routeBean);
stopsForRouteBean.setStopGroupings(stopGroupings);
stopsForRouteBean.setStops(stops);
// LineDirectionStructure
LineDirectionStructure lds = new LineDirectionStructure();
DirectionRefStructure drs = new DirectionRefStructure();
LineRefStructure lrs = new LineRefStructure();
lds.setDirectionRef(drs);
lds.setLineRef(lrs);
drs.setValue("0");
lrs.setValue("1_100194");
// Location Structure
LocationStructure ls = new LocationStructure();
BigDecimal lat = new BigDecimal(47.610813);
BigDecimal lon = new BigDecimal(-122.338662);
ls.setLongitude(lon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
ls.setLatitude(lat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
// StopNames
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue("3rd Ave & Pine St");
List<NaturalLanguageStringStructure> stopNames = new ArrayList<NaturalLanguageStringStructure>();
stopNames.add(stopName);
// StopPointRef
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue("1_430");
// Monitored
Boolean monitored = true;
// AnnotatedStopPointStructure
AnnotatedStopPointStructure mockStopPoint = new AnnotatedStopPointStructure();
mockStopPoint.setLines(new AnnotatedStopPointStructure.Lines());
mockStopPoint.getLines().getLineRefOrLineDirection().add(lds);
mockStopPoint.setLocation(ls);
mockStopPoint.getStopName().add(stopName);
mockStopPoint.setStopPointRef(stopPointRef);
mockStopPoint.setMonitored(monitored);
List<AnnotatedStopPointStructure> mockStopPoints = new ArrayList<AnnotatedStopPointStructure>(1);
mockStopPoints.add(mockStopPoint);
Map<Boolean, List<AnnotatedStopPointStructure>> annotatedStopPointMap = new HashMap<Boolean, List<AnnotatedStopPointStructure>>();
annotatedStopPointMap.put(true, mockStopPoints);
when(realtimeService.getAnnotatedStopPointStructures(anyListOf(String.class), anyListOf(AgencyAndId.class), any(DetailLevel.class), anyLong(), anyMapOf(Filters.class, String.class))).thenReturn(annotatedStopPointMap);
// XML Serializer
SiriXmlSerializerV2 serializer = new SiriXmlSerializerV2();
when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
// Print Writer
PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {
@Override
public void write(int b) throws IOException {
// Do nothing
}
});
when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
when(transitDataService.getRouteForId("1_430")).thenReturn(routeBean);
when(transitDataService.getStopsForRoute("1_430")).thenReturn(stopsForRouteBean);
when(transitDataService.stopHasUpcomingScheduledService(anyString(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
when(transitDataService.getAgencyIdsWithCoverageArea()).thenReturn(agencies);
}
Aggregations