use of com.google.api.services.tasks.Tasks in project data-transfer-project by google.
the class GoogleTasksExporter method getTasks.
private ExportResult getTasks(Tasks tasksService, IdOnlyContainerResource resource, PaginationData paginationData) throws IOException {
Tasks.TasksOperations.List query = tasksService.tasks().list(resource.getId()).setMaxResults(PAGE_SIZE);
if (paginationData != null) {
query.setPageToken(((StringPaginationToken) paginationData).getToken());
}
com.google.api.services.tasks.model.Tasks result = query.execute();
List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(resource.getId(), t.getTitle(), t.getNotes())).collect(Collectors.toList());
PaginationData newPage = null;
ResultType resultType = ResultType.END;
if (result.getNextPageToken() != null) {
newPage = new StringPaginationToken(result.getNextPageToken());
resultType = ResultType.CONTINUE;
}
TaskContainerResource taskContainerResource = new TaskContainerResource(null, newTasks);
return new ExportResult<>(resultType, taskContainerResource, new ContinuationData(newPage));
}
use of com.google.api.services.tasks.Tasks in project data-transfer-project by google.
the class GoogleTasksExporter method export.
@Override
public ExportResult<TaskContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, ExportInformation exportInformation) {
// Create a new tasks service for the authorized user
Tasks tasksService = getOrCreateTasksService(authData);
IdOnlyContainerResource resource = (IdOnlyContainerResource) exportInformation.getContainerResource();
try {
if (resource != null) {
return getTasks(tasksService, resource, exportInformation.getPaginationData());
} else {
return getTasksList(tasksService, exportInformation.getPaginationData());
}
} catch (Exception e) {
return new ExportResult<>(ResultType.ERROR, "Error retrieving tasks: " + e.getMessage());
}
}
use of com.google.api.services.tasks.Tasks in project data-transfer-project by google.
the class GoogleTasksImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, TokensAndUrlAuthData authData, TaskContainerResource data) {
Tasks tasksService = getOrCreateTasksService(authData);
TempTasksData tempTasksData = jobStore.findData(TempTasksData.class, jobId);
if (tempTasksData == null) {
tempTasksData = new TempTasksData(jobId.toString());
jobStore.create(jobId, tempTasksData);
}
for (TaskListModel oldTasksList : data.getLists()) {
// TempTasksData shouldn't be null since we added it.
tempTasksData = jobStore.findData(TempTasksData.class, jobId);
TaskList newTaskList = new TaskList().setTitle("Imported copy - " + oldTasksList.getName());
TaskList insertedTaskList;
try {
insertedTaskList = tasksService.tasklists().insert(newTaskList).execute();
} catch (IOException e) {
return new ImportResult(ResultType.ERROR, "Error inserting taskList: " + e.getMessage());
}
logger.info("Storing {} as {}", oldTasksList.getId(), insertedTaskList.getId());
tempTasksData.addTaskListId(oldTasksList.getId(), insertedTaskList.getId());
jobStore.update(jobId, tempTasksData);
}
tempTasksData = jobStore.findData(TempTasksData.class, jobId);
for (TaskModel oldTask : data.getTasks()) {
Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
String newTaskId = tempTasksData.lookupNewTaskListId(newTask.getId());
try {
tasksService.tasks().insert(newTaskId, newTask).execute();
} catch (IOException e) {
return new ImportResult(ResultType.ERROR, "Error inserting task: " + e.getMessage());
}
}
return new ImportResult(ResultType.OK);
}
use of com.google.api.services.tasks.Tasks in project jbpm-work-items by kiegroup.
the class GetTasksWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
Map<String, Object> results = new HashMap<String, Object>();
String numbOfTasksStr = (String) workItem.getParameter("NumOfTasks");
List<TaskInfo> tasksResultsList = new ArrayList<>();
try {
if (numbOfTasksStr == null || !StringUtils.isNumeric(numbOfTasksStr)) {
logger.error("Missing or invalid num of tasks input.");
throw new IllegalArgumentException("Missing or invalid num of tasks input.");
}
Long numOfTasksLong = Long.valueOf(numbOfTasksStr);
if (numOfTasksLong <= 0) {
logger.error("Number of tasks requested must be greater than zero.");
throw new IllegalArgumentException("Number of tasks requested must be greater than zero.");
}
Tasks service = auth.getTasksService(appName, clientSecret);
TaskLists result = service.tasklists().list().setMaxResults(numOfTasksLong).execute();
if (result == null) {
logger.error("Invalid task list result.");
throw new Exception("Invalid task list result.");
}
List<TaskList> tasklist = result.getItems();
if (tasklist != null) {
for (TaskList tl : tasklist) {
tasksResultsList.add(new TaskInfo(tl));
}
}
results.put(RESULTS_VALUES, tasksResultsList);
workItemManager.completeWorkItem(workItem.getId(), results);
} catch (Exception e) {
handleException(e);
}
}
use of com.google.api.services.tasks.Tasks in project jbpm-work-items by kiegroup.
the class AddTaskWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
String taskName = (String) workItem.getParameter("TaskName");
String taskKind = (String) workItem.getParameter("TaskKind");
if (taskName == null) {
logger.error("Missing task name input.");
throw new IllegalArgumentException("Missing task name input.");
}
try {
Tasks service = auth.getTasksService(appName, clientSecret);
TaskList taskList = new TaskList();
taskList.setTitle(taskName);
taskList.setId(taskName);
taskList.setKind(taskKind);
taskList.setUpdated(new DateTime(new Date()));
service.tasklists().insert(taskList).execute();
workItemManager.completeWorkItem(workItem.getId(), null);
} catch (Exception e) {
handleException(e);
}
}
Aggregations