use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemAdapterService method registerRootAndCreateSomeDocs.
protected void registerRootAndCreateSomeDocs() throws Exception {
syncRootFolder = session.createDocumentModel("/", "syncRoot", "Folder");
syncRootFolder = session.createDocument(syncRootFolder);
// Register the root folder as sync root
NuxeoDriveManager driveManager = Framework.getService(NuxeoDriveManager.class);
driveManager.registerSynchronizationRoot(session.getPrincipal(), syncRootFolder, session);
syncRootItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItem(syncRootFolder);
syncRootItemId = syncRootItem.getId();
file = session.createDocumentModel(syncRootFolder.getPathAsString(), "aFile", "File");
file.setPropertyValue("dc:creator", "Joe");
file.setPropertyValue("dc:lastContributor", "Joe");
Blob blob = new StringBlob("Content of Joe's file.");
blob.setFilename("Joe's file.txt");
file.setPropertyValue("file:content", (Serializable) blob);
file.putContextData(DocumentValidationService.CTX_MAP_KEY, Forcing.TURN_OFF);
file.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true);
file = session.createDocument(file);
folder = session.createDocumentModel(syncRootFolder.getPathAsString(), "aFolder", "Folder");
folder.setPropertyValue("dc:title", "Jack's folder");
folder.setPropertyValue("dc:creator", "Jack");
folder.setPropertyValue("dc:lastContributor", "Jack");
folder.putContextData(DocumentValidationService.CTX_MAP_KEY, Forcing.TURN_OFF);
folder.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true);
folder = session.createDocument(folder);
custom = session.createDocumentModel(syncRootFolder.getPathAsString(), "aCustom", "Custom");
custom.setPropertyValue("dc:creator", "Bonnie");
custom.setPropertyValue("dc:lastContributor", "Bonnie");
blob = new StringBlob("Content of the custom document's blob.");
blob.setFilename("Bonnie's file.txt");
custom.setPropertyValue("file:content", (Serializable) blob);
custom.putContextData(DocumentValidationService.CTX_MAP_KEY, Forcing.TURN_OFF);
custom.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true);
custom = session.createDocument(custom);
session.save();
}
use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveCreateTestDocuments method run.
@OperationMethod
public Blob run(DocumentModel parent) throws Exception {
NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
FileManager fileManager = Framework.getService(FileManager.class);
for (int i = 0; i < number; i++) {
String name = String.format(namePattern, i);
Blob content = new StringBlob(String.format(contentPattern, i));
content.setFilename(name);
fileManager.createDocumentFromBlob(session, content, parent.getPathAsString(), false, name);
if (delay > 0) {
Thread.sleep(delay);
}
}
return new StringBlob(number.toString(), "text/plain");
}
use of org.nuxeo.ecm.core.api.impl.blob.StringBlob in project nuxeo-drive-server by nuxeo.
the class TestDriveVersioning method testAutomaticVersioning.
@Test
@Deploy({ "org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml" })
public void testAutomaticVersioning() 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-not-drive-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 not be versioned since same contributor,
// last modification was done before the versioning delay
// and the "drive-force-versioning" policy prevents automatic versioning
// from performing a minor increment,
// see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
// Should be checked out since not previously checked out
assertEquals("0.1+", 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 => should be versioned with a major increment by the "versioning-delay" policy
// since last modification was done after the versioning delay
// and a minor increment by the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("1.1", 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 lastMajorFileVersion = fileVersions.get(1);
versionedBlob = (Blob) lastMajorFileVersion.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("1.2", 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 new 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 new draft.txt", updatedBlob.getFilename());
// Check versioning => should not be versioned since same contributor,
// last modification was done before the versioning delay
// and the "drive-force-versioning" policy prevents automatic versioning
// from performing a minor increment,
// see test-nuxeodrive-versioning-file-policy-not-drive-contrib.xml
// Should be checked out since not previously checked out
assertEquals("1.2+", 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());
// ------------------------------------------------------
// 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 => should be versioned with a major increment by the "collaborative-save" policy
// since updated by a different contributor
// and a minor increment by the "version-file" policy
// Should not be checked out since the "version-file" policy is not applied before update
assertEquals("2.1", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(6, fileVersions.size());
lastMajorFileVersion = fileVersions.get(4);
versionedBlob = (Blob) lastMajorFileVersion.getPropertyValue("file:content");
assertEquals("File name modified again as new draft.txt", versionedBlob.getFilename());
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("2.2", 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 TestDriveVersioning method testDefaultConfiguration.
@Test
public void testDefaultConfiguration() 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
assertEquals("0.0", 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 not be versioned since same contributor
// and last modification was done before the versioning delay
// Should not be checked out since previously checked out
assertEquals("0.0", 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 => should be versioned with a major increment by the "versioning-delay" policy
// since last modification was done after the versioning delay
// Should be checked out since the "versioning-delay" policy is applied before update
assertEquals("1.0+", file.getVersionLabel());
List<DocumentModel> fileVersions = session.getVersions(file.getRef());
assertEquals(1, fileVersions.size());
DocumentModel lastFileVersion = fileVersions.get(0);
Blob versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("New blob.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 => should be versioned with a major increment by the "versioning-delay" policy
// since last modification was done after the versioning delay
// Should be checked out since the "versioning-delay" policy is applied before update
assertEquals("2.0+", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(2, fileVersions.size());
lastFileVersion = fileVersions.get(1);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified.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 same contributor
// and last modification was done before the versioning delay
// Should not be checked out since previously checked out
assertEquals("2.0+", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(2, fileVersions.size());
lastFileVersion = fileVersions.get(1);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified.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 => should be versioned with a major increment by the "collaborative-save" policy
// since updated by a different contributor
// Should be checked out since the "collaborative-save" policy is applied before update
assertEquals("3.0+", file.getVersionLabel());
fileVersions = session.getVersions(file.getRef());
assertEquals(3, fileVersions.size());
lastFileVersion = fileVersions.get(2);
versionedBlob = (Blob) lastFileVersion.getPropertyValue("file:content");
assertEquals("File name modified again as draft.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 => should be versioned with a major increment by the "versioning-delay" policy
// since last modification was done after the versioning delay
// Should be checked out since the "versioning-delay" policy is applied before update
assertEquals("4.0+", 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 by Joe.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 TestDriveVersioning method createTestDocs.
@Before
public void createTestDocs() throws Exception {
principal = session.getPrincipal();
syncRootFolder = session.createDocumentModel("/", "syncRoot", "Folder");
syncRootFolder = session.createDocument(syncRootFolder);
nuxeoDriveManager.registerSynchronizationRoot(principal, syncRootFolder, session);
// File
file = session.createDocumentModel(syncRootFolder.getPathAsString(), "aFile", "File");
Blob blob = new StringBlob("Content of Joe's file.");
blob.setFilename("Joe.odt");
file.setPropertyValue("file:content", (Serializable) blob);
file = session.createDocument(file);
session.save();
// Get default file system item factory
defaultFileSystemItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultFileSystemItemFactory");
}
Aggregations