private FileStatus toFileStatus(File metadata) { return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(), FOLDER_MIME_TYPE.equals(metadata.getMimeType()), -1, -1, metadata.getModifiedTime().getValue(), new Path(metadata.getId())); }
private String importSingleFolder( UUID jobId, Drive driveInterface, String folderName, String folderId, String parentId) throws IOException { File newFolder = new File() .setName(folderName) .setMimeType(DriveExporter.FOLDER_MIME_TYPE); if (!Strings.isNullOrEmpty(parentId)) { newFolder.setParents(ImmutableList.of(parentId)); } File resultFolder = driveInterface.files().create(newFolder).execute(); DriveFolderMapping mapping = new DriveFolderMapping(folderId, resultFolder.getId()); jobStore.update(jobId, folderId, mapping); return resultFolder.getId(); }
protected void doCreateFolder() throws Exception { if ( !getName().getBaseName().isEmpty() ) { File folder = new File(); folder.setName( getName().getBaseName() ); folder.setMimeType( MIME_TYPES.FOLDER.mimeType ); folder = driveService.files().create( folder ).execute(); if ( folder != null ) { id = folder.getId(); mimeType = MIME_TYPES.get( folder.getMimeType() ); } } }
private void resolveFileMetadata() throws Exception { String parentId = null; if ( getName().getParent() != null ) { File parent = searchFile( getName().getParent().getBaseName(), null ); if ( parent != null ) { FileType mime = MIME_TYPES.get( parent.getMimeType() ); if ( mime.equals( FileType.FOLDER ) ) { parentId = parent.getId(); } } } String fileName = getName().getBaseName(); File file = searchFile( fileName, parentId ); if ( file != null ) { mimeType = MIME_TYPES.get( file.getMimeType() ); id = file.getId(); } else { if ( getName().getURI().equals( GoogleDriveFileProvider.SCHEME + ":///" ) ) { mimeType = FileType.FOLDER; } } }
public void close() throws IOException { File file = new File(); file.setName( getName().getBaseName() ); if ( parent != null ) { file.setParents( Collections.singletonList( parent.getId() ) ); } ByteArrayContent fileContent = new ByteArrayContent( "application/octet-stream", toByteArray() ); if ( count > 0 ) { driveService.files().create( file, fileContent ).execute(); ( (GoogleDriveFileSystem) getFileSystem() ).clearFileFromCache( getName() ); } } };
folders.add(new BlobbyStorageContainerResource(file.getName(), file.getId(), null, null)); } else if (FUSION_TABLE_MIME_TYPE.equals(file.getMimeType())) { monitor.info(() -> "Exporting of fusion tables is not yet supported: " + file); driveInterface .files() .export(file.getId(), newMimeType) .executeMedia() .getContent(); driveInterface .files() .get(file.getId()) .setAlt("media") .executeMedia() .getContent(); jobStore.create(jobId, file.getId(), inputStream); files.add( new DigitalDocumentWrapper( file.getName(), file.getModifiedTime().toStringRfc3339(), newMimeType), file.getMimeType(), file.getId())); } catch (Exception e) { monitor.severe(() -> "Error exporting " + file, e);
private File modifySpreadsheet(final File original, final java.io.File export) throws IOException { final String id = original.getId(); LOGGER.debug("Updating an existing Google spreadsheet: {}.", id); final File result = actuallyModifySpreadsheet(original, export); LOGGER.debug("Google spreadsheet updated."); return result; }
public boolean isGoogleAppsDocument(File file) { String mimeType = file.getMimeType(); if (mimeType != null && mimeType.startsWith("application/vnd.google-apps") && !mimeType.equals("application/vnd.google-apps.folder")) { LOGGER.log(Level.FINE, "Not touching file " + file.getId() + " because it is a Google Apps document."); return true; } return false; }
private File modifySpreadsheet(final File original, final java.io.File export) throws IOException { final String id = original.getId(); LOGGER.debug("Updating an existing Google spreadsheet: {}.", id); final File result = actuallyModifySpreadsheet(original, export); LOGGER.debug("Google spreadsheet updated."); return result; }
@Override public Map<String, Object> getReturnValues() { Map<String, Object> r = result.toMap(); r.put(GoogleDrivePutDefinition.RETURN_FILE_ID, sentFile.getId()); r.put(GoogleDrivePutDefinition.RETURN_PARENT_FOLDER_ID, sentFile.getParents().get(0)); return r; }
@Override protected boolean appliesTo(final String method, final String url) { return Objects.equals(method, "POST") && Objects.equals(url, "https://sheets.googleapis.com/v4/spreadsheets/" + parent.getId() + ":batchUpdate"); }
@Override protected boolean appliesTo(final String method, final String url) { return Objects.equals(method, "GET") && url.startsWith("https://www.googleapis.com/drive/v3/files/" + file.getId()); }
private FileStatus toFileStatus(File metadata) { return new FileStatus(metadata.getSize() == null ? 0L : metadata.getSize(), FOLDER_MIME_TYPE.equals(metadata.getMimeType()), -1, -1, metadata.getModifiedTime().getValue(), new Path(metadata.getId())); }
private static Stream<File> getFilesInFolder(final Drive driveService, final String parentId) throws IOException { LOGGER.debug("Listing files in folder {}.", parentId); return driveService.files().list() .setQ("'" + parentId + "' in parents and trashed = false") .setFields("nextPageToken, files(" + getFields("mimeType") + ")") .execute() .getFiles() .stream() .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId())); }
@Test void updateWalletSpreadsheet() throws IOException { final DriveOverview overview = DriveOverview.create(SESSION_INFO, drive, sheets); // copy the spreadsheet since it does not exist final File result = overview.latestWallet(GoogleUtil.getDownloaded()); assertThat(result.getId()).isEqualTo(walletSpreadsheet.getId()); }
private void setReturnValues(RuntimeContainer container) { String componentId = container.getCurrentComponentId(); container.setComponentData(componentId, getStudioName(GoogleDrivePutDefinition.RETURN_PARENT_FOLDER_ID), sentFile.getParents().get(0)); container.setComponentData(componentId, getStudioName(GoogleDrivePutDefinition.RETURN_FILE_ID), sentFile.getId()); } }
private File actuallyModifySpreadsheet(final File original, final java.io.File export) throws IOException { final FileContent fc = new FileContent(MIME_TYPE_XLS_SPREADSHEET, export); return driveService.files().update(original.getId(), null, fc) .setFields(getFields()) .execute(); }
@Override protected MockLowLevelHttpResponse respond(final String method, final String url) { /* * * "location" header handles the redirect from first part to second part, otherwise API will throw NPE. the * value given is synthetic and has no relation to anything that Google may put there. */ return new MockLowLevelHttpResponse() .setContent(toJson(file)) .addHeader("Location", ROOT + "?id=" + file.getId() + "uploadType=resumable"); } }
public void shareFile(File file, String to) throws IOException { BatchRequest batch = drive.batch(); Permission userPermission = new Permission() .setType("user") .setRole("writer") .setValue(to); drive.permissions().insert(file.getId(), userPermission) .setSendNotificationEmails(true) .setFields("id") .queue(batch, callback); batch.execute(); }
@BeforeEach void prepareFolder() { transport = new MultiRequestMockHttpTransport(); transport.addReponseHandler(new FilesInFolderResponseHandler("root", stonkyFolder)); stonkyFolderContent = new FilesInFolderResponseHandler(stonkyFolder.getId()); transport.addReponseHandler(stonkyFolderContent); drive = Util.createDriveService(credential, transport); sheets = Util.createSheetsService(credential, transport); }