Search in sources :

Example 36 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemAdapterService method testContribOverride.

@Test
public void testContribOverride() throws Exception {
    assumeFalse("Cannot test reload for in-memory repository", coreFeature.getStorageConfiguration().isDBSMem());
    deployer.deploy("org.nuxeo.drive.core.test:OSGI-INF/test-nuxeodrive-adapter-service-contrib-override.xml");
    registerRootAndCreateSomeDocs();
    // Re-adapt the sync root to take the override into account
    syncRootItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItem(syncRootFolder);
    syncRootItemId = syncRootItem.getId();
    // ------------------------------------------------------
    // Check file system item factory descriptors
    // ------------------------------------------------------
    Map<String, FileSystemItemFactoryDescriptor> fileSystemItemFactoryDescs = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactoryDescriptors();
    assertNotNull(fileSystemItemFactoryDescs);
    assertEquals(12, fileSystemItemFactoryDescs.size());
    FileSystemItemFactoryDescriptor desc = fileSystemItemFactoryDescs.get("defaultSyncRootFolderItemFactory");
    assertNotNull(desc);
    assertEquals(10, desc.getOrder());
    assertEquals("defaultSyncRootFolderItemFactory", desc.getName());
    assertNull(desc.getDocType());
    assertEquals("DriveSynchronized", desc.getFacet());
    FileSystemItemFactory factory = desc.getFactory();
    assertTrue(factory instanceof DefaultSyncRootFolderItemFactory);
    desc = fileSystemItemFactoryDescs.get("defaultFileSystemItemFactory");
    assertNotNull(desc);
    assertEquals(50, desc.getOrder());
    assertEquals("defaultFileSystemItemFactory", desc.getName());
    assertNull(desc.getDocType());
    assertNull(desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DefaultFileSystemItemFactory);
    desc = fileSystemItemFactoryDescs.get("dummyFacetFactory");
    assertNotNull(desc);
    assertEquals(20, desc.getOrder());
    assertEquals("dummyFacetFactory", desc.getName());
    assertNull(desc.getDocType());
    assertEquals("Folderish", desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DefaultFileSystemItemFactory);
    desc = fileSystemItemFactoryDescs.get("dummyDocTypeFactory");
    assertNotNull(desc);
    assertEquals(30, desc.getOrder());
    assertEquals("dummyDocTypeFactory", desc.getName());
    assertEquals("File", desc.getDocType());
    assertNull(desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DefaultFileSystemItemFactory);
    desc = fileSystemItemFactoryDescs.get("dummyVirtualFolderItemFactory");
    assertNotNull(desc);
    desc = fileSystemItemFactoryDescs.get("nullMergeTestFactory");
    assertNotNull(desc);
    assertEquals(200, desc.getOrder());
    assertEquals("nullMergeTestFactory", desc.getName());
    assertEquals("Note", desc.getDocType());
    assertNull(desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DummyFileItemFactory);
    // ------------------------------------------------------
    // Check ordered file system item factories
    // ------------------------------------------------------
    List<FileSystemItemFactoryWrapper> fileSystemItemFactories = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactories();
    assertNotNull(fileSystemItemFactories);
    assertEquals(6, fileSystemItemFactories.size());
    FileSystemItemFactoryWrapper factoryWrapper = fileSystemItemFactories.get(0);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertEquals("Collection", factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("CollectionSyncRootFolderItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(1);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertEquals("DriveSynchronized", factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultSyncRootFolderItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(2);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertEquals("Folderish", factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(3);
    assertNotNull(factoryWrapper);
    assertEquals("File", factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(4);
    assertNotNull(factoryWrapper);
    factoryWrapper = fileSystemItemFactories.get(5);
    assertNotNull(factoryWrapper);
    assertEquals("Note", factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
    // -------------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc)
    // -------------------------------------------------------------
    // File => should try the dummyDocTypeFactory bound to the
    // DefaultFileSystemItemFactory class, returning null because the
    // document has no file, then try the dummyVirtualFolderItemFactory
    // bound to the DummyVirtualFolderItemFactory, returning null because
    // virtual
    file.setPropertyValue("file:content", null);
    session.saveDocument(file);
    FileSystemItem fsItem = fileSystemItemAdapterService.getFileSystemItem(file);
    assertNull(fsItem);
    // Folder => should use the dummyFacetFactory bound to the
    // DefaultFileSystemItemFactory class
    fsItem = fileSystemItemAdapterService.getFileSystemItem(folder);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertEquals("dummyFacetFactory#test#" + folder.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Jack's folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertEquals("Jack", fsItem.getCreator());
    assertEquals("Jack", fsItem.getLastContributor());
    // Custom => should try the dummyVirtualFolderItemFactory
    // bound to the DummyVirtualFolderItemFactory, returning null because
    // virtual
    fsItem = fileSystemItemAdapterService.getFileSystemItem(custom);
    assertNull(fsItem);
    // -------------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc, String parentId)
    // -------------------------------------------------------------
    // Folder => should use the dummyFacetFactory bound to the
    // DefaultFileSystemItemFactory class
    fsItem = fileSystemItemAdapterService.getFileSystemItem(folder, syncRootItem);
    assertNotNull(fsItem);
    assertEquals(syncRootItemId, fsItem.getParentId());
    // -------------------------------------------------------------
    // Check #getFileSystemItemFactoryForId(String id)
    // -------------------------------------------------------------
    // Disabled default factory
    String fsItemId = "defaultFileSystemItemFactory#test#someId";
    try {
        fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
        fail("No fileSystemItemFactory should be found for FileSystemItem id.");
    } catch (NuxeoDriveContribException e) {
        assertEquals("No fileSystemItemFactory found for FileSystemItem with id defaultFileSystemItemFactory#test#someId. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\"> and make sure there is at least one defining a FileSystemItemFactory class for which the #canHandleFileSystemItemId(String id) method returns true.", e.getMessage());
    }
    // Factory with #canHandleFileSystemItemId returning true
    fsItemId = "dummyDocTypeFactory#test#someId";
    FileSystemItemFactory fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
    assertNotNull(fsItemFactory);
    assertEquals("dummyDocTypeFactory", fsItemFactory.getName());
    assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
    // Other test factory with #canHandleFileSystemItemId returning true
    fsItemId = "dummyFacetFactory#test#someId";
    fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
    assertNotNull(fsItemFactory);
    assertEquals("dummyFacetFactory", fsItemFactory.getName());
    assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
    // Top level folder item factory
    fsItemId = "org.nuxeo.drive.service.adapter.DummyTopLevelFolderItemFactory#";
    fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
    assertNotNull(fsItemFactory);
    assertTrue(fsItemFactory.getName().endsWith("DummyTopLevelFolderItemFactory"));
    assertTrue(fsItemFactory.getClass().getName().endsWith("DummyTopLevelFolderItemFactory"));
    assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
    // -------------------------------------------------------------
    // Check #getTopLevelFolderItemFactory()
    // -------------------------------------------------------------
    TopLevelFolderItemFactory topLevelFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
    assertNotNull(topLevelFactory);
    assertTrue(topLevelFactory.getClass().getName().endsWith("DummyTopLevelFolderItemFactory"));
    assertTrue(topLevelFactory instanceof DummyTopLevelFolderItemFactory);
    // -------------------------------------------------------------
    // Check #getActiveFileSystemItemFactories()
    // -------------------------------------------------------------
    Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
    assertEquals(6, activeFactories.size());
    assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("dummyDocTypeFactory"));
    assertTrue(activeFactories.contains("dummyFacetFactory"));
    assertTrue(activeFactories.contains("dummyVirtualFolderItemFactory"));
    assertTrue(activeFactories.contains("nullMergeTestFactory"));
}
Also used : DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) NuxeoDriveContribException(org.nuxeo.drive.adapter.NuxeoDriveContribException) TopLevelFolderItemFactory(org.nuxeo.drive.service.TopLevelFolderItemFactory) DefaultTopLevelFolderItemFactory(org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactoryWrapper(org.nuxeo.drive.service.impl.FileSystemItemFactoryWrapper) DefaultSyncRootFolderItemFactory(org.nuxeo.drive.service.impl.DefaultSyncRootFolderItemFactory) FileSystemItemFactoryDescriptor(org.nuxeo.drive.service.impl.FileSystemItemFactoryDescriptor) Test(org.junit.Test)

Example 37 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemManagerService method testReadOperations.

@Test
public void testReadOperations() throws Exception {
    // ------------------------------------------------------
    // Check #getTopLevelFolder
    // ------------------------------------------------------
    List<FileSystemItem> topLevelChildren = fileSystemItemManagerService.getTopLevelFolder(principal).getChildren();
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());
    FileSystemItem childFsItem = topLevelChildren.get(0);
    assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
    assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot1.getId(), childFsItem.getId());
    assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("syncRoot1", childFsItem.getName());
    childFsItem = topLevelChildren.get(1);
    assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
    assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot2.getId(), childFsItem.getId());
    assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("syncRoot2", childFsItem.getName());
    // ------------------------------------------------------
    // Check #exists
    // ------------------------------------------------------
    // Non existent doc id
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentId", principal));
    // File
    assertTrue(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal));
    // Not adaptable as a FileSystemItem
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal));
    // Deleted
    custom.followTransition("delete");
    assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
    // ------------------------------------------------------------
    // Check #getFileSystemItemById(String id, Principal principal)
    // ------------------------------------------------------------
    // Folder
    FileSystemItem fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getId());
    String expectedSyncRoot1Id = DEFAULT_SYNC_ROOT_ITEM_ID_PREFIX + syncRoot1.getId();
    assertEquals(expectedSyncRoot1Id, fsItem.getParentId());
    assertEquals("Jack's folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    List<FileSystemItem> children = ((FolderItem) fsItem).getChildren();
    assertNotNull(children);
    assertEquals(4, children.size());
    // File
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Joe.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    FileItem fileFsItem = (FileItem) fsItem;
    assertTrue(fileFsItem.getCanUpdate());
    assertEquals("nxfile/test/" + file.getId() + "/blobholder:0/Joe.odt", fileFsItem.getDownloadURL());
    assertEquals("MD5", fileFsItem.getDigestAlgorithm());
    assertEquals(file.getAdapter(BlobHolder.class).getBlob().getDigest(), fileFsItem.getDigest());
    Blob fileItemBlob = fileFsItem.getBlob();
    assertEquals("Joe.odt", fileItemBlob.getFilename());
    assertEquals("Content of Joe's file.", fileItemBlob.getString());
    // FolderishFile
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Sarah's folderish file", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
    // Not adaptable as a FileSystemItem
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
    assertNull(fsItem);
    // Deleted
    assertNull(fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
    // Sub folder
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    assertEquals("Tony's sub folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
    // -------------------------------------------------------------------
    // Check #getFileSystemItemById(String id, String parentId, Principal
    // principal)
    // -------------------------------------------------------------------
    fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
    // ------------------------------------------------------
    // Check #getChildren
    // ------------------------------------------------------
    // Need to flush VCS cache for the session used in DocumentBackedFolderItem#getChildren() to be aware of changes
    // in the current session
    session.save();
    children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertNotNull(children);
    assertEquals(4, children.size());
    // Ordered
    checkChildren(children, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), true);
    children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
    assertTrue(children.isEmpty());
    // ------------------------------------------------------
    // Check #scrollDescendants
    // ------------------------------------------------------
    // Need to flush VCS cache for the session used in DocumentBackedFolderItem#scrollDescendants to be aware of
    // changes in the current session
    session.save();
    FolderItem folderItem = (FolderItem) fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertTrue(folderItem.getCanScrollDescendants());
    // Scroll through all descendants in one breath
    ScrollFileSystemItemList folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal, null, 10, 1000);
    assertNotNull(folderDescendants);
    assertNotNull(folderDescendants.getScrollId());
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
    // Scroll through descendants in several steps
    folderDescendants.clear();
    ScrollFileSystemItemList descendantsBatch;
    int batchSize = 2;
    String scrollId = null;
    while (!(descendantsBatch = folderItem.scrollDescendants(scrollId, batchSize, 1000)).isEmpty()) {
        assertTrue(descendantsBatch.size() > 0);
        scrollId = descendantsBatch.getScrollId();
        folderDescendants.addAll(descendantsBatch);
    }
    assertEquals(4, folderDescendants.size());
    // Order is not determined
    checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
    folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal, null, 10, 1000);
    assertTrue(folderDescendants.isEmpty());
    // ------------------------------------------------------
    // Check #canMove
    // ------------------------------------------------------
    // Not allowed to move a file system item to a non FolderItem
    String srcFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId();
    String destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId();
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, principal));
    // Not allowed to move a file system item if no REMOVE permission on the
    // source backing doc
    Principal joePrincipal = new NuxeoPrincipalImpl("joe");
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    nuxeoDriveManager.registerSynchronizationRoot(joePrincipal, syncRoot1, session);
    // Under Oracle, the READ ACL optims are not visible from the joe
    // session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId();
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // Not allowed to move a file system item if no ADD_CHILDREN permission
    // on the destination backing doc
    setPermission(folder, "joe", SecurityConstants.WRITE, true);
    setPermission(subFolder, "joe", SecurityConstants.READ, true);
    setPermission(subFolder, SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING, true);
    setPermission(subFolder, SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false);
    assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // OK: REMOVE permission on the source backing doc + REMOVE_CHILDREN
    // permission on its parent + ADD_CHILDREN permission on the destination
    // backing doc
    resetPermissions(subFolder, SecurityConstants.EVERYONE);
    resetPermissions(subFolder, "joe");
    setPermission(subFolder, "joe", SecurityConstants.WRITE, true);
    assertTrue(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
    // Reset permissions
    resetPermissions(rootDoc, "joe");
    resetPermissions(folder, "joe");
    resetPermissions(subFolder, "joe");
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileItem(org.nuxeo.drive.adapter.FileItem) NuxeoPrincipalImpl(org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) Principal(java.security.Principal) Test(org.junit.Test)

Example 38 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.

the class TestDriveVersioning method testSyncRootVersioning.

@Test
public void testSyncRootVersioning() throws Exception {
    // Expect no versions initially
    // Cannot use DocumentModel#getVersionLabel since it relies on the uid schema not held by the Folder type
    assertTrue(session.getVersions(syncRootFolder.getRef()).isEmpty());
    // Wait for the versioning delay and update the synchronization root
    Thread.sleep(VERSIONING_DELAY);
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
    syncRootFolderItem.rename("syncRootRenamed");
    syncRootFolder = session.getDocument(syncRootFolder.getRef());
    // Expect no versions since the "versioning-delay" policy doesn't apply to folderish documents
    assertTrue(session.getVersions(syncRootFolder.getRef()).isEmpty());
}
Also used : DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) Test(org.junit.Test)

Example 39 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem 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 40 with FolderItem

use of org.nuxeo.drive.adapter.FolderItem 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

FolderItem (org.nuxeo.drive.adapter.FolderItem)43 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)24 Test (org.junit.Test)22 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)16 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)14 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)10 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 FileItem (org.nuxeo.drive.adapter.FileItem)8 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)8 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)8 Blob (org.nuxeo.ecm.core.api.Blob)8 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)7 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)6 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)4 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)4 Deploy (org.nuxeo.runtime.test.runner.Deploy)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)3