def reserve_recid(record, *args, **kwargs): """Reserve a new record id for the record and set it inside.""" if record.get('recid', None) is None: pid = PersistentIdentifier.create('recid', pid_value=None, pid_provider='invenio') pid.reserve() record['recid'] = int(pid.pid_value)
def _mint_pid(obj, dummy_eng): d = Deposition(obj) recjson = d.get_latest_sip(sealed=False).metadata if 'recid' not in recjson: raise Exception("'recid' not found in sip metadata.") pid_text = None pid = recjson.get(pid_field, None) if not pid: # No pid found in recjson, so create new pid with user supplied # function. pid_text = recjson[pid_field] = pid_creator(recjson) else: # Pid found - check if it should be minted if existing_pid_checker and existing_pid_checker(pid, recjson): pid_text = pid # Create an assign pid internally - actually registration will happen # asynchronously later. if pid_text: current_app.logger.info("Registering pid %s" % pid_text) pid_obj = PersistentIdentifier.create(pid_store_type, pid_text) if pid_obj is None: pid_obj = PersistentIdentifier.get(pid_store_type, pid_text) try: pid_obj.assign("rec", recjson['recid']) except Exception: register_exception(alert_admin=True) d.update()
def _mint_pid(obj, dummy_eng): d = Deposition(obj) recjson = d.get_latest_sip(sealed=False).metadata if 'recid' not in recjson: raise Exception("'recid' not found in sip metadata.") pid_text = None pid = recjson.get(pid_field, None) if not pid: # No pid found in recjson, so create new pid with user supplied # function. pid_text = recjson[pid_field] = pid_creator(recjson) else: # Pid found - check if it should be minted if existing_pid_checker and existing_pid_checker(pid, recjson): pid_text = pid # Create an assign pid internally - actually registration will happen # asynchronously later. if pid_text: current_app.logger.info("Registering pid %s" % pid_text) pid_obj = PersistentIdentifier.create(pid_store_type, pid_text) if pid_obj is None: pid_obj = PersistentIdentifier.get(pid_store_type, pid_text) try: pid_obj.assign("rec", recjson['recid']) except Exception: register_exception(alert_admin=True) d.update()
def reserve_recid(record, *args, **kwargs): """Reserve a new record id for the record and set it inside.""" if record.get('recid', None) is None: pid = PersistentIdentifier.create('recid', pid_value=None, pid_provider='invenio') pid.reserve() record['recid'] = int(pid.pid_value)
def setUp(self): self.app.config['CFG_DATACITE_URL'] = 'https://mds.example.org/' self.app.config['CFG_DATACITE_USERNAME'] = '******' self.app.config['CFG_DATACITE_PASSWORD'] = '******' self.app.config['CFG_DATACITE_DOI_PREFIX'] = "10.1234" from invenio.modules.pidstore.models import PersistentIdentifier self.pid = PersistentIdentifier.create("doi", "10.1234/invenio.1234") if not self.pid: raise RuntimeError("Dirty database state.")
def setUp(self): self.app.config['CFG_DATACITE_URL'] = 'https://mds.example.org/' self.app.config['CFG_DATACITE_USERNAME'] = '******' self.app.config['CFG_DATACITE_PASSWORD'] = '******' self.app.config['CFG_DATACITE_DOI_PREFIX'] = "10.1234" from invenio.modules.pidstore.models import PersistentIdentifier self.pid = PersistentIdentifier.create("doi", "10.1234/invenio.1234") if not self.pid: raise RuntimeError("Dirty database state.")
def _reserve_record_id(obj, eng): record = obj[1] eng.log.info('Reserve a recid for the new record') try: pid = PersistentIdentifier.create('recid', pid_value=None, pid_provider='invenio') record['recid'] = int(pid.pid_value) pid.reserve() eng.log.info("Finish reserving a recid '%s' for the new record", (pid.pid_value, )) except Exception as e: raise UploaderWorkflowException(step, e.message)
def _reserve_record_id(obj, eng): record = obj[1] eng.log.info('Reserve a recid for the new record') try: pid = PersistentIdentifier.create('recid', pid_value=None, pid_provider='invenio') record['recid'] = int(pid.pid_value) pid.reserve() eng.log.info("Finish reserving a recid '%s' for the new record", (pid.pid_value, )) except Exception as e: raise UploaderWorkflowException(step, e.message)
def update_pidstore(record, *args, **kwargs): """Save each PID present in the record to the PID storage.""" if not hasattr(record, 'persistent_identifiers'): return for pid_name, pid_values in record.persistent_identifiers: for pid_value in pid_values: pid = PersistentIdentifier.get( pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if pid is None: pid = PersistentIdentifier.create( pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if not pid.has_object('rec', record['recid']): pid.assign('rec', record['recid'])
def update_pidstore(record, *args, **kwargs): """Save each PID present in the record to the PID storage.""" if not hasattr(record, 'persistent_identifiers'): return for pid_name, pid_values in record.persistent_identifiers: for pid_value in pid_values: pid = PersistentIdentifier.get(pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if pid is None: pid = PersistentIdentifier.create(pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if not pid.has_object('rec', record['recid']): pid.assign('rec', record['recid'])
def doi_action(record): if record.get('doi', None) is not None: return json_error(400, 'Record already has a DOI.') recid = record['recid'] doi = build_doi(recid) current_app.logger.info("Registering pid %s" % doi) pid = PersistentIdentifier.create(DOI_PID_TYPE, doi) if pid is None: pid = PersistentIdentifier.get(DOI_PID_TYPE, doi) try: pid.assign('rec', recid) datacite_register.delay(recid) except Exception, e: register_exception(alert_admin=True) return json_error(400, '%s' % e)
def _update_pidstore(obj, eng): record = obj[1] eng.log.info('Look for PIDs inside the current record and register ' 'them in the DB') if not hasattr(record, 'persistent_identifiers'): raise UploaderWorkflowException( step, msg="An 'persistent_identifiers' method is needed") eng.log.info("Found PIDs '%s'", (record.persistent_identifiers, )) for pid_name, pid_values in record.persistent_identifiers: eng.log.info("Found PID '%s'", (pid_name, )) for pid_value in pid_values: pid = PersistentIdentifier.get( pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if pid is None: pid = PersistentIdentifier.create( pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if not pid.has_object('rec', record['recid']): pid.assign('rec', record['recid']) eng.log.info('Finish looking for PIDs inside the current record and ' 'register them in the DB')
def _update_pidstore(obj, eng): record = obj[1] eng.log.info('Look for PIDs inside the current record and register ' 'them in the DB') if not hasattr(record, 'persistent_identifiers'): raise UploaderWorkflowException( step, msg="An 'persistent_identifiers' method is needed") eng.log.info("Found PIDs '%s'", (record.persistent_identifiers, )) for pid_name, pid_values in record.persistent_identifiers: eng.log.info("Found PID '%s'", (pid_name, )) for pid_value in pid_values: pid = PersistentIdentifier.get(pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if pid is None: pid = PersistentIdentifier.create( pid_value.get('type'), pid_value.get('value'), pid_value.get('provider')) if not pid.has_object('rec', record['recid']): pid.assign('rec', record['recid']) eng.log.info('Finish looking for PIDs inside the current record and ' 'register them in the DB')