def _process_file_descriptions(obj, eng): d = Deposition(obj) try: draft = d.get_draft("_files") except DraftDoesNotExists: return # draft_files = draft.values.get('file_description', []) for f in d.files: for df in draft.values.get('file_description', []): if f.uuid == df.get('file_id', None): f.description = df.get('description', '') d.update()
def _merge_record(obj, eng): d = Deposition(obj) sip = d.get_latest_sip(sealed=False) # Get the current record, which contains all fields. current_record = get_record( sip.metadata.get('recid'), reset_cache=True ) form_class = d.get_draft(draft_id).form_class # Create a simplified record from the current record, that only # contains fields concerning this deposition. current_simple_record = deposition_record( current_record, [form_class], pre_process_load=pre_process_load, post_process_load=post_process_load, process_export=partial(process_export, d), ) # Create a simplified record from the changes the user have made. changed_simple_record = make_record(sip.metadata, is_dump=True) # Make an initial patch of current record (e.g. some default values set # by the form, might not exists in the current record) for k in current_simple_record: if k not in current_record: current_record[k] = current_simple_record[k] # Export clean dumps current_simple_json = current_simple_record.dumps(clean=True) changed_simple_json = changed_simple_record.dumps(clean=True) current_full_json = current_record.dumps(clean=True) # Merge changes from changed record into the current record. sip.metadata = merge_func( d, current_full_json, current_simple_json, changed_simple_json, ) # Ensure we are based on latest version_id to prevent being rejected in # the bibupload queue. hst_record = HstRECORD.query.filter_by( id_bibrec=sip.metadata.get('recid') ).order_by(HstRECORD.job_date.desc()).first() sip.metadata['modification_date'] = hst_record.job_date.isoformat() d.update()
def skip_files(obj, eng): if has_doi(obj, eng): return True d = Deposition(obj) try: draft = d.get_draft("_metadata") if draft.values.get('upload_type', '') == 'dataset': if int(draft.values.get('instrument', -1)) != -1: current_app.logger.debug(draft.values) return True except (DraftDoesNotExists, ValueError): # this should never happen pass return False