use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testResetSyncRootsOnCopyDisabled.
@Test
@Deploy("org.nuxeo.drive.core:OSGI-INF/test-nuxeodrive-reset-sync-roots-on-copy-disabled-contrib.xml")
public void testResetSyncRootsOnCopyDisabled() {
nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder_1_1, session);
// Copy a sync root
DocumentModel copy = session.copy(folder_1_1.getRef(), workspace_2.getRef(), null);
txFeature.nextTransaction();
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), copy));
nuxeoDriveManager.invalidateSynchronizationRootsCache(session.getPrincipal().getName());
// Copy a folder containing a sync root
copy = session.copy(workspace_1.getRef(), workspace_2.getRef(), null);
txFeature.nextTransaction();
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), session.getDocument(new PathRef(copy.getPathAsString() + "/" + folder_1_1.getName()))));
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testAddToLocallyEditedCollection.
@Test
public void testAddToLocallyEditedCollection() {
// Create a test document and add it to the "Locally Edited" collection
DocumentModel doc1 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile1", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc1);
// Check that the "Locally Edited" collection has been created, the test
// document is member of it and the collection is registered as a
// synchronization root
CollectionManager cm = Framework.getService(CollectionManager.class);
DocumentModel userCollections = cm.getUserDefaultCollections(doc1, session);
DocumentRef locallyEditedCollectionRef = new PathRef(userCollections.getPath().toString(), NuxeoDriveManager.LOCALLY_EDITED_COLLECTION_NAME);
assertTrue(session.exists(locallyEditedCollectionRef));
DocumentModel locallyEditedCollection = session.getDocument(locallyEditedCollectionRef);
assertTrue(cm.isCollection(locallyEditedCollection));
// Re-fetch document from session to refresh it
doc1 = session.getDocument(doc1.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc1, session));
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
// Add another document to the "Locally Edited" collection, check
// collection membership
DocumentModel doc2 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile2", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc2);
doc2 = session.getDocument(doc2.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc2, session));
// Unregister the "Locally Edited" collection and add another document
// to it, check collection membership and the collection is registered
// as a synchronization root once again
nuxeoDriveManager.unregisterSynchronizationRoot(session.getPrincipal(), locallyEditedCollection, session);
DocumentModel doc3 = session.createDocument(session.createDocumentModel(workspace_1.getPathAsString(), "driveEditFile3", "File"));
nuxeoDriveManager.addToLocallyEditedCollection(session, doc3);
doc3 = session.getDocument(doc3.getRef());
assertTrue(cm.isInCollection(locallyEditedCollection, doc3, session));
assertTrue(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), locallyEditedCollection));
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method createUserSessionsAndFolders.
@Before
public void createUserSessionsAndFolders() throws Exception {
try (Session userDir = directoryService.open("userDirectory")) {
if (userDir.getEntry("user1") != null) {
userDir.deleteEntry("user1");
}
Map<String, Object> user1 = new HashMap<>();
user1.put("username", "user1");
user1.put("groups", Arrays.asList(new String[] { "members" }));
userDir.createEntry(user1);
if (userDir.getEntry("user2") != null) {
userDir.deleteEntry("user2");
}
Map<String, Object> user2 = new HashMap<>();
user2.put("username", "user2");
user2.put("groups", Arrays.asList(new String[] { "members" }));
userDir.createEntry(user2);
}
workspace_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "workspace-1", "Workspace"));
folder_1_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-1", "folder-1-1", "Folder"));
workspace_2 = session.createDocument(session.createDocumentModel("/default-domain/workspaces", "workspace-2", "Workspace"));
folder_2_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-2", "folder-2-1", "Folder"));
setPermissions(workspace_1, new ACE("members", SecurityConstants.READ));
setPermissions(workspace_2, new ACE("members", SecurityConstants.READ_WRITE));
user1Session = coreFeature.openCoreSession(userManager.getPrincipal("user1"));
user2Session = coreFeature.openCoreSession(userManager.getPrincipal("user2"));
user1Workspace = userWorkspaceService.getCurrentUserPersonalWorkspace(user1Session, user1Session.getDocument(new PathRef("/default-domain"))).getRef();
user2Workspace = userWorkspaceService.getCurrentUserPersonalWorkspace(user2Session, user2Session.getDocument(new PathRef("/default-domain"))).getRef();
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.
the class TestNuxeoDriveManager method testGetSynchronizationRoots.
@Test
public void testGetSynchronizationRoots() throws Exception {
// Register synchronization roots
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), user1Session.getDocument(user1Workspace), user1Session);
nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), doc(user1Session, "/default-domain/workspaces/workspace-2"), user1Session);
// Check synchronization root references
Set<IdRef> rootRefs = nuxeoDriveManager.getSynchronizationRootReferences(user1Session);
assertEquals(2, rootRefs.size());
assertTrue(rootRefs.contains(user1Workspace));
assertTrue(rootRefs.contains(new IdRef(user1Session.getDocument(new PathRef("/default-domain/workspaces/workspace-2")).getId())));
// Check synchronization root paths
Map<String, SynchronizationRoots> synRootMap = nuxeoDriveManager.getSynchronizationRoots(user1Session.getPrincipal());
Set<String> rootPaths = synRootMap.get(session.getRepositoryName()).paths;
assertEquals(2, rootPaths.size());
assertTrue(rootPaths.contains("/default-domain/UserWorkspaces/user1"));
assertTrue(rootPaths.contains("/default-domain/workspaces/workspace-2"));
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemManagerService method testWriteOperations.
@Test
public void testWriteOperations() throws Exception {
// Not allowed to create a folder in a non FolderItem
try {
fileSystemItemManagerService.createFolder(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), "A new folder", principal, false);
fail("Folder creation in a non folder item should fail.");
} catch (NuxeoException e) {
assertEquals(String.format("Cannot create a folder in file system item with id %s because it is not a folder but is: " + "DocumentBackedFileItem(id=\"%s\", name=\"Joe.odt\")", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId()), e.getMessage());
}
// Folder creation
FolderItem newFolderItem = fileSystemItemManagerService.createFolder(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), "A new folder", principal, false);
assertNotNull(newFolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), newFolderItem.getParentId());
assertEquals("A new folder", newFolderItem.getName());
DocumentModelList folderChildren = session.query(String.format("select * from Document where ecm:parentId = '%s' and ecm:primaryType = 'Folder' order by dc:title asc", folder.getId()));
DocumentModel newFolder = folderChildren.get(0);
assertTrue(newFolder.isFolder());
assertEquals("A new folder", newFolder.getTitle());
// Parent folder children check
assertEquals(6, fileSystemItemManagerService.getChildren(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), principal).size());
// NXP-21854: Check overwrite parameter
// Test overwrite=false
FolderItem differentFolderItem = fileSystemItemManagerService.createFolder(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), "A new folder", principal, false);
assertNotNull(differentFolderItem);
assertNotEquals(newFolderItem.getId(), differentFolderItem.getId());
assertEquals("A new folder", differentFolderItem.getName());
// Test overwrite=true
FolderItem otherFolderItem = fileSystemItemManagerService.createFolder(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), "Test overwrite", principal, false);
assertNotNull(otherFolderItem);
assertEquals("Test overwrite", otherFolderItem.getName());
FolderItem sameFolderItem = fileSystemItemManagerService.createFolder(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), "Test overwrite", principal, true);
assertNotNull(sameFolderItem);
assertEquals(otherFolderItem.getId(), sameFolderItem.getId());
assertEquals("Test overwrite", sameFolderItem.getName());
// ------------------------------------------------------
// Check #createFile
// ------------------------------------------------------
// File creation
Blob blob = new StringBlob("Content of a new file.");
blob.setFilename("New file.odt");
blob.setMimeType("application/vnd.oasis.opendocument.text");
FileItem fileItem = fileSystemItemManagerService.createFile(newFolderItem.getId(), blob, principal, false);
assertNotNull(fileItem);
assertEquals(newFolderItem.getId(), fileItem.getParentId());
assertEquals("New file.odt", fileItem.getName());
folderChildren = session.query(String.format("select * from Document where ecm:parentId = '%s'", newFolder.getId()));
assertEquals(1, folderChildren.size());
DocumentModel newFile = folderChildren.get(0);
assertEquals("File", newFile.getType());
assertEquals("New file.odt", newFile.getTitle());
assertEquals("/syncRoot1/aFolder/A new folder/New file.odt", newFile.getPathAsString());
Blob newFileBlob = (Blob) newFile.getPropertyValue("file:content");
assertEquals("New file.odt", newFileBlob.getFilename());
assertEquals("Content of a new file.", newFileBlob.getString());
assertEquals("nxfile/test/" + newFile.getId() + "/blobholder:0/New%20file.odt", fileItem.getDownloadURL());
assertEquals("MD5", fileItem.getDigestAlgorithm());
assertEquals(newFileBlob.getDigest(), fileItem.getDigest());
// NXP-21854: Check overwrite parameter
// Test overwrite=false
FileItem differentFileItem = fileSystemItemManagerService.createFile(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), blob, principal, false);
assertNotNull(differentFileItem);
assertNotEquals(fileItem.getId(), differentFileItem.getId());
assertEquals("New file.odt", differentFileItem.getName());
// Test overwrite=true
Blob otherBlob = new StringBlob("Content of a new file.");
otherBlob.setFilename("Test overwrite.odt");
otherBlob.setMimeType("application/vnd.oasis.opendocument.text");
FileItem otherFileItem = fileSystemItemManagerService.createFile(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), otherBlob, principal, false);
assertNotNull(otherFileItem);
assertEquals("Test overwrite.odt", otherFileItem.getName());
FileItem sameFileItem = fileSystemItemManagerService.createFile(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), otherBlob, principal, true);
assertNotNull(sameFileItem);
assertEquals(otherFileItem.getId(), sameFileItem.getId());
assertEquals("Test overwrite.odt", sameFileItem.getName());
// Parent folder children check
assertEquals(1, fileSystemItemManagerService.getChildren(newFolderItem.getId(), principal).size());
// ------------------------------------------------------
// Check #updateFile
// ------------------------------------------------------
String fileItemId = fileItem.getId();
String fileItemParentId = fileItem.getParentId();
blob = new StringBlob("Modified content of an existing file.");
fileItem = fileSystemItemManagerService.updateFile(fileItemId, blob, principal);
assertNotNull(fileItem);
assertEquals(fileItemId, fileItem.getId());
assertEquals(fileItemParentId, fileItem.getParentId());
assertEquals("New file.odt", fileItem.getName());
folderChildren = session.query(String.format("select * from Document where ecm:parentId = '%s'", newFolder.getId()));
assertEquals(1, folderChildren.size());
DocumentModel updatedFile = folderChildren.get(0);
assertEquals("File", updatedFile.getType());
assertEquals("New file.odt", updatedFile.getTitle());
assertEquals("/syncRoot1/aFolder/A new folder/New file.odt", updatedFile.getPathAsString());
Blob updatedFileBlob = (Blob) updatedFile.getPropertyValue("file:content");
assertEquals("New file.odt", updatedFileBlob.getFilename());
assertEquals("Modified content of an existing file.", updatedFileBlob.getString());
assertEquals("nxfile/test/" + updatedFile.getId() + "/blobholder:0/New%20file.odt", fileItem.getDownloadURL());
assertEquals("MD5", fileItem.getDigestAlgorithm());
assertEquals(updatedFileBlob.getDigest(), fileItem.getDigest());
// ------------------------------------------------------
// Check #delete
// ------------------------------------------------------
// File deletion
fileSystemItemManagerService.delete(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + updatedFile.getId(), principal);
updatedFile = session.getDocument(new IdRef(updatedFile.getId()));
assertTrue(updatedFile.isTrashed());
// Parent folder children check
assertTrue(fileSystemItemManagerService.getChildren(newFolderItem.getId(), principal).isEmpty());
// ------------------------------------------------------
// Check #rename
// ------------------------------------------------------
// Folder rename
String fsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId();
FileSystemItem fsItem = fileSystemItemManagerService.rename(fsItemId, "Jack's folder has a new name", principal);
assertEquals(fsItemId, fsItem.getId());
String expectedSyncRoot1Id = DEFAULT_SYNC_ROOT_ITEM_ID_PREFIX + syncRoot1.getId();
assertEquals(expectedSyncRoot1Id, fsItem.getParentId());
assertEquals("Jack's folder has a new name", fsItem.getName());
folder = session.getDocument(folder.getRef());
assertEquals("Jack's folder has a new name", folder.getTitle());
// File rename with title != filename
// => should rename filename but not title
assertEquals("aFile", file.getTitle());
assertEquals("Joe.odt", ((Blob) file.getPropertyValue("file:content")).getFilename());
fsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId();
fsItem = fileSystemItemManagerService.rename(fsItemId, "File new name.odt", principal);
assertEquals(fsItemId, fsItem.getId());
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folder.getId(), fsItem.getParentId());
assertEquals("File new name.odt", fsItem.getName());
file = session.getDocument(file.getRef());
assertEquals("aFile", file.getTitle());
Blob fileBlob = (Blob) file.getPropertyValue("file:content");
assertEquals("File new name.odt", fileBlob.getFilename());
fileItem = (FileItem) fsItem;
assertEquals("nxfile/test/" + file.getId() + "/blobholder:0/File%20new%20name.odt", fileItem.getDownloadURL());
assertEquals("MD5", fileItem.getDigestAlgorithm());
assertEquals(fileBlob.getDigest(), fileItem.getDigest());
// File rename with title == filename
// => should rename filename and title
blob = new StringBlob("File for a doc with title == filename.");
blob.setFilename("Title-filename equality.odt");
blob.setMimeType("application/vnd.oasis.opendocument.text");
fileItem = fileSystemItemManagerService.createFile(newFolderItem.getId(), blob, principal, false);
// Note that the PathSegmentService truncates doc title at 24 characters
newFile = session.getDocument(new PathRef("/syncRoot1/aFolder/A new folder/Title-filename equality."));
assertEquals("Title-filename equality.odt", newFile.getTitle());
assertEquals("Title-filename equality.odt", ((Blob) newFile.getPropertyValue("file:content")).getFilename());
fileItem = (FileItem) fileSystemItemManagerService.rename(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFile.getId(), "Renamed title-filename equality.odt", principal);
assertEquals("Renamed title-filename equality.odt", fileItem.getName());
newFile = session.getDocument(newFile.getRef());
assertEquals("Renamed title-filename equality.odt", newFile.getTitle());
newFileBlob = (Blob) newFile.getPropertyValue("file:content");
assertEquals("Renamed title-filename equality.odt", newFileBlob.getFilename());
assertEquals("nxfile/test/" + newFile.getId() + "/blobholder:0/Renamed%20title-filename%20equality.odt", fileItem.getDownloadURL());
assertEquals("MD5", fileItem.getDigestAlgorithm());
assertEquals(newFileBlob.getDigest(), fileItem.getDigest());
// ------------------------------------------------------
// Check #move
// ------------------------------------------------------
// 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();
try {
fileSystemItemManagerService.move(srcFsItemId, destFsItemId, principal);
fail("Move to a non folder item should fail.");
} catch (NuxeoException e) {
assertEquals(String.format("Cannot move a file system item to file system item with id %s because it is not a folder.", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId()), e.getMessage());
}
// Move to a FolderItem
destFsItemId = DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder.getId();
FileSystemItem movedFsItem = fileSystemItemManagerService.move(srcFsItemId, destFsItemId, principal);
assertEquals(srcFsItemId, movedFsItem.getId());
assertEquals(destFsItemId, movedFsItem.getParentId());
assertEquals("aNote.txt", movedFsItem.getName());
note = session.getDocument(note.getRef());
assertEquals("/syncRoot1/aFolder/aSubFolder/aNote", note.getPathAsString());
assertEquals("aNote", note.getTitle());
}
Aggregations