@Test public void testList() throws Exception { final StoregateIdProvider nodeid = new StoregateIdProvider(session).withCache(cache); final AttributedList<Path> list = new StoregateListService(session, nodeid).list( new Path("/My files", EnumSet.of(directory, Path.Type.volume)), new DisabledListProgressListener()); assertNotNull(list); assertFalse(list.isEmpty()); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); for(RootFolder root : session.roots()) { switch(root.getRootFolderType()) { case 0: case 1: final PathAttributes attr = new PathAttributes().withVersionId(root.getId()); attr.setModificationDate(root.getModified().getMillis()); attr.setCreationDate(root.getCreated().getMillis()); list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr)); break; } } listener.chunk(directory, list); return list; } else { try { final AttributedList<Path> children = new AttributedList<>(); final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid); int pageIndex = 0; FileContents files; do { files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", 0, true, false, false ); for(File f : files.getFiles()) { final PathAttributes attrs = attributes.toAttributes(f); final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path p = new Path(directory, f.getName(), type, attrs); children.add(p); listener.chunk(directory, children); } pageIndex++; } while(children.size() < files.getTotalRowCount()); return children; } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Listing directory {0} failed", e, directory); } } }
StoregateListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); for(RootFolder root : session.roots()) { switch(root.getRootFolderType()) { case 0: case 1: final PathAttributes attr = new PathAttributes().withVersionId(root.getId()); attr.setModificationDate(root.getModified().getMillis()); attr.setCreationDate(root.getCreated().getMillis()); list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr)); break; } } listener.chunk(directory, list); return list; } else { try { final AttributedList<Path> children = new AttributedList<>(); final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid); int pageIndex = 0; FileContents files; do { files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", 0, true, false, false ); for(File f : files.getFiles()) { final PathAttributes attrs = attributes.toAttributes(f); final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path p = new Path(directory, f.getName(), type, attrs); children.add(p); listener.chunk(directory, children); } pageIndex++; } while(children.size() < files.getTotalRowCount()); return children; } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Listing directory {0} failed", e, directory); } } } }
StoregateListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); for(RootFolder root : session.roots()) { switch(root.getRootFolderType()) { case 0: case 1: final PathAttributes attr = new PathAttributes().withVersionId(root.getId()); attr.setModificationDate(root.getModified().getMillis()); attr.setCreationDate(root.getCreated().getMillis()); list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr)); break; } } listener.chunk(directory, list); return list; } else { try { final AttributedList<Path> children = new AttributedList<>(); final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid); int pageIndex = 0; FileContents files; do { files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", 0, true, false, false ); for(File f : files.getFiles()) { final PathAttributes attrs = attributes.toAttributes(f); final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path p = new Path(directory, f.getName(), type, attrs); children.add(p); listener.chunk(directory, children); } pageIndex++; } while(children.size() < files.getTotalRowCount()); return children; } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Listing directory {0} failed", e, directory); } } } StoregateListService(final StoregateSession session, final StoregateIdProvider fileid); }
StoregateListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); for(RootFolder root : session.roots()) { switch(root.getRootFolderType()) { case 0: case 1: final PathAttributes attr = new PathAttributes().withVersionId(root.getId()); attr.setModificationDate(root.getModified().getMillis()); attr.setCreationDate(root.getCreated().getMillis()); list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr)); break; } } listener.chunk(directory, list); return list; } else { try { final AttributedList<Path> children = new AttributedList<>(); final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid); int pageIndex = 0; FileContents files; do { files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", 0, true, false, false ); for(File f : files.getFiles()) { final PathAttributes attrs = attributes.toAttributes(f); final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path p = new Path(directory, f.getName(), type, attrs); children.add(p); listener.chunk(directory, children); } pageIndex++; } while(children.size() < files.getTotalRowCount()); return children; } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Listing directory {0} failed", e, directory); } } } StoregateListService(final StoregateSession session, final StoregateIdProvider fileid); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); @Override ListService withCache(final Cache<Path> cache); }
StoregateListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); for(RootFolder root : session.roots()) { switch(root.getRootFolderType()) { case 0: case 1: final PathAttributes attr = new PathAttributes().withVersionId(root.getId()); attr.setModificationDate(root.getModified().getMillis()); attr.setCreationDate(root.getCreated().getMillis()); list.add(new Path(PathNormalizer.normalize(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attr)); break; } } listener.chunk(directory, list); return list; } else { try { final AttributedList<Path> children = new AttributedList<>(); final StoregateAttributesFinderFeature attributes = new StoregateAttributesFinderFeature(session, fileid); int pageIndex = 0; FileContents files; do { files = new FilesApi(this.session.getClient()).filesGet(URIEncoder.encode(fileid.getPrefixedPath(directory)), pageIndex, chunksize, "Name asc", 0, true, false, false ); for(File f : files.getFiles()) { final PathAttributes attrs = attributes.toAttributes(f); final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file); final Path p = new Path(directory, f.getName(), type, attrs); children.add(p); listener.chunk(directory, children); } pageIndex++; } while(children.size() < files.getTotalRowCount()); return children; } catch(ApiException e) { throw new StoregateExceptionMappingService().map("Listing directory {0} failed", e, directory); } } } StoregateListService(final StoregateSession session, final StoregateIdProvider fileid); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); @Override ListService withCache(final Cache<Path> cache);  }