Search in sources :

Example 1 with VirtualFolderItemFactory

use of org.nuxeo.drive.service.VirtualFolderItemFactory 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 2 with VirtualFolderItemFactory

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

the class UserWorkspaceTopLevelFolderItem method getChildren.

/*--------------------- FolderItem -----------------*/
@Override
public List<FileSystemItem> getChildren() {
    // already the case
    if (!getNuxeoDriveManager().isSynchronizationRoot(principal, userWorkspace)) {
        try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
            getNuxeoDriveManager().registerSynchronizationRoot(principal, userWorkspace, session);
        }
    }
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    // Add user workspace children
    children.addAll(super.getChildren());
    // Add synchronization root parent folder
    if (syncRootParentFactoryName == null) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No synchronization root parent factory name parameter for factory %s, the synchronization roots won't be synchronized client side.", factoryName));
        }
    } else {
        VirtualFolderItemFactory syncRootParentFactory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(syncRootParentFactoryName);
        FolderItem syncRootParent = syncRootParentFactory.getVirtualFolderItem(principal);
        if (syncRootParent != null) {
            children.add(syncRootParent);
        }
    }
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) ArrayList(java.util.ArrayList) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) VirtualFolderItemFactory(org.nuxeo.drive.service.VirtualFolderItemFactory)

Example 3 with VirtualFolderItemFactory

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

the class PermissionTopLevelFolderItem method getChildren.

@Override
public List<FileSystemItem> getChildren() {
    List<FileSystemItem> children = new ArrayList<FileSystemItem>();
    for (String childFactoryName : childrenFactoryNames) {
        VirtualFolderItemFactory factory = getFileSystemItemAdapterService().getVirtualFolderItemFactory(childFactoryName);
        FolderItem child = factory.getVirtualFolderItem(principal);
        if (child != null) {
            children.add(child);
        }
    }
    return children;
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) AbstractVirtualFolderItem(org.nuxeo.drive.adapter.impl.AbstractVirtualFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) ArrayList(java.util.ArrayList) VirtualFolderItemFactory(org.nuxeo.drive.service.VirtualFolderItemFactory)

Aggregations

FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)3 VirtualFolderItemFactory (org.nuxeo.drive.service.VirtualFolderItemFactory)3 ArrayList (java.util.ArrayList)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 Test (org.junit.Test)1 FileItem (org.nuxeo.drive.adapter.FileItem)1 NuxeoDriveContribException (org.nuxeo.drive.adapter.NuxeoDriveContribException)1 AbstractVirtualFolderItem (org.nuxeo.drive.adapter.impl.AbstractVirtualFolderItem)1 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)1 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)1 TopLevelFolderItemFactory (org.nuxeo.drive.service.TopLevelFolderItemFactory)1 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)1 DefaultSyncRootFolderItemFactory (org.nuxeo.drive.service.impl.DefaultSyncRootFolderItemFactory)1 DefaultTopLevelFolderItemFactory (org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory)1 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)1 FileSystemItemFactoryDescriptor (org.nuxeo.drive.service.impl.FileSystemItemFactoryDescriptor)1 FileSystemItemFactoryWrapper (org.nuxeo.drive.service.impl.FileSystemItemFactoryWrapper)1 Blob (org.nuxeo.ecm.core.api.Blob)1 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)1 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)1