use of org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testGetChangeSummaryOnRootDocuments.
@Test
public void testGetChangeSummaryOnRootDocuments() throws Exception {
Principal admin = new NuxeoPrincipalImpl("Administrator");
Principal otherUser = new NuxeoPrincipalImpl("some-other-user");
Set<IdRef> activeRootRefs;
FileSystemChangeSummary changeSummary;
List<FileSystemItemChange> changes;
try {
// No root registered by default: no changes
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
changeSummary = getChangeSummary(admin);
assertNotNull(changeSummary);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Register a root for someone else
nuxeoDriveManager.registerSynchronizationRoot(otherUser, folder1, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Administrator does not see any change
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
changeSummary = getChangeSummary(admin);
assertNotNull(changeSummary);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertFalse(changeSummary.getHasTooManyChanges());
// Register a new sync root
nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertEquals(1, activeRootRefs.size());
assertEquals(folder1.getRef(), activeRootRefs.iterator().next());
// The new sync root is detected in the change summary
changeSummary = getChangeSummary(admin);
assertNotNull(changeSummary);
changes = changeSummary.getFileSystemChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
// Check that root unregistration is detected as a deletion
nuxeoDriveManager.unregisterSynchronizationRoot(admin, folder1, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
changeSummary = getChangeSummary(admin);
changes = changeSummary.getFileSystemChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "deleted", "test", "test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
// Register back the root, it's activity is again detected by the
// client
nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertEquals(activeRootRefs.size(), 1);
changeSummary = getChangeSummary(admin);
changes = changeSummary.getFileSystemChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
// Test deletion of a root
session.followTransition(folder1.getRef(), "delete");
} finally {
commitAndWaitForAsyncCompletion();
}
try {
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
// The root is no longer active
activeRootRefs = nuxeoDriveManager.getSynchronizationRootReferences(session);
assertNotNull(activeRootRefs);
assertTrue(activeRootRefs.isEmpty());
// The deletion of the root itself is mapped as filesystem
// deletion event
changeSummary = getChangeSummary(admin);
changes = changeSummary.getFileSystemChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(folder1.getId(), "deleted", "test", "test#" + folder1.getId()), toSimpleFileSystemItemChange(changes.get(0)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testGetChangeSummary.
@Test
public void testGetChangeSummary() throws Exception {
FileSystemChangeSummary changeSummary;
Principal admin = new NuxeoPrincipalImpl("Administrator");
DocumentModel doc1;
DocumentModel doc2;
try {
// No sync roots => shouldn't find any changes
changeSummary = getChangeSummary(admin);
assertNotNull(changeSummary);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Register sync roots => should find changes: the newly
// synchronized root folders as they are updated by the
// synchronization
// registration process
nuxeoDriveManager.registerSynchronizationRoot(admin, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(admin, folder2, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changeSummary = getChangeSummary(admin);
assertEquals(2, changeSummary.getFileSystemChanges().size());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
} finally {
commitAndWaitForAsyncCompletion();
}
// Create 3 documents, only 2 in sync roots => should find 2 changes
try {
doc1 = session.createDocumentModel("/folder1", "doc1", "File");
doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
doc1 = session.createDocument(doc1);
doc2 = session.createDocumentModel("/folder2", "doc2", "File");
doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
doc2 = session.createDocument(doc2);
session.createDocument(session.createDocumentModel("/folder3", "doc3", "File"));
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changeSummary = getChangeSummary(admin);
List<FileSystemItemChange> changes = changeSummary.getFileSystemChanges();
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
SimpleFileSystemItemChange simpleChange = new SimpleFileSystemItemChange(doc2.getId(), "documentCreated", "test");
simpleChange.setLifeCycleState("project");
expectedChanges.add(simpleChange);
simpleChange = new SimpleFileSystemItemChange(doc1.getId(), "documentCreated", "test");
simpleChange.setLifeCycleState("project");
expectedChanges.add(simpleChange);
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Create a document that should not be synchronized because not
// adaptable as a FileSystemItem (not Folderish nor a BlobHolder
// with a
// blob) => should not be considered as a change
session.createDocument(session.createDocumentModel("/folder1", "notSynchronizableDoc", "NotSynchronizable"));
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changeSummary = getChangeSummary(admin);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Create 2 documents in the same sync root: "/folder1" and 1 document in another sync root => should find 2
// changes for "/folder1"
DocumentModel doc3 = session.createDocumentModel("/folder1", "doc3", "File");
doc3.setPropertyValue("file:content", new StringBlob("The content of file 3."));
doc3 = session.createDocument(doc3);
DocumentModel doc4 = session.createDocumentModel("/folder1", "doc4", "File");
doc4.setPropertyValue("file:content", new StringBlob("The content of file 4."));
doc4 = session.createDocument(doc4);
DocumentModel doc5 = session.createDocumentModel("/folder2", "doc5", "File");
doc5.setPropertyValue("file:content", new StringBlob("The content of file 5."));
doc5 = session.createDocument(doc5);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
changeSummary = getChangeSummary(admin);
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
assertEquals(3, changeSummary.getFileSystemChanges().size());
// No changes since last successful sync
changeSummary = getChangeSummary(admin);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Test too many changes
session.followTransition(doc1.getRef(), "delete");
session.followTransition(doc2.getRef(), "delete");
} finally {
commitAndWaitForAsyncCompletion();
}
Framework.getProperties().put("org.nuxeo.drive.document.change.limit", "1");
changeSummary = getChangeSummary(admin);
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.TRUE, changeSummary.getHasTooManyChanges());
}
use of org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemManagerService method testReadOperations.
@Test
public void testReadOperations() throws Exception {
// ------------------------------------------------------
// Check #getTopLevelFolder
// ------------------------------------------------------
List<FileSystemItem> topLevelChildren = fileSystemItemManagerService.getTopLevelFolder(principal).getChildren();
assertNotNull(topLevelChildren);
assertEquals(2, topLevelChildren.size());
FileSystemItem childFsItem = topLevelChildren.get(0);
assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot1.getId(), childFsItem.getId());
assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("syncRoot1", childFsItem.getName());
childFsItem = topLevelChildren.get(1);
assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot2.getId(), childFsItem.getId());
assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("syncRoot2", childFsItem.getName());
// ------------------------------------------------------
// Check #exists
// ------------------------------------------------------
// Non existent doc id
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentId", principal));
// File
assertTrue(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal));
// Not adaptable as a FileSystemItem
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal));
// Deleted
custom.followTransition("delete");
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
// ------------------------------------------------------------
// Check #getFileSystemItemById(String id, Principal principal)
// ------------------------------------------------------------
// Folder
FileSystemItem fsItem = fileSystemItemManagerService.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());
String expectedSyncRoot1Id = DEFAULT_SYNC_ROOT_ITEM_ID_PREFIX + syncRoot1.getId();
assertEquals(expectedSyncRoot1Id, fsItem.getParentId());
assertEquals("Jack's folder", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
List<FileSystemItem> children = ((FolderItem) fsItem).getChildren();
assertNotNull(children);
assertEquals(4, children.size());
// File
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Joe.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
FileItem fileFsItem = (FileItem) fsItem;
assertTrue(fileFsItem.getCanUpdate());
assertEquals("nxfile/test/" + file.getId() + "/blobholder:0/Joe.odt", fileFsItem.getDownloadURL());
assertEquals("MD5", fileFsItem.getDigestAlgorithm());
assertEquals(file.getAdapter(BlobHolder.class).getBlob().getDigest(), fileFsItem.getDigest());
Blob fileItemBlob = fileFsItem.getBlob();
assertEquals("Joe.odt", fileItemBlob.getFilename());
assertEquals("Content of Joe's file.", fileItemBlob.getString());
// FolderishFile
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Sarah's folderish file", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
// Not adaptable as a FileSystemItem
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
assertNull(fsItem);
// Deleted
assertNull(fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
// Sub folder
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Tony's sub folder", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
// -------------------------------------------------------------------
// Check #getFileSystemItemById(String id, String parentId, Principal
// principal)
// -------------------------------------------------------------------
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
// ------------------------------------------------------
// Check #getChildren
// ------------------------------------------------------
// Need to flush VCS cache for the session used in DocumentBackedFolderItem#getChildren() to be aware of changes
// in the current session
session.save();
children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertNotNull(children);
assertEquals(4, children.size());
// Ordered
checkChildren(children, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), true);
children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
assertTrue(children.isEmpty());
// ------------------------------------------------------
// Check #scrollDescendants
// ------------------------------------------------------
// Need to flush VCS cache for the session used in DocumentBackedFolderItem#scrollDescendants to be aware of
// changes in the current session
session.save();
FolderItem folderItem = (FolderItem) fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertTrue(folderItem.getCanScrollDescendants());
// Scroll through all descendants in one breath
ScrollFileSystemItemList folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal, null, 10, 1000);
assertNotNull(folderDescendants);
assertNotNull(folderDescendants.getScrollId());
assertEquals(4, folderDescendants.size());
// Order is not determined
checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
// Scroll through descendants in several steps
folderDescendants.clear();
ScrollFileSystemItemList descendantsBatch;
int batchSize = 2;
String scrollId = null;
while (!(descendantsBatch = folderItem.scrollDescendants(scrollId, batchSize, 1000)).isEmpty()) {
assertTrue(descendantsBatch.size() > 0);
scrollId = descendantsBatch.getScrollId();
folderDescendants.addAll(descendantsBatch);
}
assertEquals(4, folderDescendants.size());
// Order is not determined
checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal, null, 10, 1000);
assertTrue(folderDescendants.isEmpty());
// ------------------------------------------------------
// Check #canMove
// ------------------------------------------------------
// Not allowed to move a file system item to a non FolderItem
String srcFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId();
String destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId();
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, principal));
// Not allowed to move a file system item if no REMOVE permission on the
// source backing doc
Principal joePrincipal = new NuxeoPrincipalImpl("joe");
DocumentModel rootDoc = session.getRootDocument();
setPermission(rootDoc, "joe", SecurityConstants.READ, true);
nuxeoDriveManager.registerSynchronizationRoot(joePrincipal, syncRoot1, session);
// Under Oracle, the READ ACL optims are not visible from the joe
// session while the transaction has not been committed.
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId();
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// Not allowed to move a file system item if no ADD_CHILDREN permission
// on the destination backing doc
setPermission(folder, "joe", SecurityConstants.WRITE, true);
setPermission(subFolder, "joe", SecurityConstants.READ, true);
setPermission(subFolder, SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING, true);
setPermission(subFolder, SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false);
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// OK: REMOVE permission on the source backing doc + REMOVE_CHILDREN
// permission on its parent + ADD_CHILDREN permission on the destination
// backing doc
resetPermissions(subFolder, SecurityConstants.EVERYONE);
resetPermissions(subFolder, "joe");
setPermission(subFolder, "joe", SecurityConstants.WRITE, true);
assertTrue(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// Reset permissions
resetPermissions(rootDoc, "joe");
resetPermissions(folder, "joe");
resetPermissions(subFolder, "joe");
}
Aggregations