def get(self, deposit_id, **kwargs): """ Get the list of files already uploaded Test this with: $ curl -v http://0.0.0.0:4000/api/deposition/DEPOSITION_ID/files?access_token=xxx should return the list of deposited files """ CFG_B2SHARE_UPLOAD_FOLDER = current_app.config.get( "CFG_B2SHARE_UPLOAD_FOLDER") deposition_status = os.path.join(CFG_B2SHARE_UPLOAD_FOLDER, deposit_id, 'uncommitted') if not os.path.exists(deposition_status): return {'message': 'Bad deposit_id parameter or already closed deposition.', 'status': 404}, 404 self.check_user(deposit_id) files = [{'name': f['name'], 'size': f['size'] } for f in get_depositing_files_metadata(deposit_id)] return {'files':files}
def post(self, deposit_id, **kwargs): """ Creates a new deposition Test this with: $ curl -v -X POST -H "Content-Type: application/json" -d '{"domain":"generic", "title":"REST Test Title", "description":"REST Test Description"}' http://0.0.0.0:4000/api/deposition/DEPOSITION_ID/commit\?access_token\=xxx """ CFG_B2SHARE_UPLOAD_FOLDER = current_app.config.get( "CFG_B2SHARE_UPLOAD_FOLDER") deposition_status = os.path.join(CFG_B2SHARE_UPLOAD_FOLDER, deposit_id, 'uncommitted') if not os.path.exists(deposition_status): return {'message': 'Bad deposit_id parameter or already closed deposition.', 'status': 404}, 404 if not get_depositing_files_metadata(deposit_id): return {'message':'No files: add files to this deposition first', 'status':400}, 400 try: form = request.get_json() except: return {'message':'Invalid POST data', 'status':400}, 400 os.remove(deposition_status) domain = form.get('domain', '').lower() if domain in metadata_classes(): metaclass = metadata_classes()[domain] meta = metaclass() else: domains = ", ".join(metadata_classes().keys()) json_data = { 'message': 'Invalid domain. The submitted metadata must '+\ 'contain a valid "domain" field. Valid domains '+\ 'are: '+ domains, 'status': 400, } return json_data, 400 if not is_current_user_allowed_to_deposit(meta): return {'message':'depositions to this domain are restricted', 'status':401}, 401 if 'open_access' not in form: return {'message':'open_access boolean field required', 'status':400}, 400 if not form['open_access'] or form['open_access'] == 'restricted': del form['open_access'] # action required by the b2share_marc_handler if not form.get('language'): form['language'] = meta.language_default form = ImmutableMultiDict(form) MetaForm = model_form(meta.__class__, base_class=FormWithKey, exclude=['submission', 'submission_type'], field_args=meta.field_args, converter=HTML5ModelConverter()) meta_form = MetaForm(form, meta, csrf_enabled=False) if meta_form.validate_on_submit(): recid, marc = create_marc(form, deposit_id, current_user['email'], meta) tmp_file = write_marc_to_temp_file(marc) # all usual tasks have priority 0; we want the bibuploads to run first from invenio.legacy.bibsched.bibtask import task_low_level_submission task_low_level_submission('bibupload', 'webdeposit', '--priority', '1', '-r', tmp_file) #TODO: remove the existing deposition folder?; the user can now # repeatedly create records with the same deposition location = "/api/record/%d" % (recid,) json_data = { 'message': "New record submitted for processing", 'location': "/api/record/%d" % (recid,), 'record_id': recid, } return json_data, 201, {'Location':location} # return location header else: fields = {} for (fname, field) in meta.field_args.iteritems(): if not field.get('hidden'): fields[fname] = { 'description' : field.get('description') } if self.is_required_field(metaclass, fname): fields[fname]['required'] = True if field.get('cardinality') == 'n': fields[fname]['multiple'] = True if field.get('data_source'): fields[fname]['options'] = field.get('data_source') json_data = { 'message': 'Invalid metadata, please review the required fields', 'status': 400, 'fields': fields, } return json_data, 400