Search in sources :

Example 1 with UserWorkspaceSyncRootParentFolderItem

use of org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem in project nuxeo-drive-server by nuxeo.

the class UserWorkspaceSyncRootParentFactory method getVirtualFolderItem.

@Override
public FolderItem getVirtualFolderItem(Principal principal) {
    FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
    FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
    if (topLevelFolder == null) {
        throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
    }
    return new UserWorkspaceSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
Also used : FileSystemItemManager(org.nuxeo.drive.service.FileSystemItemManager) UserWorkspaceSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) UserWorkspaceSyncRootParentFolderItem(org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 2 with UserWorkspaceSyncRootParentFolderItem

use of org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem 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

UserWorkspaceSyncRootParentFolderItem (org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 List (java.util.List)1 Test (org.junit.Test)1 FolderItem (org.nuxeo.drive.adapter.FolderItem)1 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)1 DocumentBackedFileItem (org.nuxeo.drive.adapter.impl.DocumentBackedFileItem)1 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)1 UserWorkspaceTopLevelFolderItem (org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceTopLevelFolderItem)1 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)1 TopLevelFolderItemFactory (org.nuxeo.drive.service.TopLevelFolderItemFactory)1 Blob (org.nuxeo.ecm.automation.client.model.Blob)1 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)1