use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testFolderishCollection4.
/**
* <pre>
* /collectionSyncRoot1 -> synchronization root
* /folder1 -> isMemberOf(collectionSyncRoot1)
* |-- collectionFolder
* /collectionSyncRoot2 -> synchronization root
* /testDoc -> isMemberOf(collectionFolder, collectionSyncRoot2)
* </pre>
*/
@Test
public void testFolderishCollection4() throws Exception {
DocumentModel collectionSyncRoot1;
DocumentModel collectionSyncRoot2;
DocumentModel testDoc;
List<FileSystemItemChange> changes;
try {
log.trace("testFolderishCollection4():" + "\nCreate a collection \"collectionSyncRoot1\" and register it as a synchronization root;" + "\nAdd \"folder1\" to the \"collectionSyncRoot1\" collection;" + "\nCreate a folder with the Collection facet (\"collectionFolder\") inside (\"folder1\");" + "\nCreate a collection \"collectionSyncRoot\" and register it as a synchronization root;" + "\nCreate a document \"testDoc\" and add it to both collections \"collectionFolder\" and \"collectionSyncRoot\".\n");
collectionSyncRoot1 = collectionManager.createCollection(session, "collectionSyncRoot1", null, "/");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot1, session);
collectionManager.addToCollection(collectionSyncRoot1, folder1, session);
DocumentModel collectionFolder = session.createDocumentModel("/folder1", "collectionFolder", "FolderishCollection");
collectionFolder = session.createDocument(collectionFolder);
collectionSyncRoot2 = collectionManager.createCollection(session, "collectionSyncRoot2", null, "/");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), collectionSyncRoot2, session);
testDoc = session.createDocumentModel("/", "testDoc", "File");
testDoc.setPropertyValue("file:content", new StringBlob("The content of testDoc."));
testDoc = session.createDocument(testDoc);
collectionManager.addToCollection(collectionFolder, testDoc, session);
collectionManager.addToCollection(collectionSyncRoot2, testDoc, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Expecting 11 (among which 10 distinct) changes:
// - addedToCollection for testDoc
// - documentModified for collectionSyncRoot2
// - addedToCollection for testDoc
// - documentCreated for testDoc
// - rootRegistered for collectionSyncRoot2
// - documentCreated for collectionSyncRoot2
// - addedToCollection for folder1
// - documentModified for collectionSyncRoot1
// - rootRegistered for collectionSyncRoot1
// - documentCreated for collectionSyncRoot1
// - documentCreated for folder1
changes = getChanges(session.getPrincipal());
assertEquals(11, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(testDoc.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot2.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "addedToCollection"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentModified"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(collectionSyncRoot1.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testMoveToOtherUsersSyncRoot.
@Test
public void testMoveToOtherUsersSyncRoot() throws Exception {
DocumentModel subFolder;
List<FileSystemItemChange> changes;
try {
// Create a subfolder in folder1 as Administrator
subFolder = session.createDocument(session.createDocumentModel(folder1.getPathAsString(), "subFolder", "Folder"));
// Register folder1 as a sync root for user1
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder1, user1Session);
// Register folder2 as a sync root for Administrator
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder2, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes for user1, expecting 3:
// - rootRegistered for folder1
// - documentCreated for subFolder1
// - documentCreated for folder1 at init
changes = getChanges(user1Session.getPrincipal());
assertEquals(3, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "rootRegistered"));
expectedChanges.add(new SimpleFileSystemItemChange(subFolder.getId(), "documentCreated"));
expectedChanges.add(new SimpleFileSystemItemChange(folder1.getId(), "documentCreated"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// As Administrator, move subfolder from folder1 (sync root for
// user1) to folder2 (sync root for Administrator but not for
// user1)
session.move(subFolder.getRef(), folder2.getRef(), null);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes for user1, expecting 1: deleted for subFolder
changes = getChanges(user1Session.getPrincipal());
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(subFolder.getId(), "deleted"), toSimpleFileSystemItemChange(changes.get(0)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange 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.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testLockUnlock.
@Test
public void testLockUnlock() throws Exception {
DocumentModel doc;
List<FileSystemItemChange> changes;
try {
log.trace("Register a sync root and create a document inside it");
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder1, session);
doc = session.createDocumentModel("/folder1", "doc", "File");
doc.setPropertyValue("file:content", new StringBlob("The file content"));
doc = session.createDocument(doc);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 3:
// - documentCreated for doc
// - rootRegistered for folder1
// - documentCreated for folder1
changes = getChanges(session.getPrincipal());
assertEquals(3, changes.size());
log.trace("Lock doc");
session.setLock(doc.getRef());
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 1:
// - documentLocked for doc
changes = getChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentLocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
log.trace("Unlock doc");
session.removeLock(doc.getRef());
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 1:
// - documentUnlocked for doc
changes = getChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(doc.getId(), "documentUnlocked", "test", "defaultFileSystemItemFactory#test#" + doc.getId(), "doc"), toSimpleFileSystemItemChange(changes.get(0)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
use of org.nuxeo.drive.service.FileSystemItemChange in project nuxeo-drive-server by nuxeo.
the class AuditChangeFinderTestSuite method testSection.
@Test
public void testSection() throws Exception {
DocumentModel section;
DocumentModel doc1;
DocumentModel proxy1;
DocumentModel proxy2;
List<FileSystemItemChange> changes;
try {
// Create a Section and register it as a synchronization root
section = session.createDocument(session.createDocumentModel("/", "sectionSyncRoot", "Section"));
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), section, session);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 2:
// - rootRegistered for section
// - documentCreated for section
changes = getChanges(session.getPrincipal());
assertEquals(2, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(section.getId(), "rootRegistered", "test", "defaultSyncRootFolderItemFactory#test#" + section.getId(), "sectionSyncRoot"));
expectedChanges.add(new SimpleFileSystemItemChange(section.getId(), "documentCreated", "test", "defaultSyncRootFolderItemFactory#test#" + section.getId(), "sectionSyncRoot"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Publish 2 documents in the section
doc1 = session.createDocumentModel("/folder1", "doc1", "File");
doc1.setPropertyValue("file:content", new StringBlob("The content of file 1."));
doc1 = session.createDocument(doc1);
proxy1 = session.publishDocument(doc1, section);
DocumentModel doc2 = session.createDocumentModel("/folder1", "doc2", "File");
doc2.setPropertyValue("file:content", new StringBlob("The content of file 2."));
doc2 = session.createDocument(doc2);
proxy2 = session.publishDocument(doc2, section);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 4:
// - documentProxyPublished for proxy2
// - documentCreated for proxy2
// - documentProxyPublished for proxy1
// - documentCreated for proxy1
changes = getChanges();
assertEquals(4, changes.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(proxy2.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy2.getId(), "doc2"));
expectedChanges.add(new SimpleFileSystemItemChange(proxy2.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + proxy2.getId(), "doc2"));
expectedChanges.add(new SimpleFileSystemItemChange(proxy1.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"));
expectedChanges.add(new SimpleFileSystemItemChange(proxy1.getId(), "documentCreated", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"));
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, toSimpleFileSystemItemChanges(changes)));
// Update an existing proxy
doc1.setPropertyValue("file:content", new StringBlob("The updated content of file 1."));
session.saveDocument(doc1);
session.publishDocument(doc1, section);
} finally {
commitAndWaitForAsyncCompletion();
}
try {
// Check changes, expecting 1:
// - documentProxyPublished for proxy1
changes = getChanges();
assertEquals(1, changes.size());
assertEquals(new SimpleFileSystemItemChange(proxy1.getId(), "documentProxyPublished", "test", "defaultFileSystemItemFactory#test#" + proxy1.getId(), "doc1"), toSimpleFileSystemItemChange(changes.get(0)));
} finally {
commitAndWaitForAsyncCompletion();
}
}
Aggregations