use of org.nuxeo.ecm.core.api.IdRef 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.IdRef 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());
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveActions method getCurrentSynchronizationRoot.
@Factory(value = CURRENT_SYNCHRONIZATION_ROOT, scope = ScopeType.EVENT)
public DocumentModel getCurrentSynchronizationRoot() {
// Use the event context as request cache
Context cache = Contexts.getEventContext();
Boolean isUnderSync = (Boolean) cache.get(IS_UNDER_SYNCHRONIZATION_ROOT);
if (isUnderSync == null) {
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
Set<IdRef> references = driveManager.getSynchronizationRootReferences(documentManager);
DocumentModelList path = navigationContext.getCurrentPath();
DocumentModel root = null;
// considered the current synchronization root
for (DocumentModel parent : path) {
if (references.contains(parent.getRef())) {
root = parent;
break;
}
}
cache.set(CURRENT_SYNCHRONIZATION_ROOT, root);
cache.set(IS_UNDER_SYNCHRONIZATION_ROOT, root != null);
}
return (DocumentModel) cache.get(CURRENT_SYNCHRONIZATION_ROOT);
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveActions method getSynchronizationRoots.
public DocumentModelList getSynchronizationRoots() {
DocumentModelList syncRoots = new DocumentModelListImpl();
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
Set<IdRef> syncRootRefs = driveManager.getSynchronizationRootReferences(documentManager);
for (IdRef syncRootRef : syncRootRefs) {
syncRoots.add(documentManager.getDocument(syncRootRef));
}
return syncRoots;
}
use of org.nuxeo.ecm.core.api.IdRef in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method testRegisteredSyncRootChildChange.
@Test
public void testRegisteredSyncRootChildChange() throws InterruptedException {
commitAndWaitForAsyncCompletion();
DocumentModel folderA;
DocumentModel folderC;
// Create the tree structure
try {
createFolderTree(session1, userWorkspace1.getPathAsString(), 5);
folderA = session1.getChild(userWorkspace1.getRef(), "Folder A");
DocumentModel folderB = session1.getChild(folderA.getRef(), "Folder B");
folderC = session1.getChild(folderB.getRef(), "Folder C");
setPermission(session1, folderA, "user2", SecurityConstants.EVERYTHING, true);
setPermission(session1, folderC, "user2", SecurityConstants.READ, true);
} finally {
commitAndWaitForAsyncCompletion();
}
lastEventLogId = nuxeoDriveManager.getChangeFinder().getUpperBound();
// Register FolderA as a synchronization root for user2
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderA, session2);
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("rootRegistered", change.getEventId());
assertEquals("Folder A", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
try {
resetPermissions(session1, folderA.getRef(), "user2");
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("securityUpdated", change.getEventId());
assertNull(change.getFileSystemItemName());
assertNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
// Register Folder C as a synchronization root for user2
try {
nuxeoDriveManager.registerSynchronizationRoot(session2.getPrincipal(), folderC, session2);
assertFalse(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderA.getId())));
assertTrue(nuxeoDriveManager.getSynchronizationRootReferences(session2).contains(new IdRef(folderC.getId())));
} finally {
commitAndWaitForAsyncCompletion();
}
// Check file system item change
try {
assertEquals(1, session2.getChildren(folderC.getRef()).size());
List<FileSystemItemChange> changes = getChanges(principal2);
assertEquals(1, changes.size());
FileSystemItemChange change = changes.get(0);
assertEquals("rootRegistered", change.getEventId());
assertEquals("Folder C", change.getFileSystemItemName());
assertNotNull(change.getFileSystemItem());
} finally {
commitAndWaitForAsyncCompletion();
}
}
Aggregations