use of org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem in project nuxeo-drive-server by nuxeo.
the class TestPermissionHierarchy method testClientSideUser1.
@Test
public void testClientSideUser1() throws Exception {
// ---------------------------------------------
// Check active factories
// ---------------------------------------------
TopLevelFolderItemFactory topLevelFolderItemFactory = fileSystemItemAdapterService.getTopLevelFolderItemFactory();
assertEquals("org.nuxeo.drive.hierarchy.permission.factory.PermissionTopLevelFactory", topLevelFolderItemFactory.getName());
Set<String> activeFactories = fileSystemItemAdapterService.getActiveFileSystemItemFactories();
assertEquals(5, activeFactories.size());
assertTrue(activeFactories.contains("collectionSyncRootFolderItemFactory"));
assertTrue(activeFactories.contains("defaultFileSystemItemFactory"));
assertTrue(activeFactories.contains("userSyncRootParentFactory"));
assertTrue(activeFactories.contains("permissionSyncRootFactory"));
assertTrue(activeFactories.contains("sharedSyncRootParentFactory"));
// ---------------------------------------------
// Check top level folder: "Nuxeo Drive"
// ---------------------------------------------
Blob topLevelFolderJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetTopLevelFolder.ID).execute();
assertNotNull(topLevelFolderJSON);
PermissionTopLevelFolderItem topLevelFolder = mapper.readValue(topLevelFolderJSON.getStream(), PermissionTopLevelFolderItem.class);
assertNotNull(topLevelFolder);
assertEquals(TOP_LEVEL_ID, topLevelFolder.getId());
assertNull(topLevelFolder.getParentId());
assertEquals("/" + TOP_LEVEL_ID, topLevelFolder.getPath());
assertEquals("Nuxeo Drive", topLevelFolder.getName());
assertTrue(topLevelFolder.isFolder());
assertEquals("system", topLevelFolder.getCreator());
assertEquals("system", topLevelFolder.getLastContributor());
assertFalse(topLevelFolder.getCanRename());
assertFalse(topLevelFolder.getCanDelete());
assertFalse(topLevelFolder.getCanCreateChild());
/**
* <pre>
* ===================================================
* User workspace registered as a synchronization root
* ===================================================
* => Expected client side for user1:
*
* Nuxeo Drive
* |-- My Docs
* | |-- user1File2
* | |-- user1Folder1
* | | |-- user1File1
* | | |-- user1Folder2
* | |-- user1Folder3
* | | |-- user1File3
* | |-- user1Folder4
* |
* |-- Other Docs
* | |-- user2Folder1
* | | |-- user2File1
* | | |-- user2Folder2
* | |-- user2Folder3
* | | |-- user2File3
* </pre>
*/
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// ---------------------------------------------
// Check top level folder children
// ---------------------------------------------
// 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 permission 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(2, topLevelChildren.size());
// Check "My Docs"
UserSyncRootParentFolderItem userSyncRootParent = readValue(topLevelChildren.get(0), UserSyncRootParentFolderItem.class);
assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
assertEquals("My Docs", userSyncRootParent.getName());
assertTrue(userSyncRootParent.isFolder());
assertEquals("user1", userSyncRootParent.getCreator());
assertEquals("user1", userSyncRootParent.getLastContributor());
assertFalse(userSyncRootParent.getCanRename());
assertFalse(userSyncRootParent.getCanDelete());
// Can create a child since "My Docs" is the user workspace
assertTrue(userSyncRootParent.getCanCreateChild());
// Check "Other Docs"
SharedSyncRootParentFolderItem sharedSyncRootParent = readValue(topLevelChildren.get(1), SharedSyncRootParentFolderItem.class);
assertEquals(SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getId());
assertEquals(TOP_LEVEL_ID, sharedSyncRootParent.getParentId());
assertEquals("/" + TOP_LEVEL_ID + "/" + SHARED_SYNC_ROOT_PARENT_ID, sharedSyncRootParent.getPath());
assertEquals("Other Docs", sharedSyncRootParent.getName());
assertTrue(sharedSyncRootParent.isFolder());
assertEquals("system", sharedSyncRootParent.getCreator());
assertEquals("system", sharedSyncRootParent.getLastContributor());
assertFalse(sharedSyncRootParent.getCanRename());
assertFalse(sharedSyncRootParent.getCanDelete());
assertFalse(sharedSyncRootParent.getCanCreateChild());
// --------------------------------------------
// Check user synchronization roots
// --------------------------------------------
// Check descendants
assertTrue(userSyncRootParent.getCanScrollDescendants());
assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(user1File2, user1Folder1, user1File1, user1Folder2, user1Folder3, user1File3, user1Folder4).stream().map(doc -> DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + doc.getId()).collect(Collectors.toList()), mapper.readValue(((Blob) clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", userSyncRootParent.getId()).set("batchSize", 10).execute()).getStream(), JsonNode.class).findValuesAsText("id")));
// Get children
Blob userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
ArrayNode userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
assertNotNull(userSyncRoots);
assertEquals(4, userSyncRoots.size());
DocumentBackedFolderItem folderItem;
DocumentBackedFileItem childFileItem;
DocumentBackedFileItem fileItem;
DocumentBackedFolderItem childFolderItem;
JsonNode[] rootNodes = sortNodeByName(userSyncRoots);
// user1File2
fileItem = readValue(rootNodes[0], DocumentBackedFileItem.class);
checkFileItem(fileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File2, userWorkspace1ItemId, userWorkspace1ItemPath, "user1File2.txt", "user1", "user1");
// user1Folder1
folderItem = readValue(rootNodes[1], 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[] nodes = sortNodeByName(folderItemChildren);
// user1File1
childFileItem = readValue(nodes[0], DocumentBackedFileItem.class);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File1, folderItem.getId(), folderItem.getPath(), "user1File1.txt", "user1", "user1");
// user1Folder2
childFolderItem = readValue(nodes[1], DocumentBackedFolderItem.class);
checkFolderItem(childFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder2, folderItem.getId(), folderItem.getPath(), "user1Folder2", "user1", "user1");
}
// user1Folder3
folderItem = readValue(rootNodes[2], DocumentBackedFolderItem.class);
checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1");
{
folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(folderItemChildren);
assertEquals(1, folderItemChildren.size());
// user1File3
childFileItem = readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1");
}
// user1Folder4
folderItem = readValue(rootNodes[3], DocumentBackedFolderItem.class);
checkFolderItem(folderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1");
// ---------------------------------------------
// Check shared synchronization roots
// ---------------------------------------------
// Check descendants
assertFalse(topLevelFolder.getCanScrollDescendants());
try {
clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", sharedSyncRootParent.getId()).set("batchSize", 10).execute();
fail("Scrolling through the descendants of the shared sync root parent folder item should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
}
// Get children
Blob sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
List<DefaultSyncRootFolderItem> sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
Collections.sort(sharedSyncRoots);
assertNotNull(sharedSyncRoots);
assertEquals(2, sharedSyncRoots.size());
// user2Folder1
DefaultSyncRootFolderItem sharedSyncRoot = sharedSyncRoots.get(0);
checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder1.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder1", "user2", "user1");
Blob sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
ArrayNode sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(sharedSyncRootChildren);
assertEquals(2, sharedSyncRootChildren.size());
DocumentBackedFolderItem sharedSyncRootChildFolderItem;
DocumentBackedFileItem sharedSyncRootChildFileItem;
{
JsonNode[] nodes = sortNodeByName(sharedSyncRootChildren);
// user2File1
sharedSyncRootChildFileItem = readValue(nodes[0], DocumentBackedFileItem.class);
checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File1.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File1.txt", "user2", "user2");
// user2Folder2
sharedSyncRootChildFolderItem = readValue(nodes[1], DocumentBackedFolderItem.class);
checkFolderItem(sharedSyncRootChildFolderItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2Folder2.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2Folder2", "user2", "user2");
}
// user2Folder3
sharedSyncRoot = sharedSyncRoots.get(1);
checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1");
sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(sharedSyncRootChildren);
assertEquals(1, sharedSyncRootChildren.size());
// user2File3
sharedSyncRootChildFileItem = readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2");
/**
* <pre>
* =======================================================
* User workspace NOT registered as a synchronization root
* =======================================================
* => Expected client side for user1:
*
* Nuxeo Drive
* |-- My Docs
* |
* |-- Other Docs (unchanged)
* | |-- user2Folder1
* | | |-- user2File1
* | | |-- user2Folder2
* | |-- user2Folder3
* | | |-- user2File3
* </pre>
*/
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), userWorkspace1, session1);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// ---------------------------------------------
// Check "My Docs"
// ---------------------------------------------
Blob userSyncRootParentJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetFileSystemItem.ID).set("id", userWorkspace1ItemId).execute();
assertNotNull(userSyncRootParentJSON);
userSyncRootParent = mapper.readValue(userSyncRootParentJSON.getStream(), UserSyncRootParentFolderItem.class);
assertEquals(userWorkspace1ItemId, userSyncRootParent.getId());
assertEquals(TOP_LEVEL_ID, userSyncRootParent.getParentId());
assertEquals(userWorkspace1ItemPath, userSyncRootParent.getPath());
assertEquals("My Docs", userSyncRootParent.getName());
assertTrue(userSyncRootParent.isFolder());
assertEquals("user1", userSyncRootParent.getCreator());
assertEquals("user1", userSyncRootParent.getLastContributor());
assertFalse(userSyncRootParent.getCanRename());
assertFalse(userSyncRootParent.getCanDelete());
// Cannot create a child since "My Docs" is only the parent of the
// synchronization roots, not the user workspace
assertFalse(userSyncRootParent.getCanCreateChild());
// --------------------------------------------
// Check user synchronization roots
// --------------------------------------------
// Check descendants
assertFalse(topLevelFolder.getCanScrollDescendants());
try {
clientSession1.newRequest(NuxeoDriveScrollDescendants.ID).set("id", userSyncRootParent.getId()).set("batchSize", 10).execute();
fail("Scrolling through the descendants of the user sync root parent folder item not registered as a sync root should be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.ScrollDescendants", e.getMessage());
}
// Get children
userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
assertNotNull(userSyncRoots);
assertEquals(0, userSyncRoots.size());
/**
* <pre>
* =======================================================
* User workspace NOT registered as a synchronization root
* but specific folders yes: user1Folder3, user1Folder4
* =======================================================
* => Expected client side for user1:
*
* Nuxeo Drive
* |-- My Docs
* | |-- user1Folder3
* | | |-- user1File3
* | |-- user1Folder4
* |
* |-- Other Docs (unchanged)
* | |-- user2Folder1
* | | |-- user2File1
* | | |-- user2Folder2
* | |-- user2Folder3
* | | |-- user2File3
* </pre>
*/
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder3, session1);
nuxeoDriveManager.registerSynchronizationRoot(session1.getPrincipal(), user1Folder4, session1);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// --------------------------------------------
// Check user synchronization roots
// --------------------------------------------
userSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", userSyncRootParent.getId()).execute();
userSyncRoots = mapper.readValue(userSyncRootsJSON.getStream(), ArrayNode.class);
assertNotNull(userSyncRoots);
assertEquals(2, userSyncRoots.size());
// user1Folder3
folderItem = readValue(userSyncRoots.get(0), DocumentBackedFolderItem.class);
checkFolderItem(folderItem, SYNC_ROOT_ID_PREFIX, user1Folder3, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder3", "user1", "user1");
folderItemChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", folderItem.getId()).execute();
folderItemChildren = mapper.readValue(folderItemChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(folderItemChildren);
assertEquals(1, folderItemChildren.size());
// user1File3
childFileItem = readValue(folderItemChildren.get(0), DocumentBackedFileItem.class);
checkFileItem(childFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, user1File3, folderItem.getId(), folderItem.getPath(), "user1File3.txt", "user1", "user1");
// user1Folder4
folderItem = readValue(userSyncRoots.get(1), DocumentBackedFolderItem.class);
checkFolderItem(folderItem, SYNC_ROOT_ID_PREFIX, user1Folder4, userWorkspace1ItemId, userWorkspace1ItemPath, "user1Folder4", "user1", "user1");
/**
* <pre>
* =======================================================
* Unregister a shared folder: user2Folder1
* =======================================================
* => Expected client side for user1:
*
* Nuxeo Drive
* |-- My Docs (unchanged)
* | |-- user1Folder3
* | | |-- user1File3
* | |-- user1Folder4
* |
* |-- Other Docs
* | |-- user2Folder3
* | | |-- user2File3
* </pre>
*/
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
nuxeoDriveManager.unregisterSynchronizationRoot(session1.getPrincipal(), session1.getDocument(user2Folder1.getRef()), session1);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// ---------------------------------------------
// Check shared synchronization roots
// ---------------------------------------------
sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
assertNotNull(sharedSyncRoots);
assertEquals(1, sharedSyncRoots.size());
// user2Folder3
sharedSyncRoot = sharedSyncRoots.get(0);
checkFolderItem(sharedSyncRoot, SYNC_ROOT_ID_PREFIX, session1.getDocument(user2Folder3.getRef()), sharedSyncRootParent.getId(), sharedSyncRootParent.getPath(), "user2Folder3", "user2", "user1");
sharedSyncRootChildrenJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRoot.getId()).execute();
sharedSyncRootChildren = mapper.readValue(sharedSyncRootChildrenJSON.getStream(), ArrayNode.class);
assertNotNull(sharedSyncRootChildren);
assertEquals(1, sharedSyncRootChildren.size());
// user2File3
sharedSyncRootChildFileItem = readValue(sharedSyncRootChildren.get(0), DocumentBackedFileItem.class);
checkFileItem(sharedSyncRootChildFileItem, DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX, session1.getDocument(user2File3.getRef()), sharedSyncRoot.getId(), sharedSyncRoot.getPath(), "user2File3.txt", "user2", "user2");
/**
* <pre>
* =======================================================
* Remove permission on a shared folder: user2Folder3
* =======================================================
* => Expected client side for user1:
*
* Nuxeo Drive
* |-- My Docs (unchanged)
* | |-- user1Folder3
* | | |-- user1File3
* | |-- user1Folder4
* |
* |-- Other Docs
* </pre>
*/
resetPermissions(user2Folder3.getRef(), "user1");
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
// ---------------------------------------------
// Check shared synchronization roots
// ---------------------------------------------
sharedSyncRootsJSON = (Blob) clientSession1.newRequest(NuxeoDriveGetChildren.ID).set("id", sharedSyncRootParent.getId()).execute();
sharedSyncRoots = mapper.readValue(sharedSyncRootsJSON.getStream(), new TypeReference<List<DefaultSyncRootFolderItem>>() {
});
assertNotNull(sharedSyncRoots);
assertEquals(0, sharedSyncRoots.size());
}
use of org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem 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();
}
}
use of org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testCreateFolder.
@Test
public void testCreateFolder() throws Exception {
Blob newFolderJSON = (Blob) clientSession.newRequest(NuxeoDriveCreateFolder.ID).set("parentId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).set("name", "newFolder").execute();
assertNotNull(newFolderJSON);
DocumentBackedFolderItem newFolder = mapper.readValue(newFolderJSON.getStream(), DocumentBackedFolderItem.class);
assertNotNull(newFolder);
// Need to flush VCS cache to be aware of changes in the session used by the file system item
session.save();
DocumentModel newFolderDoc = session.getDocument(new PathRef("/folder2/newFolder"));
assertEquals("Folder", newFolderDoc.getType());
assertEquals("newFolder", newFolderDoc.getTitle());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFolderDoc.getId(), newFolder.getId());
assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId(), newFolder.getParentId());
assertEquals("newFolder", newFolder.getName());
assertTrue(newFolder.isFolder());
assertEquals("Administrator", newFolder.getCreator());
assertEquals("Administrator", newFolder.getLastContributor());
assertTrue(newFolder.getCanRename());
assertTrue(newFolder.getCanDelete());
assertTrue(newFolder.getCanCreateChild());
}
use of org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testRename.
@Test
public void testRename() throws Exception {
// ------------------------------------------------------
// File
// ------------------------------------------------------
Blob renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("name", "Renamed file 1.odt").execute();
assertNotNull(renamedFSItemJSON);
DocumentBackedFileItem renamedFileItem = mapper.readValue(renamedFSItemJSON.getStream(), DocumentBackedFileItem.class);
assertNotNull(renamedFileItem);
assertEquals("Renamed file 1.odt", renamedFileItem.getName());
// Need to flush VCS cache to be aware of changes in the session used by the file system item
session.save();
DocumentModel renamedFileDoc = session.getDocument(new IdRef(file1.getId()));
assertEquals("file1", renamedFileDoc.getTitle());
org.nuxeo.ecm.core.api.Blob renamedFileBlob = (org.nuxeo.ecm.core.api.Blob) renamedFileDoc.getPropertyValue("file:content");
assertNotNull(renamedFileBlob);
assertEquals("Renamed file 1.odt", renamedFileBlob.getFilename());
assertEquals("nxfile/test/" + file1.getId() + "/blobholder:0/Renamed%20file%201.odt", renamedFileItem.getDownloadURL());
assertEquals("MD5", renamedFileItem.getDigestAlgorithm());
assertEquals(renamedFileBlob.getDigest(), renamedFileItem.getDigest());
// ------------------------------------------------------
// Folder
// ------------------------------------------------------
renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId()).set("name", "Renamed sub-folder 1").execute();
assertNotNull(renamedFSItemJSON);
DocumentBackedFolderItem renamedFolderItem = mapper.readValue(renamedFSItemJSON.getStream(), DocumentBackedFolderItem.class);
assertNotNull(renamedFolderItem);
assertEquals("Renamed sub-folder 1", renamedFolderItem.getName());
// Need to flush VCS cache to be aware of changes in the session used by the file system item
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
DocumentModel renamedFolderDoc = session.getDocument(new IdRef(subFolder1.getId()));
assertEquals("Renamed sub-folder 1", renamedFolderDoc.getTitle());
// ------------------------------------------------------
// Sync root
// ------------------------------------------------------
renamedFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveRename.ID).set("id", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).set("name", "New name for sync root").execute();
assertNotNull(renamedFSItemJSON);
DefaultSyncRootFolderItem renamedSyncRootItem = mapper.readValue(renamedFSItemJSON.getStream(), DefaultSyncRootFolderItem.class);
assertNotNull(renamedSyncRootItem);
assertEquals("New name for sync root", renamedSyncRootItem.getName());
// Need to flush VCS cache to be aware of changes in the session used by the file system item
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
DocumentModel renamedSyncRootDoc = session.getDocument(new IdRef(syncRoot1.getId()));
assertEquals("New name for sync root", renamedSyncRootDoc.getTitle());
// ------------------------------------------------------
try {
clientSession.newRequest(NuxeoDriveRename.ID).set("id", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).set("name", "New name for top level folder").execute();
fail("Top level folder renaming shoud be unsupported.");
} catch (Exception e) {
assertEquals("Failed to invoke operation: NuxeoDrive.Rename", e.getMessage());
}
}
Aggregations