Search in sources :

Example 1 with FileManager

use of org.nuxeo.ecm.platform.filemanager.api.FileManager in project nuxeo-filesystem-connectors by nuxeo.

the class SimpleBackend method updateDocument.

@Override
public DocumentModel updateDocument(DocumentModel doc, String name, Blob content) {
    FileManager fileManager = Framework.getService(FileManager.class);
    String parentPath = new Path(doc.getPathAsString()).removeLastSegments(1).toString();
    try {
        // this cannot be done before the update anymore
        // doc.putContextData(SOURCE_EDIT_KEYWORD, "webdav");
        // overwrite=true
        doc = fileManager.createDocumentFromBlob(getSession(), content, parentPath, true, name);
    } catch (IOException e) {
        throw new NuxeoException("Error while updating document", e);
    }
    return doc;
}
Also used : Path(org.nuxeo.common.utils.Path) IOException(java.io.IOException) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) FileManager(org.nuxeo.ecm.platform.filemanager.api.FileManager)

Example 2 with FileManager

use of org.nuxeo.ecm.platform.filemanager.api.FileManager in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveCreateTestDocuments method run.

@OperationMethod
public Blob run(DocumentModel parent) throws Exception {
    NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
    FileManager fileManager = Framework.getService(FileManager.class);
    for (int i = 0; i < number; i++) {
        String name = String.format(namePattern, i);
        Blob content = new StringBlob(String.format(contentPattern, i));
        content.setFilename(name);
        fileManager.createDocumentFromBlob(session, content, parent.getPathAsString(), false, name);
        if (delay > 0) {
            Thread.sleep(delay);
        }
    }
    return new StringBlob(number.toString(), "text/plain");
}
Also used : StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) Blob(org.nuxeo.ecm.core.api.Blob) StringBlob(org.nuxeo.ecm.core.api.impl.blob.StringBlob) FileManager(org.nuxeo.ecm.platform.filemanager.api.FileManager) OperationMethod(org.nuxeo.ecm.automation.core.annotations.OperationMethod)

Example 3 with FileManager

use of org.nuxeo.ecm.platform.filemanager.api.FileManager 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

FileManager (org.nuxeo.ecm.platform.filemanager.api.FileManager)3 IOException (java.io.IOException)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 Path (org.nuxeo.common.utils.Path)1 OperationMethod (org.nuxeo.ecm.automation.core.annotations.OperationMethod)1 Blob (org.nuxeo.ecm.core.api.Blob)1 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)1 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)1 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)1