use of org.nuxeo.drive.adapter.FileItem 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.drive.adapter.FileItem 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.drive.adapter.FileItem 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.drive.adapter.FileItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method checkChildren.
protected void checkChildren(List<FileSystemItem> folderChildren, String folderId, String noteId, String fileId, String subFolderId, String otherFileId, boolean ordered) throws Exception {
boolean isNoteFound = false;
boolean isFileFound = false;
boolean isSubFolderFound = false;
boolean isOtherFileFound = false;
int childrenCount = 0;
for (FileSystemItem fsItem : folderChildren) {
// Check Note
if (!isNoteFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + noteId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 0) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Note child.txt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Note child.txt", fileItemBlob.getFilename());
assertEquals("This is the Note child.", fileItemBlob.getString());
isNoteFound = true;
childrenCount++;
}
} else // Check File
if (!isFileFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + fileId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 1) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("File child.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("File child.odt", fileItemBlob.getFilename());
assertEquals("This is the File child.", fileItemBlob.getString());
isFileFound = true;
childrenCount++;
}
} else // Check sub-Folder
if (!isSubFolderFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolderId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 2) {
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Sub-folder", fsItem.getName());
assertTrue(fsItem.isFolder());
FolderItem folderItem = (FolderItem) fsItem;
List<FileSystemItem> childFolderChildren = folderItem.getChildren();
assertNotNull(childFolderChildren);
assertEquals(0, childFolderChildren.size());
assertTrue(folderItem.getCanScrollDescendants());
ScrollFileSystemItemList childFolderDescendants = folderItem.scrollDescendants(null, 10, 1000);
assertNotNull(childFolderDescendants);
assertNotNull(childFolderDescendants.getScrollId());
assertEquals(0, childFolderDescendants.size());
isSubFolderFound = true;
childrenCount++;
}
} else // Check other File
if (!isOtherFileFound && (DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + otherFileId).equals(fsItem.getId())) {
if (!ordered || ordered && childrenCount == 3) {
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderId, fsItem.getParentId());
assertEquals("Another file.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Another file.odt", fileItemBlob.getFilename());
assertEquals("Content of another file.", fileItemBlob.getString());
isOtherFileFound = true;
childrenCount++;
}
} else {
fail(String.format("FileSystemItem %s doesn't match any expected.", fsItem.getId()));
}
}
}
use of org.nuxeo.drive.adapter.FileItem in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveUpdateFile method run.
@OperationMethod
public Blob run(Blob blob) throws ParseException, IOException {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
NuxeoDriveOperationHelper.normalizeMimeTypeAndEncoding(blob);
FileItem fileItem;
if (parentId == null) {
fileItem = fileSystemItemManager.updateFile(id, blob, ctx.getPrincipal());
} else {
fileItem = fileSystemItemManager.updateFile(id, parentId, blob, ctx.getPrincipal());
}
return Blobs.createJSONBlobFromValue(fileItem);
}
Aggregations