diff --git a/idr_gallery/urls.py b/idr_gallery/urls.py index 100b2457..082240ed 100644 --- a/idr_gallery/urls.py +++ b/idr_gallery/urls.py @@ -22,6 +22,10 @@ re_path(r'^gallery-api/thumbnails/$', views.api_thumbnails, name='idr_gallery_api_thumbnails'), + # Find annotations by namespace ?ns=idr.gallery.etc + path("gallery_api/annotations/", views.api_annotations, + name='idr_gallery_annotations'), + # handle mapr URLs and redirect to search e.g. /mapr/gene/?value=PAX7 # First URL is matched by mapr itself, so not used while mapr istalled... # we want a regex that matches mapr_key but not favicon diff --git a/idr_gallery/views.py b/idr_gallery/views.py index c5af00be..2e81744f 100644 --- a/idr_gallery/views.py +++ b/idr_gallery/views.py @@ -14,7 +14,7 @@ from omeroweb.webclient.decorators import login_required, render_response from omeroweb.api.decorators import login_required as api_login_required from omeroweb.api.api_settings import API_MAX_LIMIT -from omeroweb.webclient.tree import marshal_annotations +from omeroweb.webclient.tree import marshal_annotations, _marshal_annotation import requests @@ -519,6 +519,39 @@ def api_thumbnails(request, conn=None, **kwargs): return rv +@render_response() +@api_login_required() # 403 JsonResponse if not logged in +def api_annotations(request, conn=None, **kwargs): + """ + Return annotations for a given namespace e.g. + ?ns=idr.gallery.etc + """ + ns = request.GET.get("ns") + if not ns: + return HttpResponseBadRequest("Missing 'ns' query parameter") + dtypes = request.GET.getlist("type") + if len(dtypes) == 0: + return HttpResponseBadRequest("Missing e.g. ?type=project") + + query_service = conn.getQueryService() + params = omero.sys.ParametersI() + params.addString("ns", ns) + anns = [] + for dtype in dtypes: + query = """select oal from %sAnnotationLink as oal + join fetch oal.details.creationEvent + join fetch oal.details.owner + left outer join fetch oal.child as ch + left outer join fetch oal.parent as pa + join fetch ch.details.creationEvent + where ch.ns = :ns""" % dtype.capitalize() + result = query_service.findAllByQuery(query, params, conn.SERVICE_OPTS) + for link in result: + if link.child is not None and link.parent is not None: + anns.append(_marshal_annotation(conn, link.child, link)) + return {"annotations": anns} + + def get_bff_url(request, data_url, fname, ext="csv"): """ We build config into query params for the BFF app