inspirehep.modules.orcid package¶
Submodules¶
inspirehep.modules.orcid.builder module¶
Builds an ORCID work record.
-
class
inspirehep.modules.orcid.builder.
OrcidBuilder
[source]¶ Bases:
object
Class used to build ORCID-compatible work records in JSON.
-
add_citation
(_type, value)[source]¶ Add a citation string.
Parameters: - _type (string) – citation type, one of: https://git.io/vdKXv#L313-L321
- value (string) – citation string for the provided citation type
-
add_contributor
(credit_name, role='author', orcid=None, email=None)[source]¶ Adds a contributor entry to the record.
Parameters:
-
add_country
(country_code)[source]¶ Set country if the ORCID record.
Parameters: country_code (string) – ISO ALPHA-2 country code
-
add_external_id
(type, value, url=None, relationship=None)[source]¶ Add external identifier to the record.
Parameters:
-
add_journal_title
(journal_title)[source]¶ Set title of the publication containing the record.
Parameters: journal_title (string) – Title of publication containing the record.
After ORCID v2.0 schema (https://git.io/vdKXv#L268-L280): “The title of the publication or group under which the work was published. - If a journal, include the journal title of the work. - If a book chapter, use the book title. - If a translation or a manual, use the series title. - If a dictionary entry, use the dictionary title. - If a conference poster, abstract or paper, use the conference name.”
-
add_publication_date
(partial_date)[source]¶ Set publication date field.
Parameters: partial_date (inspire_utils.date.PartialDate) – publication date
-
add_title
(title, subtitle=None, translated_title=None)[source]¶ Set a title of the work, and optionaly a subtitle.
Parameters:
-
add_type
(work_type)[source]¶ Add a work type.
Parameters: work_type (string) – type of work, see: https://git.io/vdKXv#L118-L155
-
get_xml
()[source]¶ Get an XML record.
Returns: ORCID work record compatible with API v2.0 Return type: lxml.etree._Element
-
set_put_code
(put_code)[source]¶ Set the put-code of an ORCID record, to update existing one.
Parameters: put_code (string | integer) – a number, being a put code
-
set_visibility
(visibility)[source]¶ Set visibility setting on ORCID.
Can only be set during record creation.
Parameters: visibility (string) – one of (private, limited, registered-only, public), see https://git.io/vdKXt#L904-L937
-
inspirehep.modules.orcid.cache module¶
-
class
inspirehep.modules.orcid.cache.
OrcidCache
(orcid, recid)[source]¶ Bases:
object
-
has_work_content_changed
[source]¶ True if the work content has changed compared to the cached version.
Parameters: inspire_record (InspireRecord) – InspireRecord instance. If provided, the hash for the record content is re-computed.
-
redis
¶
-
write_work_putcode
[source]¶ Write the putcode and the hash for the given (orcid, recid).
Parameters: - putcode (string) – the putcode used to push the record to ORCID.
- inspire_record (InspireRecord) – InspireRecord instance. If provided, the hash for the record content is re-computed.
Raises: ValueError
– when the putcode is empty.
-
inspirehep.modules.orcid.converter module¶
Handle conversion from INSPIRE records to ORCID.
-
class
inspirehep.modules.orcid.converter.
ExternalIdentifier
(type, value)¶ Bases:
tuple
-
type
¶ Alias for field number 0
-
value
¶ Alias for field number 1
-
-
class
inspirehep.modules.orcid.converter.
OrcidConverter
(record, url_pattern, put_code=None, visibility=None)[source]¶ Bases:
object
Coverter for the Orcid format.
-
INSPIRE_DOCTYPE_TO_ORCID_TYPE
= {'note': 'other', 'proceedings': 'edited-book', 'book': 'book', 'book chapter': 'book-chapter', 'thesis': 'dissertation', 'conference paper': 'conference-paper', 'report': 'report', 'article': 'journal-article', 'activity report': 'report'}¶
-
INSPIRE_TO_ORCID_ROLES_MAP
= {'supervisor': None, 'editor': 'editor', 'author': 'author'}¶
-
added_external_identifiers
¶
-
arxiv_eprint
¶ Get arXiv ID of a record.
-
bibtex_citation
¶
-
book_series_title
¶ Get record’s book series title.
-
conference_country
¶ Get conference record country.
-
conference_title
¶ Get record’s conference title.
-
doi
¶ Get DOI of a record.
-
get_xml
[source]¶ Create an ORCID XML representation of the record.
Parameters: do_add_bibtex_citation (bool) – True to add BibTeX-serialized record Returns: ORCID XML work record Return type: lxml.etree._Element
-
journal_title
¶ Get record’s journal title.
ORCID identifier for an INSPIRE author field.
Parameters: author (dict) – an author field from INSPIRE literature record Returns: ORCID identifier of an author, if available Return type: string
ORCID role for an INSPIRE author field.
Parameters: author (dict) – an author field from INSPIRE literature record Returns: ORCID role of a person Return type: string
-
orcid_work_type
¶ Get record’s ORCID work type.
-
publication_date
¶ (Partial) date of publication.
Returns: publication date Return type: partial_date (inspire_utils.date.PartialDate)
-
recid
¶ Get INSPIRE record ID.
-
subtitle
¶ Get record subtitle.
-
title
¶ Get record title.
-
inspirehep.modules.orcid.domain_models module¶
inspirehep.modules.orcid.exceptions module¶
-
exception
inspirehep.modules.orcid.exceptions.
BaseOrcidPusherException
(*args, **kwargs)[source]¶ Bases:
exceptions.Exception
-
exception
inspirehep.modules.orcid.exceptions.
DuplicatedExternalIdentifierPusherException
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
The underneath Orcid service client response raised DuplicatedExternalIdentifierPusherException. We checked for the clashing work, pushed it and repeated the original operation which failed again.
-
exception
inspirehep.modules.orcid.exceptions.
InputDataInvalidException
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
The underneath Orcid service client response included an error related to input data like TokenInvalidException, OrcidNotFoundException, PutcodeNotFoundPutException. Note: that re-trying would not help in this case.
-
exception
inspirehep.modules.orcid.exceptions.
PutcodeNotFoundInCacheAfterCachingAllPutcodes
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
No putcode was found in cache after having cached all author putcodes.
-
exception
inspirehep.modules.orcid.exceptions.
PutcodeNotFoundInOrcidException
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
No putcode was found in ORCID API.
-
exception
inspirehep.modules.orcid.exceptions.
RecordNotFoundException
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
-
exception
inspirehep.modules.orcid.exceptions.
StaleRecordDBVersionException
(*args, **kwargs)[source]¶ Bases:
inspirehep.modules.orcid.exceptions.BaseOrcidPusherException
inspirehep.modules.orcid.ext module¶
Search extension.
inspirehep.modules.orcid.putcode_getter module¶
-
class
inspirehep.modules.orcid.putcode_getter.
OrcidPutcodeGetter
(orcid, oauth_token)[source]¶ Bases:
object
-
get_all_inspire_putcodes_and_recids_iter
()[source]¶ Query ORCID api and get all the Inspire putcodes for the given ORCID.
-
get_putcodes_and_recids_by_identifiers_iter
(identifiers)[source]¶ Yield putcode and recid for each work matched by the external identifiers. Note: external identifiers of type ‘other-id’ are skipped.
Parameters: identifiers (List[inspirehep.modules.orcid.converter.ExternalIdentifier]) – list af all external identifiers added after the xml conversion.
-
inspirehep.modules.orcid.tasks module¶
Manage ORCID OAUTH token migration from INSPIRE legacy instance.
-
exception
inspirehep.modules.orcid.tasks.
RemoteTokenOrcidMismatch
(user, orcids)[source]¶ Bases:
exceptions.Exception
-
(task)
inspirehep.modules.orcid.tasks.
import_legacy_orcid_tokens
[source]¶ Celery task to import OAUTH ORCID tokens from legacy. Note: bind=True for compatibility with @time_execution.
-
inspirehep.modules.orcid.tasks.
legacy_orcid_arrays
()[source]¶ Generator to fetch token data from redis.
Note: this function consumes the queue populated by the legacy tasklet: inspire/bibtasklets/bst_orcidsync.py
Yields: list – user data in the form of [orcid, token, email, name]
-
(task)
inspirehep.modules.orcid.tasks.
orcid_push
[source]¶ Celery task to push a record to ORCID.
Parameters: - self (celery.Task) – the task
- orcid (String) – an orcid identifier.
- rec_id (Int) – inspire record’s id to push to ORCID.
- oauth_token (String) – orcid token.
- kwargs_to_pusher (Dict) – extra kwargs to pass to the pusher object.
inspirehep.modules.orcid.utils module¶
ORCID utils.
-
class
inspirehep.modules.orcid.utils.
RetryMixin
(*args, **kwargs)[source]¶ Bases:
celery.app.task.Task
-
request
¶
-
-
inspirehep.modules.orcid.utils.
account_setup
(remote, token, resp)[source]¶ Perform additional setup after user have been logged in.
This is a modified version of invenio_oauthclient.contrib.orcid.account_setup that stores additional metadata.
Parameters: - remote – The remote application.
- token – The token value.
- resp – The response.
-
inspirehep.modules.orcid.utils.
apply_celery_task_with_retry
(task_func, args=None, kwargs=None, max_retries=5, countdown=10, time_limit=None)[source]¶ When executing a (bind=True) task synchronously (with mytask.apply() or just calling it as a function mytask()) the self.retry() does not work, but the original exception is raised (without any retry) so you “lose” the exception management logic written in the task code.
This function overcome such limitation. Example:
# Celery task: @shared_task(bind=True) def normalize_name_task(self, first_name, last_name, nick_name=’‘):
- try:
- result = ... network call ...
- except RequestException as exc:
- exception = None
raise self.retry(max_retries=3, countdown=5, exc=exception)
return result
# Call the task sync with retry: result = apply_celery_task_with_retry(
normalize_name_task, args=(‘John’, ‘Doe’), kwargs=dict(nick_name=’Dee’), max_retries=2, countdown=5*60, time_limit=2*60*60)
Note: it assumes that @shared_task is the first (the one on top) decorator for the Celery task.
Parameters: - task_func – Celery task function to be run.
- args – the positional arguments to pass on to the task.
- kwargs – the keyword arguments to pass on to the task.
- max_retries – maximum number of retries before raising MaxRetriesExceededError.
- countdown –
hard time limit for each attempt. If the last attempt It can be a callable, eg:
backoff = lambda retry_count: 2 ** (retry_count + 1) apply_celery_task_with_retry(..., countdown=backoff) - time_limit – hard time limit for each single attempt in seconds. If the last attempt fails because of the time limit, raises TimeLimitExceeded.
Returns: what the task_func returns.
-
inspirehep.modules.orcid.utils.
get_literature_recids_for_orcid
(orcid)[source]¶ Return the Literature recids that were claimed by an ORCiD.
We record the fact that the Author record X has claimed the Literature record Y by storing in Y an author object with a
$ref
pointing to X and the keycurated_relation
set toTrue
. Therefore this method first searches the DB for the Author records for the one containing the given ORCiD, and then uses its recid to search in ES for the Literature records that satisfy the above property.Parameters: orcid (str) – the ORCiD. Returns: the recids of the Literature records that were claimed by that ORCiD. Return type: list(int)
-
inspirehep.modules.orcid.utils.
get_orcids_for_push
(record)[source]¶ Obtain the ORCIDs associated to the list of authors in the Literature record.
The ORCIDs are looked up both in the
ids
of theauthors
and in the Author records that have claimed the paper.Parameters: record (dict) – metadata from a Literature record Returns: all ORCIDs associated to these authors Return type: Iterator[str]
-
inspirehep.modules.orcid.utils.
get_push_access_tokens
(orcids)[source]¶ Get the remote tokens for the given ORCIDs.
Parameters: orcids (List[str]) – ORCIDs to get the tokens for. Returns: pairs of (ORCID, access_token), for ORCIDs having a token. These are similar to named tuples, in that the values can be retrieved by index or by attribute, respectively id
andaccess_token
.Return type: sqlalchemy.util._collections.result
Module contents¶
ORCID integration module.