Search in sources :

Example 41 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchy method createFolder.

protected DocumentModel createFolder(CoreSession session, String path, String name, String type) throws InterruptedException {
    DocumentModel folder = session.createDocumentModel(path, name, type);
    folder = session.createDocument(folder);
    return folder;
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 42 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class TestPermissionHierarchy method createFile.

protected DocumentModel createFile(CoreSession session, String path, String name, String type, String fileName, String content) throws InterruptedException {
    DocumentModel file = session.createDocumentModel(path, name, type);
    org.nuxeo.ecm.core.api.Blob blob = new org.nuxeo.ecm.core.api.impl.blob.StringBlob(content);
    blob.setFilename(fileName);
    file.setPropertyValue("file:content", (Serializable) blob);
    file = session.createDocument(file);
    return file;
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 43 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class TestUserWorkspaceHierarchy method createFile.

protected DocumentModel createFile(CoreSession session, String path, String name, String type, String fileName, String content) throws InterruptedException {
    DocumentModel file = session.createDocumentModel(path, name, type);
    org.nuxeo.ecm.core.api.Blob blob = new org.nuxeo.ecm.core.api.impl.blob.StringBlob(content);
    blob.setFilename(fileName);
    file.setPropertyValue("file:content", (Serializable) blob);
    file = session.createDocument(file);
    return file;
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 44 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testMove.

@Test
public void testMove() throws Exception {
    // ------------------------------------------------------
    try {
        clientSession.newRequest(NuxeoDriveMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file2.getId()).execute();
        fail("Move to a non folder item should fail.");
    } catch (Exception e) {
        String expectedMessage = String.format("Failed to invoke operation: NuxeoDrive.Move, Failed to invoke operation NuxeoDrive.Move, " + "Cannot move a file system item to file system item with id %s because it is not a folder.", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file2.getId());
        assertEquals(expectedMessage, e.getMessage());
    }
    // ------------------------------------------------------
    try {
        clientSession.newRequest(NuxeoDriveMove.ID).set("srcId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
        fail("Should not be able to move a synchronization root folder item.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.Move", e.getMessage());
    }
    // ------------------------------------------------------
    try {
        clientSession.newRequest(NuxeoDriveMove.ID).set("srcId", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
        fail("Should not be able to move the top level folder item.");
    } catch (Exception e) {
        assertEquals("Failed to invoke operation: NuxeoDrive.Move", e.getMessage());
    }
    // ------------------------------------------------------
    // File to Folder => succeed
    // ------------------------------------------------------
    Blob movedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
    assertNotNull(movedFSItemJSON);
    DocumentBackedFileItem movedFileItem = mapper.readValue(movedFSItemJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(movedFileItem);
    assertEquals("First file.odt", movedFileItem.getName());
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel movedFileDoc = session.getDocument(new IdRef(file1.getId()));
    assertEquals("/folder2/file1", movedFileDoc.getPathAsString());
    assertEquals("file1", movedFileDoc.getTitle());
    org.nuxeo.ecm.core.api.Blob movedFileBlob = (org.nuxeo.ecm.core.api.Blob) movedFileDoc.getPropertyValue("file:content");
    assertNotNull(movedFileBlob);
    assertEquals("First file.odt", movedFileBlob.getFilename());
    assertEquals("MD5", movedFileItem.getDigestAlgorithm());
    assertEquals(movedFileBlob.getDigest(), movedFileItem.getDigest());
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 45 with DocumentModel

use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testUpdateFile.

@Test
public void testUpdateFile() throws Exception {
    StringBlob blob = new StringBlob("This is the updated content of file 1.");
    blob.setFileName("Updated file 1.odt");
    Blob updatedFileJSON = (Blob) clientSession.newRequest(NuxeoDriveUpdateFile.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).setInput(blob).execute();
    assertNotNull(updatedFileJSON);
    DocumentBackedFileItem updatedFile = mapper.readValue(updatedFileJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(updatedFile);
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel updatedFileDoc = session.getDocument(new IdRef(file1.getId()));
    assertEquals("File", updatedFileDoc.getType());
    assertEquals("file1", updatedFileDoc.getTitle());
    org.nuxeo.ecm.core.api.Blob updatedFileBlob = (org.nuxeo.ecm.core.api.Blob) updatedFileDoc.getPropertyValue("file:content");
    assertNotNull(updatedFileBlob);
    assertEquals("Updated file 1.odt", updatedFileBlob.getFilename());
    assertEquals("This is the updated content of file 1.", updatedFileBlob.getString());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + updatedFileDoc.getId(), updatedFile.getId());
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId(), updatedFile.getParentId());
    assertEquals("Updated file 1.odt", updatedFile.getName());
    assertFalse(updatedFile.isFolder());
    assertEquals("Administrator", updatedFile.getCreator());
    assertEquals("Administrator", updatedFile.getLastContributor());
    assertTrue(updatedFile.getCanRename());
    assertTrue(updatedFile.getCanDelete());
    assertTrue(updatedFile.getCanUpdate());
    assertEquals("nxfile/test/" + updatedFileDoc.getId() + "/blobholder:0/Updated%20file%201.odt", updatedFile.getDownloadURL());
    assertEquals("MD5", updatedFile.getDigestAlgorithm());
    assertEquals(updatedFileBlob.getDigest(), updatedFile.getDigest());
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7