From 0823f141b0bfb0d74a960625c2d344ee615abf18 Mon Sep 17 00:00:00 2001 From: Renzo Frigato Date: Mon, 29 Feb 2016 14:49:30 -0800 Subject: [PATCH] allow shallow hierarchy on /uploader --- api/dao/reaperutil.py | 18 ++++++++++++++---- api/schemas/input/uploader.json | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/dao/reaperutil.py b/api/dao/reaperutil.py index 2b1394867..54c3f24c5 100644 --- a/api/dao/reaperutil.py +++ b/api/dao/reaperutil.py @@ -177,17 +177,21 @@ def create_root_to_leaf_hierarchy(metadata, files): group = metadata['group'] project = metadata['project'] - session = metadata['session'] - acquisition = metadata['acquisition'] + session = metadata.get('session') + acquisition = metadata.get('acquisition') now = datetime.datetime.utcnow() group_obj = config.db.groups.find_one({'_id': group['_id']}) if not group_obj: raise APIStorageException('group does not exist') - project['modified'] = session['modified'] = acquisition['modified'] = now + project['modified'] = now project_files = merge_fileinfos(files, project.pop('files', [])) - project_obj = config.db.projects.find_one_and_update({'label': project['label']}, + project_obj = config.db.projects.find_one_and_update( + { + 'label': project['label'], + 'group': group['_id'] + }, { '$setOnInsert': dict( group=group_obj['_id'], @@ -203,6 +207,9 @@ def create_root_to_leaf_hierarchy(metadata, files): target_containers.append( (TargetContainer(project_obj, 'projects'), project_files) ) + if not session: + return target_containers + session['modified'] = now session_files = merge_fileinfos(files, session.pop('files', [])) session_operations = { '$setOnInsert': dict( @@ -226,6 +233,9 @@ def create_root_to_leaf_hierarchy(metadata, files): target_containers.append( (TargetContainer(session_obj, 'sessions'), session_files) ) + if not acquisition: + return target_containers + acquisition['modified'] = now acquisition_files = merge_fileinfos(files, acquisition.pop('files', [])) acq_operations = { '$setOnInsert': dict( diff --git a/api/schemas/input/uploader.json b/api/schemas/input/uploader.json index eb31e6b58..b40e0f944 100644 --- a/api/schemas/input/uploader.json +++ b/api/schemas/input/uploader.json @@ -64,6 +64,6 @@ "required": ["label"] } }, - "required": ["acquisition", "group", "project", "session"], + "required": ["group", "project"], "additionalProperties": false }