use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImpl method validateActions.
private Set<TaskError> validateActions(Task task, Channel channel) {
LOGGER.debug("Validating all actions in task: {} with ID: {}", task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
for (TaskActionInformation action : task.getActions()) {
errors.addAll(validateAction(task, channel, action));
}
logResultOfValidation("actions", task.getName(), errors);
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TriggerEventServiceImpl method validateTrigger.
@Override
@Transactional
public Set<TaskError> validateTrigger(TaskTriggerInformation trigger) {
Set<TaskError> errors = new HashSet<>();
String subject = trigger.getSubject();
String moduleName = trigger.getModuleName();
boolean channelExists = false;
boolean validTrigger = false;
if (channelsDataService.countFindByModuleName(moduleName) != 0) {
channelExists = true;
validTrigger = triggerEventsDataService.countByChannelModuleNameAndSubject(moduleName, subject) > 0;
}
if (!validTrigger && dynamicChannelLoader.channelExists(moduleName)) {
channelExists = true;
validTrigger = dynamicChannelLoader.validateTrigger(moduleName, subject);
}
if (channelExists) {
if (!validTrigger) {
errors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
}
} else {
errors.add(new TaskError("task.validation.error.triggerChannelNotRegistered"));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskDataProviderServiceImpl method registerProvider.
@Override
@Transactional
public void registerProvider(final InputStream stream) {
final Type type = new TypeToken<TaskDataProvider>() {
}.getType();
final TaskDataProvider provider = (TaskDataProvider) motechJsonReader.readFromStream(stream, type);
if (TaskDataProviderValidator.validateIsNotEmpty(provider)) {
LOGGER.info("Registering a task data provider with name: {}", provider.getName());
Set<TaskError> errors = TaskDataProviderValidator.validate(provider);
if (!isEmpty(errors)) {
throw new ValidationException(TaskDataProviderValidator.TASK_DATA_PROVIDER, TaskError.toDtos(errors));
}
addProvider(provider);
} else {
LOGGER.info("Registering an empty task data provider with name: {} is not possible", provider.getName());
}
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImplTest method shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors.
@Test
public void shouldRemoveValidationErrorAndUpdateTaskOnlyIfItHasAnyValidationErrors() {
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);
when(channelService.getChannel(trigger.getModuleName())).thenReturn(triggerChannel);
when(triggerEventService.triggerExists(task.getTrigger())).thenReturn(true);
taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
Task actualTask = verifyCreateAndCaptureTask();
assertFalse(actualTask.hasValidationErrors());
}
use of org.motechproject.tasks.domain.mds.task.TaskError in project motech by motech.
the class TaskServiceImplTest method shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers.
@Test
public void shouldValidateTasksOfDependentModulesAfterChannelUpdateForInvalidTriggers() {
Task task = new Task("name", trigger, new ArrayList<>(asList(action)), new TaskConfig(), true, false);
task.setId(6l);
when(tasksDataService.executeQuery(any(QueryExecution.class))).thenReturn(asList(task));
when(tasksDataService.findById(6l)).thenReturn(task);
Channel triggerChannel = new Channel("test", "test-trigger", "0.15", "", asList(new TriggerEvent("send", "SENDING", "", 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);
Set<TaskError> triggerValidationErrors = new HashSet<>();
triggerValidationErrors.add(new TaskError("task.validation.error.triggerNotExist", trigger.getDisplayName()));
when(triggerEventService.validateTrigger(eq(trigger))).thenReturn(triggerValidationErrors);
taskService.validateTasksAfterChannelUpdate(getChannelUpdateEvent(trigger));
Task actualTask = verifyUpdateAndCaptureTask(times(2));
assertFalse(actualTask.isEnabled());
List<Object> errors = new ArrayList<Object>(actualTask.getValidationErrors());
assertEquals(1, errors.size());
assertThat(errors, hasItem(hasProperty("message", equalTo("task.validation.error.triggerNotExist"))));
}
Aggregations