use of org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem in project nuxeo-drive-server by nuxeo.
the class UserWorkspaceSyncRootParentFactory method getVirtualFolderItem.
@Override
public FolderItem getVirtualFolderItem(Principal principal) {
FileSystemItemManager fileSystemItemManager = Framework.getService(FileSystemItemManager.class);
FolderItem topLevelFolder = fileSystemItemManager.getTopLevelFolder(principal);
if (topLevelFolder == null) {
throw new NuxeoException("Found no top level folder item. Please check your contribution to the following extension point: <extension target=\"org.nuxeo.drive.service.FileSystemItemAdapterService\" point=\"topLevelFolderItemFactory\">.");
}
return new UserWorkspaceSyncRootParentFolderItem(getName(), principal, topLevelFolder.getId(), topLevelFolder.getPath(), folderName);
}
use of org.nuxeo.drive.hierarchy.userworkspace.adapter.UserWorkspaceSyncRootParentFolderItem in project nuxeo-drive-server by nuxeo.
the class TestUserWorkspaceHierarchy method testClientSideUser1.
/**
* <pre>
* Expected client side for user1
* ==============================
*
* Nuxeo Drive
* |-- My synchronized folders
* | |-- user1Folder3
* | | |-- user1File3
* | |-- user1Folder4
* | | |-- user1File4
* |-- user1File2
* |-- user1Folder1
* | |-- user1File1
* | |-- user1Folder2
* </pre>
*/
@Test
public void testClientSideUser1() throws Exception {
// Temporarily ignore under MySQL waiting for https://jira.nuxeo.com/browse/NXP-15969 to be fixed
if (storageConfiguration.isVCSMySQL()) {
return;
}
// ---------------------------------------------
// Check active factories
// ---------------------------------------------
TopLevelFolderItemFactory topLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
assertEquals("org.nuxeo.drive.hierarchy.userworkspace.factory.UserWorkspaceTopLevelFactory", topLevelFolderItemFactory.getName());
Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
assertEquals(4, activeFactories.size());
assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
assertTrue(activeFactories.contains("userWorkspaceSyncRootParentFactory"));
assertTrue(activeFactories.contains("userWorkspaceSyncRootFactory"));
// ---------------------------------------------
// Check top level folder: "Nuxeo Drive"
// ---------------------------------------------
Blob topLevelFolderJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
assertNotNull(topLevelFolderJSON);
UserWorkspaceTopLevelFolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), UserWorkspaceTopLevelFolderItem.class);
assertNotNull(topLevelFolder);
assertEquals(userWorkspace1ItemId, topLevelFolder.getId());
assertNull(topLevelFolder.getParentId());
assertEquals(userWorkspace1ItemPath, topLevelFolder.getPath());
assertEquals("Nuxeo Drive", topLevelFolder.getName());
assertTrue(topLevelFolder.isFolder());
assertEquals("user1", topLevelFolder.getCreator());
assertEquals("user1", topLevelFolder.getLastContributor());
assertFalse(topLevelFolder.getCanRename());
assertFalse(topLevelFolder.getCanDelete());
assertTrue(topLevelFolder.getCanCreateChild());
// Check descendants
assertFalse(topLevelFolder.getCanScrollDescendants());
try {
clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", topLevelFolder.getId()).set("batchSize", 10).execute();
fail("Scrolling through the descendants of the user workspace top level folder item should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
}
// Get children
Blob topLevelChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", topLevelFolder.getId()).execute();
ArrayNode topLevelChildren = mapper.readValue(topLevelChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(topLevelChildren);
assertEquals(3, topLevelChildren.size());
JsonNode[] topLevelChildrenNodes = sortNodeByName(topLevelChildren);
// ---------------------------------------------
// Check synchronization roots
// ---------------------------------------------
// My synchronized folders
UserWorkspaceSyncRootParentFolderItem syncRootParent = readValue(topLevelChildrenNodes[0], UserWorkspaceSyncRootParentFolderItem.class);
assertEquals(SYNC_ROOT_PARENT_ID, syncRootParent.getId());
assertEquals(userWorkspace1ItemId, syncRootParent.getParentId());
assertEquals("/" + userWorkspace1ItemId + "/" + SYNC_ROOT_PARENT_ID, syncRootParent.getPath());
assertEquals("My synchronized folders", syncRootParent.getName());
assertTrue(syncRootParent.isFolder());
assertEquals("system", syncRootParent.getCreator());
assertEquals("system", syncRootParent.getLastContributor());
assertFalse(syncRootParent.getCanRename());
assertFalse(syncRootParent.getCanDelete());
assertFalse(syncRootParent.getCanCreateChild());
// Check descendants
assertFalse(syncRootParent.getCanScrollDescendants());
try {
clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", syncRootParent.getId()).set("batchSize", 10).execute();
fail("Scrolling through the descendants of a virtual folder item should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
}
// Get children
Blob syncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootParent.getId()).execute();
List<DefaultSyncRootFolderItem> syncRoots = mapper.readValue(syncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
assertNotNull(syncRoots);
assertEquals(2, syncRoots.size());
Collections.sort(syncRoots);
// user1Folder3
DefaultSyncRootFolderItem syncRootItem = syncRoots.get(0);
checkFolderItem(syncRootItem, SYNC_ROOT_ID_PREFIX, user1Folder3, SYNC_ROOT_PARENT_ID, syncRootParentItemPath, "user1Folder3", "user1", "user1");
Blob syncRootItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootItem.getId()).execute();
List<DocumentBackedFileItem> syncRootItemChildren = mapper.readValue(syncRootItemChildrenJSON.getStream(), new TypeReference<List<DocumentBackedFileItem>>() {
});
assertNotNull(syncRootItemChildren);
assertEquals(1, syncRootItemChildren.size());
// user1File3
DocumentBackedFileItem childFileItem = syncRootItemChildren.get(0);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, syncRootItem.getId(), syncRootItem.getPath(), "user1File3.txt", "user1", "user1");
// user1Folder4
syncRootItem = syncRoots.get(1);
checkFolderItem(syncRootItem, SYNC_ROOT_ID_PREFIX, user1Folder4, SYNC_ROOT_PARENT_ID, syncRootParentItemPath, "user1Folder4", "user1", "user1");
syncRootItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootItem.getId()).execute();
syncRootItemChildren = mapper.readValue(syncRootItemChildrenJSON.getStream(), new TypeReference<List<DocumentBackedFileItem>>() {
});
assertNotNull(syncRootItemChildren);
assertEquals(1, syncRootItemChildren.size());
// user1File4
childFileItem = syncRootItemChildren.get(0);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File4, syncRootItem.getId(), syncRootItem.getPath(), "user1File4.txt", "user1", "user1");
// ---------------------------------------------
// Check user workspace children
// ---------------------------------------------
// user1File2
DocumentBackedFileItem fileItem = readValue(topLevelChildrenNodes[1], DocumentBackedFileItem.class);
checkFileItem(fileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File2, userWorkspace1ItemId, userWorkspace1ItemPath, "user1File2.txt", "user1", "user1");
// user1Folder1
DocumentBackedFolderItem folderItem = readValue(topLevelChildrenNodes[2], DocumentBackedFolderItem.class);
checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder1, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder1", "user1", "user1");
Blob folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
ArrayNode folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(folderItemChildren);
assertEquals(2, folderItemChildren.size());
{
JsonNode[] folderItemChildrenNodes = sortNodeByName(folderItemChildren);
// user1File1
childFileItem = readValue(folderItemChildrenNodes[0], DocumentBackedFileItem.class);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File1, folderItem.getId(), folderItem.getPath(), "user1File1.txt", "user1", "user1");
// user1Folder2
DocumentBackedFolderItem childFolderItem = readValue(folderItemChildrenNodes[1], DocumentBackedFolderItem.class);
checkFolderItem(childFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder2, folderItem.getId(), folderItem.getPath(), "user1Folder2", "user1", "user1");
}
// ---------------------------------------------
// Check registering user workspace as a
// synchronization root is ignored
// ---------------------------------------------
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
try {
nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
syncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", syncRootParent.getId()).execute();
syncRoots = mapper.readValue(syncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
assertEquals(2, syncRoots.size());
} finally {
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
}
}
Aggregations