Search in sources :

Example 1 with TimeRangeBean

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

the class AlertsAction method fillActiveWindows.

private void fillActiveWindows(Alert.Builder alert, List<TimeRangeBean> activeWindows) {
    if (activeWindows != null) {
        for (TimeRangeBean range : activeWindows) {
            com.google.transit.realtime.GtfsRealtime.TimeRange.Builder timeRange = com.google.transit.realtime.GtfsRealtime.TimeRange.newBuilder();
            // TODO - check to see what valid ranges are
            // if (range.getFrom() > 0)
            timeRange.setStart(range.getFrom());
            if (range.getTo() <= 0)
                timeRange.setEnd(Long.MAX_VALUE);
            alert.addActivePeriod(timeRange);
        }
    }
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)

Example 2 with TimeRangeBean

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

the class MessagesAction method getMessagesForRoute.

private List<Message> getMessagesForRoute(String agencyId, String routeId) {
    List<Message> messageList = new ArrayList<Message>();
    ListBean<ServiceAlertBean> serviceAlertBeans = getAllSituations(agencyId, routeId);
    serviceAlerts: for (ServiceAlertBean serviceAlert : serviceAlertBeans.getList()) {
        if (serviceAlert.getActiveWindows() != null) {
            long currentTime = SystemTime.currentTimeMillis();
            for (TimeRangeBean timerange : serviceAlert.getActiveWindows()) {
                if (timerange.getFrom() < currentTime || timerange.getTo() < currentTime) {
                    continue serviceAlerts;
                }
            }
        }
        Message message = new Message();
        message.setId(serviceAlert.getId());
        message.setCreator(serviceAlert.getSource());
        // message.setEndBoundaryStr(serviceAlert.getPublicationWindows().toString());
        String messageText = "";
        for (NaturalLanguageStringBean description : serviceAlert.getDescriptions()) {
            messageText += description.getValue();
        }
        message.setMessageText(new MessageText(messageText));
        messageList.add(message);
    }
    return messageList;
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) Message(org.onebusaway.nextbus.model.nextbus.Message) NaturalLanguageStringBean(org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean) ArrayList(java.util.ArrayList) MessageText(org.onebusaway.nextbus.model.nextbus.MessageText) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 3 with TimeRangeBean

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

the class AlertsForAgencyActionTest method test.

@Test
public void test() {
    long now = System.currentTimeMillis();
    List<ServiceAlertBean> alerts = new ArrayList<ServiceAlertBean>();
    {
        ServiceAlertBean alert = new ServiceAlertBean();
        alerts.add(alert);
        TimeRangeBean range = new TimeRangeBean(1234 * 1000, 5678 * 1000);
        alert.setActiveWindows(Arrays.asList(range));
        SituationAffectsBean affects = new SituationAffectsBean();
        affects.setAgencyId("1");
        affects.setRouteId("1_r0");
        affects.setStopId("1_s0");
        affects.setTripId("1_t0");
        SituationAffectsBean alsoAffects = new SituationAffectsBean();
        alsoAffects.setAgencyId("2");
        alert.setAllAffects(Arrays.asList(affects, alsoAffects));
        alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en"), new NaturalLanguageStringBean("Nombre", "es")));
        alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en"), new NaturalLanguageStringBean("DescripciĆ³n", "es")));
    }
    {
        ServiceAlertBean alert = new ServiceAlertBean();
        alerts.add(alert);
        TimeRangeBean range = new TimeRangeBean(5678 * 1000, 1234 * 1000);
        alert.setActiveWindows(Arrays.asList(range));
        SituationAffectsBean affects = new SituationAffectsBean();
        affects.setAgencyId("2");
        affects.setRouteId("1_r1");
        affects.setStopId("1_s1");
        affects.setTripId("1_t1");
        alert.setAllAffects(Arrays.asList(affects));
        alert.setSummaries(Arrays.asList(new NaturalLanguageStringBean("Name", "en")));
        alert.setDescriptions(Arrays.asList(new NaturalLanguageStringBean("Description", "en")));
    }
    ListBean<ServiceAlertBean> bean = new ListBean<ServiceAlertBean>();
    bean.setList(alerts);
    Mockito.when(_service.getAllServiceAlertsForAgencyId("1")).thenReturn(bean);
    _action.setId("1");
    _action.setTime(new Date(now));
    _action.show();
    ResponseBean model = _action.getModel();
    FeedMessage feed = (FeedMessage) model.getData();
    assertEquals(now / 1000, feed.getHeader().getTimestamp());
    assertEquals(2, feed.getEntityCount());
    {
        FeedEntity entity = feed.getEntity(0);
        assertEquals("1", entity.getId());
        Alert alert = entity.getAlert();
        assertEquals(1, alert.getActivePeriodCount());
        TimeRange range = alert.getActivePeriod(0);
        assertEquals(1234, range.getStart());
        assertEquals(5678, range.getEnd());
        assertEquals(2, alert.getInformedEntityCount());
        {
            EntitySelector affects = alert.getInformedEntity(0);
            assertEquals("1", affects.getAgencyId());
            assertEquals("r0", affects.getRouteId());
            assertEquals("t0", affects.getTrip().getTripId());
            assertEquals("s0", affects.getStopId());
        }
        {
            EntitySelector affects = alert.getInformedEntity(1);
            assertEquals("2", affects.getAgencyId());
        }
        TranslatedString header = alert.getHeaderText();
        assertEquals(2, header.getTranslationCount());
        {
            Translation translation = header.getTranslation(0);
            assertEquals("Name", translation.getText());
            assertEquals("en", translation.getLanguage());
        }
        {
            Translation translation = header.getTranslation(1);
            assertEquals("Nombre", translation.getText());
            assertEquals("es", translation.getLanguage());
        }
        TranslatedString description = alert.getDescriptionText();
        assertEquals(2, description.getTranslationCount());
        {
            Translation translation = description.getTranslation(0);
            assertEquals("Description", translation.getText());
            assertEquals("en", translation.getLanguage());
        }
        {
            Translation translation = description.getTranslation(1);
            assertEquals("DescripciĆ³n", translation.getText());
            assertEquals("es", translation.getLanguage());
        }
    }
    {
        FeedEntity entity = feed.getEntity(1);
        assertEquals("2", entity.getId());
        Alert alert = entity.getAlert();
        assertEquals(1, alert.getActivePeriodCount());
        TimeRange range = alert.getActivePeriod(0);
        assertEquals(5678, range.getStart());
        assertEquals(1234, range.getEnd());
        assertEquals(1, alert.getInformedEntityCount());
        {
            EntitySelector affects = alert.getInformedEntity(0);
            assertEquals("2", affects.getAgencyId());
            assertEquals("r1", affects.getRouteId());
            assertEquals("t1", affects.getTrip().getTripId());
            assertEquals("s1", affects.getStopId());
        }
    }
}
Also used : TranslatedString(com.google.transit.realtime.GtfsRealtime.TranslatedString) EntitySelector(com.google.transit.realtime.GtfsRealtime.EntitySelector) Translation(com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) Date(java.util.Date) TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) TimeRange(com.google.transit.realtime.GtfsRealtime.TimeRange) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) NaturalLanguageStringBean(org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean) ResponseBean(org.onebusaway.api.model.ResponseBean) Alert(com.google.transit.realtime.GtfsRealtime.Alert) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) Test(org.junit.Test)

Example 4 with TimeRangeBean

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

the class ServiceAlertAction method setEndDate.

public void setEndDate(Date endDate) {
    List<TimeRangeBean> publicationWindows = _model.getPublicationWindows();
    if (publicationWindows == null) {
        publicationWindows = new ArrayList<TimeRangeBean>();
        _model.setPublicationWindows(publicationWindows);
    }
    if (publicationWindows.isEmpty()) {
        publicationWindows.add(new TimeRangeBean());
    }
    TimeRangeBean timeRangeBean = publicationWindows.get(0);
    if (endDate != null) {
        timeRangeBean.setTo(endDate.getTime());
    } else {
        timeRangeBean.setTo(0);
    }
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)

Example 5 with TimeRangeBean

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

the class ServiceAlertAction method getEndDate.

public String getEndDate() {
    List<TimeRangeBean> publicationWindows = _model.getPublicationWindows();
    if (publicationWindows == null || publicationWindows.isEmpty() || publicationWindows.get(0).getTo() == 0) {
        return null;
    }
    Date date = new Date(publicationWindows.get(0).getTo());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    return sdf.format(date);
}
Also used : TimeRangeBean(org.onebusaway.transit_data.model.service_alerts.TimeRangeBean) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)15 Date (java.util.Date)5 SimpleDateFormat (java.text.SimpleDateFormat)4 ArrayList (java.util.ArrayList)4 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)3 SituationAffectsBean (org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean)3 Alert (com.google.transit.realtime.GtfsRealtime.Alert)2 EntitySelector (com.google.transit.realtime.GtfsRealtime.EntitySelector)2 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)2 TimeRange (com.google.transit.realtime.GtfsRealtime.TimeRange)2 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)2 FeedMessage (com.google.transit.realtime.GtfsRealtime.FeedMessage)1 TranslatedString (com.google.transit.realtime.GtfsRealtime.TranslatedString)1 Translation (com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation)1 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 Test (org.junit.Test)1 ResponseBean (org.onebusaway.api.model.ResponseBean)1 SituationAffectsV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationAffectsV2Bean)1 SituationConsequenceV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationConsequenceV2Bean)1 SituationV2Bean (org.onebusaway.api.model.transit.service_alerts.SituationV2Bean)1