Search in sources :

Example 46 with ServiceAlertBean

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

the class BeanFactoryV2 method getTripStatus.

public TripStatusV2Bean getTripStatus(TripStatusBean tripStatus) {
    TripStatusV2Bean bean = new TripStatusV2Bean();
    TripBean activeTrip = tripStatus.getActiveTrip();
    if (activeTrip != null) {
        bean.setActiveTripId(activeTrip.getId());
        bean.setBlockTripSequence(tripStatus.getBlockTripSequence());
        addToReferences(activeTrip);
    }
    bean.setServiceDate(tripStatus.getServiceDate());
    FrequencyBean frequency = tripStatus.getFrequency();
    if (frequency != null)
        bean.setFrequency(getFrequency(frequency));
    bean.setScheduledDistanceAlongTrip(tripStatus.getScheduledDistanceAlongTrip());
    bean.setTotalDistanceAlongTrip(tripStatus.getTotalDistanceAlongTrip());
    bean.setPosition(tripStatus.getLocation());
    if (tripStatus.isOrientationSet())
        bean.setOrientation(tripStatus.getOrientation());
    StopBean closestStop = tripStatus.getClosestStop();
    if (closestStop != null) {
        bean.setClosestStop(closestStop.getId());
        addToReferences(closestStop);
        bean.setClosestStopTimeOffset(tripStatus.getClosestStopTimeOffset());
    }
    StopBean nextStop = tripStatus.getNextStop();
    if (nextStop != null) {
        bean.setNextStop(nextStop.getId());
        addToReferences(nextStop);
        bean.setNextStopTimeOffset(tripStatus.getNextStopTimeOffset());
    }
    bean.setPhase(tripStatus.getPhase());
    bean.setStatus(tripStatus.getStatus());
    bean.setPredicted(tripStatus.isPredicted());
    if (tripStatus.getLastUpdateTime() > 0)
        bean.setLastUpdateTime(tripStatus.getLastUpdateTime());
    if (tripStatus.getLastLocationUpdateTime() > 0)
        bean.setLastLocationUpdateTime(tripStatus.getLastLocationUpdateTime());
    if (tripStatus.isLastKnownDistanceAlongTripSet())
        bean.setLastKnownDistanceAlongTrip(tripStatus.getLastKnownDistanceAlongTrip());
    bean.setLastKnownLocation(tripStatus.getLastKnownLocation());
    if (tripStatus.isLastKnownOrientationSet())
        bean.setLastKnownOrientation(tripStatus.getLastKnownOrientation());
    if (tripStatus.isScheduleDeviationSet())
        bean.setScheduleDeviation((int) tripStatus.getScheduleDeviation());
    if (tripStatus.isDistanceAlongTripSet())
        bean.setDistanceAlongTrip(tripStatus.getDistanceAlongTrip());
    bean.setVehicleId(tripStatus.getVehicleId());
    List<ServiceAlertBean> situations = tripStatus.getSituations();
    if (situations != null && !situations.isEmpty()) {
        List<String> situationIds = new ArrayList<String>();
        for (ServiceAlertBean situation : situations) {
            situationIds.add(situation.getId());
            addToReferences(situation);
        }
        bean.setSituationIds(situationIds);
    }
    return bean;
}
Also used : FrequencyBean(org.onebusaway.transit_data.model.schedule.FrequencyBean) ArrayList(java.util.ArrayList) BlockTripBean(org.onebusaway.transit_data.model.blocks.BlockTripBean) TripBean(org.onebusaway.transit_data.model.trips.TripBean) StopBean(org.onebusaway.transit_data.model.StopBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 47 with ServiceAlertBean

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

the class SearchResultFactoryImplTest method createServiceAlerts.

private List<ServiceAlertBean> createServiceAlerts(String[] descriptions, String[] summaries) {
    List<ServiceAlertBean> serviceAlerts = new ArrayList<ServiceAlertBean>();
    ServiceAlertBean saBean = new ServiceAlertBean();
    serviceAlerts.add(saBean);
    if (descriptions.length > 0)
        saBean.setDescriptions(createTextList(descriptions));
    if (summaries.length > 0)
        saBean.setSummaries(createTextList(summaries));
    return serviceAlerts;
}
Also used : ArrayList(java.util.ArrayList) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 48 with ServiceAlertBean

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

the class ArrivalsAndDeparturesAction method getServiceAlertsForStop.

private List<ServiceAlertBean> getServiceAlertsForStop(String stopId) {
    SituationQueryBean query = new SituationQueryBean();
    SituationQueryBean.AffectsBean affects = new SituationQueryBean.AffectsBean();
    query.getAffects().add(affects);
    affects.setStopId(stopId);
    ListBean<ServiceAlertBean> alerts = _transitDataService.getServiceAlerts(query);
    if (alerts != null) {
        return alerts.getList();
    }
    return Collections.emptyList();
}
Also used : SituationQueryBean(org.onebusaway.transit_data.model.service_alerts.SituationQueryBean) ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 49 with ServiceAlertBean

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

the class ServiceAlertAction method prepare.

@Override
public void prepare() throws Exception {
    try {
        if (_alertId != null && !_alertId.trim().isEmpty()) {
            _model = _transitDataService.getServiceAlertForId(_alertId);
            _model.setAllAffects(null);
        } else {
            _model = new ServiceAlertBean();
        }
    } catch (RuntimeException e) {
        _log.error("Unable to retrieve Service Alerts for agency Id", e);
        throw e;
    }
}
Also used : ServiceAlertBean(org.onebusaway.transit_data.model.service_alerts.ServiceAlertBean)

Example 50 with ServiceAlertBean

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

the class ServiceAlertAffectsAction method update.

public String update() throws IOException, JSONException {
    if (_id == null || _index == -1) {
        return INPUT;
    }
    ServiceAlertBean alert = null;
    try {
        alert = _transitDataService.getServiceAlertForId(_id);
    } catch (RuntimeException e) {
        _log.error("Error retrieving Service Alerts", e);
        throw e;
    }
    if (alert == null) {
        return INPUT;
    }
    List<SituationAffectsBean> allAffects = alert.getAllAffects();
    if (allAffects == null || _index >= allAffects.size()) {
        return INPUT;
    }
    _model.setAgencyId(string(_model.getAgencyId()));
    _model.setRouteId(string(_model.getRouteId()));
    _model.setDirectionId(string(_model.getDirectionId()));
    _model.setTripId(string(_model.getTripId()));
    _model.setStopId(string(_model.getStopId()));
    allAffects.set(_index, _model);
    try {
        _transitDataService.updateServiceAlert(alert);
    } catch (RuntimeException e) {
        _log.error("Error updating Service Alert Affects clause", e);
        throw e;
    }
    return SUCCESS;
}
Also used : SituationAffectsBean(org.onebusaway.transit_data.model.service_alerts.SituationAffectsBean) 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