Search in sources :

Example 1 with FileSystemItemFactory

use of org.nuxeo.drive.service.FileSystemItemFactory in project nuxeo-drive-server by nuxeo.

the class DefaultFileSystemItemFactoryFixture method testLockedDocument.

@Test
public void testLockedDocument() {
    setPermission(syncRootFolder, "joe", SecurityConstants.READ_WRITE, true);
    setPermission(syncRootFolder, "jack", SecurityConstants.READ_WRITE, true);
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, joeSession);
        DocumentModel joeFile = joeSession.getDocument(file.getRef());
        log.trace("Check readonly flags on an unlocked document");
        FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItem(joeFile);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
        assertTrue(((FileItem) fsItem).getCanUpdate());
        assertNull(fsItem.getLockInfo());
        log.trace("Check readonly flags on an document locked by the current user");
        joeSession.setLock(joeFile.getRef());
        // Re-fetch document to clear lock info
        joeFile = joeSession.getDocument(file.getRef());
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(joeFile);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
        assertTrue(((FileItem) fsItem).getCanUpdate());
        Lock lockInfo = fsItem.getLockInfo();
        assertNotNull(lockInfo);
        assertEquals("joe", lockInfo.getOwner());
        assertNotNull(lockInfo.getCreated());
        // Check that the lock info is not fetched for FileSystemItem
        // adaptation when calling getChildren or
        // scrollDescendants
        FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
        FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
        List<FileSystemItem> children = syncRootFolderItem.getChildren();
        assertEquals(5, children.size());
        for (FileSystemItem child : children) {
            assertNull(child.getLockInfo());
        }
        children = syncRootFolderItem.scrollDescendants(null, 10, 1000);
        assertEquals(5, children.size());
        for (FileSystemItem child : children) {
            assertNull(child.getLockInfo());
        }
        try (CloseableCoreSession jackSession = coreFeature.openCoreSession("jack")) {
            nuxeoDriveManager.registerSynchronizationRoot(jackSession.getPrincipal(), syncRootFolder, jackSession);
            DocumentModel jackFile = jackSession.getDocument(file.getRef());
            log.trace("Check readonly flags for a non administrator on a document locked by another user");
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(jackFile);
            assertFalse(fsItem.getCanRename());
            assertFalse(fsItem.getCanDelete());
            assertFalse(((FileItem) fsItem).getCanUpdate());
            lockInfo = fsItem.getLockInfo();
            assertNotNull(lockInfo);
            assertEquals("joe", lockInfo.getOwner());
            assertNotNull(lockInfo.getCreated());
            log.trace("Check readonly flags for an administrator on a document locked by another user");
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
            assertTrue(fsItem.getCanRename());
            assertTrue(fsItem.getCanDelete());
            assertTrue(((FileItem) fsItem).getCanUpdate());
            lockInfo = fsItem.getLockInfo();
            assertNotNull(lockInfo);
            assertEquals("joe", lockInfo.getOwner());
            assertNotNull(lockInfo.getCreated());
            log.trace("Check readonly flags for a non administrator on an unlocked document");
            joeSession.removeLock(joeFile.getRef());
            // Re-fetch document to clear lock info
            jackFile = jackSession.getDocument(file.getRef());
            fsItem = defaultFileSystemItemFactory.getFileSystemItem(jackFile);
            assertTrue(fsItem.getCanRename());
            assertTrue(fsItem.getCanDelete());
            assertTrue(((FileItem) fsItem).getCanUpdate());
            assertNull(fsItem.getLockInfo());
        }
    }
    resetPermissions(syncRootFolder, "jack");
    resetPermissions(syncRootFolder, "joe");
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Lock(org.nuxeo.ecm.core.api.Lock) Test(org.junit.Test)

Example 2 with FileSystemItemFactory

use of org.nuxeo.drive.service.FileSystemItemFactory in project nuxeo-drive-server by nuxeo.

the class DefaultFileSystemItemFactoryFixture method testScrollDescendantsIncludingCollections.

@Test
public void testScrollDescendantsIncludingCollections() {
    log.trace("Add a document to a new collection \"testCollection\" created in \"/default-domain/UserWorkspaces/Administrator/Collections\"");
    collectionManager.addToNewCollection("testCollection", null, file, session);
    DocumentModel userCollections = collectionManager.getUserDefaultCollections(null, session);
    DocumentModel userWorkspace = session.getParentDocument(userCollections.getRef());
    log.trace("Create \"testFolder\" in \"/default-domain/UserWorkspaces/Administrator\"");
    DocumentModel testFolder = session.createDocumentModel(userWorkspace.getPathAsString(), "testFolder", "Folder");
    testFolder = session.createDocument(testFolder);
    log.trace("Register \"/default-domain/UserWorkspaces/Administrator\" as a synchronization root for Administrator");
    nuxeoDriveManager.registerSynchronizationRoot(principal, userWorkspace, session);
    log.trace("Scroll through the descendants of \"/default-domain/UserWorkspaces/Administrator\", expecting one: \"testFolder\", " + "the \"Collections\" folder and its descendants being ignored");
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem userWorkspaceFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(userWorkspace);
    ScrollFileSystemItemList descendants = userWorkspaceFolderItem.scrollDescendants(null, 10, 1000);
    assertEquals(1, descendants.size());
    FileSystemItem descendant = descendants.get(0);
    assertTrue(descendant.isFolder());
    assertEquals("testFolder", descendant.getName());
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 3 with FileSystemItemFactory

use of org.nuxeo.drive.service.FileSystemItemFactory in project nuxeo-drive-server by nuxeo.

the class FileSystemItemAdapterServiceImpl method getFileSystemItemFactoryForId.

/**
 * Iterates on the ordered contributed file system item factories until if finds one that can handle the given
 * {@link FileSystemItem} id.
 */
@Override
public FileSystemItemFactory getFileSystemItemFactoryForId(String id) {
    Iterator<FileSystemItemFactoryWrapper> factoriesIt = fileSystemItemFactories.iterator();
    while (factoriesIt.hasNext()) {
        FileSystemItemFactoryWrapper factoryWrapper = factoriesIt.next();
        FileSystemItemFactory factory = factoryWrapper.getFactory();
        if (factory.canHandleFileSystemItemId(id)) {
            return factory;
        }
    }
    // No fileSystemItemFactory found, try the topLevelFolderItemFactory
    if (getTopLevelFolderItemFactory().canHandleFileSystemItemId(id)) {
        return getTopLevelFolderItemFactory();
    }
    throw new NuxeoDriveContribException(String.format("No fileSystemItemFactory found for FileSystemItem with id %s. 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.", id));
}
Also used : FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) NuxeoDriveContribException(org.nuxeo.drive.adapter.NuxeoDriveContribException)

Example 4 with FileSystemItemFactory

use of org.nuxeo.drive.service.FileSystemItemFactory in project nuxeo-drive-server by nuxeo.

the class FileSystemItemFactoryDescriptor method getFactory.

public FileSystemItemFactory getFactory() {
    FileSystemItemFactory factory;
    try {
        factory = factoryClass.newInstance();
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
    factory.setName(name);
    factory.handleParameters(parameters);
    return factory;
}
Also used : FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory)

Example 5 with FileSystemItemFactory

use of org.nuxeo.drive.service.FileSystemItemFactory in project nuxeo-drive-server by nuxeo.

the class TestCollectionSyncRootFolderItemFactory method testFactory.

@Test
public void testFactory() throws Exception {
    FileSystemItemFactory collectionSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("collectionSyncRootFolderItemFactory");
    DocumentModel collection = collectionManager.createCollection(session, "testCollection", "Test collection.", "/");
    DocumentModel doc1 = session.createDocumentModel("/", "doc1", "File");
    doc1.setPropertyValue("dc:title", "doc1");
    doc1.setPropertyValue("file:content", new StringBlob("Content of file 1."));
    doc1 = session.createDocument(doc1);
    collectionManager.addToCollection(collection, doc1, session);
    assertTrue(collectionManager.isInCollection(collection, doc1, session));
    DocumentModel doc2 = session.createDocumentModel("/", "doc2", "File");
    doc2.setPropertyValue("dc:title", "doc2");
    doc2.setPropertyValue("file:content", new StringBlob("Content of file 2."));
    doc2 = session.createDocument(doc2);
    collectionManager.addToCollection(collection, doc2, session);
    assertTrue(collectionManager.isInCollection(collection, doc2, session));
    log.trace("Check document that is not a Collection");
    assertFalse(collectionSyncRootFolderItemFactory.isFileSystemItem(session.getRootDocument()));
    log.trace("Check Collection not registered as a sync root");
    assertFalse(collectionSyncRootFolderItemFactory.isFileSystemItem(collection));
    log.trace("Check Collection registered as a sync root");
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collection, session);
    assertTrue(collectionSyncRootFolderItemFactory.isFileSystemItem(collection));
    log.trace("Adapt test collection as a FileSystemItem");
    FileSystemItem fsItem = collectionSyncRootFolderItemFactory.getFileSystemItem(collection);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof CollectionSyncRootFolderItem);
    log.trace("Check children");
    FolderItem collectionFSItem = (FolderItem) fsItem;
    List<FileSystemItem> collectionChildren = collectionFSItem.getChildren();
    assertEquals(2, collectionChildren.size());
    FileSystemItem child1 = collectionChildren.get(0);
    assertTrue(child1 instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc1.getId(), child1.getId());
    assertEquals(COLLECTION_SYNC_ROOT_ITEM_ID_PREFIX + collection.getId(), child1.getParentId());
    assertEquals("doc1", child1.getName());
    FileSystemItem child2 = collectionChildren.get(1);
    assertTrue(child2 instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc2.getId(), child2.getId());
    assertEquals(COLLECTION_SYNC_ROOT_ITEM_ID_PREFIX + collection.getId(), child2.getParentId());
    assertEquals("doc2", child2.getName());
    log.trace("Check FolderItem#getCanScrollDescendants");
    assertFalse(collectionFSItem.getCanScrollDescendants());
    log.trace("Check descendants");
    try {
        collectionFSItem.scrollDescendants(null, 10, 1000);
        fail("Should not be able to scroll through the descendants of a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot scroll through the descendants of a collection sync root folder item, please call getChildren() instead.", e.getMessage());
    }
    log.trace("Check FolderItem#getCanCreateChild");
    assertFalse(collectionFSItem.getCanCreateChild());
    log.trace("Check FolderItem#createFile");
    try {
        collectionFSItem.createFile(new StringBlob("Child file content."));
        fail("Should not be able to create a file in a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a file in a collection synchronization root.", e.getMessage());
    }
    log.trace("Check FolderItem#createFolder");
    try {
        collectionFSItem.createFolder("Child folder");
        fail("Should not be able to create a folder in a CollectionSyncRootFolderItem.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a folder in a collection synchronization root.", e.getMessage());
    }
    log.trace("Test AbstractDocumentBackedFileSystemItem#delete");
    child1.delete();
    doc1 = session.getDocument(doc1.getRef());
    assertFalse(doc1.isTrashed());
    assertFalse(collectionManager.isInCollection(collection, doc1, session));
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) CollectionSyncRootFolderItem(org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) CollectionSyncRootFolderItem(org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)11 Test (org.junit.Test)8 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)8 FolderItem (org.nuxeo.drive.adapter.FolderItem)7 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)7 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)6 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)5 NuxeoDriveContribException (org.nuxeo.drive.adapter.NuxeoDriveContribException)3 FileItem (org.nuxeo.drive.adapter.FileItem)2 TopLevelFolderItemFactory (org.nuxeo.drive.service.TopLevelFolderItemFactory)2 DefaultSyncRootFolderItemFactory (org.nuxeo.drive.service.impl.DefaultSyncRootFolderItemFactory)2 DefaultTopLevelFolderItemFactory (org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory)2 FileSystemItemFactoryDescriptor (org.nuxeo.drive.service.impl.FileSystemItemFactoryDescriptor)2 FileSystemItemFactoryWrapper (org.nuxeo.drive.service.impl.FileSystemItemFactoryWrapper)2 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2 ArrayList (java.util.ArrayList)1 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)1 CollectionSyncRootFolderItem (org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem)1 VirtualFolderItemFactory (org.nuxeo.drive.service.VirtualFolderItemFactory)1