@Test public void shouldValidateTasksAfterChannelUpdateForInvalidTaskDataProviders() { TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName",asList(new Lookup("id", "trigger.value")), true)); Task task = new Task("name", trigger, asList(action), config, true, false); task.setId(12345l); List<LookupFieldsParameter> lookupFields = new ArrayList<>(); lookupFields.add(new LookupFieldsParameter("property", asList("property"))); TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", lookupFields, null))); provider.setId(1234L); 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("receive").setSubject("RECEIVE").setDescription("") .setActionParameters(null).build())); when(tasksDataService.findById(12345l)).thenReturn(task); when(tasksDataService.retrieveAll()).thenReturn(asList(task)); when(providerService.getProvider(provider.getName())).thenReturn(provider); when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel); when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel); taskService.validateTasksAfterTaskDataProviderUpdate(getProviderUpdateEvent(provider.getName())); Task actualTask = verifyUpdateAndCaptureTask(); assertFalse(actualTask.isEnabled()); List<Object> errors = new ArrayList<>(actualTask.getValidationErrors()); assertEquals(1, errors.size()); assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.providerObjectLookupNotExist")))); }
@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); } } }
TaskServiceImpl implements TaskService { @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); } } } }
TaskServiceImpl implements TaskService { @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); } } }  }
TaskServiceImpl implements TaskService { @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); } } }  @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 = 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); } } }  @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; }