use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestGetChangeSummaryMultiRepo method testGetDocumentChangesSummary.
@Test
public void testGetDocumentChangesSummary() throws Exception {
// Register 3 sync roots and create 3 documents: 2 in the 'test'
// repository, 1 in the 'other' repository
DocumentModel doc1;
DocumentModel doc2;
DocumentModel doc3;
Principal administrator = session.getPrincipal();
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder3, otherSession);
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);
doc3 = otherSession.createDocumentModel("/folder3", "doc3", "File");
doc3.setPropertyValue("file:content", new StringBlob("The content of file 3."));
doc3 = otherSession.createDocument(doc3);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// Look in all repositories => should find 3 changes
FileSystemChangeSummary changeSummary = getChangeSummary();
List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc3.getId(), "documentChanged", "other"));
Set<SimpleFileSystemItemChange> changes = new HashSet<>();
docChanges.forEach(docChange -> {
changes.add(new SimpleFileSystemItemChange(docChange.getDocUuid(), docChange.getEventId(), docChange.getRepositoryId()));
assertNotNull(docChange.getFileSystemItem());
});
assertTrue(CollectionUtils.isEqualCollection(expectedChanges, changes));
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Update documents
doc1.setPropertyValue("dc:description", "Added description to doc1.");
doc2.setPropertyValue("dc:description", "Added description to doc1.");
doc3.setPropertyValue("dc:description", "Added description to doc1.");
session.saveDocument(doc1);
session.saveDocument(doc2);
otherSession.saveDocument(doc3);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
changeSummary = getChangeSummary();
docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
}
use of org.nuxeo.ecm.core.api.DocumentModel 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.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveActions method unsynchronizeCurrentDocument.
public void unsynchronizeCurrentDocument() {
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
Principal principal = documentManager.getPrincipal();
DocumentModel syncRoot = navigationContext.getCurrentDocument();
driveManager.unregisterSynchronizationRoot(principal, syncRoot, documentManager);
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveSetupIntegrationTests method createTestWorkspace.
protected void createTestWorkspace(String[] testUserNames) {
// Create test workspace
String testWorkspaceParentPath = NuxeoDriveIntegrationTestsHelper.getDefaultDomainPath(session) + "/" + NuxeoDriveIntegrationTestsHelper.TEST_WORKSPACE_PARENT_NAME;
DocumentModel testWorkspace = session.createDocumentModel(testWorkspaceParentPath, TEST_WORKSPACE_NAME, "Workspace");
testWorkspace.setPropertyValue("dc:title", TEST_WORKSPACE_TITLE);
session.createDocument(testWorkspace);
// Grant the given permission to the test users on the test workspace
String testWorkspacePath = testWorkspaceParentPath + "/" + TEST_WORKSPACE_NAME;
DocumentRef testWorkspaceDocRef = new PathRef(testWorkspacePath);
ACP acp = session.getACP(testWorkspaceDocRef);
ACL localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
for (String testUserName : testUserNames) {
localACL.add(new ACE(testUserName, permission, true));
}
session.setACP(testWorkspaceDocRef, acp, false);
}
use of org.nuxeo.ecm.core.api.DocumentModel in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method createFile.
protected DocumentModel createFile(CoreSession session, String path, String name, String type, String fileName, String content) {
DocumentModel file = session.createDocumentModel(path, name, type);
Blob blob = new StringBlob(content);
blob.setFilename(fileName);
file.setPropertyValue("file:content", (Serializable) blob);
return session.createDocument(file);
}
Aggregations