Search in sources :

Example 1 with Message

use of org.onebusaway.nextbus.model.nextbus.Message 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 2 with Message

use of org.onebusaway.nextbus.model.nextbus.Message in project onebusaway-application-modules by camsys.

the class MessagesAction method getModel.

@Override
public Body<Message> getModel() {
    Body<Message> body = new Body<Message>();
    List<String> agencyIds = processAgencyIds(getA());
    List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
    if (processRouteIds(routeId, routeIds, agencyIds, body)) {
        for (AgencyAndId routeId : routeIds) {
            body.getResponse().addAll(getMessagesForRoute(agencyId, routeId.toString()));
        }
    }
    return body;
}
Also used : Message(org.onebusaway.nextbus.model.nextbus.Message) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) Body(org.onebusaway.nextbus.model.nextbus.Body)

Aggregations

ArrayList (java.util.ArrayList)2 Message (org.onebusaway.nextbus.model.nextbus.Message)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 Body (org.onebusaway.nextbus.model.nextbus.Body)1 MessageText (org.onebusaway.nextbus.model.nextbus.MessageText)1 NaturalLanguageStringBean (org.onebusaway.transit_data.model.service_alerts.NaturalLanguageStringBean)1 ServiceAlertBean (org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)1 TimeRangeBean (org.onebusaway.transit_data.model.service_alerts.TimeRangeBean)1