Search in sources :

Example 41 with DateTime

use of com.google.api.client.util.DateTime in project data-transfer-project by google.

the class GoogleTasksImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, TaskContainerResource data) throws Exception {
    Tasks tasksService = getOrCreateTasksService(authData);
    for (TaskListModel oldTasksList : data.getLists()) {
        TaskList newTaskList = new TaskList().setTitle("Imported copy - " + oldTasksList.getName());
        idempotentImportExecutor.executeAndSwallowIOExceptions(oldTasksList.getId(), oldTasksList.getName(), () -> tasksService.tasklists().insert(newTaskList).execute().getId());
    }
    for (TaskModel oldTask : data.getTasks()) {
        Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
        if (oldTask.getCompletedTime() != null) {
            newTask.setCompleted(new DateTime(oldTask.getCompletedTime().toEpochMilli()));
        }
        if (oldTask.getDueTime() != null) {
            newTask.setDue(new DateTime(oldTask.getDueTime().toEpochMilli()));
        }
        // If its not cached that means the task list create failed.
        if (idempotentImportExecutor.isKeyCached(oldTask.getTaskListId())) {
            String newTaskListId = idempotentImportExecutor.getCachedValue(oldTask.getTaskListId());
            idempotentImportExecutor.executeAndSwallowIOExceptions(oldTask.getTaskListId() + oldTask.getText(), oldTask.getText(), () -> tasksService.tasks().insert(newTaskListId, newTask).execute().getId());
        }
    }
    return new ImportResult(ResultType.OK);
}
Also used : Task(com.google.api.services.tasks.model.Task) Tasks(com.google.api.services.tasks.Tasks) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TaskList(com.google.api.services.tasks.model.TaskList) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) DateTime(com.google.api.client.util.DateTime)

Aggregations

DateTime (com.google.api.client.util.DateTime)41 Event (com.google.api.services.calendar.model.Event)13 EventDateTime (com.google.api.services.calendar.model.EventDateTime)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)9 Calendar (com.google.api.services.calendar.Calendar)8 Events (com.google.api.services.calendar.model.Events)7 File (com.google.api.services.drive.model.File)7 CalendarData (com.cloudcraftgaming.discal.api.object.calendar.CalendarData)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Test (org.junit.Test)6 Map (java.util.Map)5 ParseException (java.text.ParseException)4 GuildSettings (com.cloudcraftgaming.discal.api.object.GuildSettings)3 EventData (com.cloudcraftgaming.discal.api.object.event.EventData)3 Recurrence (com.cloudcraftgaming.discal.api.object.event.Recurrence)3 WebGuild (com.cloudcraftgaming.discal.api.object.web.WebGuild)3 FileList (com.google.api.services.drive.model.FileList)3 StorageObject (com.google.api.services.storage.model.StorageObject)3