@Test public void testSearch() throws Exception { final String name = new AlphanumericRandomStringService().random(); final Path workdir = new DropboxHomeFinderFeature(session).find(); final Path file = new Path(workdir, name, EnumSet.of(Path.Type.file)); new DropboxTouchFeature(session).touch(file, new TransferStatus()); final DropboxSearchFeature feature = new DropboxSearchFeature(session); assertTrue(feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener()).contains(file)); assertTrue(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)), new DisabledListProgressListener()).contains(file)); try { assertFalse(feature.search(new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new SearchFilter(name), new DisabledListProgressListener()).contains(file)); } catch(NotfoundException e) { } final Path subdir = new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); new DropboxDirectoryFeature(session).mkdir(subdir, null, new TransferStatus()); assertFalse(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file)); final Path filesubdir = new DropboxTouchFeature(session).touch(new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus()); { final AttributedList<Path> result = feature.search(workdir, new SearchFilter(filesubdir.getName()), new DisabledListProgressListener()); assertTrue(result.contains(filesubdir)); assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent()); } new DropboxDeleteFeature(session).delete(Arrays.asList(file, filesubdir, subdir), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()) .withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start(); this.parse(workdir, listener, list, result); while(result.getHasMore()) { this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor())); if(this.parse(workdir, listener, list, result)) { return null; } } return list; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } }
DropboxSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()) .withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start(); this.parse(workdir, listener, list, result); while(result.getHasMore()) { this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor())); if(this.parse(workdir, listener, list, result)) { return null; } } return list; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } } }
DropboxSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()) .withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start(); this.parse(workdir, listener, list, result); while(result.getHasMore()) { this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor())); if(this.parse(workdir, listener, list, result)) { return null; } } return list; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } } DropboxSearchFeature(final DropboxSession session); }
DropboxSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()) .withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start(); this.parse(workdir, listener, list, result); while(result.getHasMore()) { this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor())); if(this.parse(workdir, listener, list, result)) { return null; } } return list; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } } DropboxSearchFeature(final DropboxSession session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache); }
DropboxSearchFeature implements Search { @Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> list = new AttributedList<>(); long start = 0; SearchV2Result result = new DbxUserFilesRequests(session.getClient(workdir)).searchV2Builder(regex.toPattern().pattern()) .withOptions(SearchOptions.newBuilder().withPath(containerService.getKey(workdir)).build()).start(); this.parse(workdir, listener, list, result); while(result.getHasMore()) { this.parse(workdir, listener, list, result = new DbxUserFilesRequests(session.getClient(workdir)).searchContinueV2(result.getCursor())); if(this.parse(workdir, listener, list, result)) { return null; } } return list; } catch(DbxException e) { throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, workdir); } } DropboxSearchFeature(final DropboxSession session); @Override AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener); @Override boolean isRecursive(); @Override Search withCache(final Cache<Path> cache);  }