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);
}
}
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()));
}
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()));
}
Aggregations