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;
}
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());
}
}
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;
}
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;
}
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()));
}
Aggregations