Search in sources :

Example 21 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskServiceImpl method getTask.

@Override
@Transactional
public Task getTask(Long taskId) {
    Task task = tasksDataService.findById(taskId);
    checkChannelAvailableInTask(task);
    return task;
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskServiceImpl method validateName.

private void validateName(Task task) {
    Long taskId = task.getId();
    List<Task> tasksWithName = tasksDataService.findTasksByName(task.getName());
    if (taskId == null && tasksWithName.size() > 0) {
        throw new TaskNameAlreadyExistsException(task.getName());
    } else if (taskId != null && tasksWithName.size() > 0 && !tasksWithName.get(0).getId().equals(taskId)) {
        throw new TaskNameAlreadyExistsException(task.getName());
    }
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) TaskNameAlreadyExistsException(org.motechproject.tasks.exception.TaskNameAlreadyExistsException)

Example 23 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskDeserializer method deserialize.

@Override
public Task deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    jsonNode = jsonParser.readValueAsTree();
    task = new Task();
    ObjectCodec codec = jsonParser.getCodec();
    if (codec instanceof ObjectMapper) {
        mapper = (ObjectMapper) codec;
    } else {
        mapper = new ObjectMapper();
    }
    TypeFactory typeFactory = mapper.getTypeFactory();
    JavaType stringType = typeFactory.constructType(String.class);
    JavaType longType = typeFactory.constructType(Long.class);
    JavaType intType = typeFactory.constructType(Integer.class);
    JavaType dateTime = typeFactory.constructType(DateTime.class);
    JavaType booleanType = typeFactory.constructType(boolean.class);
    JavaType timeType = typeFactory.constructType(Time.class);
    setProperty("id", longType);
    setProperty("owner", stringType);
    setProperty("creator", stringType);
    setProperty("creationDate", dateTime);
    setProperty("modificationDate", dateTime);
    setProperty("modifiedBy", stringType);
    setProperty("description", stringType);
    setProperty("name", stringType);
    setProperty("enabled", stringType);
    setProperty("hasRegisteredChannel", stringType);
    setProperty("taskConfig", typeFactory.constructType(TaskConfig.class));
    setProperty("trigger", typeFactory.constructType(TaskTriggerInformation.class));
    setProperty("numberOfRetries", intType);
    setProperty("retryIntervalInMilliseconds", intType);
    setProperty("retryTaskOnFailure", stringType);
    setProperty("useTimeWindow", booleanType);
    setProperty("startTime", timeType);
    setProperty("endTime", timeType);
    setProperty("validationErrors", typeFactory.constructCollectionType(Set.class, TaskError.class));
    setProperty("actions", typeFactory.constructCollectionType(List.class, TaskActionInformation.class));
    setProperty("days", typeFactory.constructCollectionType(List.class, String.class));
    return task;
}
Also used : TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) JavaType(org.codehaus.jackson.type.JavaType) Set(java.util.Set) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) List(java.util.List) ObjectCodec(org.codehaus.jackson.ObjectCodec) TypeFactory(org.codehaus.jackson.map.type.TypeFactory) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 24 with Task

use of org.motechproject.tasks.domain.mds.task.Task in project motech by motech.

the class TaskBuilder method build.

public Task build() {
    Task task = new Task();
    task.setName(name);
    task.setDescription(description);
    task.setTrigger(trigger);
    task.setEnabled(enabled);
    task.setActions(actions);
    task.setTaskConfig(taskConfig);
    if (null != id) {
        task.setId(id);
    }
    return task;
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task)

Example 25 with Task

use of org.motechproject.tasks.domain.mds.task.Task 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)

Aggregations

Task (org.motechproject.tasks.domain.mds.task.Task)86 Test (org.junit.Test)65 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)35 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)26 HashMap (java.util.HashMap)21 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)19 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)19 ArrayList (java.util.ArrayList)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)17 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)16 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)15 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)13 Channel (org.motechproject.tasks.domain.mds.channel.Channel)12 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)11 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 MotechEvent (org.motechproject.event.MotechEvent)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)9