Java Code Examples for com.google.api.services.drive.model.File#setTrashed()

The following examples show how to use com.google.api.services.drive.model.File#setTrashed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DriveDeleteFeature.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) throws BackgroundException {
    for(Path file : files.keySet()) {
        if(file.getType().contains(Path.Type.placeholder)) {
            continue;
        }
        callback.delete(file);
        try {
            if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) {
                session.getClient().teamdrives().delete(fileid.getFileid(file, new DisabledListProgressListener())).execute();
            }
            else {
                if(PreferencesFactory.get().getBoolean("googledrive.delete.trash")) {
                    final File properties = new File();
                    properties.setTrashed(true);
                    session.getClient().files().update(fileid.getFileid(file, new DisabledListProgressListener()), properties)
                        .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
                }
                else {
                    session.getClient().files().delete(fileid.getFileid(file, new DisabledListProgressListener()))
                        .setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute();
                }
            }
        }
        catch(IOException e) {
            throw new DriveExceptionMappingService().map("Cannot delete {0}", e, file);
        }
    }
}
 
Example 2
Source File: GoogleDriveListReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartOnly() throws Exception {
    FileList fileList = new FileList();
    File f = new File();
    f.setName("sd");
    f.setMimeType("text/text");
    f.setId("id-1");
    f.setModifiedTime(com.google.api.client.util.DateTime.parseRfc3339("2017-09-29T10:00:00"));
    f.setSize(100L);
    f.setKind("drive#fileName");
    f.setTrashed(false);
    f.setParents(Collections.singletonList(FOLDER_ROOT));
    f.setWebViewLink("https://toto.com");
    fileList.setFiles(Arrays.asList(f));

    when(mockList.execute()).thenReturn(fileList);
    //
    source.initialize(container, properties);
    GoogleDriveListReader reader = ((GoogleDriveListReader) source.createReader(container));
    assertTrue(reader.start());
    IndexedRecord record = (IndexedRecord) reader.getCurrent();
    assertNotNull(record);
    assertEquals(9, record.getSchema().getFields().size());
    assertEquals("id-1", record.get(0));
    assertEquals("sd", record.get(1));
    assertFalse(reader.advance());
    reader.close();
}
 
Example 3
Source File: GoogleDriveListReaderTest.java    From components with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdvance() throws Exception {
    FileList fileList = new FileList();
    for (int i = 0; i < 5; i++) {
        File f = new File();
        f.setName("sd" + i);
        f.setMimeType("text/text");
        f.setId("id-" + i);
        f.setModifiedTime(com.google.api.client.util.DateTime.parseRfc3339("2017-09-29T10:00:00"));
        f.setSize(100L);
        f.setKind("drive#fileName");
        f.setTrashed(false);
        f.setParents(Collections.singletonList(FOLDER_ROOT));
        f.setWebViewLink("https://toto.com");
        fileList.setFiles(Arrays.asList(f));
    }
    when(mockList.execute()).thenReturn(fileList);
    //
    properties.folder.setValue("A");
    source.initialize(container, properties);
    GoogleDriveListReader reader = ((GoogleDriveListReader) source.createReader(container));
    assertTrue(reader.start());
    while (reader.advance()) {
        assertNotNull(reader.getCurrent());
    }
    reader.close();
}
 
Example 4
Source File: GoogleDriveInputReaderTest.java    From components with Apache License 2.0 4 votes vote down vote up
@Test
public void testAdvance() throws Exception {
    dataSource = spy(dataSource);
    Drive drive = mock(Drive.class, RETURNS_DEEP_STUBS);
    GoogleDriveUtils utils = mock(GoogleDriveUtils.class, RETURNS_DEEP_STUBS);
    doReturn(drive).when(dataSource).getDriveService();
    doReturn(utils).when(dataSource).getDriveUtils();

    List mockList = mock(List.class, RETURNS_DEEP_STUBS);
    when(drive.files().list()).thenReturn(mockList);
    //
    // String qA = "name='A' and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false";
    //
    // when(drive.files().list().setQ(eq(qA)).execute()).thenReturn(createFolderFileList("A", false));
    //
    // GoogleDriveAbstractListReader alr = mock(GoogleDriveAbstractListReader.class);
    // doReturn(true).when(alr).start();

    inputProperties.getDatasetProperties().folder.setValue("A");

    FileList fileList = new FileList();
    File f = new File();
    f.setName("sd");
    f.setMimeType("text/text");
    f.setId("id-1");
    f.setModifiedTime(com.google.api.client.util.DateTime.parseRfc3339("2017-09-29T10:00:00"));
    f.setSize(100L);
    f.setKind("drive#fileName");
    f.setTrashed(false);
    f.setParents(Collections.singletonList(FOLDER_ROOT));
    f.setWebViewLink("https://toto.com");
    fileList.setFiles(Arrays.asList(f, f, f, f, f));

    when(mockList.execute()).thenReturn(fileList);

    dataSource.initialize(container, inputProperties);
    reader = (GoogleDriveInputReader) dataSource.createReader(container);
    reader.setLimit(2);
    assertTrue(reader.start());
    reader.getCurrent();
    assertTrue(reader.advance());
    reader.getCurrent();
    assertFalse(reader.advance());
}
 
Example 5
Source File: GoogleDrive.java    From google-drive-ftp-adapter with GNU Lesser General Public License v3.0 4 votes vote down vote up
public File trashFile(String fileId) {
    File patch = new File();
    patch.setTrashed(true);
    return patchFile(fileId, patch, 3);
}