Search in sources :

Example 21 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException 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 22 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException 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 23 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-drive-server by nuxeo.

the class FileSystemItemManagerImpl method updateFile.

protected FileItem updateFile(FileSystemItem fsItem, Blob blob) {
    if (fsItem == null) {
        throw new NuxeoException("Cannot update the content of file system item because it doesn't exist.");
    }
    if (!(fsItem instanceof FileItem)) {
        throw new NuxeoException(String.format("Cannot update the content of file system item with id %s because it is not a file.", fsItem.getId()));
    }
    FileItem file = (FileItem) fsItem;
    file.setBlob(blob);
    return file;
}
Also used : FileItem(org.nuxeo.drive.adapter.FileItem) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException)

Example 24 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException 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 25 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException 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

NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)31 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)11 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)9 IOException (java.io.IOException)5 Blob (org.nuxeo.ecm.core.api.Blob)5 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)5 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)4 Principal (java.security.Principal)3 DefaultSyncRootFolderItem (org.nuxeo.drive.adapter.impl.DefaultSyncRootFolderItem)3 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Path (org.nuxeo.common.utils.Path)2