Search in sources :

Example 1 with AlarmDetails

use of org.onebusaway.api.services.AlarmDetails in project onebusaway-application-modules by camsys.

the class AlarmServiceImpl method fireAlarm.

@Override
public void fireAlarm(String alarmId) {
    AlarmDetails details = _alarmsById.remove(alarmId);
    if (details == null)
        return;
    if (details instanceof ApnsAlarmDetails) {
        ApnsAlarmDetails apnsDetails = (ApnsAlarmDetails) details;
        JSONObject data = getDataAsJson(apnsDetails.getData());
        String payload = getDataAsApnsPayload(alarmId, data);
        boolean isProduction = isProduction(data);
        for (ApplePushNotificationService service : _applePushNotificationServices) {
            if (service.isProduction() == isProduction) {
                service.pushNotification(apnsDetails.getDeviceToken(), payload);
                return;
            }
        }
        _log.warn("no appropriate ApplePushNotificationService found for alarm: production=" + isProduction);
    }
}
Also used : AlarmDetails(org.onebusaway.api.services.AlarmDetails) JSONObject(org.json.JSONObject) ApplePushNotificationService(org.onebusaway.api.services.apns.ApplePushNotificationService)

Example 2 with AlarmDetails

use of org.onebusaway.api.services.AlarmDetails in project onebusaway-application-modules by camsys.

the class RegisterAlarmForArrivalAndDepartureAtStopAction method show.

public DefaultHttpHeaders show() throws ServiceException {
    if (hasErrors())
        return setValidationErrorsResponse();
    if (_query.getTime() == 0)
        _query.setTime(SystemTime.currentTimeMillis());
    AlarmDetails details = _alarmService.alterAlarmQuery(_alarm, _data);
    String alarmId = _service.registerAlarmForArrivalAndDepartureAtStop(_query, _alarm);
    if (alarmId == null)
        return setResourceNotFoundResponse();
    if (details != null) {
        _alarmService.registerAlarm(alarmId, details);
    }
    if (isVersion(V2)) {
        RegisteredAlarmV2Bean bean = new RegisteredAlarmV2Bean();
        bean.setAlarmId(alarmId);
        BeanFactoryV2 factory = getBeanFactoryV2();
        return setOkResponse(factory.entry(bean));
    } else {
        return setUnknownVersionResponse();
    }
}
Also used : AlarmDetails(org.onebusaway.api.services.AlarmDetails) RegisteredAlarmV2Bean(org.onebusaway.api.model.transit.RegisteredAlarmV2Bean) BeanFactoryV2(org.onebusaway.api.model.transit.BeanFactoryV2)

Aggregations

AlarmDetails (org.onebusaway.api.services.AlarmDetails)2 JSONObject (org.json.JSONObject)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1 RegisteredAlarmV2Bean (org.onebusaway.api.model.transit.RegisteredAlarmV2Bean)1 ApplePushNotificationService (org.onebusaway.api.services.apns.ApplePushNotificationService)1