use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskValidator method validateTrigger.
/**
* Validates the trigger of the given task by checking if it is specified in the given channel.
*
* @param task the task for which the trigger should be validated, not null
* @return the set of encountered errors
*/
@Transactional
public Set<TaskError> validateTrigger(Task task) {
Set<TaskError> errors = new HashSet<>();
TaskTriggerInformation triggerInformation = task.getTrigger();
boolean exists = triggerEventService.triggerExists(triggerInformation);
if (!exists) {
errors.add(new TaskError("task.validation.error.triggerNotExist", triggerInformation.getDisplayName()));
}
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskControllerTest method shouldSaveExistingTask.
@Test
public void shouldSaveExistingTask() {
Task expected = new Task("name", null, null);
expected.setId(TASK_ID);
expected.setTrigger(new TaskTriggerInformation());
controller.saveTask(expected);
verify(taskWebService).save(expected);
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskServiceImpl method validateProvider.
private Set<TaskError> validateProvider(TaskDataProvider provider, DataSource dataSource, Task task, Map<Long, TaskDataProvider> availableDataProviders) {
LOGGER.debug("Validating task data provider: {} in task: {} with ID: {}", dataSource.getProviderName(), task.getName(), task.getId());
Set<TaskError> errors = new HashSet<>();
TaskTriggerInformation trigger = task.getTrigger();
if (provider != null) {
errors.addAll(taskValidator.validateProvider(provider, dataSource, triggerEventService.getTrigger(trigger), availableDataProviders));
} else {
errors.add(new TaskError("task.validation.error.providerNotExist", dataSource.getProviderName()));
}
logResultOfValidation("task data provider", task.getName(), errors);
return errors;
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class TaskDataServiceBundleIT method shouldFindActiveTasksByTriggerSubject.
@Test
public void shouldFindActiveTasksByTriggerSubject() {
TaskActionInformation action = new TaskActionInformation("send", "test", MDS_ENTITIES_BUNDLE, "0.15", "SEND", new HashMap<String, String>());
TaskTriggerInformation trigger1 = new TaskTriggerInformation("receive-1", "test", MDS_ENTITIES_BUNDLE, "0.14", "RECEIVE-1", null);
TaskTriggerInformation trigger2 = new TaskTriggerInformation("receive-2", "test", "test", "0.14", "RECEIVE-2", null);
Task expected1 = new Task("name1", trigger1, asList(action), null, true, true);
Task expected2 = new Task("name2", trigger2, asList(action), null, true, false);
Task expected3 = new Task("name3", new TaskTriggerInformation(trigger1), asList(action), null, true, true);
tasksDataService.create(expected1);
tasksDataService.create(expected2);
tasksDataService.create(expected3);
assertEquals(new ArrayList<Task>(), taskService.findActiveTasksForTriggerSubject(""));
assertEquals(asList(expected1, expected3), taskService.findActiveTasksForTriggerSubject(trigger1.getSubject()));
assertEquals(new ArrayList<Task>(), taskService.findActiveTasksForTriggerSubject(trigger2.getSubject()));
}
use of org.motechproject.tasks.domain.mds.task.TaskTriggerInformation in project motech by motech.
the class DynamicChannelLoaderImplTest method testGetTrigger.
@Test
public void testGetTrigger() throws Exception {
TaskTriggerInformation info = prepareTaskTriggerInformation();
TriggerEvent triggerEvent = prepareTriggerEvent();
when(provider.getTrigger(eq(info))).thenReturn(triggerEvent);
TriggerEvent fetched = channelLoader.getTrigger(info);
assertEquals(triggerEvent, fetched);
verify(provider).getTrigger(eq(info));
}
Aggregations