@Override public void getAllAlerts( EventHandler<ModelListEvent<Alert>> successHandler, EventHandler<ErrorEvent> failureHandler) { try { List<Alert> allAlerts = alertDao.findAll(); successHandler.handle(new ModelListEvent<Alert>(allAlerts)); } catch (SQLException e) { Log.e(LOG_TAG, SQL_EXCEPTION_LOG, e); failureHandler.handle(new ErrorEvent(ErrorType.SQL_EXCEPTION)); } }
@Override public void cancelAlert( Alert alert, EventHandler<Void> successHandler, EventHandler<ErrorEvent> failureHandler) { try { alertDao.delete(alert); successHandler.handle(null); } catch (SQLException e) { Log.e(LOG_TAG, SQL_EXCEPTION_LOG, e); failureHandler.handle(new ErrorEvent(ErrorType.SQL_EXCEPTION)); } }
@Override public void updateAlert( Alert alert, EventHandler<ModelEvent<Alert>> successHandler, EventHandler<ErrorEvent> failureHandler) { try { alert = alertDao.update(alert); successHandler.handle(new ModelEvent<Alert>(alert)); } catch (Exception e) { // TODO: Handle } }
@Override public void saveAlert( Alert alert, EventHandler<ModelEvent<Alert>> successHandler, EventHandler<ErrorEvent> failureHandler) { try { Alert result = alertDao.save(alert); successHandler.handle(new ModelEvent<Alert>(result)); } catch (SQLException e) { Log.e(LOG_TAG, SQL_EXCEPTION_LOG, e); failureHandler.handle(new ErrorEvent(ErrorType.SQL_EXCEPTION)); } }
@Override public void getAlert( Long id, EventHandler<ModelEvent<Alert>> successHandler, EventHandler<ErrorEvent> failureHandler) { try { Alert alert = alertDao.findById(id); successHandler.handle(new ModelEvent<Alert>(alert)); } catch (Exception e) { Log.e(LOG_TAG, SQL_EXCEPTION_LOG, e); failureHandler.handle(new ErrorEvent(ErrorType.SQL_EXCEPTION)); } }
@Override public boolean shouldTriggerAlert(Long id) { Alert alert = alertDao.findById(id); Date now = new Date(); if (alert != null && alert.isActive() && (alert.getStartDate() == null || alert.getStartDate().before(now)) && (alert.getEndDate() == null || alert.getEndDate().after(now))) { return true; } return false; }