Ejemplo n.º 1
0
  /**
   * Closes or marks the alert as read based on the received event.
   *
   * @param event the event - id of the alert to update is the only expected parameter
   */
  @MotechListener(subjects = {CLOSE_ALERT_SUBJECT, MARK_ALERT_READ_SUBJECT})
  public void updateStatus(MotechEvent event) {
    Long id = Long.valueOf(getValueAsString(event, ALERT_ID));
    UpdateCriteria criteria = new UpdateCriteria();

    if (event.getSubject().equals(CLOSE_ALERT_SUBJECT)) {
      criteria.status(AlertStatus.CLOSED);
    } else {
      criteria.status(AlertStatus.READ);
    }

    alertService.update(id, criteria);
  }
Ejemplo n.º 2
0
  /**
   * Creates a new alert from the received event.
   *
   * @param event the event to build the alert from
   */
  @MotechListener(subjects = {CREATE_ALERT_SUBJECT})
  public void create(MotechEvent event) {
    String externalId = getValueAsString(event, EXTERNAL_ID_KEY);
    String alertName = getValueAsString(event, ALERT_NAME);
    String alertDescription = getValueAsString(event, ALERT_DESCRIPTION);
    AlertType alertType = getValueAsEnum(AlertType.class, event, ALERT_TYPE);
    AlertStatus alertStatus = getValueAsEnum(AlertStatus.class, event, ALERT_STATUS);
    Integer alertPriority = Integer.valueOf(getValueAsString(event, ALERT_PRIORITY));
    Map<String, String> alertData = (Map<String, String>) getValue(event, ALERT_DATA);

    alertService.create(
        externalId, alertName, alertDescription, alertType, alertStatus, alertPriority, alertData);
  }