Search in sources :

Example 31 with NuxeoException

use of org.nuxeo.ecm.core.api.NuxeoException in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method createFile.

@Override
public DocumentModel createFile(String parentPath, String name, Blob content) {
    DocumentModel parent = resolveLocation(parentPath);
    if (!parent.isFolder()) {
        throw new NuxeoException("Can not create a child in a non folderish node");
    }
    try {
        cleanTrashPath(parent, name);
        DocumentModel file;
        if (Framework.isBooleanPropertyTrue(ALWAYS_CREATE_FILE_PROP)) {
            // compat for older versions, always create a File
            file = getSession().createDocumentModel(parent.getPathAsString(), name, "File");
            file.setPropertyValue("dc:title", name);
            if (content != null) {
                BlobHolder bh = file.getAdapter(BlobHolder.class);
                if (bh != null) {
                    bh.setBlob(content);
                }
            }
            file = getSession().createDocument(file);
        } else {
            // use the FileManager to create the file
            FileManager fileManager = Framework.getService(FileManager.class);
            file = fileManager.createDocumentFromBlob(getSession(), content, parent.getPathAsString(), false, name);
        }
        getPathCache().put(parseLocation(parentPath) + "/" + name, file);
        return file;
    } catch (IOException e) {
        throw new NuxeoException("Error child creating new folder", e);
    }
}
Also used : BlobHolder(org.nuxeo.ecm.core.api.blobholder.BlobHolder) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) IOException(java.io.IOException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) FileManager(org.nuxeo.ecm.platform.filemanager.api.FileManager)

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