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

Add mock endpoints for suggest

parent 86da1841
No related branches found
No related tags found
No related merge requests found
......@@ -17,10 +17,26 @@ SINGULAR_TO_PLURAL = {
'job': 'jobs',
'project': 'projects',
'session': 'sessions',
'subject': 'subjects',
'user': 'users',
}
PLURAL_TO_SINGULAR = {p: s for s, p in SINGULAR_TO_PLURAL.iteritems()}
# NOTE: Following structures have subject as a hierarhcy level although
# it is not yet a formalized level of the hierarchy throughout API
CONTAINER_HIERARCHY = [
'groups',
'projects',
'subjects',
'sessions',
'acquisitions'
]
# Generate {child: parent} and {parent: child} maps from ordered hierarchy list
CHILD_FROM_PARENT = {p: CONTAINER_HIERARCHY[ind+1] for ind, p in enumerate(CONTAINER_HIERARCHY[:-1] )}
PARENT_FROM_CHILD = {c: CONTAINER_HIERARCHY[ind] for ind, c in enumerate(CONTAINER_HIERARCHY[1:] )}
def propagate_changes(cont_name, cont_ids, query, update, include_refs=False):
"""
......
import bson
import datetime
import dateutil
from random import randint
from .. import config
from .. import util
......@@ -570,6 +571,57 @@ class ContainerHandler(base.RequestHandler):
else:
self.abort(404, 'Element not removed from container {} {}'.format(self.storage.cont_name, _id))
# def tree(self, cont_name, cid, **kwargs):
# """
# Given a container reference, return display information about parents, children and files.
# Container types acceptable for reference:
# - Groups
# - Projects
# - Subjects
# - Sessions
# - Acquisitions
# - Analyses
# NOTE: Access via this endpoint is not logged. Only information necessary for display should be returned.
# NOTE: Subject level is supported ahead of official separation in DB and API routes.
# """
# ## Mocked returns for development
# response = {
# 'cont_type': cont_name,
# '_id': cid,
# 'label': '{} {}'.format(containerutil.singularize(cont_name), cid),
# 'parents': []
# 'files': [{'name': 'file_'+i+'.zip'} for i in range(rantint(0,5))],
# 'children': {}
# }
# if containerutil.singularize(cont_name) in containerutil.CHILD_FROM_PARENT:
# child_cont = containerutil.CHILD_FROM_PARENT[cont_name]
# s_child_cont = containerutil.singularize(child_cont)
# response['children'][child_cont] = [{'cont_name': s_child_cont, '_id': ''+i, 'label': s_child_cont+' '+i} for i in range(rantint(0,5))]
# parent_cont = None
# if cont_type == 'analyses':
# parent_cont = 'sessions'
# else:
# response['children']['analyses'] = 'analyses': [{'cont_name': 'analysis', '_id': ''+i, 'label': 'analysis '+i} for i in range(rantint(0,5))]
# parent_cont = containerutil.PARENT_FROM_CHILD.get(cont_name)
# while parent_cont:
# response['parents'].append({'cont_type': parent_cont, '_id': 1, 'label': '{} {}'.format(containerutil.singularize(parent_name), 1)})
# parent_cont = containerutil.PARENT_FROM_CHILD.get(parent_cont)
# return response
def get_groups_with_project(self):
"""
method to return the list of groups for which there are projects accessible to the user
......
......@@ -7,6 +7,7 @@ import os
import StringIO
from jsonschema import ValidationError
from urlparse import urlparse
from random import randint
from . import batch
from .. import config
......@@ -16,9 +17,9 @@ from ..auth import require_drone, require_login, require_admin, has_access
from ..auth.apikeys import JobApiKey
from ..dao import hierarchy
from ..dao.containerstorage import ProjectStorage, SessionStorage, AcquisitionStorage
from ..dao.containerutil import ContainerReference, pluralize
from ..util import humanize_validation_error, set_for_download
from ..validators import validate_data, verify_payload_exists
from ..dao.containerutil import ContainerReference, pluralize, singularize, CHILD_FROM_PARENT, PARENT_FROM_CHILD
from ..web import base
from ..web.encoder import pseudo_consistent_json_encode
from ..web.errors import APIPermissionException, APINotFoundException, InputValidationException
......@@ -67,12 +68,58 @@ class GearHandler(base.RequestHandler):
@require_login
def suggest(self, _id, cont_name, cid):
cr = ContainerReference(cont_name, cid)
if not self.superuser_request:
cr.check_access(self.uid, 'ro')
"""
Given a container reference, return display information about parents, children and files
as well as information about which best match each gear input
Container types acceptable for reference:
- Groups
- Projects
- Subjects
- Sessions
- Acquisitions
- Analyses
NOTE: Access via this endpoint is not logged. Only information necessary for display should be returned.
NOTE: Subject level is supported ahead of official separation in DB and API routes.
"""
## Mocked returns for development
response = {
'cont_type': cont_name,
'_id': cid,
'label': '{} {}'.format(singularize(cont_name), cid),
'parents': [],
'files': [{'name': 'file_{}.zip'.format(i)} for i in range(randint(0,5))],
'children': []
}
if cont_name in CHILD_FROM_PARENT:
child_cont = CHILD_FROM_PARENT[cont_name]
s_child_cont = singularize(child_cont)
response['children'].extend([{'cont_type': child_cont, '_id': ''+str(i), 'label': s_child_cont+' '+str(i)} for i in range(randint(1,5))])
parent_cont = None
if cont_name == 'analyses':
parent_cont = 'sessions'
else:
response['children'].extend([{'cont_type': 'analyses', '_id': str(i), 'label': 'analysis '+str(i)} for i in range(randint(0,5))])
parent_cont = PARENT_FROM_CHILD.get(cont_name)
while parent_cont:
response['parents'].append({'cont_type': parent_cont, '_id': 1, 'label': '{} {}'.format(singularize(parent_cont), 1)})
parent_cont = PARENT_FROM_CHILD.get(parent_cont)
gear = get_gear(_id)
return suggest_container(gear, cont_name+'s', cid)
for f in response['files']:
f['suggested'] = {}
for i in gear['gear'].get('inputs', {}).iterkeys():
f['suggested'][i] = bool(randint(0,1))
return response
@require_admin
def upload(self): # pragma: no cover
......
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