use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testSection.
@Test
public void testSection() {
// Check that a Section is adaptable as a FileSystemItem by the
// defaultSyncRootFolderItemFactory
DocumentModel section = session.createDocument(session.createDocumentModel("/", "sectionSyncRoot", "Section"));
nuxeoDriveManager.registerSynchronizationRoot(principal, section, session);
FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
FolderItem sectionItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(section);
assertNotNull(sectionItem);
assertFalse(sectionItem.getCanCreateChild());
assertFalse(sectionItem.getCanRename());
assertTrue(sectionItem.getCanDelete());
// Publish documents in the Section and check its children
session.publishDocument(file, section);
session.publishDocument(note, section);
session.save();
List<FileSystemItem> children = sectionItem.getChildren();
assertEquals(2, children.size());
FileSystemItem child = children.get(0);
assertFalse(child.getCanRename());
assertFalse(child.getCanDelete());
}
use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl 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.service.impl.FileSystemItemAdapterServiceImpl 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.service.impl.FileSystemItemAdapterServiceImpl in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchyFileSystemChanges method init.
@Before
public void init() throws Exception {
// Enable deletion listener because the tear down disables it
eventServiceAdmin.setListenerEnabledFlag("nuxeoDriveFileSystemDeletionListener", true);
// Create test users
createUser("user1", "user1");
createUser("user2", "user2");
// Open a core session for each user
session1 = coreFeature.openCoreSession("user1");
session2 = coreFeature.openCoreSession("user2");
principal1 = session1.getPrincipal();
principal2 = session2.getPrincipal();
// Create personal workspace for user1
userWorkspace1 = userWorkspaceService.getCurrentUserPersonalWorkspace(session1, null);
userWorkspace1ItemId = USER_SYNC_ROOT_PARENT_ID_PREFIX + userWorkspace1.getId();
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// Wait for personal workspace creation event to be logged in the audit
eventService.waitForAsyncCompletion();
// Make sure to set ordered active factories
FileSystemItemAdapterServiceImpl fileSystemItemAdapterService = (FileSystemItemAdapterServiceImpl) Framework.getService(FileSystemItemAdapterService.class);
fileSystemItemAdapterService.setActiveFactories();
}
use of org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl in project nuxeo-drive-server by nuxeo.
the class TestDriveVersioning method testSyncRootVersioning.
@Test
public void testSyncRootVersioning() throws Exception {
// Expect no versions initially
// Cannot use DocumentModel#getVersionLabel since it relies on the uid schema not held by the Folder type
assertTrue(session.getVersions(syncRootFolder.getRef()).isEmpty());
// Wait for the versioning delay and update the synchronization root
Thread.sleep(VERSIONING_DELAY);
FileSystemItemFactory defaultSyncRootFolderItemFactory = ((FileSystemItemAdapterServiceImpl) fileSystemItemAdapterService).getFileSystemItemFactory("defaultSyncRootFolderItemFactory");
FolderItem syncRootFolderItem = (FolderItem) defaultSyncRootFolderItemFactory.getFileSystemItem(syncRootFolder);
syncRootFolderItem.rename("syncRootRenamed");
syncRootFolder = session.getDocument(syncRootFolder.getRef());
// Expect no versions since the "versioning-delay" policy doesn't apply to folderish documents
assertTrue(session.getVersions(syncRootFolder.getRef()).isEmpty());
}
Aggregations