Search in sources :

Example 26 with FolderItem

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

the class FileSystemItemManagerImpl method getChildren.

@Override
public List<FileSystemItem> getChildren(String id, Principal principal) {
    FileSystemItem fileSystemItem = getFileSystemItemById(id, principal);
    if (fileSystemItem == null) {
        throw new NuxeoException(String.format("Cannot get the children of file system item with id %s because it doesn't exist.", id));
    }
    if (!(fileSystemItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot get the children of file system item with id %s because it is not a folder.", id));
    }
    FolderItem folderItem = (FolderItem) fileSystemItem;
    return folderItem.getChildren();
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 27 with FolderItem

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

the class FileSystemItemManagerImpl method createFolder.

/*------------- Write operations ---------------*/
@Override
public FolderItem createFolder(String parentId, String name, Principal principal, boolean overwrite) {
    FileSystemItem parentFsItem = getFileSystemItemById(parentId, principal);
    if (parentFsItem == null) {
        throw new NuxeoException(String.format("Cannot create a folder in file system item with id %s because it doesn't exist.", parentId));
    }
    if (!(parentFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot create a folder in file system item with id %s because it is not a folder but is: %s", parentId, parentFsItem));
    }
    FolderItem parentFolder = (FolderItem) parentFsItem;
    return parentFolder.createFolder(name, overwrite);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 28 with FolderItem

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

the class FileSystemItemManagerImpl method canMove.

@Override
public boolean canMove(String srcId, String destId, Principal principal) {
    FileSystemItem srcFsItem = getFileSystemItemById(srcId, principal);
    if (srcFsItem == null) {
        return false;
    }
    FileSystemItem destFsItem = getFileSystemItemById(destId, principal);
    if (!(destFsItem instanceof FolderItem)) {
        return false;
    }
    return srcFsItem.canMove((FolderItem) destFsItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem)

Example 29 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testGetFileSystemItem.

@Test
public void testGetFileSystemItem() throws Exception {
    // ------------------------------------------------------
    // Check downloadable FileSystemItems
    // ------------------------------------------------------
    // File
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(file));
    FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Joe.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    Blob fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("Joe.odt", fileItemBlob.getFilename());
    assertEquals("Content of Joe's file.", fileItemBlob.getString());
    // Note
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(note));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
    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());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("aNote.txt", fileItemBlob.getFilename());
    assertEquals("Content of Bob's note.", fileItemBlob.getString());
    // Custom doc type with the "file" schema
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FileItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Bonnie's file.odt", fsItem.getName());
    assertFalse(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    fileItemBlob = ((FileItem) fsItem).getBlob();
    assertEquals("Bonnie's file.odt", fileItemBlob.getFilename());
    assertEquals("Content of Bonnie's file.", fileItemBlob.getString());
    // File without a blob => not adaptable as a FileSystemItem
    file.setPropertyValue("file:content", null);
    file = session.saveDocument(file);
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(file));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
    assertNull(fsItem);
    // Deleted file => not adaptable as a FileSystemItem
    custom.followTransition("delete");
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(custom));
    assertNull(defaultFileSystemItemFactory.getFileSystemItem(custom));
    // Deleted file with explicit "includeDeleted" => adaptable as a
    // FileSystemItem
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom, true));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom, true);
    assertNotNull(fsItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
    assertEquals("Bonnie's file.odt", fsItem.getName());
    // Version
    // Note is now automatically versioned at each save
    assertEquals("0.1", note.getVersionLabel());
    note.checkOut();
    DocumentRef versionRef = session.checkIn(note.getRef(), VersioningOption.MINOR, null);
    DocumentModel version = session.getDocument(versionRef);
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(version));
    // Proxy
    DocumentModel proxy = session.createProxy(note.getRef(), folder.getRef());
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(proxy));
    // HiddenInNavigation
    note.addFacet("HiddenInNavigation");
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(note));
    note.removeFacet("HiddenInNavigation");
    // ------------------------------------------------------
    // Check folderish FileSystemItems
    // ------------------------------------------------------
    // Folder
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folder));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(folder);
    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());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    FolderItem folderItem = (FolderItem) fsItem;
    List<FileSystemItem> children = folderItem.getChildren();
    assertNotNull(children);
    assertEquals(0, children.size());
    assertTrue(folderItem.getCanScrollDescendants());
    ScrollFileSystemItemList descendants = folderItem.scrollDescendants(null, 10, 1000);
    assertNotNull(descendants);
    assertNotNull(descendants.getScrollId());
    assertEquals(0, descendants.size());
    // FolderishFile => adaptable as a FolderItem since the default
    // FileSystemItem factory gives precedence to the Folderish facet
    assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folderishFile));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(folderishFile);
    assertNotNull(fsItem);
    assertTrue(fsItem instanceof FolderItem);
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
    assertEquals(syncRootItemId, fsItem.getParentId());
    assertEquals("Sarah's folderish file", fsItem.getName());
    assertTrue(fsItem.isFolder());
    assertEquals("Administrator", fsItem.getCreator());
    assertEquals("Administrator", fsItem.getLastContributor());
    // ------------------------------------------------------
    // Check not downloadable nor folderish
    // ------------------------------------------------------
    assertFalse(defaultFileSystemItemFactory.isFileSystemItem(notAFileSystemItem));
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(notAFileSystemItem);
    assertNull(fsItem);
    // -------------------------------------------------------------
    // Check #getFileSystemItem(DocumentModel doc, FolderItem parentItem)
    // -------------------------------------------------------------
    FolderItem syncRootSystemItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItemFactoryForId(syncRootItemId).getFileSystemItemById(syncRootItemId, principal);
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, syncRootSystemItem);
    assertEquals(syncRootItemId, fsItem.getParentId());
    // Passing a null parent will force a null parentId
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, null);
    assertNull(fsItem.getParentId());
    // ------------------------------------------------------------------
    // Check FileSystemItem#getCanRename and FileSystemItem#getCanDelete
    // ------------------------------------------------------------------
    // As Administrator
    fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
    assertTrue(fsItem.getCanRename());
    assertTrue(fsItem.getCanDelete());
    // As a user with READ permission
    DocumentModel rootDoc = session.getRootDocument();
    setPermission(rootDoc, "joe", SecurityConstants.READ, true);
    // Under Oracle, the READ ACL optims are not visible from the joe
    // session while the transaction has not been committed.
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
        nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
        note = joeSession.getDocument(note.getRef());
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
        assertFalse(fsItem.getCanRename());
        assertFalse(fsItem.getCanDelete());
        // As a user with WRITE permission
        setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
        fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
        assertTrue(fsItem.getCanRename());
        assertTrue(fsItem.getCanDelete());
    }
    resetPermissions(rootDoc, "joe");
}
Also used : ScrollFileSystemItemList(org.nuxeo.drive.adapter.ScrollFileSystemItemList) 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) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 30 with FolderItem

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

the class DefaultFileSystemItemFactoryFixture method testSection.

@Test
public void testSection() {
    // Check that a Section is adaptable as a FileSystemItem by the
    // defaultSyncRootFolderItemFactory
    DocumentModel section = session.createDocument(session.createDocumentModel("/", "sectionSyncRoot", "Section"));
    nuxeoDriveManager.registerSynchronizationRoot(principal, section, session);
    FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
    FolderItem sectionItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(section);
    assertNotNull(sectionItem);
    assertFalse(sectionItem.getCanCreateChild());
    assertFalse(sectionItem.getCanRename());
    assertTrue(sectionItem.getCanDelete());
    // Publish documents in the Section and check its children
    session.publishDocument(file, section);
    session.publishDocument(note, section);
    session.save();
    List<FileSystemItem> children = sectionItem.getChildren();
    assertEquals(2, children.size());
    FileSystemItem child = children.get(0);
    assertFalse(child.getCanRename());
    assertFalse(child.getCanDelete());
}
Also used : DefaultFileSystemItemFactory(org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory) FileSystemItemFactory(org.nuxeo.drive.service.FileSystemItemFactory) FolderItem(org.nuxeo.drive.adapter.FolderItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FileSystemItemAdapterServiceImpl(org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

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