Search in sources :

Example 1 with DocumentNotFoundException

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

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

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

the class AbstractFileSystemItemFactory method getFileSystemItemById.

@Override
public FileSystemItem getFileSystemItemById(String id, String parentId, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        FileSystemItem parentItem = Framework.getService(FileSystemItemAdapterService.class).getFileSystemItemFactoryForId(parentId).getFileSystemItemById(parentId, principal);
        if (!(parentItem instanceof FolderItem)) {
            throw new NuxeoException(String.format("FileSystemItem with id %s should be a FolderItem", parentId));
        }
        DocumentModel doc = getDocumentById(docId, session);
        return getFileSystemItem(doc, (FolderItem) parentItem);
    } catch (DocumentNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No doc related to id %s, returning null.", docId));
        }
        return null;
    } catch (DocumentSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("User %s cannot access doc %s, returning null.", principal.getName(), docId));
        }
        return null;
    }
}
Also used : AbstractFileSystemItem(org.nuxeo.drive.adapter.impl.AbstractFileSystemItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 4 with DocumentNotFoundException

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

the class AbstractFileSystemItemFactory method exists.

/**
 * The default factory considers that a {@link FileSystemItem} with the given id exists if the backing
 * {@link DocumentModel} can be fetched and {@link #isFileSystemItem(DocumentModel)} returns true.
 *
 * @see #isFileSystemItem(DocumentModel)
 */
@Override
public boolean exists(String id, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        DocumentModel doc = getDocumentById(docId, session);
        return isFileSystemItem(doc);
    } catch (DocumentNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No doc related to id %s, returning false.", docId));
        }
        return false;
    } catch (DocumentSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("User %s cannot access doc %s, returning false.", principal.getName(), docId));
        }
        return false;
    }
}
Also used : DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 5 with DocumentNotFoundException

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

the class NuxeoDriveManagerImpl method queryAndFetchSynchronizationRoots.

protected Map<String, SynchronizationRoots> queryAndFetchSynchronizationRoots(CoreSession session, String query) {
    Map<String, SynchronizationRoots> syncRoots = new HashMap<String, SynchronizationRoots>();
    Set<IdRef> references = new LinkedHashSet<IdRef>();
    Set<String> paths = new LinkedHashSet<String>();
    IterableQueryResult results = session.queryAndFetch(query, NXQL.NXQL);
    try {
        for (Map<String, Serializable> result : results) {
            IdRef docRef = new IdRef(result.get("ecm:uuid").toString());
            try {
                DocumentModel doc = session.getDocument(docRef);
                references.add(docRef);
                paths.add(doc.getPathAsString());
            } catch (DocumentNotFoundException e) {
                log.warn(String.format("Document %s not found, not adding it to the list of synchronization roots for user %s.", docRef, session.getPrincipal().getName()));
            } catch (DocumentSecurityException e) {
                log.warn(String.format("User %s cannot access document %s, not adding it to the list of synchronization roots.", session.getPrincipal().getName(), docRef));
            }
        }
    } finally {
        results.close();
    }
    SynchronizationRoots repoSyncRoots = new SynchronizationRoots(session.getRepositoryName(), paths, references);
    syncRoots.put(session.getRepositoryName(), repoSyncRoots);
    return syncRoots;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) HashMap(java.util.HashMap) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) IterableQueryResult(org.nuxeo.ecm.core.api.IterableQueryResult)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)6 DocumentNotFoundException (org.nuxeo.ecm.core.api.DocumentNotFoundException)6 DocumentSecurityException (org.nuxeo.ecm.core.api.DocumentSecurityException)3 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)2 IdRef (org.nuxeo.ecm.core.api.IdRef)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 Serializable (java.io.Serializable)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Test (org.junit.Test)1 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)1 FolderItem (org.nuxeo.drive.adapter.FolderItem)1 AbstractFileSystemItem (org.nuxeo.drive.adapter.impl.AbstractFileSystemItem)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 Session (org.nuxeo.ecm.automation.client.Session)1 Blob (org.nuxeo.ecm.automation.client.model.Blob)1 CoreSession (org.nuxeo.ecm.core.api.CoreSession)1