Search in sources :

Example 6 with ScrollFileSystemItemList

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()));
        }
    }
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem)

Example 7 with ScrollFileSystemItemList

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);
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 8 with ScrollFileSystemItemList

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()));
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) ElasticSearchAdmin(org.nuxeo.elasticsearch.api.ElasticSearchAdmin) RunWith(org.junit.runner.RunWith) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Inject(javax.inject.Inject) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FeaturesRunner(org.nuxeo.runtime.test.runner.FeaturesRunner) FileSystemItemAdapterService(org.nuxeo.drive.service.FileSystemItemAdapterService) TransactionHelper(org.nuxeo.runtime.transaction.TransactionHelper) RepositoryElasticSearchFeature(org.nuxeo.elasticsearch.test.RepositoryElasticSearchFeature) Before(org.junit.Before) WorkManager(org.nuxeo.ecm.core.work.api.WorkManager) Assert.assertNotNull(org.junit.Assert.assertNotNull) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) FolderItem(org.nuxeo.drive.adapter.FolderItem) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) TimeUnit(java.util.concurrent.TimeUnit) Deploy(org.nuxeo.runtime.test.runner.Deploy) List(java.util.List) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) Features(org.nuxeo.runtime.test.runner.Features) ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) NuxeoDriveFeature(org.nuxeo.drive.test.NuxeoDriveFeature) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Assert(org.junit.Assert) Blob(org.nuxeo.ecm.core.api.Blob) Assert.assertEquals(org.junit.Assert.assertEquals) FolderItem(org.nuxeo.drive.adapter.FolderItem) Test(org.junit.Test)

Aggregations

ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)8 FolderItem (org.nuxeo.drive.adapter.FolderItem)7 Test (org.junit.Test)6 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)6 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)6 Blob (org.nuxeo.ecm.core.api.Blob)4 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)4 FileItem (org.nuxeo.drive.adapter.FileItem)3 Serializable (java.io.Serializable)2 Principal (java.security.Principal)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)2 FileSystemItemAdapterService (org.nuxeo.drive.service.FileSystemItemAdapterService)2