protected String[] doListChildren() throws Exception { String[] children = null; if ( isFolder() ) { id = id == null ? "root" : id; String fileQuery = "'" + id + "' in parents and trashed=false"; FileList files = driveService.files().list().setQ( fileQuery ).execute(); List<String> fileNames = new ArrayList<String>(); for ( File file : files.getFiles() ) { fileNames.add( file.getName() ); } children = fileNames.toArray( new String[0] ); } return children; }
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); new DigitalDocumentWrapper( new DtpDigitalDocument( file.getName(), file.getModifiedTime().toStringRfc3339(), newMimeType), file.getMimeType(), file.getId()));
public boolean fileNameValid(File file) { String title = file.getName(); if (title == null || title.contains("/") || title.contains("\\")) { return false; } return true; }
private static Optional<File> getSpreadsheetWithName(final Stream<File> all, final String name) { LOGGER.debug("Looking up spreadsheet with name: {}.", name); return listSpreadsheets(all) .filter(f -> Objects.equals(f.getName(), name)) .findFirst(); }
private static Optional<File> getSpreadsheetWithName(final Stream<File> all, final String name) { LOGGER.debug("Looking up spreadsheet with name: {}.", name); return listSpreadsheets(all) .filter(f -> Objects.equals(f.getName(), name)) .findFirst(); }
private void removeDuplicates(List<File> resultList) { Map<String, File> fileNameMap = new HashMap<>(); Iterator<File> iterator = resultList.iterator(); while (iterator.hasNext()) { File file = iterator.next(); String title = file.getName(); File titleFound = fileNameMap.get(title); if (titleFound == null) { fileNameMap.put(title, file); } else { LOGGER.log(Level.WARNING, "Ignoring remote file '" + title + "' (id: '" + file.getId() + "') because its title/name appears more than once in this folder."); iterator.remove(); } } }
public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService, final Sheets sheetService) throws IOException { final String folderName = getFolderName(sessionInfo); LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName); final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList()); final Optional<File> result = files.stream() .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId())) .filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER)) .filter(f -> Objects.equals(f.getName(), folderName)) .findFirst(); if (result.isPresent()) { return create(sessionInfo, driveService, sheetService, result.get()); } else { return new DriveOverview(sessionInfo, driveService, sheetService); } }
public static DriveOverview create(final SessionInfo sessionInfo, final Drive driveService, final Sheets sheetService) throws IOException { final String folderName = getFolderName(sessionInfo); LOGGER.debug("Listing all files in the root of Google Drive, looking up folder: {}.", folderName); final List<File> files = getFilesInFolder(driveService, "root").collect(Collectors.toList()); final Optional<File> result = files.stream() .peek(f -> LOGGER.debug("Found '{}' ({}) as {}.", f.getName(), f.getMimeType(), f.getId())) .filter(f -> Objects.equals(f.getMimeType(), MIME_TYPE_FOLDER)) .filter(f -> Objects.equals(f.getName(), folderName)) .findFirst(); if (result.isPresent()) { return create(sessionInfo, driveService, sheetService, result.get()); } else { return new DriveOverview(sessionInfo, driveService, sheetService); } }
public Iterator<SyncItem> getChildrenIterator() { Collections.sort(children, (o1, o2) -> { if(o1.getLocalFile().isPresent() && o2.getLocalFile().isPresent()) { return o1.getLocalFile().get().getName().compareTo(o2.getLocalFile().get().getName()); } else if(o1.getRemoteFile().isPresent() && o2.getRemoteFile().isPresent()) { return o1.getRemoteFile().get().getName().compareTo(o2.getRemoteFile().get().getName()); } else if(o1.getLocalFile().isPresent() && o2.getRemoteFile().isPresent()) { return o1.getLocalFile().get().getName().compareTo(o2.getRemoteFile().get().getName()); } else if(o2.getLocalFile().isPresent() && o1.getRemoteFile().isPresent()) { return o2.getLocalFile().get().getName().compareTo(o1.getRemoteFile().get().getName()); } return 0; }); return children.iterator(); }
private File createOrReuseStonky() throws IOException { final String masterId = Properties.STONKY_MASTER.getValue() .orElseGet(() -> Util.wrap(this::autodetectLatestStonkyVersion).get()); LOGGER.debug("Will look for Stonky master spreadsheet: {}.", masterId); final File upstream = Util.getFile(driveService, masterId); final File parent = getOrCreateRoboZonkyFolder(); final String expectedName = "My " + upstream.getName(); // such as "My Stonky 0.8 [Public Beta Release]" final Optional<File> stonky = listSpreadsheets(getFilesInFolder(driveService, parent)) .filter(s -> Objects.equals(s.getName(), expectedName)) .findFirst(); if (stonky.isPresent()) { final File result = stonky.get(); LOGGER.debug("Found a copy of Stonky: {}.", result.getId()); return result; } else { return Util.copyFile(driveService, upstream, parent, expectedName); } }
private File createOrReuseStonky() throws IOException { final String masterId = Properties.STONKY_MASTER.getValue() .orElseGet(() -> Util.wrap(this::autodetectLatestStonkyVersion).get()); LOGGER.debug("Will look for Stonky master spreadsheet: {}.", masterId); final File upstream = Util.getFile(driveService, masterId); final File parent = getOrCreateRoboZonkyFolder(); final String expectedName = "My " + upstream.getName(); // such as "My Stonky 0.8 [Public Beta Release]" final Optional<File> stonky = listSpreadsheets(getFilesInFolder(driveService, parent)) .filter(s -> Objects.equals(s.getName(), expectedName)) .findFirst(); if (stonky.isPresent()) { final File result = stonky.get(); LOGGER.debug("Found a copy of Stonky: {}.", result.getId()); return result; } else { return Util.copyFile(driveService, upstream, parent, expectedName); } }
public File getFile(String id) { Drive drive = driveFactory.getDrive(this.credential); try { File file = executeWithRetry(options, () -> drive.files().get(id).execute()); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Got file : " + file.getId() + ":" + file.getName()); } return file; } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to execute get file request: " + e.getMessage(), e); } }
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())); }
private void processRemoteChildNotFound(com.google.api.services.drive.model.File remoteChild, SyncDirectory syncDirectory) { LOGGER.log(Level.FINE, "Deleting remote file/directory '" + remoteChild.getName() + "' because locally it does not exist any more."); if (googleDriveAdapter.isDirectory(remoteChild)) { googleDriveAdapter.deleteDirectory(remoteChild); ReportFactory.getInstance(options).log(new ReportEntry(syncDirectory.getPath() + "/" + remoteChild.getName(), ReportEntry.Status.Synchronized, ReportEntry.Action.Deleted)); } else { if (!googleDriveAdapter.isGoogleAppsDocument(remoteChild)) { googleDriveAdapter.deleteFile(remoteChild); ReportFactory.getInstance(options).log(new ReportEntry(syncDirectory.getPath() + "/" + remoteChild.getName(), ReportEntry.Status.Synchronized, ReportEntry.Action.Deleted)); } } }
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())); }
/** * Blocking version of {@link #fetchGameStatesSync()} * * @return game states * @throws IOException */ public Array<String> fetchGameStatesSync() throws IOException { if (!driveApiEnabled) throw new UnsupportedOperationException(); Array<String> games = new Array<String>(); FileList l = GApiGateway.drive.files().list() .setSpaces("appDataFolder") .setFields("files(name)") .execute(); for (File f : l.getFiles()) { games.add(f.getName()); } return games; }
private GFile create(File file) { GFile newFile = new GFile(file.getName() != null ? file.getName() : file.getOriginalFilename()); newFile.setId(file.getId()); newFile.setLastModified(file.getModifiedTime() != null ? file.getModifiedTime().getValue() : 0); newFile.setDirectory(GFile.MIME_TYPE.GOOGLE_FOLDER.getValue().equals(file.getMimeType())); newFile.setSize(file.getSize() != null ? file.getSize() : 0); // null for directories newFile.setMimeType(file.getMimeType()); newFile.setMd5Checksum(file.getMd5Checksum()); if (file.getParents() != null) { Set<String> newParents = new HashSet<>(); for (String newParent : file.getParents()) { newParents.add(newParent.equals(ROOT_FOLDER_ID) ? "root" : newParent); } newFile.setParents(newParents); } else { // does this happen? newFile.setParents(Collections.singleton("root")); } newFile.setTrashed(file.getTrashed() != null && file.getTrashed()); return newFile; }
private IndexedRecord convertSearchResultToIndexedRecord(File file) { // Main record IndexedRecord main = new GenericData.Record(schema); main.put(0, file.getId()); main.put(1, file.getName()); main.put(2, file.getMimeType()); main.put(3, file.getModifiedTime().getValue()); main.put(4, file.getSize()); main.put(5, file.getKind()); main.put(6, file.getTrashed()); main.put(7, file.getParents().toString()); // TODO This should be a List<String> main.put(8, file.getWebViewLink()); return main; }
private IndexedRecord convertSearchResultToIndexedRecord(File file) { // Main record IndexedRecord main = new GenericData.Record(schema); main.put(0, file.getId()); main.put(1, file.getName()); main.put(2, file.getMimeType()); main.put(3, file.getModifiedTime().getValue()); main.put(4, file.getSize()); main.put(5, file.getKind()); main.put(6, file.getTrashed()); main.put(7, file.getParents().toString()); // TODO This should be a List<String> main.put(8, file.getWebViewLink()); return main; }