private FileList createFileList(java.util.List<String> fileIds, String folderId) { FileList fileList = new FileList(); java.util.List<File> list = Lists.newArrayList(); for (String fileId : fileIds) { File f = new File(); f.setId(fileId); f.setModifiedTime(new DateTime(System.currentTimeMillis())); list.add(f); } if (folderId != null) { File f = new File(); f.setMimeType(FOLDER_MIME_TYPE); f.setId(folderId); f.setModifiedTime(new DateTime(System.currentTimeMillis())); list.add(f); } fileList.setFiles(list); return fileList; } }
private void importSingleFile( UUID jobId, Drive driveInterface, DigitalDocumentWrapper file, String parentId) throws IOException { InputStreamContent content = new InputStreamContent( null, jobStore.getStream(jobId, file.getCachedContentId())); DtpDigitalDocument dtpDigitalDocument = file.getDtpDigitalDocument(); File driveFile = new File().setName(dtpDigitalDocument.getName()); if (!Strings.isNullOrEmpty(parentId)) { driveFile.setParents(ImmutableList.of(parentId)); } if (!Strings.isNullOrEmpty(dtpDigitalDocument.getDateModified())) { driveFile.setModifiedTime(DateTime.parseRfc3339(dtpDigitalDocument.getDateModified())); } if (!Strings.isNullOrEmpty(file.getOriginalEncodingFormat()) && file.getOriginalEncodingFormat().startsWith("application/vnd.google-apps.")) { driveFile.setMimeType(file.getOriginalEncodingFormat()); } driveInterface.files().create( driveFile, content ).execute(); }
final File file = new File(); file.setId("testId"); file.setModifiedTime(new DateTime(System.currentTimeMillis()));
private File mkdir_impl(GFile gFile, int retry) { try { // New file logger.info("Creating new directory..."); File file = new File(); file.setMimeType("application/vnd.google-apps.folder"); file.setName(gFile.getName()); file.setModifiedTime(new DateTime(System.currentTimeMillis())); file.setParents(new ArrayList<>(gFile.getParents())); file = drive.files().create(file).setFields(REQUEST_FILE_FIELDS).execute(); logger.info("Directory created successfully: " + file.getId()); return file; } catch (IOException e) { if (retry > 0) { try { Thread.sleep(1000); } catch (InterruptedException e1) { throw new RuntimeException(e1); } logger.warn("Uploading file failed. Retrying... '" + gFile.getId()); return mkdir_impl(gFile, --retry); } throw new RuntimeException("Exception uploading file " + gFile.getId(), e); } }
public void store(SyncDirectory syncDirectory) { Drive drive = driveFactory.getDrive(this.credential); try { java.io.File localFile = syncDirectory.getLocalFile().get(); File remoteFile = new File(); remoteFile.setName(localFile.getName()); remoteFile.setMimeType(MIME_TYPE_FOLDER); remoteFile.setParents(createParentReferenceList(syncDirectory)); BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis())); LOGGER.log(Level.FINE, "Inserting new directory '" + syncDirectory.getPath() + "'."); if (!options.isDryRun()) { File insertedFile = executeWithRetry(options, () -> drive.files().create(remoteFile).execute()); syncDirectory.setRemoteFile(Optional.of(insertedFile)); } } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e); } }
public void updateMetadata(SyncItem syncItem) { Drive drive = driveFactory.getDrive(this.credential); try { java.io.File localFile = syncItem.getLocalFile().get(); File remoteFile = syncItem.getRemoteFile().get(); BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); if (isGoogleAppsDocument(remoteFile)) { return; } LOGGER.log(Level.FINE, "Updating metadata of remote file " + remoteFile.getId() + " (" + syncItem.getPath() + ")."); if (!options.isDryRun()) { File newRemoteFile = new File(); newRemoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis())); Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), newRemoteFile).setFields("modifiedTime"); File updatedFile = executeWithRetry(options, () -> updateRequest.execute()); syncItem.setRemoteFile(Optional.of(updatedFile)); } } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e); } }
file.setModifiedTime(new DateTime(gFile.getLastModified() != 0 ? gFile.getLastModified() : System.currentTimeMillis())); file.setName(gFile.getName());
public void updateFile(SyncItem syncItem) { Drive drive = driveFactory.getDrive(this.credential); try { java.io.File localFile = syncItem.getLocalFile().get(); File remoteFile = syncItem.getRemoteFile().get(); BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis())); if (isGoogleAppsDocument(remoteFile)) { return; } LOGGER.log(Level.INFO, "Updating file " + remoteFile.getId() + " (" + syncItem.getPath() + ")."); if (!options.isDryRun()) { Drive.Files.Update updateRequest = drive.files().update(remoteFile.getId(), remoteFile, new FileContent(determineMimeType(localFile), localFile)); //updateRequest.setModifiedDate(true); File updatedFile = executeWithRetry(options, () -> updateRequest.execute()); syncItem.setRemoteFile(Optional.of(updatedFile)); } } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to update file: " + e.getMessage(), e); } }
/** * Touches the file, changing the name or date modified * * @param fileId the file id to patch * @param newName the new file name * @param newLastModified the new last modified date * @return the patched file */ public GFile patchFile(String fileId, String newName, long newLastModified) { File patch = new File(); if (newName != null) { patch.setName(newName); } if (newLastModified > 0) { patch.setModifiedTime(new DateTime(newLastModified)); } return create(patchFile(fileId, patch, 3)); }
remoteFile.setParents(createParentReferenceList(syncFile)); BasicFileAttributes attr = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); remoteFile.setModifiedTime(new DateTime(attr.lastModifiedTime().toMillis())); LOGGER.log(Level.INFO, "Uploading new file '" + syncFile.getPath() + "' (" + bytesWithUnit(attr.size()) + ")."); if (!options.isDryRun()) {
public static File getFile(final String name, final String id) { final File result = new File(); result.setId(id); result.setMimeType("application/vnd.google-apps.files"); result.setName(name); result.setModifiedTime(new DateTime(System.currentTimeMillis())); return result; }
@Override public void setTimestamp(final Path file, final Long modified) throws BackgroundException { try { final String fileid = this.fileid.getFileid(file, new DisabledListProgressListener()); final File properties = new File(); properties.setModifiedTime(new DateTime(modified)); session.getClient().files().update(fileid, properties).setFields("modifiedTime"). setSupportsTeamDrives(PreferencesFactory.get().getBoolean("googledrive.teamdrive.enable")).execute(); } catch(IOException e) { throw new DriveExceptionMappingService().map("Failure to write attributes of {0}", e, file); } } }