use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class FileSystemItemManagerImpl method canMove.
@Override
public boolean canMove(String srcId, String destId, Principal principal) {
FileSystemItem srcFsItem = getFileSystemItemById(srcId, principal);
if (srcFsItem == null) {
return false;
}
FileSystemItem destFsItem = getFileSystemItemById(destId, principal);
if (!(destFsItem instanceof FolderItem)) {
return false;
}
return srcFsItem.canMove((FolderItem) destFsItem);
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class FileSystemItemManagerImpl method rename.
@Override
public FileSystemItem rename(String id, String name, Principal principal) {
FileSystemItem fsItem = getFileSystemItemById(id, principal);
if (fsItem == null) {
throw new NuxeoException(String.format("Cannot rename file system item with id %s because it doesn't exist.", id));
}
fsItem.rename(name);
return fsItem;
}
use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.
the class DefaultFileSystemItemFactoryFixture method testGetFileSystemItem.
@Test
public void testGetFileSystemItem() throws Exception {
// ------------------------------------------------------
// Check downloadable FileSystemItems
// ------------------------------------------------------
// File
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(file));
FileSystemItem fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Joe.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
assertEquals("Administrator", fsItem.getCreator());
assertEquals("Administrator", fsItem.getLastContributor());
Blob fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Joe.odt", fileItemBlob.getFilename());
assertEquals("Content of Joe's file.", fileItemBlob.getString());
// Note
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(note));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
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());
assertEquals("Administrator", fsItem.getCreator());
assertEquals("Administrator", fsItem.getLastContributor());
fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("aNote.txt", fileItemBlob.getFilename());
assertEquals("Content of Bob's note.", fileItemBlob.getString());
// Custom doc type with the "file" schema
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FileItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Bonnie's file.odt", fsItem.getName());
assertFalse(fsItem.isFolder());
assertEquals("Administrator", fsItem.getCreator());
assertEquals("Administrator", fsItem.getLastContributor());
fileItemBlob = ((FileItem) fsItem).getBlob();
assertEquals("Bonnie's file.odt", fileItemBlob.getFilename());
assertEquals("Content of Bonnie's file.", fileItemBlob.getString());
// File without a blob => not adaptable as a FileSystemItem
file.setPropertyValue("file:content", null);
file = session.saveDocument(file);
assertFalse(defaultFileSystemItemFactory.isFileSystemItem(file));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(file);
assertNull(fsItem);
// Deleted file => not adaptable as a FileSystemItem
custom.followTransition("delete");
assertFalse(defaultFileSystemItemFactory.isFileSystemItem(custom));
assertNull(defaultFileSystemItemFactory.getFileSystemItem(custom));
// Deleted file with explicit "includeDeleted" => adaptable as a
// FileSystemItem
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(custom, true));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(custom, true);
assertNotNull(fsItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + custom.getId(), fsItem.getId());
assertEquals("Bonnie's file.odt", fsItem.getName());
// Version
// Note is now automatically versioned at each save
assertEquals("0.1", note.getVersionLabel());
note.checkOut();
DocumentRef versionRef = session.checkIn(note.getRef(), VersioningOption.MINOR, null);
DocumentModel version = session.getDocument(versionRef);
assertFalse(defaultFileSystemItemFactory.isFileSystemItem(version));
// Proxy
DocumentModel proxy = session.createProxy(note.getRef(), folder.getRef());
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(proxy));
// HiddenInNavigation
note.addFacet("HiddenInNavigation");
assertFalse(defaultFileSystemItemFactory.isFileSystemItem(note));
note.removeFacet("HiddenInNavigation");
// ------------------------------------------------------
// Check folderish FileSystemItems
// ------------------------------------------------------
// Folder
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folder));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(folder);
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());
assertEquals("Administrator", fsItem.getCreator());
assertEquals("Administrator", fsItem.getLastContributor());
FolderItem folderItem = (FolderItem) fsItem;
List<FileSystemItem> children = folderItem.getChildren();
assertNotNull(children);
assertEquals(0, children.size());
assertTrue(folderItem.getCanScrollDescendants());
ScrollFileSystemItemList descendants = folderItem.scrollDescendants(null, 10, 1000);
assertNotNull(descendants);
assertNotNull(descendants.getScrollId());
assertEquals(0, descendants.size());
// FolderishFile => adaptable as a FolderItem since the default
// FileSystemItem factory gives precedence to the Folderish facet
assertTrue(defaultFileSystemItemFactory.isFileSystemItem(folderishFile));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(folderishFile);
assertNotNull(fsItem);
assertTrue(fsItem instanceof FolderItem);
assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + folderishFile.getId(), fsItem.getId());
assertEquals(syncRootItemId, fsItem.getParentId());
assertEquals("Sarah's folderish file", fsItem.getName());
assertTrue(fsItem.isFolder());
assertEquals("Administrator", fsItem.getCreator());
assertEquals("Administrator", fsItem.getLastContributor());
// ------------------------------------------------------
// Check not downloadable nor folderish
// ------------------------------------------------------
assertFalse(defaultFileSystemItemFactory.isFileSystemItem(notAFileSystemItem));
fsItem = defaultFileSystemItemFactory.getFileSystemItem(notAFileSystemItem);
assertNull(fsItem);
// -------------------------------------------------------------
// Check #getFileSystemItem(DocumentModel doc, FolderItem parentItem)
// -------------------------------------------------------------
FolderItem syncRootSystemItem = (FolderItem) fileSystemItemAdapterService.getFileSystemItemFactoryForId(syncRootItemId).getFileSystemItemById(syncRootItemId, principal);
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, syncRootSystemItem);
assertEquals(syncRootItemId, fsItem.getParentId());
// Passing a null parent will force a null parentId
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note, null);
assertNull(fsItem.getParentId());
// ------------------------------------------------------------------
// Check FileSystemItem#getCanRename and FileSystemItem#getCanDelete
// ------------------------------------------------------------------
// As Administrator
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
// As a user with READ permission
DocumentModel rootDoc = session.getRootDocument();
setPermission(rootDoc, "joe", SecurityConstants.READ, true);
// Under Oracle, the READ ACL optims are not visible from the joe
// session while the transaction has not been committed.
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
try (CloseableCoreSession joeSession = coreFeature.openCoreSession("joe")) {
nuxeoDriveManager.registerSynchronizationRoot(joeSession.getPrincipal(), syncRootFolder, session);
note = joeSession.getDocument(note.getRef());
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
assertFalse(fsItem.getCanRename());
assertFalse(fsItem.getCanDelete());
// As a user with WRITE permission
setPermission(rootDoc, "joe", SecurityConstants.WRITE, true);
fsItem = defaultFileSystemItemFactory.getFileSystemItem(note);
assertTrue(fsItem.getCanRename());
assertTrue(fsItem.getCanDelete());
}
resetPermissions(rootDoc, "joe");
}
use of org.nuxeo.drive.adapter.FileSystemItem 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.adapter.FileSystemItem 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());
}
Aggregations