Search in sources :

Example 31 with ServiceAlertBean

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

the class NotifyResource method tweetServiceAlert.

@GET
@Produces("application/json")
public Response tweetServiceAlert(@QueryParam("serviceAlertId") String serviceAlertId) {
    // construct a short message based on the contents of the service alert
    ServiceAlertBean serviceAlertBean = null;
    try {
        serviceAlertBean = _transitDataService.getServiceAlertForId(serviceAlertId);
        return Response.serverError().build();
    } catch (Exception any) {
        _log.error("retrieval of service alert failed!", any);
    }
    String tweet = toTweet(serviceAlertBean);
    String responseJson = null;
    try {
        responseJson = _notificationService.tweet(tweet);
    } catch (IOException ioe) {
        _log.error("tweet failed!", ioe);
        return Response.serverError().build();
    }
    return Response.ok(responseJson).build();
}
Also used : IOException(java.io.IOException) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) IOException(java.io.IOException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with ServiceAlertBean

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

the class VehicleMonitoringActionTest method testExecuteByRouteNoActivity.

@Test
public void testExecuteByRouteNoActivity() throws Exception {
    when(request.getParameter(eq("LineRef"))).thenReturn("40_100479");
    when(request.getParameter(eq("OperatorRef"))).thenReturn("1");
    PrintWriter nothingPrintWriter = new PrintWriter(new OutputStream() {

        @Override
        public void write(int b) throws IOException {
        // Do nothing
        }
    });
    when(servletResponse.getWriter()).thenReturn(nothingPrintWriter);
    List<VehicleActivityStructure> vehicleActivities = new ArrayList<VehicleActivityStructure>();
    when(realtimeService.getVehicleActivityForRoute(eq("40_100479"), anyString(), eq(0), anyLong(), eq(false))).thenReturn(vehicleActivities);
    ServiceAlertBean serviceAlertBean = ServiceAlertsTestSupport.createServiceAlertBean("1_1");
    when(transitDataService.getServiceAlertForId(anyString())).thenReturn(serviceAlertBean);
    RouteBean routeBean = RouteBean.builder().create();
    when(transitDataService.getRouteForId(anyString())).thenReturn(routeBean);
    ListBean<ServiceAlertBean> serviceAlertListBean = new ListBean<ServiceAlertBean>();
    List<ServiceAlertBean> list = new ArrayList<ServiceAlertBean>();
    list.add(serviceAlertBean);
    serviceAlertListBean.setList(list);
    when(transitDataService.getServiceAlerts(any(SituationQueryBean.class))).thenReturn(serviceAlertListBean);
    SiriXmlSerializer serializer = new SiriXmlSerializer();
    when(realtimeService.getSiriXmlSerializer()).thenReturn(serializer);
    action.setServletRequest(request);
    action.setServletResponse(servletResponse);
    action.index();
    String monitoring = action.getVehicleMonitoring();
    assertTrue("Result XML does not match expected", monitoring.matches("(?s).*<SituationExchangeDelivery><Situations><PtSituationElement><SituationNumber>1_1</SituationNumber><Summary xml:lang=\"EN\">summary</Summary><Description xml:lang=\"EN\">description</Description><Affects><VehicleJourneys><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100277</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>0</DirectionRef></AffectedVehicleJourney><AffectedVehicleJourney><LineRef>1_100194</LineRef><DirectionRef>1</DirectionRef></AffectedVehicleJourney></VehicleJourneys></Affects></PtSituationElement></Situations></SituationExchangeDelivery></ServiceDelivery></Siri>.*"));
}
Also used : OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) IOException(java.io.IOException) Matchers.anyString(org.mockito.Matchers.anyString) RouteBean(org.onebusaway.transit_data.model.RouteBean) SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) SiriXmlSerializer(org.onebusaway.transit_data_federation.siri.SiriXmlSerializer) VehicleActivityStructure(uk.org.siri.siri.VehicleActivityStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 33 with ServiceAlertBean

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

the class AbstractSearchResultFactoryImpl method populateServiceAlerts.

protected void populateServiceAlerts(Set<String> serviceAlertDescriptions, List<ServiceAlertBean> serviceAlertBeans, boolean htmlizeNewlines) {
    if (serviceAlertBeans == null)
        return;
    for (ServiceAlertBean serviceAlertBean : serviceAlertBeans) {
        boolean descriptionsAdded = false;
        descriptionsAdded = setDescription(serviceAlertDescriptions, serviceAlertBean.getDescriptions(), htmlizeNewlines) || setDescription(serviceAlertDescriptions, serviceAlertBean.getSummaries(), htmlizeNewlines);
        if (!descriptionsAdded) {
            serviceAlertDescriptions.add("(no description)");
        }
    }
}
Also used : ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 34 with ServiceAlertBean

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

the class ServiceAlertsHelper method addSituationExchangeToServiceDelivery.

public void addSituationExchangeToServiceDelivery(ServiceDelivery serviceDelivery, Collection<ServiceAlertBean> serviceAlerts) {
    Situations situations = new Situations();
    for (ServiceAlertBean serviceAlert : serviceAlerts) {
        situations.getPtSituationElement().add(getServiceAlertBeanAsPtSituationElementStructure(serviceAlert));
    }
    if (situations.getPtSituationElement().size() > 0) {
        SituationExchangeDeliveryStructure situationExchangeDelivery = new SituationExchangeDeliveryStructure();
        situationExchangeDelivery.setSituations(situations);
        serviceDelivery.getSituationExchangeDelivery().add(situationExchangeDelivery);
    }
}
Also used : SituationExchangeDeliveryStructure(uk.org.siri.siri.SituationExchangeDeliveryStructure) Situations(uk.org.siri.siri.SituationExchangeDeliveryStructure.Situations) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 35 with ServiceAlertBean

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

the class ServiceAlertsHelper method addFromQuery.

private void addFromQuery(TransitDataService nycTransitDataService, Map<String, PtSituationElementStructure> ptSituationElements, SituationQueryBean queryBean) {
    ListBean<ServiceAlertBean> serviceAlerts = nycTransitDataService.getServiceAlerts(queryBean);
    ServiceAlertsHelper helper = new ServiceAlertsHelper();
    for (ServiceAlertBean bean : serviceAlerts.getList()) {
        PtSituationElementStructure ptSit = helper.getServiceAlertBeanAsPtSituationElementStructure(bean);
        ptSituationElements.put(ptSit.getSituationNumber().getValue(), ptSit);
    }
}
Also used : PtSituationElementStructure(uk.org.siri.siri.PtSituationElementStructure) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Aggregations

ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)54 ArrayList (java.util.ArrayList)22 SituationQueryBean (org.onebusaway.transit_data.model.service_alerts.SituationQueryBean)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)8 StopBean (org.onebusaway.transit_data.model.StopBean)8 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)8 HashMap (java.util.HashMap)7 List (java.util.List)5 RouteBean (org.onebusaway.transit_data.model.RouteBean)5 TripBean (org.onebusaway.transit_data.model.trips.TripBean)5 Test (org.junit.Test)4 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)4 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)4 PtSituationElementStructure (uk.org.siri.siri.PtSituationElementStructure)4 PtSituationElementStructure (uk.org.siri.siri_2.PtSituationElementStructure)4 HashSet (java.util.HashSet)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)3 BlockTripBean (org.onebusaway.transit_data.model.blocks.BlockTripBean)3 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)3