@Test public void shouldSaveTask() { Map<String, String> map = new HashMap<>(); map.put("phone", "12345"); TaskConfig config = new TaskConfig().add(new DataSource("TestProvider", 1234L, 1L, "Test", "id", "specifiedName", asList(new Lookup("id", "trigger.value")), true)); action.setValues(map); Task task = new Task("name", trigger, asList(action), config, true, false); task.setNumberOfRetries(5); task.setRetryTaskOnFailure(true); Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SEND", "", asList(new EventParameter("test", "value")), "")), null); ActionEvent actionEvent = new ActionEventBuilder().setDisplayName("receive").setSubject("RECEIVE") .setDescription("").setActionParameters(null).build(); actionEvent.addParameter(new ActionParameterBuilder().setDisplayName("Phone").setKey("phone").build(), true); Channel actionChannel = new Channel("test", "test-action", "0.14", "", null, asList(actionEvent)); TaskDataProvider provider = new TaskDataProvider("TestProvider", asList(new TaskDataProviderObject("test", "Test", asList(new LookupFieldsParameter("id", asList("id"))), null))); provider.setId(1234L); when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel); when(channelService.getChannel(action.getModuleName())).thenReturn(actionChannel); when(providerService.getProvider("TestProvider")).thenReturn(provider); when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true); taskService.save(task); verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerSubject()); verify(triggerHandler).registerHandlerFor(task.getTrigger().getEffectiveListenerRetrySubject(), true); verifyCreateAndCaptureTask(); }
@Override @Transactional public Set<TaskError> save(final Task task) { LOGGER.info("Saving task: {} with ID: {}", task.getName(), task.getId()); Set<TaskError> errors = taskValidator.validate(task); if (task.isEnabled() && !isEmpty(errors)) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } validateName(task); errors.addAll(validateTrigger(task)); errors.addAll(validateDataSources(task)); errors.addAll(validateActions(task)); if (!isEmpty(errors)) { if (task.isEnabled()) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } else { task.setValidationErrors(errors); } } else { task.setValidationErrors(null); } if(!checkTimeWindowInTask(task)) { task.setEnabled(false); } addOrUpdate(task); registerHandler(task); LOGGER.info("Saved task: {} with ID: {}", task.getName(), task.getId()); return errors; }
TaskServiceImpl implements TaskService { @Override @Transactional public Set<TaskError> save(final Task task) { LOGGER.info("Saving task: {} with ID: {}", task.getName(), task.getId()); Set<TaskError> errors = taskValidator.validate(task); if (task.isEnabled() && !isEmpty(errors)) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } validateName(task); errors.addAll(validateTrigger(task)); errors.addAll(validateDataSources(task)); errors.addAll(validateActions(task)); if (!isEmpty(errors)) { if (task.isEnabled()) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } else { task.setValidationErrors(errors); } } else { task.setValidationErrors(null); } if(!checkTimeWindowInTask(task)) { task.setEnabled(false); } addOrUpdate(task); registerHandler(task); LOGGER.info("Saved task: {} with ID: {}", task.getName(), task.getId()); return errors; } }
TaskServiceImpl implements TaskService { @Override @Transactional public Set<TaskError> save(final Task task) { LOGGER.info("Saving task: {} with ID: {}", task.getName(), task.getId()); Set<TaskError> errors = taskValidator.validate(task); if (task.isEnabled() && !isEmpty(errors)) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } validateName(task); errors.addAll(validateTrigger(task)); errors.addAll(validateDataSources(task)); errors.addAll(validateActions(task)); if (!isEmpty(errors)) { if (task.isEnabled()) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } else { task.setValidationErrors(errors); } } else { task.setValidationErrors(null); } if(!checkTimeWindowInTask(task)) { task.setEnabled(false); } addOrUpdate(task); registerHandler(task); LOGGER.info("Saved task: {} with ID: {}", task.getName(), task.getId()); return errors; }  }
TaskServiceImpl implements TaskService { @Override @Transactional public Set<TaskError> save(final Task task) { LOGGER.info("Saving task: {} with ID: {}", task.getName(), task.getId()); Set<TaskError> errors = taskValidator.validate(task); if (task.isEnabled() && !isEmpty(errors)) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } validateName(task); errors.addAll(validateTrigger(task)); errors.addAll(validateDataSources(task)); errors.addAll(validateActions(task)); if (!isEmpty(errors)) { if (task.isEnabled()) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } else { task.setValidationErrors(errors); } } else { task.setValidationErrors(null); } if(!checkTimeWindowInTask(task)) { task.setEnabled(false); } addOrUpdate(task); registerHandler(task); LOGGER.info("Saved task: {} with ID: {}", task.getName(), task.getId()); return 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 { @Override @Transactional public Set<TaskError> save(final Task task) { LOGGER.info("Saving task: {} with ID: {}", task.getName(), task.getId()); Set<TaskError> errors = taskValidator.validate(task); if (task.isEnabled() && !isEmpty(errors)) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } validateName(task); errors.addAll(validateTrigger(task)); errors.addAll(validateDataSources(task)); errors.addAll(validateActions(task)); if (!isEmpty(errors)) { if (task.isEnabled()) { throw new ValidationException(TaskValidator.TASK, TaskError.toDtos(errors)); } else { task.setValidationErrors(errors); } } else { task.setValidationErrors(null); } if(!checkTimeWindowInTask(task)) { task.setEnabled(false); } addOrUpdate(task); registerHandler(task); LOGGER.info("Saved task: {} with ID: {}", task.getName(), task.getId()); return 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; }