Search in sources :

Example 1 with AgencyBean

use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.

the class AgencyBeanServiceImpl method getAgencyForId.

@Cacheable
public AgencyBean getAgencyForId(String id) {
    AgencyNarrative agency = _narrativeService.getAgencyForId(id);
    if (agency == null)
        return null;
    AgencyBean bean = new AgencyBean();
    bean.setId(id);
    bean.setLang(agency.getLang());
    bean.setName(agency.getName());
    bean.setPhone(agency.getPhone());
    bean.setEmail(agency.getEmail());
    bean.setTimezone(agency.getTimezone());
    bean.setUrl(agency.getUrl());
    bean.setDisclaimer(agency.getDisclaimer());
    bean.setPrivateService(agency.isPrivateService());
    bean.setFareUrl(agency.getFareUrl());
    bean.setEmail(agency.getEmail());
    return bean;
}
Also used : AgencyNarrative(org.onebusaway.transit_data_federation.model.narrative.AgencyNarrative) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 2 with AgencyBean

use of org.onebusaway.transit_data.model.AgencyBean 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);
}
Also used : Builder(org.onebusaway.transit_data.model.RouteBean.Builder) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) Before(org.junit.Before)

Example 3 with AgencyBean

use of org.onebusaway.transit_data.model.AgencyBean 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);
}
Also used : NaturalLanguageStringStructure(uk.org.siri.siri_2.NaturalLanguageStringStructure) LineDirectionStructure(uk.org.siri.siri_2.LineDirectionStructure) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Builder(org.onebusaway.transit_data.model.RouteBean.Builder) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Matchers.anyString(org.mockito.Matchers.anyString) LocationStructure(uk.org.siri.siri_2.LocationStructure) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Filters(org.onebusaway.api.actions.siri.impl.SiriSupportV2.Filters) ArrayList(java.util.ArrayList) List(java.util.List) StopPointRefStructure(uk.org.siri.siri_2.StopPointRefStructure) AgencyBean(org.onebusaway.transit_data.model.AgencyBean) PrintWriter(java.io.PrintWriter) AnnotatedStopPointStructure(uk.org.siri.siri_2.AnnotatedStopPointStructure) LineRefStructure(uk.org.siri.siri_2.LineRefStructure) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) DetailLevel(org.onebusaway.api.actions.siri.model.DetailLevel) SiriXmlSerializerV2(org.onebusaway.transit_data_federation.siri.SiriXmlSerializerV2) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) DirectionRefStructure(uk.org.siri.siri_2.DirectionRefStructure) CoordinateBounds(org.onebusaway.geospatial.model.CoordinateBounds) Before(org.junit.Before)

Example 4 with AgencyBean

use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesAction method buildPredictedArrivals.

protected void buildPredictedArrivals(List<ArrivalAndDepartureBean> arrivals, List<StopBean> list) {
    if (arrivals.isEmpty()) {
        addMessage(Messages.ARRIVAL_INFO_NO_SCHEDULED_ARRIVALS);
    }
    Collections.sort(arrivals, new ArrivalAndDepartureComparator());
    long now = SystemTime.currentTimeMillis();
    boolean hasAlerts = stopsHaveAlerts(list);
    for (ArrivalAndDepartureBean adb : arrivals) {
        TripBean trip = adb.getTrip();
        RouteBean route = trip.getRoute();
        addMessage(Messages.ROUTE);
        String routeNumber = RoutePresenter.getNameForRoute(route);
        addText(_routeNumberPronunciation.modify(routeNumber));
        addText(", ");
        String headsign = trip.getTripHeadsign();
        if (headsign != null) {
            // addMessage(Messages.TO);
            String destination = _destinationPronunciation.modify(headsign);
            destination = destination.replaceAll("\\&", "and");
            addText(destination);
            addText(", ");
        }
        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.");
        }
        addText(". ");
        if (!hasAlerts && adb.getSituations() != null && adb.getSituations().size() > 0) {
            hasAlerts = true;
        }
    }
    if (hasAlerts) {
        addText(getAlertPresentText());
    }
    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(",");
        }
    }
    addMessage(Messages.STOP_FOUND_BOOKMARK_THIS_LOCATION);
}
Also used : RouteBean(org.onebusaway.transit_data.model.RouteBean) ArrivalAndDepartureComparator(org.onebusaway.presentation.impl.ArrivalAndDepartureComparator) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) Date(java.util.Date) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 5 with AgencyBean

use of org.onebusaway.transit_data.model.AgencyBean in project onebusaway-application-modules by camsys.

the class AgencyPresenter method getAgenciesForArrivalAndDepartures.

public static List<AgencyBean> getAgenciesForArrivalAndDepartures(List<ArrivalAndDepartureBean> arrivalsAndDepartures) {
    Map<String, AgencyBean> agenciesById = new HashMap<String, AgencyBean>();
    for (ArrivalAndDepartureBean aad : arrivalsAndDepartures) {
        AgencyBean agency = aad.getTrip().getRoute().getAgency();
        agenciesById.put(agency.getId(), agency);
    }
    List<AgencyBean> agencies = new ArrayList<AgencyBean>();
    agencies.addAll(agenciesById.values());
    Collections.sort(agencies, _agencyNameComparator);
    return agencies;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Aggregations

AgencyBean (org.onebusaway.transit_data.model.AgencyBean)12 RouteBean (org.onebusaway.transit_data.model.RouteBean)6 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)4 HashMap (java.util.HashMap)3 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)3 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)3 Date (java.util.Date)2 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ArrivalAndDepartureComparator (org.onebusaway.presentation.impl.ArrivalAndDepartureComparator)2 AgencyWithCoverageBean (org.onebusaway.transit_data.model.AgencyWithCoverageBean)2 NameBean (org.onebusaway.transit_data.model.NameBean)2 Builder (org.onebusaway.transit_data.model.RouteBean.Builder)2 StopBean (org.onebusaway.transit_data.model.StopBean)2 TripBean (org.onebusaway.transit_data.model.trips.TripBean)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2