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);
}
}
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;
}
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;
}
}
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;
}
}
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;
}
Aggregations