Search in sources :

Example 1 with DefaultTopLevelFolderItem

use of org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem in project nuxeo-drive-server by nuxeo.

the class TestDefaultTopLevelFolderItemFactory method testFactory.

@Test
public void testFactory() throws Exception {
    // -------------------------------------------------------------
    // Check TopLevelFolderItemFactory#getTopLevelFolderItem(String
    // Principal)
    // -------------------------------------------------------------
    FolderItem topLevelFolderItem = defaultTopLevelFolderItemFactory.getTopLevelFolderItem(session.getPrincipal());
    assertNotNull(topLevelFolderItem);
    assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
    assertTrue(topLevelFolderItem.getId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertTrue(topLevelFolderItem.getPath().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertTrue(topLevelFolderItem.getPath().startsWith("/"));
    assertNull(topLevelFolderItem.getParentId());
    assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
    assertTrue(topLevelFolderItem.isFolder());
    assertEquals("system", topLevelFolderItem.getCreator());
    assertEquals("system", topLevelFolderItem.getLastContributor());
    assertFalse(topLevelFolderItem.getCanRename());
    try {
        topLevelFolderItem.rename("newName");
        fail("Should not be able to rename the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot rename a virtual folder item.", e.getMessage());
    }
    assertFalse(topLevelFolderItem.getCanDelete());
    try {
        topLevelFolderItem.delete();
        fail("Should not be able to delete the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot delete a virtual folder item.", e.getMessage());
    }
    assertFalse(topLevelFolderItem.canMove(null));
    try {
        topLevelFolderItem.move(null);
        fail("Should not be able to move the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot move a virtual folder item.", e.getMessage());
    }
    List<FileSystemItem> children = topLevelFolderItem.getChildren();
    assertNotNull(children);
    assertEquals(2, children.size());
    assertFalse(topLevelFolderItem.getCanScrollDescendants());
    try {
        topLevelFolderItem.scrollDescendants(null, 10, 1000);
        fail("Should not be able to scroll through the descendants of the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot scroll through the descendants of a virtual folder item, please call getChildren() instead.", e.getMessage());
    }
    assertFalse(topLevelFolderItem.getCanCreateChild());
    for (FileSystemItem child : children) {
        assertEquals(topLevelFolderItem.getPath() + '/' + child.getId(), child.getPath());
    }
    try {
        topLevelFolderItem.createFile(new StringBlob("Child file content."));
        fail("Should not be able to create a file in the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a file in a virtual folder item.", e.getMessage());
    }
    try {
        topLevelFolderItem.createFolder("subFolder");
        fail("Should not be able to create a folder in the default top level folder item.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot create a folder in a virtual folder item.", e.getMessage());
    }
    // -------------------------------------------------------------
    // Check VirtualFolderItemFactory#getVirtualFolderItem(Principal
    // userName)
    // -------------------------------------------------------------
    assertEquals(topLevelFolderItem, defaultTopLevelFolderItemFactory.getVirtualFolderItem(session.getPrincipal()));
}
Also used : DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Test(org.junit.Test)

Example 2 with DefaultTopLevelFolderItem

use of org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem in project nuxeo-drive-server by nuxeo.

the class TestDefaultTopLevelFolderItemFactory method testFileSystemItemFactory.

@Test
public void testFileSystemItemFactory() {
    // #getName()
    assertEquals("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory", defaultTopLevelFolderItemFactory.getName());
    // #setName(String name)
    defaultTopLevelFolderItemFactory.setName("testName");
    assertEquals("testName", defaultTopLevelFolderItemFactory.getName());
    defaultTopLevelFolderItemFactory.setName("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory");
    // #isFileSystemItem(DocumentModel doc)
    DocumentModel fakeDoc = DocumentModelFactory.createDocumentModel("File");
    assertFalse(defaultTopLevelFolderItemFactory.isFileSystemItem(fakeDoc));
    // #getFileSystemItem(DocumentModel doc)
    assertNull(defaultTopLevelFolderItemFactory.getFileSystemItem(fakeDoc));
    // #canHandleFileSystemItemId(String id)
    assertTrue(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#"));
    assertFalse(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory#"));
    // #exists(String id, Principal principal)
    assertTrue(defaultTopLevelFolderItemFactory.exists("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal()));
    try {
        defaultTopLevelFolderItemFactory.exists("testId", session.getPrincipal());
        fail("Should be unsupported.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot check if a file system item exists for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
    }
    // #getFileSystemItemById(String id, Principal principal)
    FileSystemItem topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal());
    assertNotNull(topLevelFolderItem);
    assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
    assertNull(topLevelFolderItem.getParentId());
    assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
    try {
        defaultTopLevelFolderItemFactory.getFileSystemItemById("testId", session.getPrincipal());
        fail("Should be unsupported.");
    } catch (UnsupportedOperationException e) {
        assertEquals("Cannot get the file system item for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
    }
    // #getFileSystemItemById(String id, String parentId, Principal
    // principal)
    topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", null, session.getPrincipal());
    assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 3 with DefaultTopLevelFolderItem

use of org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testGetFileSystemItem.

@Test
public void testGetFileSystemItem() throws Exception {
    // Get top level folder
    String topLevelFolderItemId = fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId();
    Blob fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", topLevelFolderItemId).execute();
    assertNotNull(fileSystemItemJSON);
    DefaultTopLevelFolderItem topLevelFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultTopLevelFolderItem.class);
    assertNotNull(topLevelFolderItem);
    assertEquals(topLevelFolderItemId, topLevelFolderItem.getId());
    assertNull(topLevelFolderItem.getParentId());
    assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
    assertTrue(topLevelFolderItem.isFolder());
    assertEquals("system", topLevelFolderItem.getCreator());
    assertEquals("system", topLevelFolderItem.getLastContributor());
    assertFalse(topLevelFolderItem.getCanRename());
    assertFalse(topLevelFolderItem.getCanDelete());
    assertFalse(topLevelFolderItem.getCanCreateChild());
    // Get sync root
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    DefaultSyncRootFolderItem syncRootFolderItem = mapper.readValue(fileSystemItemJSON.getStream(), DefaultSyncRootFolderItem.class);
    assertNotNull(syncRootFolderItem);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), syncRootFolderItem.getId());
    assertTrue(syncRootFolderItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder1", syncRootFolderItem.getName());
    assertTrue(syncRootFolderItem.isFolder());
    assertEquals("Administrator", syncRootFolderItem.getCreator());
    assertEquals("Administrator", syncRootFolderItem.getLastContributor());
    assertTrue(syncRootFolderItem.getCanRename());
    assertTrue(syncRootFolderItem.getCanDelete());
    assertTrue(syncRootFolderItem.getCanCreateChild());
    // Get file in sync root
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    DocumentBackedFileItem fileItem = mapper.readValue(fileSystemItemJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(fileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId(), fileItem.getId());
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), fileItem.getParentId());
    assertEquals("First file.odt", fileItem.getName());
    assertFalse(fileItem.isFolder());
    assertEquals("Administrator", fileItem.getCreator());
    assertEquals("Administrator", fileItem.getLastContributor());
    assertTrue(fileItem.getCanRename());
    assertTrue(fileItem.getCanDelete());
    assertTrue(fileItem.getCanUpdate());
    assertEquals("nxfile/test/" + file1.getId() + "/blobholder:0/First%20file.odt", fileItem.getDownloadURL());
    assertEquals("MD5", fileItem.getDigestAlgorithm());
    assertEquals(((org.nuxeo.ecm.core.api.Blob) file1.getPropertyValue("file:content")).getDigest(), fileItem.getDigest());
    // Get deleted file
    file1.followTransition("delete");
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    fileSystemItemJSON = (Blob) clientSession.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).execute();
    assertNotNull(fileSystemItemJSON);
    assertNull(mapper.readValue(fileSystemItemJSON.getStream(), Object.class));
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) Test(org.junit.Test)

Example 4 with DefaultTopLevelFolderItem

use of org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testGetTopLevelChildren.

@Test
public void testGetTopLevelChildren() throws Exception {
    Blob topLevelFolderJSON = (Blob) clientSession.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
    assertNotNull(topLevelFolderJSON);
    // Check children
    FolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), new TypeReference<DefaultTopLevelFolderItem>() {
    });
    Blob topLevelChildrenJSON = (Blob) clientSession.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
    List<DefaultSyncRootFolderItem> topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
    });
    assertNotNull(topLevelChildren);
    assertEquals(2, topLevelChildren.size());
    DefaultSyncRootFolderItem child = topLevelChildren.get(0);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), child.getId());
    assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder1", child.getName());
    assertTrue(child.isFolder());
    assertEquals("Administrator", child.getCreator());
    assertEquals("Administrator", child.getLastContributor());
    assertTrue(child.getCanRename());
    assertTrue(child.getCanDelete());
    assertTrue(child.getCanCreateChild());
    child = topLevelChildren.get(1);
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId(), child.getId());
    assertTrue(child.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
    assertEquals("folder2", child.getName());
    assertTrue(child.isFolder());
    assertEquals("Administrator", child.getCreator());
    assertEquals("Administrator", child.getLastContributor());
    assertTrue(child.getCanRename());
    assertTrue(child.getCanDelete());
    assertTrue(child.getCanCreateChild());
    // Check descendants
    assertFalse(topLevelFolder.getCanScrollDescendants());
    try {
        clientSession.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
        fail("Scrolling through the descendants of the default top level folder item should be unsupported.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
    }
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DefaultTopLevelFolderItem(org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem) DefaultSyncRootFolderItem(org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem) List(java.util.List) ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DefaultTopLevelFolderItem (org.nuxeo.drive.adapter.impl.DefaultTopLevelFolderItem)4 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)3 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)2 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 Blob (org.nuxeo.ecm.automation.client.model.Blob)2 StringBlob (org.nuxeo.ecm.automation.client.model.StringBlob)2 List (java.util.List)1 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)1 DocumentBackedFileItem (org.nuxeo.drive.adapter.impl.DocumentBackedFileItem)1 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)1 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)1 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)1