use of org.nuxeo.drive.adapter.ScrollFileSystemItemList in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method checkChildren.
protected void checkChildren(List<FileSystemItem> folderChildren, String folderId, String noteId, String fileId, String subFolderId, String otherFileId, boolean ordered) throws Exception {
boolean isNoteFound = false;
boolean isFileFound = false;
boolean isSubFolderFound = false;
boolean isOtherFileFound = false;
int childrenCount = 0;
for (FileSystemItem fsItem : folderChildren) {
// Check Note
if (!isNoteFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + noteId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 0) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Note child.txt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Note child.txt", fileItemBlob.getFilename());
assertEquals("This is the Note child.", fileItemBlob.getString());
isNoteFound = true;
childrenCount++;
}
} else // Check File
if (!isFileFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + fileId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 1) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("File child.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("File child.odt", fileItemBlob.getFilename());
assertEquals("This is the File child.", fileItemBlob.getString());
isFileFound = true;
childrenCount++;
}
} else // Check sub-Folder
if (!isSubFolderFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolderId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 2) {
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Sub-folder", fsItem.getName());
assertTrue(fsItem.isFolder());
FolderItem folderItem = (FolderItem) fsItem;
List<FileSystemItem> childFolderChildren = folderItem.getChildren();
assertNotNull(childFolderChildren);
assertEquals(0, childFolderChildren.size());
assertTrue(folderItem.getCanScrollDescendants());
ScrollFileSystemItemList childFolderDescendants = folderItem.scrollDescendants(null, 10, 1000);
assertNotNull(childFolderDescendants);
assertNotNull(childFolderDescendants.getScrollId());
assertEquals(0, childFolderDescendants.size());
isSubFolderFound = true;
childrenCount++;
}
} else // Check other File
if (!isOtherFileFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + otherFileId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 3) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Another file.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Another file.odt", fileItemBlob.getFilename());
assertEquals("Content of another file.", fileItemBlob.getString());
isOtherFileFound = true;
childrenCount++;
}
} else {
fail(String.format("FileSystemItem %s doesn't match any expected.", fsItem.getId()));
}
}
}
use of org.nuxeo.drive.adapter.ScrollFileSystemItemList in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveScrollDescendants method run.
@OperationMethod
public Blob run() throws IOException {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
ScrollFileSystemItemList descendants = fileSystemItemManager.scrollDescendants(id, ctx.getPrincipal(), scrollId, batchSize, keepAlive);
return writeJSONBlob(descendants);
}
use of org.nuxeo.drive.adapter.ScrollFileSystemItemList in project nuxeo-drive-server by nuxeo.
the class TestESSyncRootFolderItem method testScrollDescendants.
@Test
public void testScrollDescendants() throws Exception {
FolderItem syncRootFolderItem = (FolderItem) esSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
assertTrue(syncRootFolderItem instanceof ESSyncRootFolderItem);
// Check scrollDescendants
assertTrue(syncRootFolderItem.getCanScrollDescendants());
// Scroll through all descendants in one breath
ScrollFileSystemItemList descendants = syncRootFolderItem.scrollDescendants(null, 300, 10000);
assertNotNull(descendants.getScrollId());
assertEquals(105, descendants.size());
// Check that descendants are ordered by path
List<String> expectedFSItemIds = session.query("SELECT * FROM Document WHERE ecm:ancestorId = '" + syncRootFolder.getId() + "' ORDER BY ecm:path").stream().map(doc -> DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc.getId()).collect(Collectors.toList());
assertEquals(expectedFSItemIds, descendants.stream().map(fsItem -> fsItem.getId()).collect(Collectors.toList()));
// Scroll through descendants in several steps
descendants.clear();
ScrollFileSystemItemList descendantsBatch;
int batchSize = 15;
String scrollId = null;
while (!(descendantsBatch = syncRootFolderItem.scrollDescendants(scrollId, batchSize, 10000)).isEmpty()) {
assertEquals(15, descendantsBatch.size());
scrollId = descendantsBatch.getScrollId();
descendants.addAll(descendantsBatch);
}
assertEquals(105, descendants.size());
// Check that descendants are ordered by path
assertEquals(expectedFSItemIds, descendants.stream().map(fsItem -> fsItem.getId()).collect(Collectors.toList()));
}
Aggregations