Search in sources :

Example 1 with FileList

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

the class GoogleDriveAPI method listOwnerFilesAfterDate.

/**
	 * Method to list files and folders of id account after date of parameter
	 */
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 = drive.files().list().setMaxResults(1000).execute();
        files = result.getItems();
    } catch (Exception e) {
        log.error("Error list files", e);
    }
    if (files == null || files.size() == 0) {
        log.error("No files found");
    } else {
        for (File file : files) {
            if (file.getShared()) {
                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) SimpleDateFormat(java.text.SimpleDateFormat) File(com.google.api.services.drive.model.File) Date(java.util.Date) GeneralSecurityException(java.security.GeneralSecurityException) ParseException(java.text.ParseException) IOException(java.io.IOException) DateTime(com.google.api.client.util.DateTime)

Example 2 with FileList

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

the class GoogleDriveAPI method listOwnerFiles.

/**
	 * Method to list all files and folders of id account
	 */
public List<File> listOwnerFiles() {
    log.debug("init listOwnerFiles()");
    List<File> result = new ArrayList<File>();
    try {
        com.google.api.services.drive.Drive.Files.List request = drive.files().list().setQ("trashed = false");
        do {
            try {
                FileList files = request.execute();
                result.addAll(files.getItems());
                request.setPageToken(files.getNextPageToken());
            } catch (Exception e) {
                System.out.println("An error occurred: " + e);
                request.setPageToken(null);
            }
        } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    } catch (Exception e) {
        log.error("Error list files", e);
    }
    log.debug("end listOwnerFiles()");
    return result;
}
Also used : FileList(com.google.api.services.drive.model.FileList) ArrayList(java.util.ArrayList) File(com.google.api.services.drive.model.File) GeneralSecurityException(java.security.GeneralSecurityException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 3 with FileList

use of com.google.api.services.drive.model.FileList in project camel by apache.

the class DriveFilesIntegrationTest method testList.

@Test
public void testList() throws Exception {
    // upload a test file
    File testFile = uploadTestFile();
    FileList result = requestBody("direct://LIST", null);
    assertNotNull("list result", result);
    assertTrue(result.getItems().size() >= 1);
    File testFile2 = uploadTestFile();
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("CamelGoogleDrive.maxResults", 1);
    result = requestBodyAndHeaders("direct://LIST", null, headers);
    assertNotNull("list result", result);
    assertTrue(result.getItems().size() == 1);
    // test paging the list
    List<File> resultList = new ArrayList<File>();
    String pageToken;
    int i = 0;
    do {
        result = requestBodyAndHeaders("direct://LIST", null, headers);
        resultList.addAll(result.getItems());
        pageToken = result.getNextPageToken();
        headers.put("CamelGoogleDrive.pageToken", pageToken);
        i++;
    } while (pageToken != null && pageToken.length() > 0 && i < 2);
    // we should have 2 files in result (one file for each of the 2 pages)
    assertTrue(resultList.size() == 2);
    // they should be different files
    assertFalse(resultList.get(0).getId().equals(resultList.get(1)));
}
Also used : FileList(com.google.api.services.drive.model.FileList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 4 with FileList

use of com.google.api.services.drive.model.FileList in project camel by apache.

the class FilesConsumerIntegrationTest method testListConsumer.

@Test
public void testListConsumer() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    assertMockEndpointsSatisfied();
    FileList fileList = mock.getReceivedExchanges().get(0).getIn().getBody(com.google.api.services.drive.model.FileList.class);
    assertTrue(fileInList(fileId, fileList));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) FileList(com.google.api.services.drive.model.FileList) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 5 with FileList

use of com.google.api.services.drive.model.FileList in project Aegis by Decad3nce.

the class BackupGoogleAccountsActivity method getAegisFolder.

private static String getAegisFolder() {
    Files.List request = null;
    String folderID = null;
    try {
        request = service.files().list().setQ("mimeType= 'application/vnd.google-apps.folder' and title = 'aeGis Backup' and trashed = false");
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    do {
        FileList files;
        try {
            files = request.execute();
            for (File file : files.getItems()) {
                folderID = file.getId();
            }
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    //Log.i(TAG, "FolderID: " + folderID);
    return folderID;
}
Also used : FileList(com.google.api.services.drive.model.FileList) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) Files(com.google.api.services.drive.Drive.Files) File(com.google.api.services.drive.model.File)

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