use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testCreateFilesWithSameName.
@Test
public void testCreateFilesWithSameName() {
FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
Blob blob = new StringBlob("This is a blob.");
blob.setFilename("File01.txt");
FileItem fileItem = folderItem.createFile(blob);
FileItem fileItem2 = folderItem.createFile(blob);
assertNotEquals(fileItem.getId(), fileItem2.getId());
}
use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testGetFileSystemItemById.
@Test
public void testGetFileSystemItemById() throws Exception {
// Non existent doc id, must return null
assertNull(defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + "nonExistentDocId", principal));
// File without a blob
file.setPropertyValue("file:content", null);
file = session.saveDocument(file);
session.save();
FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), principal);
assertNull(fsItem);
// Note
fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), principal);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("aNote.txt", fsItem.getName());
assertFalse(fsItem.isFolder());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("aNote.txt", fileItemBlob.getFilename());
assertEquals("Content of Bob's note.", fileItemBlob.getString());
// Folder
fsItem = defaultFileSystemItemFactory.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());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Jack's folder", fsItem.getName());
assertTrue(fsItem.isFolder());
FolderItem folderItem = (FolderItem) fsItem;
assertTrue(folderItem.getChildren().isEmpty());
assertTrue(folderItem.getCanScrollDescendants());
assertTrue(folderItem.scrollDescendants(null, 10, 1000).isEmpty());
// Not adaptable as a FileSystemItem
fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + notAFileSystemItem.getId(), principal);
assertNull(fsItem);
// Deleted
custom.followTransition("delete");
fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), principal);
assertNull(fsItem);
// Use parent id
fsItem = defaultFileSystemItemFactory.getFileSystemItemById(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), syncRootItemId, principal);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + note.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
}
use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testCreateFoldersWithSameName.
@Test
public void testCreateFoldersWithSameName() {
FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
FolderItem subFolderItem = folderItem.createFolder("subfolder01");
FolderItem subFolderItem2 = folderItem.createFolder("subfolder01");
assertNotEquals(subFolderItem.getId(), subFolderItem2.getId());
}
use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testFolderItemChildrenPageProviderOverride.
@Test
public void testFolderItemChildrenPageProviderOverride() throws Exception {
assumeFalse("Cannot test reload for in-memory repository", coreFeature.getStorageConfiguration().isDBSMem());
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), syncRootFolder, session);
FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
assertEquals(5, syncRootFolderItem.getChildren().size());
// should save documents before runtime reset
TransactionHelper.commitOrRollbackTransaction();
try {
deployer.deploy("org.nuxeo.drive.core.test:OSGI-INF/test-nuxeodrive-pageproviders-contrib-override.xml");
} finally {
TransactionHelper.startTransaction();
}
assertEquals(2, syncRootFolderItem.getChildren().size());
}
use of org.nuxeo.drive.adapter.FolderItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testPermissionCheckOptimized.
@Test
@Deploy("org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-permissions-contrib.xml")
public void testPermissionCheckOptimized() {
setPermission(syncRootFolder, "joe", SecurityConstants.READ, true);
try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
log.trace("Register the sync root for Joe's account");
nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, joeSession);
folder = joeSession.getDocument(folder.getRef());
log.trace("Check canDelete/canCreateChild flags on folder for user joe with Read granted on parent folder");
FolderItem folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
assertFalse(folderItem.getCanDelete());
assertFalse(folderItem.getCanCreateChild());
log.trace("Check canDelete/canCreateChild flags on folder for user joe with Write granted on folder, AddChildren not granted on folder and RemoveChildren not granted on parent folder");
setPermission(folder, "joe", SecurityConstants.WRITE, true);
folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
// True here as optimized => no explicit check of AddChildren on
// folder nor RemoveChildren on parent folder
assertTrue(folderItem.getCanDelete());
assertTrue(folderItem.getCanCreateChild());
log.trace("Check canDelete flag on folder for user joe with Write (thus RemoveChildren) granted on parent folder");
setPermission(syncRootFolder, "joe", SecurityConstants.WRITE, true);
folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
// Still true with RemoveChildren on the parent folder
assertTrue(folderItem.getCanDelete());
log.trace("Check canCreateChild flag on folder for user joe with AddChildren granted on folder");
setPermission(folder, "joe", SecurityConstants.ADD_CHILDREN, true);
folderItem = (FolderItem) defaultFileSystemItemFactory.getFileSystemItem(folder);
// Still true with AddChildren on the folder
assertTrue(folderItem.getCanCreateChild());
}
resetPermissions(folder, "joe");
resetPermissions(syncRootFolder, "joe");
}
Aggregations