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;
}
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;
}
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;
}
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());
}
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());
}
Aggregations