Search in sources :

Example 31 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testCreateFilesWithSameName.

@Test
public void testCreateFilesWithSameName() {
    FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
    Blob blob = new StringBlob("This is a blob.");
    blob.setFilename("File01.txt");
    FileItem fileItem = folderItem.createFile(blob);
    FileItem fileItem2 = folderItem.createFile(blob);
    assertNotEquals(fileItem.getId(), fileItem2.getId());
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) FolderItem(org.nuxeo.drive.adapter.FolderItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Test(org.junit.Test)

Example 32 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testGetFileSystemItemById.

@Test
public void testGetFileSystemItemById() throws Exception {
    // Non existent doc id, must return null
    assertNull(defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentDocId", principal));
    // File without a blob
    file.setPropertyValue("file:content", null);
    file = session.saveDocument(file);
    session.save();
    FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
    assertNull(fsItem);
    // Note
    fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("aNote.txt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    Blob fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("aNote.txt", fileItemBlob.getFilename());
    assertEquals("Content of Bob's note.", fileItemBlob.getString());
    // Folder
    fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Jack's folder", fsItem.getName());
    assertTrue(fsItem.isFolder());
    FolderItem folderItem = (FolderItem) fsItem;
    assertTrue(folderItem.getChildren().isEmpty());
    assertTrue(folderItem.getCanScrollDescendants());
    assertTrue(folderItem.scrollDescendants(null, 10, 1000).isEmpty());
    // Not adaptable as a FileSystemItem
    fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
    assertNull(fsItem);
    // Deleted
    custom.followTransition("delete");
    fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal);
    assertNull(fsItem);
    // Use parent id
    fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), syncRootItemId, principal);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) Test(org.junit.Test)

Example 33 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testCreateFoldersWithSameName.

@Test
public void testCreateFoldersWithSameName() {
    FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
    FolderItem subFolderItem = folderItem.createFolder("subfolder01");
    FolderItem subFolderItem2 = folderItem.createFolder("subfolder01");
    assertNotEquals(subFolderItem.getId(), subFolderItem2.getId());
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) Test(org.junit.Test)

Example 34 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testFolderItemChildrenPageProviderOverride.

@Test
public void testFolderItemChildrenPageProviderOverride() throws Exception {
    assumeFalse("Cannot test reload for in-memory repository", coreFeature.getStorageConfiguration().isDBSMem());
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), syncRootFolder, session);
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
    assertEquals(5, syncRootFolderItem.getChildren().size());
    // should save documents before runtime reset
    TransactionHelper.commitOrRollbackTransaction();
    try {
        deployer.deploy("org.nuxeo.drive.core.test:OSGI-INF/test-nuxeodrive-pageproviders-contrib-override.xml");
    } finally {
        TransactionHelper.startTransaction();
    }
    assertEquals(2, syncRootFolderItem.getChildren().size());
}
Also used : DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) Test(org.junit.Test)

Example 35 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testPermissionCheckOptimized.

@Test
@Deploy("org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-permissions-contrib.xml")
public void testPermissionCheckOptimized() {
    setPermission(syncRootFolder, "joe", SecurityConstants.READ, true);
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        log.trace("Register the sync root for Joe's account");
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, joeSession);
        folder = joeSession.getDocument(folder.getRef());
        log.trace("Check canDelete/canCreateChild flags on folder for user joe with Read granted on parent folder");
        FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        assertFalse(folderItem.getCanDelete());
        assertFalse(folderItem.getCanCreateChild());
        log.trace("Check canDelete/canCreateChild flags on folder for user joe with Write granted on folder, AddChildren not granted on folder and RemoveChildren not granted on parent folder");
        setPermission(folder, "joe", SecurityConstants.WRITE, true);
        folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        // True here as optimized => no explicit check of AddChildren on
        // folder nor RemoveChildren on parent folder
        assertTrue(folderItem.getCanDelete());
        assertTrue(folderItem.getCanCreateChild());
        log.trace("Check canDelete flag on folder for user joe with Write (thus RemoveChildren) granted on parent folder");
        setPermission(syncRootFolder, "joe", SecurityConstants.WRITE, true);
        folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        // Still true with RemoveChildren on the parent folder
        assertTrue(folderItem.getCanDelete());
        log.trace("Check canCreateChild flag on folder for user joe with AddChildren granted on folder");
        setPermission(folder, "joe", SecurityConstants.ADD_CHILDREN, true);
        folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
        // Still true with AddChildren on the folder
        assertTrue(folderItem.getCanCreateChild());
    }
    resetPermissions(folder, "joe");
    resetPermissions(syncRootFolder, "joe");
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) Test(org.junit.Test) Deploy(org.nuxeo.runtime.test.runner.Deploy)

Aggregations

FolderItem (org.nuxeo.drive.adapter.FolderItem)43 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)24 Test (org.junit.Test)22 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)16 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)14 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)10 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 FileItem (org.nuxeo.drive.adapter.FileItem)8 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)8 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)8 Blob (org.nuxeo.ecm.core.api.Blob)8 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)7 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)6 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)4 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)4 Deploy (org.nuxeo.runtime.test.runner.Deploy)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DocumentBackedFolderItem (org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem)3