use of org.motechproject.event.listener.annotations.MotechListener in project motech by motech.
the class TaskServiceImpl method validateTasksAfterChannelUpdate.
@MotechListener(subjects = CHANNEL_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterChannelUpdate(MotechEvent event) {
String moduleName = event.getParameters().get(CHANNEL_MODULE_NAME).toString();
Channel channel = channelService.getChannel(moduleName);
LOGGER.debug("Handling Channel update: {} for module: {}", channel.getDisplayName(), moduleName);
List<Task> tasks = findTasksDependentOnModule(moduleName);
for (Task task : tasks) {
Set<TaskError> errors;
if (task.getTrigger() != null) {
errors = validateTrigger(task);
handleValidationErrors(task, errors, TASK_TRIGGER_VALIDATION_ERRORS);
}
errors = validateActions(task, channel);
handleValidationErrors(task, errors, TASK_ACTION_VALIDATION_ERRORS);
}
}
use of org.motechproject.event.listener.annotations.MotechListener in project motech by motech.
the class InvalidMessageEventListener method handle.
@MotechListener(subjects = MESSAGE_REDELIVERY_TEST)
public synchronized void handle(MotechEvent motechEvent) {
this.motechEvent = motechEvent;
handledTimes.add(new DateTime());
throw new RuntimeException("Message redelivery test.");
}
use of org.motechproject.event.listener.annotations.MotechListener in project motech by motech.
the class PasswordExpirationCheckEventHandler method handleEvent.
/**
* Handles PASSWORD_EXPIRATION_CHECK_EVENT event. Checks every user for the date of the last password change and sends an
* event if the user should be notified about the required password change.
*
* @param event the event to be handled
*/
@MotechListener(subjects = PASSWORD_EXPIRATION_CHECK_EVENT)
public void handleEvent(MotechEvent event) {
if (settingService.isPasswordResetReminderEnabled()) {
LOGGER.info("Daily password reset reminder triggered");
final int passwordExpirationInDays = settingService.getNumberOfDaysToChangePassword();
final int daysBeforeExpirationToSendReminder = settingService.getNumberOfDaysForReminder();
final int daysWithNoPassChangeForReminder = passwordExpirationInDays - daysBeforeExpirationToSendReminder;
for (MotechUser user : allUsers.retrieveAll()) {
final int daysWithoutPasswordChange = daysWithoutPasswordChange(user);
LOGGER.debug("User {} hasn't changed password in {} days. Notification is being after {} days without" + " password change, {} days before expiration", user.getUserName(), daysWithoutPasswordChange, daysWithNoPassChangeForReminder, daysBeforeExpirationToSendReminder);
if (daysWithoutPasswordChange == daysWithNoPassChangeForReminder) {
if (StringUtils.isNotBlank(user.getEmail())) {
sendPasswordReminderEvent(user, passwordExpirationInDays, daysBeforeExpirationToSendReminder);
} else {
LOGGER.debug("User {} doesn't have an email address set, skipping sending of reminder", user.getUserName());
}
}
}
} else {
LOGGER.info("Daily password reset reminder is disabled, skipping processing of users");
}
}
use of org.motechproject.event.listener.annotations.MotechListener in project motech by motech.
the class TaskServiceImpl method validateTasksAfterTaskDataProviderUpdate.
@MotechListener(subjects = DATA_PROVIDER_UPDATE_SUBJECT)
@Transactional
public void validateTasksAfterTaskDataProviderUpdate(MotechEvent event) {
String providerName = event.getParameters().get(DATA_PROVIDER_NAME).toString();
TaskDataProvider provider = providerService.getProvider(providerName);
LOGGER.debug("Handling a task data provider update: {}", providerName);
for (Task task : getAllTasks()) {
SortedSet<DataSource> dataSources = task.getTaskConfig().getDataSources(provider.getName());
if (isNotEmpty(dataSources)) {
Set<TaskError> errors = new HashSet<>();
for (DataSource dataSource : dataSources) {
errors.addAll(validateProvider(provider, dataSource, task, new HashMap<Long, TaskDataProvider>()));
}
errors.addAll(validateActions(task));
handleValidationErrors(task, errors, TASK_DATA_PROVIDER_VALIDATION_ERRORS);
}
}
}
use of org.motechproject.event.listener.annotations.MotechListener in project motech by motech.
the class SendEmailEventHandlerImplTest method testIfThereIsHandlerMethodForSendEmailEvent.
@Test
public void testIfThereIsHandlerMethodForSendEmailEvent() throws NoSuchMethodException {
Method handleMethod = emailEventHandler.getClass().getDeclaredMethod("handle", MotechEvent.class);
assertTrue("MotechListener annotation missing", handleMethod.isAnnotationPresent(MotechListener.class));
MotechListener annotation = handleMethod.getAnnotation(MotechListener.class);
assertArrayEquals(new String[] { SEND_EMAIL_SUBJECT }, annotation.subjects());
}
Aggregations