Search in sources :

Example 31 with File

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

the class DriveFilesIntegrationTest method testTouch.

@Test
public void testTouch() throws Exception {
    File theTestFile = uploadTestFile();
    DateTime createdDate = theTestFile.getModifiedDate();
    // using String message body for single parameter "fileId"
    File result = requestBody("direct://TOUCH", theTestFile.getId());
    assertNotNull("touch result", result);
    assertTrue(result.getModifiedDate().getValue() > createdDate.getValue());
}
Also used : File(com.google.api.services.drive.model.File) DateTime(com.google.api.client.util.DateTime) Test(org.junit.Test)

Example 32 with File

use of com.google.api.services.drive.model.File 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 33 with File

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

the class GoogleDriveAPI method downloadAllFiles.

public void downloadAllFiles(String path) {
    List<File> files = listOwnerFiles();
    for (File file : files) {
        try {
            String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
            InputStream input = resp.getContent();
            java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".xlsx");
            FileUtils.copyInputStreamToFile(input, f);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : InputStream(java.io.InputStream) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) File(com.google.api.services.drive.model.File)

Example 34 with File

use of com.google.api.services.drive.model.File 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 35 with File

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

the class GoogleDriveAPI method downloadFilesAfterDate.

public void downloadFilesAfterDate(String path, String stringDateLastChange) {
    List<File> files = listOwnerFilesAfterDate(stringDateLastChange);
    for (File file : files) {
        try {
            String downloadUrl = file.getExportLinks().get("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            HttpResponse resp = service.getRequestFactory().buildGetRequest(new GenericUrl(downloadUrl)).execute();
            InputStream input = resp.getContent();
            java.io.File f = new java.io.File(path + java.io.File.separator + file.getTitle() + ".xlsx");
            FileUtils.copyInputStreamToFile(input, f);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : InputStream(java.io.InputStream) HttpResponse(com.google.api.client.http.HttpResponse) GenericUrl(com.google.api.client.http.GenericUrl) IOException(java.io.IOException) File(com.google.api.services.drive.model.File)

Aggregations

File (com.google.api.services.drive.model.File)41 Test (org.junit.Test)19 IOException (java.io.IOException)17 HashMap (java.util.HashMap)9 FileList (com.google.api.services.drive.model.FileList)7 ParseException (java.text.ParseException)7 ArrayList (java.util.ArrayList)7 FileContent (com.google.api.client.http.FileContent)6 GeneralSecurityException (java.security.GeneralSecurityException)6 GenericUrl (com.google.api.client.http.GenericUrl)4 HttpResponse (com.google.api.client.http.HttpResponse)4 Permission (com.google.api.services.drive.model.Permission)4 User (com.google.api.services.drive.model.User)4 InputStream (java.io.InputStream)4 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)3 DateTime (com.google.api.client.util.DateTime)3 ParentReference (com.google.api.services.drive.model.ParentReference)3 Comment (com.google.api.services.drive.model.Comment)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2