use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class TestDefaultTopLevelFolderItemFactory method testFileSystemItemFactory.
@Test
public void testFileSystemItemFactory() {
// #getName()
assertEquals("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory", defaultTopLevelFolderItemFactory.getName());
// #setName(String name)
defaultTopLevelFolderItemFactory.setName("testName");
assertEquals("testName", defaultTopLevelFolderItemFactory.getName());
defaultTopLevelFolderItemFactory.setName("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory");
// #isFileSystemItem(DocumentModel doc)
DocumentModel fakeDoc = DocumentModelFactory.createDocumentModel("File");
assertFalse(defaultTopLevelFolderItemFactory.isFileSystemItem(fakeDoc));
// #getFileSystemItem(DocumentModel doc)
assertNull(defaultTopLevelFolderItemFactory.getFileSystemItem(fakeDoc));
// #canHandleFileSystemItemId(String id)
assertTrue(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#"));
assertFalse(defaultTopLevelFolderItemFactory.canHandleFileSystemItemId("org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory#"));
// #exists(String id, Principal principal)
assertTrue(defaultTopLevelFolderItemFactory.exists("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal()));
try {
defaultTopLevelFolderItemFactory.exists("testId", session.getPrincipal());
fail("Should be unsupported.");
} catch (UnsupportedOperationException e) {
assertEquals("Cannot check if a file system item exists for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
}
// #getFileSystemItemById(String id, Principal principal)
FileSystemItem topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", session.getPrincipal());
assertNotNull(topLevelFolderItem);
assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
assertNull(topLevelFolderItem.getParentId());
assertEquals("Nuxeo Drive", topLevelFolderItem.getName());
try {
defaultTopLevelFolderItemFactory.getFileSystemItemById("testId", session.getPrincipal());
fail("Should be unsupported.");
} catch (UnsupportedOperationException e) {
assertEquals("Cannot get the file system item for an id that cannot be handled from factory org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory.", e.getMessage());
}
// #getFileSystemItemById(String id, String parentId, Principal
// principal)
topLevelFolderItem = defaultTopLevelFolderItemFactory.getFileSystemItemById("org.nuxeo.drive.service.impl.DefaultTopLevelFolderItemFactory#", null, session.getPrincipal());
assertTrue(topLevelFolderItem instanceof DefaultTopLevelFolderItem);
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemAdapterService method testContribOverride.
@Test
public void testContribOverride() throws Exception {
assumeFalse("Cannot test reload for in-memory repository", coreFeature.getStorageConfiguration().isDBSMem());
deployer.deploy("org.nuxeo.drive.core.test:OSGI-INF/test-nuxeodrive-adapter-service-contrib-override.xml");
registerRootAndCreateSomeDocs();
// Re-adapt the sync root to take the override into account
syncRootItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItem(syncRootFolder);
syncRootItemId = syncRootItem.getId();
// ------------------------------------------------------
// Check file system item factory descriptors
// ------------------------------------------------------
Map<String, FileSystemItemFactoryDescriptor> fileSystemItemFactoryDescs = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactoryDescriptors();
assertNotNull(fileSystemItemFactoryDescs);
assertEquals(12, fileSystemItemFactoryDescs.size());
FileSystemItemFactoryDescriptor desc = fileSystemItemFactoryDescs.get("defaultSyncRootFolderItemFactory");
assertNotNull(desc);
assertEquals(10, desc.getOrder());
assertEquals("defaultSyncRootFolderItemFactory", desc.getName());
assertNull(desc.getDocType());
assertEquals("DriveSynchronized", desc.getFacet());
FileSystemItemFactory factory = desc.getFactory();
assertTrue(factory instanceof DefaultSyncRootFolderItemFactory);
desc = fileSystemItemFactoryDescs.get("defaultFileSystemItemFactory");
assertNotNull(desc);
assertEquals(50, desc.getOrder());
assertEquals("defaultFileSystemItemFactory", desc.getName());
assertNull(desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DefaultFileSystemItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyFacetFactory");
assertNotNull(desc);
assertEquals(20, desc.getOrder());
assertEquals("dummyFacetFactory", desc.getName());
assertNull(desc.getDocType());
assertEquals("Folderish", desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DefaultFileSystemItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyDocTypeFactory");
assertNotNull(desc);
assertEquals(30, desc.getOrder());
assertEquals("dummyDocTypeFactory", desc.getName());
assertEquals("File", desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DefaultFileSystemItemFactory);
desc = fileSystemItemFactoryDescs.get("dummyVirtualFolderItemFactory");
assertNotNull(desc);
desc = fileSystemItemFactoryDescs.get("nullMergeTestFactory");
assertNotNull(desc);
assertEquals(200, desc.getOrder());
assertEquals("nullMergeTestFactory", desc.getName());
assertEquals("Note", desc.getDocType());
assertNull(desc.getFacet());
factory = desc.getFactory();
assertTrue(factory instanceof DummyFileItemFactory);
// ------------------------------------------------------
// Check ordered file system item factories
// ------------------------------------------------------
List<FileSystemItemFactoryWrapper> fileSystemItemFactories = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactories();
assertNotNull(fileSystemItemFactories);
assertEquals(6, fileSystemItemFactories.size());
FileSystemItemFactoryWrapper factoryWrapper = fileSystemItemFactories.get(0);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("Collection", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("CollectionSyncRootFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(1);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("DriveSynchronized", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultSyncRootFolderItemFactory"));
factoryWrapper = fileSystemItemFactories.get(2);
assertNotNull(factoryWrapper);
assertNull(factoryWrapper.getDocType());
assertEquals("Folderish", factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
factoryWrapper = fileSystemItemFactories.get(3);
assertNotNull(factoryWrapper);
assertEquals("File", factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DefaultFileSystemItemFactory"));
factoryWrapper = fileSystemItemFactories.get(4);
assertNotNull(factoryWrapper);
factoryWrapper = fileSystemItemFactories.get(5);
assertNotNull(factoryWrapper);
assertEquals("Note", factoryWrapper.getDocType());
assertNull(factoryWrapper.getFacet());
assertTrue(factoryWrapper.getFactory().getClass().getName().endsWith("DummyFileItemFactory"));
// -------------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc)
// -------------------------------------------------------------
// File => should try the dummyDocTypeFactory bound to the
// DefaultFileSystemItemFactory class, returning null because the
// document has no file, then try the dummyVirtualFolderItemFactory
// bound to the DummyVirtualFolderItemFactory, returning null because
// virtual
file.setPropertyValue("file:content", null);
session.saveDocument(file);
FileSystemItem fsItem = fileSystemItemAdapterService.getFileSystemItem(file);
assertNull(fsItem);
// Folder => should use the dummyFacetFactory bound to the
// DefaultFileSystemItemFactory class
fsItem = fileSystemItemAdapterService.getFileSystemItem(folder);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertEquals("dummyFacetFactory#test#" + folder.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Jack's folder", fsItem.getName());
assertTrue(fsItem.isFolder());
assertEquals("Jack", fsItem.getCreator());
assertEquals("Jack", fsItem.getLastContributor());
// Custom => should try the dummyVirtualFolderItemFactory
// bound to the DummyVirtualFolderItemFactory, returning null because
// virtual
fsItem = fileSystemItemAdapterService.getFileSystemItem(custom);
assertNull(fsItem);
// -------------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc, String parentId)
// -------------------------------------------------------------
// Folder => should use the dummyFacetFactory bound to the
// DefaultFileSystemItemFactory class
fsItem = fileSystemItemAdapterService.getFileSystemItem(folder, syncRootItem);
assertNotNull(fsItem);
assertEquals(syncRootItemId, fsItem.getParentId());
// -------------------------------------------------------------
// Check #getFileSystemItemFactoryForId(String id)
// -------------------------------------------------------------
// Disabled default factory
String fsItemId = "defaultFileSystemItemFactory#test#someId";
try {
fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
fail("No fileSystemItemFactory should be found for FileSystemItem id.");
} catch (NuxeoDriveContribException e) {
assertEquals("No fileSystemItemFactory found for FileSystemItem with id defaultFileSystemItemFactory#test#someId. Please check the contributions to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"fileSystemItemFactory\"> and make sure there is at least one defining a FileSystemItemFactory class for which the #canHandleFileSystemItemId(String id) method returns true.", e.getMessage());
}
// Factory with #canHandleFileSystemItemId returning true
fsItemId = "dummyDocTypeFactory#test#someId";
FileSystemItemFactory fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
assertNotNull(fsItemFactory);
assertEquals("dummyDocTypeFactory", fsItemFactory.getName());
assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
// Other test factory with #canHandleFileSystemItemId returning true
fsItemId = "dummyFacetFactory#test#someId";
fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
assertNotNull(fsItemFactory);
assertEquals("dummyFacetFactory", fsItemFactory.getName());
assertTrue(fsItemFactory.getClass().getName().endsWith("DefaultFileSystemItemFactory"));
assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
// Top level folder item factory
fsItemId = "org.nuxeo.drive.service.adapter.DummyTopLevelFolderItemFactory#";
fsItemFactory = fileSystemItemAdapterService.getFileSystemItemFactoryForId(fsItemId);
assertNotNull(fsItemFactory);
assertTrue(fsItemFactory.getName().endsWith("DummyTopLevelFolderItemFactory"));
assertTrue(fsItemFactory.getClass().getName().endsWith("DummyTopLevelFolderItemFactory"));
assertTrue(fsItemFactory.canHandleFileSystemItemId(fsItemId));
// -------------------------------------------------------------
// Check #getTopLevelFolderItemFactory()
// -------------------------------------------------------------
TopLevelFolderItemFactory topLevelFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
assertNotNull(topLevelFactory);
assertTrue(topLevelFactory.getClass().getName().endsWith("DummyTopLevelFolderItemFactory"));
assertTrue(topLevelFactory instanceof DummyTopLevelFolderItemFactory);
// -------------------------------------------------------------
// Check #getActiveFileSystemItemFactories()
// -------------------------------------------------------------
Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
assertEquals(6, activeFactories.size());
assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("defaultSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("dummyDocTypeFactory"));
assertTrue(activeFactories.contains("dummyFacetFactory"));
assertTrue(activeFactories.contains("dummyVirtualFolderItemFactory"));
assertTrue(activeFactories.contains("nullMergeTestFactory"));
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemManagerService method testReadOperations.
@Test
public void testReadOperations() throws Exception {
// ------------------------------------------------------
// Check #getTopLevelFolder
// ------------------------------------------------------
List<FileSystemItem> topLevelChildren = fileSystemItemManagerService.getTopLevelFolder(principal).getChildren();
assertNotNull(topLevelChildren);
assertEquals(2, topLevelChildren.size());
FileSystemItem childFsItem = topLevelChildren.get(0);
assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot1.getId(), childFsItem.getId());
assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("syncRoot1", childFsItem.getName());
childFsItem = topLevelChildren.get(1);
assertTrue(childFsItem instanceof DefaultSyncRootFolderItem);
assertEquals("defaultSyncRootFolderItemFactory#test#" + syncRoot2.getId(), childFsItem.getId());
assertTrue(childFsItem.getParentId().endsWith("DefaultTopLevelFolderItemFactory#"));
assertEquals("syncRoot2", childFsItem.getName());
// ------------------------------------------------------
// Check #exists
// ------------------------------------------------------
// Non existent doc id
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentId", principal));
// File
assertTrue(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal));
// Not adaptable as a FileSystemItem
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal));
// Deleted
custom.followTransition("delete");
assertFalse(fileSystemItemManagerService.exists(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
// ------------------------------------------------------------
// Check #getFileSystemItemById(String id, Principal principal)
// ------------------------------------------------------------
// Folder
FileSystemItem fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getId());
String expectedSyncRoot1Id = DEFAULT_SYNC_ROOT_ITEM_ID_PREFIX + syncRoot1.getId();
assertEquals(expectedSyncRoot1Id, fsItem.getParentId());
assertEquals("Jack's folder", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
List<FileSystemItem> children = ((FolderItem) fsItem).getChildren();
assertNotNull(children);
assertEquals(4, children.size());
// File
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Joe.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
FileItem fileFsItem = (FileItem) fsItem;
assertTrue(fileFsItem.getCanUpdate());
assertEquals("nxfile/test/" + file.getId() + "/blobholder:0/Joe.odt", fileFsItem.getDownloadURL());
assertEquals("MD5", fileFsItem.getDigestAlgorithm());
assertEquals(file.getAdapter(BlobHolder.class).getBlob().getDigest(), fileFsItem.getDigest());
Blob fileItemBlob = fileFsItem.getBlob();
assertEquals("Joe.odt", fileItemBlob.getFilename());
assertEquals("Content of Joe's file.", fileItemBlob.getString());
// FolderishFile
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Sarah's folderish file", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
// Not adaptable as a FileSystemItem
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
assertNull(fsItem);
// Deleted
assertNull(fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal));
// Sub folder
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("Tony's sub folder", fsItem.getName());
assertTrue(fsItem.isFolder());
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
assertTrue(((FolderItem) fsItem).getCanCreateChild());
assertTrue(((FolderItem) fsItem).getChildren().isEmpty());
// -------------------------------------------------------------------
// Check #getFileSystemItemById(String id, String parentId, Principal
// principal)
// -------------------------------------------------------------------
fsItem = fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
// ------------------------------------------------------
// Check #getChildren
// ------------------------------------------------------
// Need to flush VCS cache for the session used in DocumentBackedFolderItem#getChildren() to be aware of changes
// in the current session
session.save();
children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertNotNull(children);
assertEquals(4, children.size());
// Ordered
checkChildren(children, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), true);
children = fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal);
assertTrue(children.isEmpty());
// ------------------------------------------------------
// Check #scrollDescendants
// ------------------------------------------------------
// Need to flush VCS cache for the session used in DocumentBackedFolderItem#scrollDescendants to be aware of
// changes in the current session
session.save();
FolderItem folderItem = (FolderItem) fileSystemItemManagerService.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal);
assertTrue(folderItem.getCanScrollDescendants());
// Scroll through all descendants in one breath
ScrollFileSystemItemList folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal, null, 10, 1000);
assertNotNull(folderDescendants);
assertNotNull(folderDescendants.getScrollId());
assertEquals(4, folderDescendants.size());
// Order is not determined
checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
// Scroll through descendants in several steps
folderDescendants.clear();
ScrollFileSystemItemList descendantsBatch;
int batchSize = 2;
String scrollId = null;
while (!(descendantsBatch = folderItem.scrollDescendants(scrollId, batchSize, 1000)).isEmpty()) {
assertTrue(descendantsBatch.size() > 0);
scrollId = descendantsBatch.getScrollId();
folderDescendants.addAll(descendantsBatch);
}
assertEquals(4, folderDescendants.size());
// Order is not determined
checkChildren(folderDescendants, folder.getId(), file.getId(), note.getId(), folderishFile.getId(), subFolder.getId(), false);
folderDescendants = fileSystemItemManagerService.scrollDescendants(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId(), principal, null, 10, 1000);
assertTrue(folderDescendants.isEmpty());
// ------------------------------------------------------
// Check #canMove
// ------------------------------------------------------
// Not allowed to move a file system item to a non FolderItem
String srcFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId();
String destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId();
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, principal));
// Not allowed to move a file system item if no REMOVE permission on the
// source backing doc
Principal joePrincipal = new NuxeoPrincipalImpl("joe");
DocumentModel rootDoc = session.getRootDocument();
setPermission(rootDoc, "joe", SecurityConstants.READ, true);
nuxeoDriveManager.registerSynchronizationRoot(joePrincipal, syncRoot1, session);
// Under Oracle, the READ ACL optims are not visible from the joe
// session while the transaction has not been committed.
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId();
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// Not allowed to move a file system item if no ADD_CHILDREN permission
// on the destination backing doc
setPermission(folder, "joe", SecurityConstants.WRITE, true);
setPermission(subFolder, "joe", SecurityConstants.READ, true);
setPermission(subFolder, SecurityConstants.ADMINISTRATOR, SecurityConstants.EVERYTHING, true);
setPermission(subFolder, SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false);
assertFalse(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// OK: REMOVE permission on the source backing doc + REMOVE_CHILDREN
// permission on its parent + ADD_CHILDREN permission on the destination
// backing doc
resetPermissions(subFolder, SecurityConstants.EVERYONE);
resetPermissions(subFolder, "joe");
setPermission(subFolder, "joe", SecurityConstants.WRITE, true);
assertTrue(fileSystemItemManagerService.canMove(srcFsItemId, destFsItemId, joePrincipal));
// Reset permissions
resetPermissions(rootDoc, "joe");
resetPermissions(folder, "joe");
resetPermissions(subFolder, "joe");
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveMove method run.
@OperationMethod
public Blob run() throws InvalidOperationException, IOException {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
FileSystemItem fsItem;
try {
fsItem = fileSystemItemManager.move(srcId, destId, ctx.getPrincipal());
} catch (UnsupportedOperationException e) {
throw new InvalidOperationException(e);
}
return Blobs.createJSONBlobFromValue(fsItem);
}
use of org.nuxeo.drive.adapter.FileSystemItem 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()));
}
}
}
Aggregations