Search in sources :

Example 6 with FileList

use of com.google.api.services.drive.model.FileList in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method listOwnerFiles.

public List<File> listOwnerFiles() {
    FileList result;
    List<File> files = new ArrayList<>();
    com.google.api.services.drive.Drive.Files.List request = null;
    try {
        do {
            request = service.files().list().setMaxResults(500);
            result = request.execute();
            files.addAll(result.getItems());
            request.setPageToken(result.getNextPageToken());
        } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    } catch (IOException e) {
        log.error("Error list files", e);
    }
    return files;
}
Also used : FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(com.google.api.services.drive.model.File)

Example 7 with FileList

use of com.google.api.services.drive.model.FileList in project local-data-aragopedia by aragonopendata.

the class GoogleDriveAPI method listOwnerFilesAfterDate.

public List<File> listOwnerFilesAfterDate(String stringDateLastChange) {
    SimpleDateFormat formatFullDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date dateLastChange = null;
    try {
        dateLastChange = formatFullDate.parse(stringDateLastChange);
    } catch (ParseException e1) {
        log.error("Error parse date in list", e1);
    }
    FileList result;
    List<File> files = null;
    try {
        result = service.files().list().setMaxResults(500).execute();
        files = result.getItems();
    } catch (IOException e) {
        log.error("Error list files", e);
    }
    if (files == null || files.size() == 0) {
        log.error("No files found");
    } else {
        log.info("Files:\n");
        for (File file : files) {
            DateTime dateTime = file.getModifiedDate();
            Date dateModifyFile = new Date(dateTime.getValue());
            if (dateModifyFile.after(dateLastChange))
                log.info("Title " + file.getTitle() + " id " + file.getId() + " DateTime " + formatFullDate.format(dateModifyFile));
        }
    }
    return files;
}
Also used : FileList(com.google.api.services.drive.model.FileList) ParseException(java.text.ParseException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(com.google.api.services.drive.model.File) Date(java.util.Date) DateTime(com.google.api.client.util.DateTime)

Aggregations

File (com.google.api.services.drive.model.File)7 FileList (com.google.api.services.drive.model.FileList)7 IOException (java.io.IOException)5 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 DateTime (com.google.api.client.util.DateTime)2 GeneralSecurityException (java.security.GeneralSecurityException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Test (org.junit.Test)2 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)1 Files (com.google.api.services.drive.Drive.Files)1 HashMap (java.util.HashMap)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1