Search in sources :

Example 1 with Level

use of org.motechproject.admin.messages.Level in project motech by motech.

the class MessageHandler method messageReceived.

/**
 * Posts a status message using the {@link StatusMessageService}. The message is built from the event payload.
 * This allows publishing status messages without a dependency on the Admin module.
 * @param event the received event
 * @see org.motechproject.admin.domain.StatusMessage
 */
@MotechListener(subjects = EventSubjects.MESSAGE_SUBJECT)
public void messageReceived(MotechEvent event) {
    String message = (String) event.getParameters().get(EventKeys.MESSAGE);
    String moduleName = (String) event.getParameters().get(EventKeys.MODULE_NAME);
    String levelStr = (String) event.getParameters().get(EventKeys.LEVEL);
    Level level = (StringUtils.isNotBlank(levelStr)) ? Level.valueOf(StringUtils.upperCase(levelStr)) : Level.INFO;
    DateTime timeout = (DateTime) event.getParameters().get(EventKeys.TIMEOUT);
    if (timeout == null) {
        statusMessageService.postMessage(message, moduleName, level);
    } else {
        statusMessageService.postMessage(message, moduleName, level, timeout);
    }
}
Also used : Level(org.motechproject.admin.messages.Level) DateTime(org.joda.time.DateTime) MotechListener(org.motechproject.event.listener.annotations.MotechListener)

Example 2 with Level

use of org.motechproject.admin.messages.Level in project motech by motech.

the class NotificationRulesDataServiceBundleIT method shouldPerformCrudOperations.

@Test
public void shouldPerformCrudOperations() {
    NotificationRule notificationRule = new NotificationRule("recip", ActionType.EMAIL, Level.CRITICAL, "admin");
    NotificationRule notificationRule2 = new NotificationRule("recip2", ActionType.SMS, Level.INFO, "tasks");
    dataService.create(notificationRule);
    dataService.create(notificationRule2);
    List<NotificationRule> notificationRules = dataService.retrieveAll();
    List<String> actual = extract(notificationRules, on(NotificationRule.class).getRecipient());
    assertThat(actual, hasItems("recip", "recip2"));
    List<ActionType> actualActions = extract(notificationRules, on(NotificationRule.class).getActionType());
    assertThat(actualActions, hasItems(ActionType.EMAIL, ActionType.SMS));
    actual = extract(notificationRules, on(NotificationRule.class).getModuleName());
    assertThat(actual, hasItems("admin", "tasks"));
    List<Level> actualLevels = extract(notificationRules, on(NotificationRule.class).getLevel());
    assertThat(actualLevels, hasItems(Level.CRITICAL, Level.INFO));
    notificationRule.setRecipient("recip3");
    dataService.update(notificationRule);
    notificationRules = dataService.retrieveAll();
    actual = extract(notificationRules, on(NotificationRule.class).getRecipient());
    assertThat(actual, hasItems("recip3", "recip2"));
    actualActions = extract(notificationRules, on(NotificationRule.class).getActionType());
    assertThat(actualActions, hasItems(ActionType.EMAIL, ActionType.SMS));
    dataService.delete(notificationRule);
    notificationRules = dataService.retrieveAll();
    assertEquals(asList("recip2"), extract(notificationRules, on(NotificationRule.class).getRecipient()));
    assertEquals(asList(ActionType.SMS), extract(notificationRules, on(NotificationRule.class).getActionType()));
    assertEquals(asList("tasks"), extract(notificationRules, on(NotificationRule.class).getModuleName()));
    assertEquals(asList(Level.INFO), extract(notificationRules, on(NotificationRule.class).getLevel()));
}
Also used : ActionType(org.motechproject.admin.messages.ActionType) NotificationRule(org.motechproject.admin.domain.NotificationRule) Level(org.motechproject.admin.messages.Level) Test(org.junit.Test)

Example 3 with Level

use of org.motechproject.admin.messages.Level in project motech by motech.

the class StatusMessagesDataServiceBundleIT method shouldPerformCrudOperations.

@Test
public void shouldPerformCrudOperations() {
    StatusMessage statusMessage1 = new StatusMessage("test", "module", Level.ERROR);
    StatusMessage statusMessage2 = new StatusMessage("test2", "module2", Level.INFO);
    dataService.create(statusMessage1);
    dataService.create(statusMessage2);
    List<StatusMessage> result = dataService.retrieveAll();
    List<String> actual = extract(result, on(StatusMessage.class).getText());
    assertThat(actual, hasItems("test", "test2"));
    actual = extract(result, on(StatusMessage.class).getModuleName());
    assertThat(actual, hasItems("module", "module2"));
    List<Level> actualLevels = extract(result, on(StatusMessage.class).getLevel());
    assertThat(actualLevels, hasItems(Level.ERROR, Level.INFO));
    statusMessage1.setText("test_changed");
    dataService.update(statusMessage1);
    dataService.delete(statusMessage2);
    result = dataService.retrieveAll();
    assertEquals(asList("test_changed"), extract(result, on(StatusMessage.class).getText()));
    assertEquals(asList("module"), extract(result, on(StatusMessage.class).getModuleName()));
    assertEquals(asList(Level.ERROR), extract(result, on(StatusMessage.class).getLevel()));
}
Also used : Level(org.motechproject.admin.messages.Level) StatusMessage(org.motechproject.admin.domain.StatusMessage) Test(org.junit.Test)

Aggregations

Level (org.motechproject.admin.messages.Level)3 Test (org.junit.Test)2 DateTime (org.joda.time.DateTime)1 NotificationRule (org.motechproject.admin.domain.NotificationRule)1 StatusMessage (org.motechproject.admin.domain.StatusMessage)1 ActionType (org.motechproject.admin.messages.ActionType)1 MotechListener (org.motechproject.event.listener.annotations.MotechListener)1