Ejemplo n.º 1
0
def push_to_orcid(sender, record, *args, **kwargs):
    """If needed, queue the push of the new changes to ORCID."""
    if not current_app.config['FEATURE_FLAG_ENABLE_ORCID_PUSH']:
        LOGGER.warning('ORCID push feature flag not enabled')
        return

    if not is_hep(record):
        return

    # Ensure there is a control number. This is not always the case because of broken store_record.
    if 'control_number' not in record:
        return

    orcids = get_orcids_for_push(record)
    orcids_and_tokens = get_push_access_tokens(orcids)

    for orcid, access_token in orcids_and_tokens:
        orcid_tasks.orcid_push.apply_async(
            queue='orcid_push',
            kwargs={
                'orcid': orcid,
                'rec_id': record['control_number'],
                'oauth_token': access_token,
            },
        )
Ejemplo n.º 2
0
def push_to_orcid(sender, record, *args, **kwargs):
    """If needed, queue the push of the new changes to ORCID."""
    if not current_app.config['FEATURE_FLAG_ENABLE_ORCID_PUSH']:
        LOGGER.warning('ORCID push feature flag not enabled')
        return

    if not is_hep(record):
        return

    # Ensure there is a control number. This is not always the case because of broken store_record.
    if 'control_number' not in record:
        return

    orcids = get_orcids_for_push(record)
    orcids_and_tokens = push_access_tokens.get_access_tokens(orcids)

    kwargs_to_pusher = dict(record_db_version=record.model.version_id)

    for orcid, access_token in orcids_and_tokens:
        orcid_tasks.orcid_push.apply_async(
            queue='orcid_push',
            kwargs={
                'orcid': orcid,
                'rec_id': record['control_number'],
                'oauth_token': access_token,
                'kwargs_to_pusher': kwargs_to_pusher,
            },
        )
Ejemplo n.º 3
0
def assign_uuid(sender, record, *args, **kwargs):
    """Assign a UUID to each signature of a Literature record."""
    if not is_hep(record):
        return

    authors = record.get('authors', [])

    for author in authors:
        if 'uuid' not in author:
            author['uuid'] = str(uuid.uuid4())
Ejemplo n.º 4
0
def assign_uuid(sender, record, *args, **kwargs):
    """Assign a UUID to each signature of a Literature record."""
    if not is_hep(record):
        return

    authors = record.get('authors', [])

    for author in authors:
        if 'uuid' not in author:
            author['uuid'] = str(uuid.uuid4())
Ejemplo n.º 5
0
def enhance_before_index(record):
    """Run all the receivers that enhance the record for ES in the right order.

    .. note::

       ``populate_recid_from_ref`` **MUST** come before ``populate_bookautocomplete``
       because the latter puts a JSON reference in a completion _source, which
       would be expanded to an incorrect ``_source_recid`` by the former.

    """
    populate_recid_from_ref(record)

    if is_hep(record):
        populate_abstract_source_suggest(record)
        populate_earliest_date(record)
        populate_author_count(record)
        populate_authors_full_name_unicode_normalized(record)
        populate_inspire_document_type(record)
        populate_name_variations(record)
        populate_number_of_references(record)
        populate_citations_count(record)
        populate_facet_author_name(record)
        populate_ui_display(record, RecordMetadataSchemaV1)

        if is_book(record):
            populate_bookautocomplete(record)

    elif is_author(record):
        populate_authors_name_variations(record)
        populate_author_suggest(record)

    elif is_institution(record):
        populate_affiliation_suggest(record)

    elif is_experiment(record):
        populate_experiment_suggest(record)

    elif is_journal(record):
        populate_title_suggest(record)

    elif is_data(record):
        populate_citations_count(record)
Ejemplo n.º 6
0
def assign_phonetic_block(sender, record, *args, **kwargs):
    """Assign a phonetic block to each signature of a Literature record.

    Uses the NYSIIS algorithm to compute a phonetic block from each
    signature's full name, skipping those that are not recognized
    as real names, but logging an error when that happens.
    """
    if not is_hep(record):
        return

    author_names = get_value(record, 'authors.full_name', default=[])

    try:
        signature_blocks = phonetic_blocks(author_names)
    except Exception as err:
        current_app.logger.error(
            'Cannot extract phonetic blocks for record %d: %s',
            record.get('control_number'), err)
        return

    for author in record.get('authors', []):
        if author['full_name'] in signature_blocks and signature_blocks[author['full_name']]:
            author['signature_block'] = signature_blocks[author['full_name']]