Search in sources :

Example 1 with FileSystemItemAdapterServiceImpl

use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl 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 FileSystemItemAdapterServiceImpl

use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl 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 FileSystemItemAdapterServiceImpl

use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl 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)

Example 4 with FileSystemItemAdapterServiceImpl

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

the class TestFileSystemItemAdapterService method testService.

@Test
public void testService() throws Exception {
    registerRootAndCreateSomeDocs();
    // ------------------------------------------------------
    // 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("dummyDocTypeFactory");
    assertNotNull(desc);
    assertEquals(20, desc.getOrder());
    assertEquals("dummyDocTypeFactory", desc.getName());
    assertEquals("File", desc.getDocType());
    assertNull(desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DummyFileItemFactory);
    desc = fileSystemItemFactoryDescs.get("dummyFacetFactory");
    assertNotNull(desc);
    assertEquals(30, desc.getOrder());
    assertEquals("dummyFacetFactory", desc.getName());
    assertNull(desc.getDocType());
    assertEquals("Folderish", desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof DummyFolderItemFactory);
    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("dummyVirtualFolderItemFactory");
    assertNotNull(desc);
    assertEquals(100, desc.getOrder());
    assertEquals("dummyVirtualFolderItemFactory", desc.getName());
    assertNull(desc.getDocType());
    assertNull(desc.getFacet());
    factory = desc.getFactory();
    assertTrue(factory instanceof VirtualFolderItemFactory);
    assertEquals("Dummy Folder", ((VirtualFolderItemFactory) factory).getFolderName());
    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(7, 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);
    assertEquals("File", factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(3);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertEquals("Folderish", factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFolderItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(4);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(5);
    assertNotNull(factoryWrapper);
    assertNull(factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyVirtualFolderItemFactory"));
    factoryWrapper = fileSystemItemFactories.get(6);
    assertNotNull(factoryWrapper);
    assertEquals("Note", factoryWrapper.getDocType());
    assertNull(factoryWrapper.getFacet());
    assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
    // ------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc)
    // ------------------------------------------------------
    // File => should use the dummyDocTypeFactory bound to the
    // DummyFileItemFactory class
    FileSystemItem fsItem = fileSystemItemAdapterService.getFileSystemItem(file);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof DummyFileItem);
    assertEquals("dummyDocTypeFactory#test#" + file.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Dummy file with id " + file.getId(), fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Joe", fsItem.getCreator());
    assertEquals("Joe", fsItem.getLastContributor());
    // Folder => should use the dummyFacetFactory bound to the
    // DummyFolderItemFactory class
    fsItem = fileSystemItemAdapterService.getFileSystemItem(folder);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof DummyFolderItem);
    assertTrue(((FolderItem) fsItem).getCanCreateChild());
    assertEquals("dummyFacetFactory#test#" + folder.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Dummy folder with id " + folder.getId(), fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertEquals("Jack", fsItem.getCreator());
    assertEquals("Jack", fsItem.getLastContributor());
    // Custom => should use the defaultFileSystemItemFactory bound to the
    // DefaultFileSystemItemFactory class
    fsItem = fileSystemItemAdapterService.getFileSystemItem(custom);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals("defaultFileSystemItemFactory#test#" + custom.getId(), fsItem.getId());
    assertEquals("/org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#/" + syncRootItemId + "/" + fsItem.getId(), fsItem.getPath());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Bonnie's file.txt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Bonnie", fsItem.getCreator());
    assertEquals("Bonnie", fsItem.getLastContributor());
    Blob fileFsItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("Bonnie's file.txt", fileFsItemBlob.getFilename());
    assertEquals("Content of the custom document's blob.", fileFsItemBlob.getString());
    // -------------------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc, boolean includeDeleted,
    // boolean relaxSyncRootConstraint)
    // -------------------------------------------------------------------
    fsItem = fileSystemItemAdapterService.getFileSystemItem(custom, false, true);
    assertNotNull(fsItem);
    assertEquals("test#" + custom.getId(), fsItem.getId());
    // ------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc, FolderItem parentItem)
    // ------------------------------------------------------
    // File => should use the dummyDocTypeFactory bound to the
    // DummyFileItemFactory class
    fsItem = fileSystemItemAdapterService.getFileSystemItem(file, syncRootItem);
    assertNotNull(fsItem);
    assertEquals(syncRootItemId, fsItem.getParentId());
    // -------------------------------------------------------------
    // Check #getFileSystemItemFactoryForId(String id)
    // -------------------------------------------------------------
    // Default factory
    String fsItemId = "defaultFileSystemItemFactory#test#someId";
    FileSystemItemFactory fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
    assertNotNull(fsItemFactory);
    assertEquals("defaultFileSystemItemFactory", fsItemFactory.getName());
    assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
    assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
    // Top level folder item factory
    fsItemId = "org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#";
    fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
    assertNotNull(fsItemFactory);
    assertTrue(fsItemFactory.getName().endsWith("DefaultTopLevelFolderItemFactory"));
    assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultTopLevelFolderItemFactory"));
    assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
    // Factory with #canHandleFileSystemItemId returning false
    fsItemId = "dummyDocTypeFactory#test#someId";
    try {
        fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
        fail("No fileSystemItemFactory should be found FileSystemItem id.");
    } catch (NuxeoDriveContribException e) {
        assertEquals("No fileSystemItemFactory found for FileSystemItem with id dummyDocTypeFactory#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());
    }
    // Non parsable id
    fsItemId = "nonParsableId";
    try {
        fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
        fail("No fileSystemItemFactory should be found for FileSystemItem id.");
    } catch (NuxeoDriveContribException e) {
        assertEquals("No fileSystemItemFactory found for FileSystemItem with id nonParsableId. 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());
    }
    // Non existent factory name
    fsItemId = "nonExistentFactoryName#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 nonExistentFactoryName#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());
    }
    // -------------------------------------------------------------
    // Check #getTopLevelFolderItemFactory()
    // -------------------------------------------------------------
    TopLevelFolderItemFactory topLevelFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
    assertNotNull(topLevelFactory);
    assertTrue(topLevelFactory.getClass().getName().endsWith("DefaultTopLevelFolderItemFactory"));
    assertTrue(topLevelFactory instanceof DefaultTopLevelFolderItemFactory);
    // -------------------------------------------------------------
    try {
        fileSystemItemAdapterService.getVirtualFolderItemFactory("nonExistentFactory");
        fail("No VirtualFolderItemFactory should be found for factory name.");
    } catch (NuxeoDriveContribException e) {
        assertEquals("No factory named nonExistentFactory. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\">.", e.getMessage());
    }
    try {
        fileSystemItemAdapterService.getVirtualFolderItemFactory("defaultFileSystemItemFactory");
        fail("No VirtualFolderItemFactory should be found for factory name.");
    } catch (NuxeoDriveContribException e) {
        assertEquals("Factory class org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory for factory defaultFileSystemItemFactory is not a VirtualFolderItemFactory.", e.getMessage());
    }
    VirtualFolderItemFactory virtualFolderItemFactory = fileSystemItemAdapterService.getVirtualFolderItemFactory("dummyVirtualFolderItemFactory");
    assertNotNull(virtualFolderItemFactory);
    assertTrue(virtualFolderItemFactory.getClass().getName().endsWith("DummyVirtualFolderItemFactory"));
    // -------------------------------------------------------------
    // Check #getActiveFileSystemItemFactories()
    // -------------------------------------------------------------
    Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
    assertEquals(7, activeFactories.size());
    assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
    assertTrue(activeFactories.contains("dummyDocTypeFactory"));
    assertTrue(activeFactories.contains("dummyFacetFactory"));
    assertTrue(activeFactories.contains("dummyVirtualFolderItemFactory"));
    assertTrue(activeFactories.contains("nullMergeTestFactory"));
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) 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) FileItem(org.nuxeo.drive.adapter.FileItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) DefaultTopLevelFolderItemFactory(org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory) FileSystemItemFactoryWrapper(org.nuxeo.drive.service.impl.FileSystemItemFactoryWrapper) DefaultSyncRootFolderItemFactory(org.nuxeo.drive.service.impl.DefaultSyncRootFolderItemFactory) VirtualFolderItemFactory(org.nuxeo.drive.service.VirtualFolderItemFactory) FileSystemItemFactoryDescriptor(org.nuxeo.drive.service.impl.FileSystemItemFactoryDescriptor) Test(org.junit.Test)

Example 5 with FileSystemItemAdapterServiceImpl

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

the class NuxeoDriveSetActiveFactories method run.

@OperationMethod
public boolean run() throws Exception {
    NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
    String contrib;
    if ("userworkspace".equals(profile)) {
        contrib = "/OSGI-INF/nuxeodrive-hierarchy-userworkspace-contrib.xml";
    } else if ("permission".equals(profile)) {
        contrib = "/OSGI-INF/nuxeodrive-hierarchy-permission-contrib.xml";
    } else {
        log.warn(String.format("No active file system item factory contribution for profile '%s'.", profile));
        return false;
    }
    URL url = NuxeoDriveSetActiveFactories.class.getResource(contrib);
    try {
        if (enable) {
            Framework.getRuntime().getContext().deploy(url);
        } else {
            Framework.getRuntime().getContext().undeploy(url);
        }
    } finally {
        Framework.getRuntime().getComponentManager().unstash();
    }
    FileSystemItemAdapterServiceImpl fileSystemItemAdapterService = (FileSystemItemAdapterServiceImpl) Framework.getService(FileSystemItemAdapterService.class);
    fileSystemItemAdapterService.setActiveFactories();
    return true;
}
Also used : FileSystemItemAdapterService(org.nuxeo.drive.service.FileSystemItemAdapterService) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) URL(java.net.URL) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Aggregations

FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)10 Test (org.junit.Test)8 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)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)4 FileItem (org.nuxeo.drive.adapter.FileItem)2 NuxeoDriveContribException (org.nuxeo.drive.adapter.NuxeoDriveContribException)2 FileSystemItemAdapterService (org.nuxeo.drive.service.FileSystemItemAdapterService)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 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2 URL (java.net.URL)1 Before (org.junit.Before)1 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)1 CollectionSyncRootFolderItem (org.nuxeo.drive.adapter.impl.CollectionSyncRootFolderItem)1