Search in sources :

Example 1 with TopLevelFolderItemFactory

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

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

the class TopLevelFolderItemFactoryDescriptor method getFactory.

public TopLevelFolderItemFactory getFactory() throws InstantiationException, IllegalAccessException {
    TopLevelFolderItemFactory factory = factoryClass.newInstance();
    factory.setName(factory.getClass().getName());
    factory.handleParameters(parameters);
    return factory;
}
Also used : TopLevelFolderItemFactory(org.nuxeo.drive.service.TopLevelFolderItemFactory)

Example 3 with TopLevelFolderItemFactory

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

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

the class TestPermissionHierarchy method testClientSideUser1.

@Test
public void testClientSideUser1() throws Exception {
    // ---------------------------------------------
    // Check active factories
    // ---------------------------------------------
    TopLevelFolderItemFactory topLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
    assertEquals("org.nuxeo.drive.hierarchy.permission.factory.PermissionTopLevelFactory", topLevelFolderItemFactory.getName());
    Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
    assertEquals(5, activeFactories.size());
    assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
    assertTrue(activeFactories.contains("userSyncRootParentFactory"));
    assertTrue(activeFactories.contains("permissionSyncRootFactory"));
    assertTrue(activeFactories.contains("sharedSyncRootParentFactory"));
    // ---------------------------------------------
    // Check top level folder: "Nuxeo Drive"
    // ---------------------------------------------
    Blob topLevelFolderJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
    assertNotNull(topLevelFolderJSON);
    PermissionTopLevelFolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), PermissionTopLevelFolderItem.class);
    assertNotNull(topLevelFolder);
    assertEquals(TOP_LEVEL_ID, topLevelFolder.getId());
    assertNull(topLevelFolder.getParentId());
    assertEquals("/" + TOP_LEVEL_ID, topLevelFolder.getPath());
    assertEquals("Nuxeo Drive", topLevelFolder.getName());
    assertTrue(topLevelFolder.isFolder());
    assertEquals("system", topLevelFolder.getCreator());
    assertEquals("system", topLevelFolder.getLastContributor());
    assertFalse(topLevelFolder.getCanRename());
    assertFalse(topLevelFolder.getCanDelete());
    assertFalse(topLevelFolder.getCanCreateChild());
    /**
     * <pre>
     * ===================================================
     * User workspace registered as a synchronization root
     * ===================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |     |-- user1File2
     *   |     |-- user1Folder1
     *   |     |     |-- user1File1
     *   |     |     |-- user1Folder2
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check top level folder children
    // ---------------------------------------------
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the permission top level folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
    // Get children
    Blob topLevelChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
    ArrayNode topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());
    // Check "My Docs"
    UserSyncRootParentFolderItem userSyncRootParent = readValue(topLevelChildren.get(0), UserSyncRootParentFolderItem.class);
    assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
    assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
    assertEquals("My Docs", userSyncRootParent.getName());
    assertTrue(userSyncRootParent.isFolder());
    assertEquals("user1", userSyncRootParent.getCreator());
    assertEquals("user1", userSyncRootParent.getLastContributor());
    assertFalse(userSyncRootParent.getCanRename());
    assertFalse(userSyncRootParent.getCanDelete());
    // Can create a child since "My Docs" is the user workspace
    assertTrue(userSyncRootParent.getCanCreateChild());
    // Check "Other Docs"
    SharedSyncRootParentFolderItem sharedSyncRootParent = readValue(topLevelChildren.get(1), SharedSyncRootParentFolderItem.class);
    assertEquals(SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, sharedSyncRootParent.getParentId());
    assertEquals("/" + TOP_LEVEL_ID + "/" + SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getPath());
    assertEquals("Other Docs", sharedSyncRootParent.getName());
    assertTrue(sharedSyncRootParent.isFolder());
    assertEquals("system", sharedSyncRootParent.getCreator());
    assertEquals("system", sharedSyncRootParent.getLastContributor());
    assertFalse(sharedSyncRootParent.getCanRename());
    assertFalse(sharedSyncRootParent.getCanDelete());
    assertFalse(sharedSyncRootParent.getCanCreateChild());
    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    // Check descendants
    assertTrue(userSyncRootParent.getCanScrollDescendants());
    assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(user1File2, user1Folder1, user1File1, user1Folder2, user1Folder3, user1File3, user1Folder4).stream().map(doc -> DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc.getId()).collect(Collectors.toList()), mapper.readValue(((Blob) clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", userSyncRootParent.getId()).set("batchSize", 10).execute()).getStream(), JsonNode.class).findValuesAsText("id")));
    // Get children
    Blob userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
    ArrayNode userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(4, userSyncRoots.size());
    DocumentBackedFolderItem folderItem;
    DocumentBackedFileItem childFileItem;
    DocumentBackedFileItem fileItem;
    DocumentBackedFolderItem childFolderItem;
    JsonNode[] rootNodes = sortNodeByName(userSyncRoots);
    // user1File2
    fileItem = readValue(rootNodes[0], DocumentBackedFileItem.class);
    checkFileItem(fileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File2, userWorkspace1ItemId, userWorkspace1ItemPath, "user1File2.txt", "user1", "user1");
    // user1Folder1
    folderItem = readValue(rootNodes[1], DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder1, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder1", "user1", "user1");
    Blob folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
    ArrayNode folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(folderItemChildren);
    assertEquals(2, folderItemChildren.size());
    {
        JsonNode[] nodes = sortNodeByName(folderItemChildren);
        // user1File1
        childFileItem = readValue(nodes[0], DocumentBackedFileItem.class);
        checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File1, folderItem.getId(), folderItem.getPath(), "user1File1.txt", "user1", "user1");
        // user1Folder2
        childFolderItem = readValue(nodes[1], DocumentBackedFolderItem.class);
        checkFolderItem(childFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder2, folderItem.getId(), folderItem.getPath(), "user1Folder2", "user1", "user1");
    }
    // user1Folder3
    folderItem = readValue(rootNodes[2], DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1");
    {
        folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
        folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
        assertNotNull(folderItemChildren);
        assertEquals(1, folderItemChildren.size());
        // user1File3
        childFileItem = readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
        checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1");
    }
    // user1Folder4
    folderItem = readValue(rootNodes[3], DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1");
    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", sharedSyncRootParent.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the shared sync root parent folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
    // Get children
    Blob sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
    List<DefaultSyncRootFolderItem> sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    Collections.sort(sharedSyncRoots);
    assertNotNull(sharedSyncRoots);
    assertEquals(2, sharedSyncRoots.size());
    // user2Folder1
    DefaultSyncRootFolderItem sharedSyncRoot = sharedSyncRoots.get(0);
    checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder1.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder1", "user2", "user1");
    Blob sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
    ArrayNode sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(2, sharedSyncRootChildren.size());
    DocumentBackedFolderItem sharedSyncRootChildFolderItem;
    DocumentBackedFileItem sharedSyncRootChildFileItem;
    {
        JsonNode[] nodes = sortNodeByName(sharedSyncRootChildren);
        // user2File1
        sharedSyncRootChildFileItem = readValue(nodes[0], DocumentBackedFileItem.class);
        checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File1.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File1.txt", "user2", "user2");
        // user2Folder2
        sharedSyncRootChildFolderItem = readValue(nodes[1], DocumentBackedFolderItem.class);
        checkFolderItem(sharedSyncRootChildFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2Folder2.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2Folder2", "user2", "user2");
    }
    // user2Folder3
    sharedSyncRoot = sharedSyncRoots.get(1);
    checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1");
    sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
    sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(1, sharedSyncRootChildren.size());
    // user2File3
    sharedSyncRootChildFileItem = readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2");
    /**
     * <pre>
     * =======================================================
     * User workspace NOT registered as a synchronization root
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |
     *   |-- Other Docs (unchanged)
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check "My Docs"
    // ---------------------------------------------
    Blob userSyncRootParentJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", userWorkspace1ItemId).execute();
    assertNotNull(userSyncRootParentJSON);
    userSyncRootParent = mapper.readValue(userSyncRootParentJSON.getStream(), UserSyncRootParentFolderItem.class);
    assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
    assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
    assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
    assertEquals("My Docs", userSyncRootParent.getName());
    assertTrue(userSyncRootParent.isFolder());
    assertEquals("user1", userSyncRootParent.getCreator());
    assertEquals("user1", userSyncRootParent.getLastContributor());
    assertFalse(userSyncRootParent.getCanRename());
    assertFalse(userSyncRootParent.getCanDelete());
    // Cannot create a child since "My Docs" is only the parent of the
    // synchronization roots, not the user workspace
    assertFalse(userSyncRootParent.getCanCreateChild());
    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", userSyncRootParent.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the user sync root parent folder item not registered as a sync root should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
    // Get children
    userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
    userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(0, userSyncRoots.size());
    /**
     * <pre>
     * =======================================================
     * User workspace NOT registered as a synchronization root
     * but specific folders yes: user1Folder3, user1Folder4
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs (unchanged)
     *   |     |-- user2Folder1
     *   |     |     |-- user2File1
     *   |     |     |-- user2Folder2
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder3, session1);
    nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder4, session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // --------------------------------------------
    // Check user synchronization roots
    // --------------------------------------------
    userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
    userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
    assertNotNull(userSyncRoots);
    assertEquals(2, userSyncRoots.size());
    // user1Folder3
    folderItem = readValue(userSyncRoots.get(0), DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, SYNC_ROOT_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1");
    folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
    folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(folderItemChildren);
    assertEquals(1, folderItemChildren.size());
    // user1File3
    childFileItem = readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1");
    // user1Folder4
    folderItem = readValue(userSyncRoots.get(1), DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, SYNC_ROOT_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1");
    /**
     * <pre>
     * =======================================================
     * Unregister a shared folder: user2Folder1
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs (unchanged)
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     *   |     |-- user2Folder3
     *   |     |     |-- user2File3
     * </pre>
     */
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), session1.getDocument(user2Folder1.getRef()), session1);
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
    sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    assertNotNull(sharedSyncRoots);
    assertEquals(1, sharedSyncRoots.size());
    // user2Folder3
    sharedSyncRoot = sharedSyncRoots.get(0);
    checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1");
    sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
    sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(sharedSyncRootChildren);
    assertEquals(1, sharedSyncRootChildren.size());
    // user2File3
    sharedSyncRootChildFileItem = readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
    checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2");
    /**
     * <pre>
     * =======================================================
     * Remove permission on a shared folder: user2Folder3
     * =======================================================
     * => Expected client side for user1:
     *
     * Nuxeo Drive
     *   |-- My Docs (unchanged)
     *   |     |-- user1Folder3
     *   |     |      |-- user1File3
     *   |     |-- user1Folder4
     *   |
     *   |-- Other Docs
     * </pre>
     */
    resetPermissions(user2Folder3.getRef(), "user1");
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ---------------------------------------------
    // Check shared synchronization roots
    // ---------------------------------------------
    sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
    sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    assertNotNull(sharedSyncRoots);
    assertEquals(0, sharedSyncRoots.size());
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) Arrays(java.util.Arrays) DirectoryService(org.nuxeo.ecm.directory.api.DirectoryService) NuxeoDriveAutomationFeature(org.nuxeo.drive.operations.NuxeoDriveAutomationFeature) Map(java.util.Map) After(org.junit.After) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) Assert.fail(org.junit.Assert.fail) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Session(org.nuxeo.ecm.automation.client.Session) JsonParseException(com.fasterxml.jackson.core.JsonParseException) SecurityConstants(org.nuxeo.ecm.core.api.security.SecurityConstants) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) NuxeoDriveManager(org.nuxeo.drive.service.NuxeoDriveManager) Set(java.util.Set) HttpAutomationClient(org.nuxeo.ecm.automation.client.jaxrs.impl.HttpAutomationClient) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) Blob(org.nuxeo.ecm.automation.client.model.Blob) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Features(org.nuxeo.runtime.test.runner.Features) NuxeoDriveGetFileSystemItem(org.nuxeo.drive.operations.NuxeoDriveGetFileSystemItem) UserSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.UserSyncRootParentFolderItem) Assert.assertFalse(org.junit.Assert.assertFalse) UserWorkspaceService(org.nuxeo.ecm.platform.userworkspace.api.UserWorkspaceService) ACP(org.nuxeo.ecm.core.api.security.ACP) Jetty(org.nuxeo.runtime.test.runner.Jetty) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) FileItem(org.nuxeo.drive.adapter.FileItem) ACL(org.nuxeo.ecm.core.api.security.ACL) CoreFeature(org.nuxeo.ecm.core.test.CoreFeature) PermissionTopLevelFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.PermissionTopLevelFolderItem) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Inject(javax.inject.Inject) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) NuxeoDriveScrollDescendants(org.nuxeo.drive.operations.NuxeoDriveScrollDescendants) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FeaturesRunner(org.nuxeo.runtime.test.runner.FeaturesRunner) CollectionUtils(org.apache.commons.collections.CollectionUtils) FileSystemItemAdapterService(org.nuxeo.drive.service.FileSystemItemAdapterService) TransactionHelper(org.nuxeo.runtime.transaction.TransactionHelper) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) NuxeoDriveGetChildren(org.nuxeo.drive.operations.NuxeoDriveGetChildren) TopLevelFolderItemFactory(org.nuxeo.drive.service.TopLevelFolderItemFactory) Before(org.junit.Before) Iterator(java.util.Iterator) JsonParser(com.fasterxml.jackson.core.JsonParser) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) SharedSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.SharedSyncRootParentFolderItem) IOException(java.io.IOException) Test(org.junit.Test) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) FolderItem(org.nuxeo.drive.adapter.FolderItem) Deploy(org.nuxeo.runtime.test.runner.Deploy) Assert.assertNull(org.junit.Assert.assertNull) NuxeoDriveGetTopLevelFolder(org.nuxeo.drive.operations.NuxeoDriveGetTopLevelFolder) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Blob(org.nuxeo.ecm.automation.client.model.Blob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) TopLevelFolderItemFactory(org.nuxeo.drive.service.TopLevelFolderItemFactory) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) PermissionTopLevelFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.PermissionTopLevelFolderItem) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) List(java.util.List) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) UserSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.UserSyncRootParentFolderItem) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SharedSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.permission.adapter.SharedSyncRootParentFolderItem) Test(org.junit.Test)

Example 5 with TopLevelFolderItemFactory

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

the class TestUserWorkspaceHierarchy method testClientSideUser1.

/**
 * <pre>
 * Expected client side for user1
 * ==============================
 *
 * Nuxeo Drive
 *   |-- My synchronized folders
 *   |     |-- user1Folder3
 *   |     |     |-- user1File3
 *   |     |-- user1Folder4
 *   |     |     |-- user1File4
 *   |-- user1File2
 *   |-- user1Folder1
 *   |     |-- user1File1
 *   |     |-- user1Folder2
 * </pre>
 */
@Test
public void testClientSideUser1() throws Exception {
    // Temporarily ignore under MySQL waiting for https://jira.nuxeo.com/browse/NXP-15969 to be fixed
    if (storageConfiguration.isVCSMySQL()) {
        return;
    }
    // ---------------------------------------------
    // Check active factories
    // ---------------------------------------------
    TopLevelFolderItemFactory topLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
    assertEquals("org.nuxeo.drive.hierarchy.userworkspace.factory.UserWorkspaceTopLevelFactory", topLevelFolderItemFactory.getName());
    Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
    assertEquals(4, activeFactories.size());
    assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
    assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
    assertTrue(activeFactories.contains("userWorkspaceSyncRootParentFactory"));
    assertTrue(activeFactories.contains("userWorkspaceSyncRootFactory"));
    // ---------------------------------------------
    // Check top level folder: "Nuxeo Drive"
    // ---------------------------------------------
    Blob topLevelFolderJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
    assertNotNull(topLevelFolderJSON);
    UserWorkspaceTopLevelFolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), UserWorkspaceTopLevelFolderItem.class);
    assertNotNull(topLevelFolder);
    assertEquals(userWorkspace1ItemId, topLevelFolder.getId());
    assertNull(topLevelFolder.getParentId());
    assertEquals(userWorkspace1ItemPath, topLevelFolder.getPath());
    assertEquals("Nuxeo Drive", topLevelFolder.getName());
    assertTrue(topLevelFolder.isFolder());
    assertEquals("user1", topLevelFolder.getCreator());
    assertEquals("user1", topLevelFolder.getLastContributor());
    assertFalse(topLevelFolder.getCanRename());
    assertFalse(topLevelFolder.getCanDelete());
    assertTrue(topLevelFolder.getCanCreateChild());
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the user workspace top level folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
    // Get children
    Blob topLevelChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
    ArrayNode topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(topLevelChildren);
    assertEquals(3, topLevelChildren.size());
    JsonNode[] topLevelChildrenNodes = sortNodeByName(topLevelChildren);
    // ---------------------------------------------
    // Check synchronization roots
    // ---------------------------------------------
    // My synchronized folders
    UserWorkspaceSyncRootParentFolderItem syncRootParent = readValue(topLevelChildrenNodes[0], UserWorkspaceSyncRootParentFolderItem.class);
    assertEquals(SYNC_ROOT_PARENT_ID, syncRootParent.getId());
    assertEquals(userWorkspace1ItemId, syncRootParent.getParentId());
    assertEquals("/" + userWorkspace1ItemId + "/" + SYNC_ROOT_PARENT_ID, syncRootParent.getPath());
    assertEquals("My synchronized folders", syncRootParent.getName());
    assertTrue(syncRootParent.isFolder());
    assertEquals("system", syncRootParent.getCreator());
    assertEquals("system", syncRootParent.getLastContributor());
    assertFalse(syncRootParent.getCanRename());
    assertFalse(syncRootParent.getCanDelete());
    assertFalse(syncRootParent.getCanCreateChild());
    // Check descendants
    assertFalse(syncRootParent.getCanScrollDescendants());
    try {
        clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", syncRootParent.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of a virtual folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
    // Get children
    Blob syncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootParent.getId()).execute();
    List<DefaultSyncRootFolderItem> syncRoots = mapper.readValue(syncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    assertNotNull(syncRoots);
    assertEquals(2, syncRoots.size());
    Collections.sort(syncRoots);
    // user1Folder3
    DefaultSyncRootFolderItem syncRootItem = syncRoots.get(0);
    checkFolderItem(syncRootItem, SYNC_ROOT_ID_PREFIX, user1Folder3, SYNC_ROOT_PARENT_ID, syncRootParentItemPath, "user1Folder3", "user1", "user1");
    Blob syncRootItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootItem.getId()).execute();
    List<DocumentBackedFileItem> syncRootItemChildren = mapper.readValue(syncRootItemChildrenJSON.getStream(), new TypeReference<List<DocumentBackedFileItem>>() {
    });
    assertNotNull(syncRootItemChildren);
    assertEquals(1, syncRootItemChildren.size());
    // user1File3
    DocumentBackedFileItem childFileItem = syncRootItemChildren.get(0);
    checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, syncRootItem.getId(), syncRootItem.getPath(), "user1File3.txt", "user1", "user1");
    // user1Folder4
    syncRootItem = syncRoots.get(1);
    checkFolderItem(syncRootItem, SYNC_ROOT_ID_PREFIX, user1Folder4, SYNC_ROOT_PARENT_ID, syncRootParentItemPath, "user1Folder4", "user1", "user1");
    syncRootItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootItem.getId()).execute();
    syncRootItemChildren = mapper.readValue(syncRootItemChildrenJSON.getStream(), new TypeReference<List<DocumentBackedFileItem>>() {
    });
    assertNotNull(syncRootItemChildren);
    assertEquals(1, syncRootItemChildren.size());
    // user1File4
    childFileItem = syncRootItemChildren.get(0);
    checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File4, syncRootItem.getId(), syncRootItem.getPath(), "user1File4.txt", "user1", "user1");
    // ---------------------------------------------
    // Check user workspace children
    // ---------------------------------------------
    // user1File2
    DocumentBackedFileItem fileItem = readValue(topLevelChildrenNodes[1], DocumentBackedFileItem.class);
    checkFileItem(fileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File2, userWorkspace1ItemId, userWorkspace1ItemPath, "user1File2.txt", "user1", "user1");
    // user1Folder1
    DocumentBackedFolderItem folderItem = readValue(topLevelChildrenNodes[2], DocumentBackedFolderItem.class);
    checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder1, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder1", "user1", "user1");
    Blob folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
    ArrayNode folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
    assertNotNull(folderItemChildren);
    assertEquals(2, folderItemChildren.size());
    {
        JsonNode[] folderItemChildrenNodes = sortNodeByName(folderItemChildren);
        // user1File1
        childFileItem = readValue(folderItemChildrenNodes[0], DocumentBackedFileItem.class);
        checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File1, folderItem.getId(), folderItem.getPath(), "user1File1.txt", "user1", "user1");
        // user1Folder2
        DocumentBackedFolderItem childFolderItem = readValue(folderItemChildrenNodes[1], DocumentBackedFolderItem.class);
        checkFolderItem(childFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder2, folderItem.getId(), folderItem.getPath(), "user1Folder2", "user1", "user1");
    }
    // ---------------------------------------------
    // Check registering user workspace as a
    // synchronization root is ignored
    // ---------------------------------------------
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try {
        nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
        TransactionHelper.commitOrRollbackTransaction();
        TransactionHelper.startTransaction();
        syncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootParent.getId()).execute();
        syncRoots = mapper.readValue(syncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
        });
        assertEquals(2, syncRoots.size());
    } finally {
        TransactionHelper.commitOrRollbackTransaction();
        TransactionHelper.startTransaction();
    }
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) JsonNode(com.fasterxml.jackson.databind.JsonNode) UserWorkspaceSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) TopLevelFolderItemFactory(org.nuxeo.drive.service.TopLevelFolderItemFactory) UserWorkspaceTopLevelFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceTopLevelFolderItem) IOException(java.io.IOException) List(java.util.List) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Aggregations

TopLevelFolderItemFactory (org.nuxeo.drive.service.TopLevelFolderItemFactory)5 Test (org.junit.Test)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 IOException (java.io.IOException)2 List (java.util.List)2 FileItem (org.nuxeo.drive.adapter.FileItem)2 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 NuxeoDriveContribException (org.nuxeo.drive.adapter.NuxeoDriveContribException)2 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)2 DocumentBackedFileItem (org.nuxeo.drive.adapter.impl.DocumentBackedFileItem)2 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)2 Blob (org.nuxeo.ecm.automation.client.model.Blob)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Serializable (java.io.Serializable)1