Skip to content
Snippets Groups Projects
Commit 6e483c08 authored by Megan Henning's avatar Megan Henning
Browse files

Add analysis file suggestion

parent 1021ead1
No related branches found
No related tags found
No related merge requests found
......@@ -24,10 +24,9 @@ class ContainerStorage(object):
self.dbc = config.db[cont_name]
def get_container(self, _id, projection=None, get_children=False):
cont = self._get_el(_id, projection)
cont = self._get_el(_id, projection=projection)
if get_children:
# TODO: This needs to exist in one place, not several
child_map = {
'groups': 'projects',
'projects': 'sessions',
......@@ -38,8 +37,10 @@ class ContainerStorage(object):
if not child_name:
raise ValueError('Children can only be listed from group, project or session level')
else:
query = {cont_name: _id}
ContainerStorage(child_name, True)._get_all_el(query, projection)
query = {self.cont_name[:-1]: bson.objectid.ObjectId(_id)}
cont[child_name] = ContainerStorage(child_name, True).exec_op('GET', query=query, projection=projection)
return cont
def exec_op(self, action, _id=None, payload=None, query=None, user=None,
......@@ -137,18 +138,3 @@ class GroupStorage(ContainerStorage):
'$setOnInsert': {'roles': roles}
},
upsert=True)
def inflate_container(cr):
"""
Given a container reference, inflate its hierarchy into a map.
Eeventually, this might want to deduplicate with logic in hierarchy.py.
"""
if cr.type != 'session':
raise Exception('Only sessions are supported for inflation right now')
oid = bson.ObjectId(cr.id)
root = ContainerStorage('sessions', True).exec_op('GET', oid, projection={'permissions': 0})
root['acquisitions'] = ContainerStorage('acquisitions', True).exec_op('GET', query={'session': oid}, projection={'permissions': 0})
return root
......@@ -72,21 +72,6 @@ def get_container(cont_name, _id):
'_id': _id,
})
def get_children(cont_name, _id, projection=None):
"""
Given a container name and id, return all children of that object in the hierarchy
"""
cid = bson.ObjectId(_id)
if cont_name == 'session':
return config.db.acquisitions.find({'session': cid}, projection)
elif cont_name == 'project':
return config.db.sessions.find({'project': cid}, projection)
elif cont_name == 'group':
# groups do not use ObjectIds
return config.db.projects.find({'group':_id}, projection)
else:
raise ValueError('Children can only be listed from group, project or session level')
def propagate_changes(cont_name, _id, query, update):
"""
Propagates changes down the heirarchy tree.
......
......@@ -7,7 +7,7 @@ from .. import util
from .. import config
from .. import validators
from ..auth import containerauth, always_ok
from ..dao import APIStorageException, containerstorage, containerutil, noop, hierarchy
from ..dao import APIStorageException, containerstorage, containerutil, noop
from ..dao.liststorage import AnalysesStorage
from ..types import Origin
from ..jobs.queue import Queue
......@@ -229,11 +229,11 @@ class ContainerHandler(base.RequestHandler):
if cont_name != 'sessions':
self.abort(400, 'Can only request jobs at the session level.')
c = self._get_container(cid)
permchecker = self._get_permchecker(c)
cont = self._get_container(cid, projection={'permissions': 0}, get_children=True)
permchecker = self._get_permchecker(cont)
permchecker(noop)('GET', cid)
children = hierarchy.get_children('session', cid)
children = cont.get('acquisitions')
id_array = [str(c['_id']) for c in children]
cont_array = [containerutil.ContainerReference('acquisition', cid) for cid in id_array]
......@@ -502,9 +502,9 @@ class ContainerHandler(base.RequestHandler):
parent_container = None
return parent_container, parent_id_property
def _get_container(self, _id):
def _get_container(self, _id, projection=None, get_children=False):
try:
container = self.storage.get_container(_id)
container = self.storage.get_container(_id, projection=projection, get_children=get_children)
except APIStorageException as e:
self.abort(400, e.message)
if container is not None:
......
......@@ -71,12 +71,21 @@ def suggest_container(gear, cont_name, cid):
schemas[x] = Draft4Validator(schema)
# It would be nice to have use a visitor here instead of manual key loops.
for acq in root['acquisitions']:
for acq in root.get('acquisitions', []):
for f in acq.get('files', []):
f['suggested'] = {}
for x in schemas:
f['suggested'][x] = schemas[x].is_valid(f)
for analysis in root.get('analyses',{}):
files = analysis.get('files', [])
files[:] = [x for x in files if x.get('output')]
for f in files:
f['suggested'] = {}
for x in schemas:
f['suggested'][x] = schemas[x].is_valid(f)
analysis['files'] = files
return root
def insert_gear(doc):
......
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