use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestDriveVersioning method testAutomaticVersioningAndDriveForceVersionDisabled.
@Test
@Deploy({ "org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-versioning-file-policy-contrib.xml" })
public void testAutomaticVersioningAndDriveForceVersionDisabled() throws Exception {
FileItem fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
// As a user with READ permission
DocumentModel rootDoc = session.getRootDocument();
setPermission(rootDoc, "joe", SecurityConstants.READ, true);
// Under Oracle, the READ ACL optims are not visible from the
// joe session while the transaction has not been committed.
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
file = joeSession.getDocument(file.getRef());
fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
assertFalse(fileItem.getCanUpdate());
// As a user with WRITE permission
setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
assertTrue(fileItem.getCanUpdate());
// Re-fetch file with Administrator session
file = session.getDocument(file.getRef());
fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
// ------------------------------------------------------
// FileItem#getBlob
// ------------------------------------------------------
Blob fileItemBlob = fileItem.getBlob();
assertEquals("Joe.odt", fileItemBlob.getFilename());
assertEquals("Content of Joe's file.", fileItemBlob.getString());
// Check initial version
// A version with a minor increment is automatically created during creation for all File documents
// by the "version-file" policy (automatic versioning),
// see test-nuxeodrive-versioning-file-policy-contrib.xml
assertEquals("0.1", file.getVersionLabel());
// ------------------------------------------------------
// 1. Change without delay
// ------------------------------------------------------
Blob newBlob = new StringBlob("This is a new file.");
newBlob.setFilename("New blob.txt");
ensureJustModified(file, session);
fileItem.setBlob(newBlob);
file = session.getDocument(file.getRef());
Blob updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("New blob.txt", updatedBlob.getFilename());
assertEquals("This is a new file.", updatedBlob.getString());
// Check versioning => should be versioned with a minor increment by the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.2", file.getVersionLabel());
// ------------------------------------------------------
// 2. Change with delay
// ------------------------------------------------------
// Wait for versioning delay
Thread.sleep(VERSIONING_DELAY);
newBlob.setFilename("File name modified.txt");
fileItem.setBlob(newBlob);
file = session.getDocument(file.getRef());
updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File name modified.txt", updatedBlob.getFilename());
// Check versioning => no major increment by the "versioning-delay" policy
// because the document is already checked in,
// but versioned with a minor increment because of the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.3", file.getVersionLabel());
List<DocumentModel> fileVersions = session.getVersions(file.getRef());
assertEquals(3, fileVersions.size());
DocumentModel firstMinorFileVersion = fileVersions.get(0);
Blob versionedBlob = (Blob) firstMinorFileVersion.getPropertyValue("file:content");
assertEquals("Joe.odt", versionedBlob.getFilename());
DocumentModel secondMinorFileVersion = fileVersions.get(1);
versionedBlob = (Blob) secondMinorFileVersion.getPropertyValue("file:content");
assertEquals("New blob.txt", versionedBlob.getFilename());
DocumentModel lastFileVersion = fileVersions.get(2);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified.txt", versionedBlob.getFilename());
// ------------------------------------------------------
// 3. Change with delay
// ------------------------------------------------------
// Wait for versioning delay
Thread.sleep(VERSIONING_DELAY);
newBlob.setFilename("File name modified again.txt");
fileItem.setBlob(newBlob);
file = session.getDocument(file.getRef());
updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File name modified again.txt", updatedBlob.getFilename());
// Check versioning => no major increment by the "versioning-delay" policy
// because the document is already checked in,
// but versioned with a minor increment because of the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.4", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(4, fileVersions.size());
lastFileVersion = fileVersions.get(3);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified again.txt", versionedBlob.getFilename());
// ------------------------------------------------------
// 4. Change without delay
// ------------------------------------------------------
newBlob.setFilename("File name modified again as draft.txt");
ensureJustModified(file, session);
fileItem.setBlob(newBlob);
file = session.getDocument(file.getRef());
updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File name modified again as draft.txt", updatedBlob.getFilename());
// Check versioning => should not be versioned since last modification was done before the versioning delay
// but versioned with a minor increment because of the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.5", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(5, fileVersions.size());
lastFileVersion = fileVersions.get(4);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified again as draft.txt", versionedBlob.getFilename());
// ------------------------------------------------------
// 5. Change without delay with another user
// ------------------------------------------------------
file = joeSession.getDocument(file.getRef());
fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
newBlob.setFilename("File name modified by Joe.txt");
fileItem.setBlob(newBlob);
// Re-fetch file with Administrator session
file = session.getDocument(file.getRef());
updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File name modified by Joe.txt", updatedBlob.getFilename());
// Check versioning => no major increment by the "collaborative-save" policy
// because the document is already checked in,
// but versioned with a minor increment because of the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.6", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(6, fileVersions.size());
lastFileVersion = fileVersions.get(5);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified by Joe.txt", versionedBlob.getFilename());
// ------------------------------------------------------
// 6. Change with delay with the same user
// ------------------------------------------------------
// Wait for versioning delay
Thread.sleep(VERSIONING_DELAY);
file = joeSession.getDocument(file.getRef());
fileItem = (FileItem) defaultFileSystemItemFactory.getFileSystemItem(file);
newBlob.setFilename("File name modified by Joe again.txt");
fileItem.setBlob(newBlob);
// Re-fetch file with Administrator session
file = session.getDocument(file.getRef());
updatedBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File name modified by Joe again.txt", updatedBlob.getFilename());
// Check versioning => no major increment by the "versioning-delay" policy
// because the document is already checked in,
// but versioned with a minor increment because of the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("0.7", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(7, fileVersions.size());
lastFileVersion = fileVersions.get(6);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified by Joe again.txt", versionedBlob.getFilename());
}
resetPermissions(rootDoc, "joe");
}
use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestGetChangeSummary method testGetChangesSummary.
@Test
public void testGetChangesSummary() throws Exception {
// No sync roots => shouldn't find any changes
FileSystemChangeSummary changeSummary = getChangeSummary();
assertTrue(changeSummary.getFileSystemChanges().isEmpty());
assertEquals(Boolean.FALSE, changeSummary.getHasTooManyChanges());
// Register sync roots and create 2 documents and 1 folder => should find 3 changes
DocumentModel doc1;
DocumentModel doc2;
DocumentModel folder3;
try {
Principal administrator = session.getPrincipal();
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder1, session);
nuxeoDriveManager.registerSynchronizationRoot(administrator, folder2, session);
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);
folder3 = session.createDocumentModel("/folder2", "folder3", "Folder");
folder3 = session.createDocument(folder3);
session.save();
} finally {
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
}
changeSummary = getChangeSummary();
List<FileSystemItemChange> docChanges = changeSummary.getFileSystemChanges();
assertEquals(3, docChanges.size());
Set<SimpleFileSystemItemChange> expectedChanges = new HashSet<>();
expectedChanges.add(new SimpleFileSystemItemChange(folder3.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc2.getId(), "documentChanged", "test"));
expectedChanges.add(new SimpleFileSystemItemChange(doc1.getId(), "documentChanged", "test"));
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());
}
Aggregations