Search in sources :

Example 31 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method move.

@Override
public FileSystemItem move(String srcId, String destId, Principal principal) {
    FileSystemItem srcFsItem = getFileSystemItemById(srcId, principal);
    if (srcFsItem == null) {
        throw new NuxeoException(String.format("Cannot move file system item with id %s because it doesn't exist.", srcId));
    }
    FileSystemItem destFsItem = getFileSystemItemById(destId, principal);
    if (destFsItem == null) {
        throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it doesn't exist.", destId));
    }
    if (!(destFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot move a file system item to file system item with id %s because it is not a folder.", destId));
    }
    return srcFsItem.move((FolderItem) destFsItem);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 32 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method scrollDescendants.

@Override
public ScrollFileSystemItemList scrollDescendants(String id, Principal principal, String scrollId, int batchSize, long keepAlive) {
    FileSystemItem fileSystemItem = getFileSystemItemById(id, principal);
    if (fileSystemItem == null) {
        throw new NuxeoException(String.format("Cannot get the descendants of file system item with id %s because it doesn't exist.", id));
    }
    if (!(fileSystemItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot get the descendants of file system item with id %s because it is not a folder.", id));
    }
    FolderItem folderItem = (FolderItem) fileSystemItem;
    return folderItem.scrollDescendants(scrollId, batchSize, keepAlive);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 33 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method createFile.

@Override
public FileItem createFile(String parentId, Blob blob, Principal principal, boolean overwrite) {
    FileSystemItem parentFsItem = getFileSystemItemById(parentId, principal);
    if (parentFsItem == null) {
        throw new NuxeoException(String.format("Cannot create a file in file system item with id %s because it doesn't exist.", parentId));
    }
    if (!(parentFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot create a file in file system item with id %s because it is not a folder but is: %s", parentId, parentFsItem));
    }
    FolderItem parentFolder = (FolderItem) parentFsItem;
    return parentFolder.createFile(blob, overwrite);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 34 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method getChildren.

@Override
public List<FileSystemItem> getChildren(String id, Principal principal) {
    FileSystemItem fileSystemItem = getFileSystemItemById(id, principal);
    if (fileSystemItem == null) {
        throw new NuxeoException(String.format("Cannot get the children of file system item with id %s because it doesn't exist.", id));
    }
    if (!(fileSystemItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot get the children of file system item with id %s because it is not a folder.", id));
    }
    FolderItem folderItem = (FolderItem) fileSystemItem;
    return folderItem.getChildren();
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 35 with FileSystemItem

use of org.nuxeo.drive.adapter.FileSystemItem in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method createFolder.

/*------------- Write operations ---------------*/
@Override
public FolderItem createFolder(String parentId, String name, Principal principal, boolean overwrite) {
    FileSystemItem parentFsItem = getFileSystemItemById(parentId, principal);
    if (parentFsItem == null) {
        throw new NuxeoException(String.format("Cannot create a folder in file system item with id %s because it doesn't exist.", parentId));
    }
    if (!(parentFsItem instanceof FolderItem)) {
        throw new NuxeoException(String.format("Cannot create a folder in file system item with id %s because it is not a folder but is: %s", parentId, parentFsItem));
    }
    FolderItem parentFolder = (FolderItem) parentFsItem;
    return parentFolder.createFolder(name, overwrite);
}
Also used : FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Aggregations

FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)48 FolderItem (org.nuxeo.drive.adapter.FolderItem)24 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)22 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)12 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)12 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)10 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)9 Blob (org.nuxeo.ecm.core.api.Blob)8 FileItem (org.nuxeo.drive.adapter.FileItem)7 IdRef (org.nuxeo.ecm.core.api.IdRef)7 FileSystemItemFactory (org.nuxeo.drive.service.FileSystemItemFactory)6 FileSystemItemAdapterServiceImpl (org.nuxeo.drive.service.impl.FileSystemItemAdapterServiceImpl)6 RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)5 ScrollFileSystemItemList (org.nuxeo.drive.adapter.ScrollFileSystemItemList)5 FileSystemItemManager (org.nuxeo.drive.service.FileSystemItemManager)5 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)5 DefaultFileSystemItemFactory (org.nuxeo.drive.service.impl.DefaultFileSystemItemFactory)5 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)5 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)4