Search in sources :

Example 1 with TaskLists

use of com.google.api.services.tasks.model.TaskLists 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);
    }
}
Also used : Tasks(com.google.api.services.tasks.Tasks) HashMap(java.util.HashMap) TaskList(com.google.api.services.tasks.model.TaskList) ArrayList(java.util.ArrayList) TaskLists(com.google.api.services.tasks.model.TaskLists)

Example 2 with TaskLists

use of com.google.api.services.tasks.model.TaskLists in project data-transfer-project by google.

the class GoogleTasksExporter method getTasksList.

private ExportResult getTasksList(Tasks tasksSerivce, PaginationData paginationData) throws IOException {
    Tasks.Tasklists.List query = tasksSerivce.tasklists().list().setMaxResults(PAGE_SIZE);
    if (paginationData != null) {
        query.setPageToken(((StringPaginationToken) paginationData).getToken());
    }
    TaskLists result = query.execute();
    ImmutableList.Builder<TaskListModel> newTaskListsBuilder = ImmutableList.builder();
    ImmutableList.Builder<IdOnlyContainerResource> newResourcesBuilder = ImmutableList.builder();
    for (TaskList taskList : result.getItems()) {
        newTaskListsBuilder.add(new TaskListModel(taskList.getId(), taskList.getTitle()));
        newResourcesBuilder.add(new IdOnlyContainerResource(taskList.getId()));
    }
    PaginationData newPage = null;
    ResultType resultType = ResultType.END;
    if (result.getNextPageToken() != null) {
        newPage = new StringPaginationToken(result.getNextPageToken());
        resultType = ResultType.CONTINUE;
    }
    List<IdOnlyContainerResource> newResources = newResourcesBuilder.build();
    if (!newResources.isEmpty()) {
        resultType = ResultType.CONTINUE;
    }
    TaskContainerResource taskContainerResource = new TaskContainerResource(newTaskListsBuilder.build(), null);
    ContinuationData continuationData = new ContinuationData(newPage);
    newResourcesBuilder.build().forEach(resource -> continuationData.addContainerResource(resource));
    return new ExportResult<>(resultType, taskContainerResource, continuationData);
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) ImmutableList(com.google.common.collect.ImmutableList) TaskList(com.google.api.services.tasks.model.TaskList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.dataportabilityproject.types.transfer.models.tasks.TaskListModel) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Example 3 with TaskLists

use of com.google.api.services.tasks.model.TaskLists in project data-transfer-project by google.

the class GoogleTaskService method getTaskLists.

private TaskModelWrapper getTaskLists(Optional<PaginationInformation> pageInfo) throws IOException {
    Tasks.Tasklists.List query = taskClient.tasklists().list().setMaxResults(PAGE_SIZE);
    if (pageInfo.isPresent()) {
        query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    TaskLists result = query.execute();
    List<TaskListModel> newTaskLists = new ArrayList<>(result.getItems().size());
    List<Resource> newResources = new ArrayList<>(result.getItems().size());
    for (TaskList taskList : result.getItems()) {
        newTaskLists.add(new TaskListModel(taskList.getId(), taskList.getTitle()));
        newResources.add(new IdOnlyResource(taskList.getId()));
    }
    PaginationInformation newPageInfo = null;
    if (result.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(result.getNextPageToken());
    }
    return new TaskModelWrapper(newTaskLists, null, new ContinuationInformation(newResources, newPageInfo));
}
Also used : TaskList(com.google.api.services.tasks.model.TaskList) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 4 with TaskLists

use of com.google.api.services.tasks.model.TaskLists in project jbpm-work-items by kiegroup.

the class GoogleTasksWorkitemHandlerTest method setUp.

@Before
public void setUp() {
    try {
        List<TaskList> testTaskList = new java.util.ArrayList<>();
        TaskList listOne = new TaskList();
        listOne.setTitle("buy groceries");
        listOne.setKind("home task");
        TaskList listTwo = new TaskList();
        listTwo.setTitle("pickup kid from school");
        listTwo.setKind("home task");
        testTaskList.add(listOne);
        testTaskList.add(listTwo);
        TaskLists taskListsModel = new TaskLists();
        taskListsModel.setItems(testTaskList);
        when(auth.getTasksService(anyString(), anyString())).thenReturn(tasksService);
        when(tasksService.tasklists()).thenReturn(taskLists);
        when(taskLists.list()).thenReturn(taskListsList);
        when(taskLists.insert(any(TaskList.class))).thenReturn(taskListsInsert);
        when(taskListsList.setMaxResults(anyLong())).thenReturn(taskListsList);
        when(taskListsList.execute()).thenReturn(taskListsModel);
        when(taskListsInsert.execute()).thenReturn(listOne);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : TaskList(com.google.api.services.tasks.model.TaskList) TaskLists(com.google.api.services.tasks.model.TaskLists) Before(org.junit.Before)

Aggregations

TaskList (com.google.api.services.tasks.model.TaskList)4 TaskLists (com.google.api.services.tasks.model.TaskLists)4 ArrayList (java.util.ArrayList)2 Tasks (com.google.api.services.tasks.Tasks)1 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)1 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)1 Resource (org.dataportabilityproject.dataModels.Resource)1 TaskListModel (org.dataportabilityproject.dataModels.tasks.TaskListModel)1 TaskModelWrapper (org.dataportabilityproject.dataModels.tasks.TaskModelWrapper)1 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)1 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)1 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)1 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)1 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)1 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)1 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)1 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)1 TaskContainerResource (org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource)1