Search in sources :

Example 6 with TaskTriggerInformation

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;
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with TaskTriggerInformation

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);
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) Test(org.junit.Test)

Example 8 with TaskTriggerInformation

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;
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) HashSet(java.util.HashSet)

Example 9 with TaskTriggerInformation

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()));
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Test(org.junit.Test)

Example 10 with TaskTriggerInformation

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));
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Test(org.junit.Test)

Aggregations

TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)28 Test (org.junit.Test)23 Task (org.motechproject.tasks.domain.mds.task.Task)16 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)14 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)8 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)7 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)7 HashMap (java.util.HashMap)6 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)6 ArrayList (java.util.ArrayList)5 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)5 Matchers.anyString (org.mockito.Matchers.anyString)4 DataProvider (org.motechproject.commons.api.DataProvider)4 MotechEvent (org.motechproject.event.MotechEvent)4 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)4 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)4 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)4 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)4 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)2