@Test public void shouldValidateTasksAfterChannelUpdateForValidTriggers() { Task task = new Task("name", trigger, asList(action), new TaskConfig(), true, false); Set<TaskError> existingErrors = new HashSet<>(); existingErrors.add(new TaskError("task.validation.error.triggerNotExist")); task.addValidationErrors(existingErrors); when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task)); Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null); Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(new ActionEventBuilder() .setDisplayName("schedule").setSubject("SCHEDULE").setDescription("") .setActionParameters(null).build())); when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel); when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel); when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true); taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger)); Task actualTask = verifyCreateAndCaptureTask(); assertTrue(actualTask.isEnabled()); assertTrue(actualTask.getValidationErrors().isEmpty()); }
@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); } }
TaskServiceImpl implements TaskService { @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); } } }
TaskServiceImpl implements TaskService { @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); } }  }
TaskServiceImpl implements TaskService { @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); } }  @Override @Transactional Set<TaskError> save(final Task task); @Override @Transactional void setEnabledOrDisabled(final Task task); @Override @Transactional ActionEvent getActionEventFor(TaskActionInformation taskActionInformation); @Override @Transactional List<Task> getAllTasks(); @Override @Transactional List<Task> findTasksByName(String name); @Override @Transactional List<Task> findActiveTasksForTrigger(final TriggerEvent trigger); @Override @Transactional List<Task> findActiveTasksForTriggerSubject(final String subject); @Override TasksEventParser findCustomParser(String name); @Override @Transactional Task getTask(Long taskId); @Override @Transactional void deleteTask(Long taskId); @MotechListener(subjects = CHANNEL_UPDATE_SUBJECT) @Transactional void validateTasksAfterChannelUpdate(MotechEvent event); @MotechListener(subjects = DATA_PROVIDER_UPDATE_SUBJECT) @Transactional void validateTasksAfterTaskDataProviderUpdate(MotechEvent event); @Override @Transactional String exportTask(Long taskId); @Override @Transactional Task importTask(String json); @Override @Transactional List<Task> findTasksDependentOnModule(final String moduleName); @Autowired void setTasksDataService(TasksDataService tasksDataService); @Autowired void setChannelService(ChannelService channelService); @Autowired void setProviderService(TaskDataProviderService providerService); @Autowired void setEventRelay(EventRelay eventRelay); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setTaskValidator(TaskValidator taskValidator); @Autowired void setTriggerEventService(TriggerEventService triggerEventService); @Autowired void setTaskMigrationManager(TaskMigrationManager taskMigrationManager); }
TaskServiceImpl implements TaskService { @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); } }  @Override @Transactional Set<TaskError> save(final Task task); @Override @Transactional void setEnabledOrDisabled(final Task task); @Override @Transactional ActionEvent getActionEventFor(TaskActionInformation taskActionInformation); @Override @Transactional List<Task> getAllTasks(); @Override @Transactional List<Task> findTasksByName(String name); @Override @Transactional List<Task> findActiveTasksForTrigger(final TriggerEvent trigger); @Override @Transactional List<Task> findActiveTasksForTriggerSubject(final String subject); @Override TasksEventParser findCustomParser(String name); @Override @Transactional Task getTask(Long taskId); @Override @Transactional void deleteTask(Long taskId); @MotechListener(subjects = CHANNEL_UPDATE_SUBJECT) @Transactional void validateTasksAfterChannelUpdate(MotechEvent event); @MotechListener(subjects = DATA_PROVIDER_UPDATE_SUBJECT) @Transactional void validateTasksAfterTaskDataProviderUpdate(MotechEvent event); @Override @Transactional String exportTask(Long taskId); @Override @Transactional Task importTask(String json); @Override @Transactional List<Task> findTasksDependentOnModule(final String moduleName); @Autowired void setTasksDataService(TasksDataService tasksDataService); @Autowired void setChannelService(ChannelService channelService); @Autowired void setProviderService(TaskDataProviderService providerService); @Autowired void setEventRelay(EventRelay eventRelay); @Autowired void setBundleContext(BundleContext bundleContext); @Autowired void setTaskValidator(TaskValidator taskValidator); @Autowired void setTriggerEventService(TriggerEventService triggerEventService); @Autowired void setTaskMigrationManager(TaskMigrationManager taskMigrationManager); static final List<String> IGNORED_FIELDS; }