Skip to content
Snippets Groups Projects
Commit efb24c61 authored by Harsha Kethineni's avatar Harsha Kethineni
Browse files

added acquisition and analysis level filtering

parent 95316aef
No related branches found
No related tags found
No related merge requests found
......@@ -344,7 +344,7 @@ class Download(base.RequestHandler):
'acquisitions': {'session': {'$in': session_ids}},
'analyses': {'parent.id': {'$in': parent_ids}}
}
if level == 'sessions':
elif level == 'sessions':
# Grab acquisitions and their ids
acquisitions = config.db.acquisitions.find({'session': req['_id']}, {'_id': 1})
......@@ -361,6 +361,15 @@ class Download(base.RequestHandler):
'analyses': {'parent.id': {'$in': parent_ids}}
}
containers = containers[1:]
elif level == 'acquisitions':
cont_query['acquisitions'] = {'_id': req['_id']}
containers = ['acquisitions']
elif level == 'analyses':
cont_query['analyses'] = {'_id': req['_id']}
containers = containers[-1:]
else:
self.abort(400, "{} not a recognized level".format(level))
res = {}
for cont_name in containers:
......@@ -382,7 +391,7 @@ class Download(base.RequestHandler):
try:
result = config.db.command('aggregate', cont_name, pipeline=pipeline)
except Exception as e: # pylint: disable=broad-except
return e
self.abort(500, str(e))
if result.get("ok"):
for doc in result.get("result"):
......
......@@ -434,3 +434,12 @@ def test_summary(data_builder, as_admin, file_form):
assert r.ok
assert len(r.json()) == 1
assert r.json().get("csv", {}).get("count",0) == 2
r = as_admin.post('/download/summary', json={"level":"acquisitions", "_id":acquisition})
assert r.ok
assert len(r.json()) == 1
assert r.json().get("csv", {}).get("count",0) == 1
r = as_admin.post('/download/summary', json={"level":"groups", "_id":missing_object_id})
assert r.status_code == 400
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment