Search in sources :

Example 6 with DocumentModel

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

the class RootResource method findResource.

@Path("{path:.+}")
public Object findResource(@PathParam("path") String path) {
    try {
        path = new String(path.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new NuxeoException(e);
    }
    Backend backend = BackendHelper.getBackend(path, request);
    if (backend == null) {
        throw new WebApplicationException(Response.Status.NOT_FOUND);
    }
    if (backend.isVirtual()) {
        return new VirtualFolderResource(path, request, backend.getVirtualFolderNames());
    }
    DocumentModel doc = null;
    try {
        doc = backend.getDocument(path);
    } catch (DocumentNotFoundException e) {
        log.error("Error during resolving path: " + path, e);
        throw new WebApplicationException(Response.Status.CONFLICT);
    }
    if (doc == null) {
        return new UnknownResource(path, request, backend);
    }
    // Send 401 error if not authorised to read.
    if (!backend.hasPermission(doc.getRef(), SecurityConstants.READ)) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    if (doc.isFolder()) {
        return new FolderResource(getDocumentPath(doc), doc, request, backend);
    } else {
        return new FileResource(getDocumentPath(doc), doc, request, backend);
    }
}
Also used : Backend(org.nuxeo.ecm.webdav.backend.Backend) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Path(javax.ws.rs.Path)

Example 7 with DocumentModel

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

the class PathCache method get.

public DocumentModel get(String path) {
    Value value = pathToUuidCache.get(path);
    if (value == null) {
        return null;
    }
    if (value.getExpiredTime() < System.currentTimeMillis()) {
        pathToUuidCache.remove(path);
        return null;
    }
    String uuid = value.getValue();
    DocumentModel model = null;
    try {
        model = session.getDocument(new IdRef(uuid));
    } catch (DocumentNotFoundException e) {
    // do nothing
    }
    if (model == null) {
        pathToUuidCache.remove(path);
    }
    return model;
}
Also used : DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 8 with DocumentModel

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

the class SimpleBackend method getChildren.

@Override
public List<DocumentModel> getChildren(DocumentRef ref) {
    List<DocumentModel> result = new ArrayList<DocumentModel>();
    List<DocumentModel> children = getSession(true).getChildren(ref);
    for (DocumentModel child : children) {
        if (child.hasFacet(FacetNames.HIDDEN_IN_NAVIGATION)) {
            continue;
        }
        if (child.isTrashed()) {
            continue;
        }
        if (!child.hasSchema("dublincore")) {
            continue;
        }
        if (child.hasFacet(FacetNames.FOLDERISH) || child.getAdapter(BlobHolder.class) != null) {
            result.add(child);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 9 with DocumentModel

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

the class SimpleBackend method createFolder.

@Override
public DocumentModel createFolder(String parentPath, String name) {
    DocumentModel parent = resolveLocation(parentPath);
    if (!parent.isFolder()) {
        throw new NuxeoException("Can not create a child in a non folderish node");
    }
    String targetType = "Folder";
    if ("WorkspaceRoot".equals(parent.getType())) {
        targetType = "Workspace";
    }
    // name = cleanName(name);
    cleanTrashPath(parent, name);
    DocumentModel folder = getSession().createDocumentModel(parent.getPathAsString(), name, targetType);
    folder.setPropertyValue("dc:title", name);
    folder = getSession().createDocument(folder);
    getPathCache().put(parseLocation(parentPath) + "/" + name, folder);
    return folder;
}
Also used : NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 10 with DocumentModel

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

the class SimpleBackend method removeItem.

@Override
public void removeItem(DocumentRef ref) {
    DocumentModel doc = getSession().getDocument(ref);
    if (doc != null) {
        getTrashService().trashDocuments(Arrays.asList(doc));
        getPathCache().remove(doc.getPathAsString());
    } else {
        log.warn("Can't move document " + ref.toString() + " to trash. Document did not found.");
    }
}
Also used : DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)128 Test (org.junit.Test)58 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)26 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)25 FileSystemItemChange (org.nuxeo.drive.service.FileSystemItemChange)24 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)22 PathRef (org.nuxeo.ecm.core.api.PathRef)21 IdRef (org.nuxeo.ecm.core.api.IdRef)18 HashSet (java.util.HashSet)17 Blob (org.nuxeo.ecm.core.api.Blob)17 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)17 ArrayList (java.util.ArrayList)16 FolderItem (org.nuxeo.drive.adapter.FolderItem)14 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)11 Principal (java.security.Principal)10 ACE (org.nuxeo.ecm.core.api.security.ACE)10 NuxeoDriveManager (org.nuxeo.drive.service.NuxeoDriveManager)9 FileItem (org.nuxeo.drive.adapter.FileItem)8 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)8 HashMap (java.util.HashMap)7