@Test public void testGetFileid() throws Exception { final Path test = new Path(DriveHomeFinderService.MYDRIVE_FOLDER, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)); new DriveTouchFeature(session, new DriveFileidProvider(session).withCache(cache)).touch(test, new TransferStatus()); assertNotNull(new DriveFileidProvider(session).withCache(cache).getFileid(test, new DisabledListProgressListener())); new DriveDeleteFeature(session, new DriveFileidProvider(session).withCache(cache)).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override DriveFileidProvider withCache(final Cache<Path> cache); }
DriveFileidProvider implements IdProvider { @Override public String getFileid(final Path file, final ListProgressListener listener) throws BackgroundException { if(StringUtils.isNotBlank(file.attributes().getVersionId())) { return file.attributes().getVersionId(); } if(file.isRoot() || file.equals(DriveHomeFinderService.MYDRIVE_FOLDER) || file.equals(DriveHomeFinderService.SHARED_FOLDER_NAME) || file.equals(DriveHomeFinderService.TEAM_DRIVES_NAME)) { return DriveHomeFinderService.ROOT_FOLDER_ID; } if(cache.isCached(file.getParent())) { final AttributedList<Path> list = cache.get(file.getParent()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null != found) { if(StringUtils.isNotBlank(found.attributes().getVersionId())) { return this.set(file, found.attributes().getVersionId()); } } } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(file.getParent())) { final Path found = new DriveTeamDrivesListService(session).withCache(cache).list(file.getParent(), listener).find( new SimplePathPredicate(file) ); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } final Path query; if(file.getType().contains(Path.Type.placeholder)) { query = new Path(file.getParent(), FilenameUtils.removeExtension(file.getName()), file.getType(), file.attributes()); } else { query = file; } final AttributedList<Path> list = new FileidDriveListService(session, this, query).list(file.getParent(), new DisabledListProgressListener()); final Path found = list.find(new IgnoreTrashedPathPredicate(file)); if(null == found) { throw new NotfoundException(file.getAbsolute()); } return this.set(file, found.attributes().getVersionId()); } DriveFileidProvider(final DriveSession session); @Override String getFileid(final Path file, final ListProgressListener listener); @Override DriveFileidProvider withCache(final Cache<Path> cache);  }