Skip to content

Commit

Permalink
general: upstream invenio-pidstore
Browse files Browse the repository at this point in the history
* No longer uses INSPIRE fork of invenio-pidstore.

* Introduces new get_pid_type_for() and get_endpoint_from_pid_type()
  helpers to map between endpoints and the corresponding pid_types,
  now that pid_types are constrained in length. (closes inspirehep#1579)

Signed-off-by: Samuele Kaplun <[email protected]>
  • Loading branch information
kaplun committed Sep 28, 2016
1 parent 3da4595 commit 89a4ce8
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 53 deletions.
42 changes: 21 additions & 21 deletions inspirehep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _(x):
# =======
RECORDS_REST_ENDPOINTS = dict(
literature=dict(
pid_type='literature',
pid_type='lit',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:LiteratureSearch',
Expand Down Expand Up @@ -322,7 +322,7 @@ def _(x):
record_class='inspirehep.modules.records.es_record:ESRecord'
),
literature_db=dict(
pid_type='literature',
pid_type='lit',
search_class='inspirehep.modules.search:LiteratureSearch',
record_serializers={
'application/json': ('invenio_records_rest.serializers'
Expand All @@ -339,7 +339,7 @@ def _(x):

),
authors=dict(
pid_type='authors',
pid_type='aut',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:AuthorsSearch',
Expand All @@ -362,7 +362,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
authors_citations=dict(
pid_type='authors',
pid_type='aut',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:AuthorsSearch',
Expand All @@ -386,7 +386,7 @@ def _(x):
':inspire_search_factory'),
),
authors_coauthors=dict(
pid_type='authors',
pid_type='aut',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:AuthorsSearch',
Expand All @@ -410,7 +410,7 @@ def _(x):
':inspire_search_factory'),
),
authors_publications=dict(
pid_type='authors',
pid_type='aut',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:AuthorsSearch',
Expand All @@ -434,7 +434,7 @@ def _(x):
':inspire_search_factory'),
),
authors_stats=dict(
pid_type='authors',
pid_type='aut',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:AuthorsSearch',
Expand All @@ -458,7 +458,7 @@ def _(x):
':inspire_search_factory'),
),
data=dict(
pid_type='data',
pid_type='dat',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:DataSearch',
Expand All @@ -481,7 +481,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
conferences=dict(
pid_type='conferences',
pid_type='con',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:ConferencesSearch',
Expand All @@ -504,7 +504,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
jobs=dict(
pid_type='jobs',
pid_type='job',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:JobsSearch',
Expand All @@ -527,7 +527,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
institutions=dict(
pid_type='institutions',
pid_type='ins',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:InstitutionsSearch',
Expand All @@ -550,7 +550,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
experiments=dict(
pid_type='experiments',
pid_type='exp',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:ExperimentsSearch',
Expand All @@ -573,7 +573,7 @@ def _(x):
search_factory_imp='inspirehep.modules.search.query:inspire_search_factory',
),
journals=dict(
pid_type='journals',
pid_type='jou',
pid_minter='inspire_recid_minter',
pid_fetcher='inspire_recid_fetcher',
search_class='inspirehep.modules.search:JournalsSearch',
Expand All @@ -599,57 +599,57 @@ def _(x):

RECORDS_UI_ENDPOINTS = dict(
literature=dict(
pid_type='literature',
pid_type='lit',
route='/literature/<pid_value>',
template='inspirehep_theme/format/record/'
'Inspire_Default_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:LiteratureRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
authors=dict(
pid_type='authors',
pid_type='aut',
route='/authors/<pid_value>',
template='inspirehep_theme/format/record/'
'authors/Author_HTML_detailed.html',
record_class='inspirehep.modules.records.wrappers:AuthorsRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
data=dict(
pid_type='data',
pid_type='dat',
route='/data/<pid_value>',
template='inspirehep_theme/format/record/Data_HTML_detailed.tpl',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
conferences=dict(
pid_type='conferences',
pid_type='con',
route='/conferences/<pid_value>',
template='inspirehep_theme/format/record/Conference_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:ConferencesRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
jobs=dict(
pid_type='jobs',
pid_type='job',
route='/jobs/<pid_value>',
template='inspirehep_theme/format/record/Job_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:JobsRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
institutions=dict(
pid_type='institutions',
pid_type='ins',
route='/institutions/<pid_value>',
template='inspirehep_theme/format/record/Institution_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:InstitutionsRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
experiments=dict(
pid_type='experiments',
pid_type='exp',
route='/experiments/<pid_value>',
template='inspirehep_theme/format/record/Experiment_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:ExperimentsRecord',
permission_factory_imp='invenio_records_rest.utils:allow_all',
),
journals=dict(
pid_type='journals',
pid_type='jou',
route='/journals/<pid_value>',
template='inspirehep_theme/format/record/Journal_HTML_detailed.tpl',
record_class='inspirehep.modules.records.wrappers:JournalsRecord',
Expand Down
23 changes: 19 additions & 4 deletions inspirehep/modules/pidstore/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@

from invenio_pidstore.providers.base import BaseProvider

from inspirehep.config import RECORDS_REST_ENDPOINTS


_PID_TYPE_TO_ENDPOINT = {value['pid_type']: key for key, value in RECORDS_REST_ENDPOINTS.items()}


def _get_next_pid_from_legacy():
"""Reserve the next pid on legacy.
Expand Down Expand Up @@ -84,8 +89,18 @@ def create(cls, object_type=None, object_uuid=None, **kwargs):

@staticmethod
def schema_to_pid_type(schema):
pid_type = os.path.splitext(os.path.basename(schema))[0]
if pid_type == 'hep':
endpoint = os.path.splitext(os.path.basename(schema))[0]
if endpoint == 'hep':
# FIXME: temp hack until we rename hep.json to literature.json
return 'literature'
return pid_type
endpoint = 'literature'
return get_pid_type_for(endpoint)


def get_pid_type_for(endpoint):
"""Get the pid_type code corresponding to the recid of the given endpoint."""
return RECORDS_REST_ENDPOINTS[endpoint]['pid_type']


def get_endpoint_from_pid_type(pid_type):
"""Return the endpoint corresponding to the given pid_type."""
return _PID_TYPE_TO_ENDPOINT[pid_type]
11 changes: 7 additions & 4 deletions inspirehep/modules/theme/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from invenio_pidstore.models import PersistentIdentifier
from invenio_search import current_search_client

from inspirehep.modules.pidstore.providers import get_pid_type_for, get_endpoint_from_pid_type
from inspirehep.modules.records.conference_series import (
CONFERENCE_CATEGORIES_TO_SERIES,
)
Expand Down Expand Up @@ -226,7 +227,7 @@ def ajax_references():
recid = request.args.get('recid', '')
collection = request.args.get('collection', '')

pid = PersistentIdentifier.get(collection, recid)
pid = PersistentIdentifier.get(get_pid_type_for(collection), recid)

record = LiteratureSearch().get_source(pid.object_uuid)

Expand All @@ -244,7 +245,7 @@ def ajax_citations():
recid = request.args.get('recid', '')
collection = request.args.get('collection', '')

pid = PersistentIdentifier.get(collection, recid)
pid = PersistentIdentifier.get(get_pid_type_for(collection), recid)

record = LiteratureSearch().get_source(pid.object_uuid)

Expand Down Expand Up @@ -471,7 +472,7 @@ def ajax_institutions_experiments():
"""Datatable handler to get experiments in an institution."""
recid = request.args.get('recid', '')

pid = PersistentIdentifier.get('institutions', recid)
pid = PersistentIdentifier.get(get_pid_type_for('institutions'), recid)

record = InstitutionsSearch().get_source(pid.object_uuid)
try:
Expand Down Expand Up @@ -570,7 +571,9 @@ def record(control_number):
abort(404)

return redirect('/{collection}/{control_number}'.format(
collection=pid.pid_type, control_number=control_number)), 301
collection=get_endpoint_from_pid_type(pid.pid_type),
control_number=control_number
)), 301


#
Expand Down
10 changes: 6 additions & 4 deletions inspirehep/utils/record_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from invenio_pidstore.models import PersistentIdentifier
from invenio_records.api import Record

from inspirehep.modules.pidstore.providers import get_pid_type_for, get_endpoint_from_pid_type


class RecordGetterError(Exception):

Expand Down Expand Up @@ -63,7 +65,7 @@ def wrapper(*args, **kwargs):

@raise_record_getter_error_and_log
def get_es_record(record_type, recid, **kwargs):
pid = PersistentIdentifier.get(record_type, recid)
pid = PersistentIdentifier.get(get_pid_type_for(record_type), recid)
search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][record_type]
search_class = import_string(search_conf['search_class'])()
return search_class.get_source(pid.object_uuid, **kwargs)
Expand All @@ -80,7 +82,7 @@ def get_es_records(record_type, recids, **kwargs):
"""
uuids = PersistentIdentifier.query.filter(
PersistentIdentifier.pid_value.in_(recids),
PersistentIdentifier.pid_type == record_type
PersistentIdentifier.pid_type == get_pid_type_for(record_type)
).all()
uuids = [str(uuid.object_uuid) for uuid in uuids]
search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][record_type]
Expand All @@ -91,12 +93,12 @@ def get_es_records(record_type, recids, **kwargs):
@raise_record_getter_error_and_log
def get_es_record_by_uuid(uuid):
pid = PersistentIdentifier.query.filter_by(object_uuid=uuid).one()
search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][pid.pid_type]
search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][get_endpoint_from_pid_type(pid.pid_type)]
search_class = import_string(search_conf['search_class'])()
return search_class.get_source(uuid)


@raise_record_getter_error_and_log
def get_db_record(record_type, recid):
pid = PersistentIdentifier.get(record_type, recid)
pid = PersistentIdentifier.get(get_pid_type_for(record_type), recid)
return Record.get_record(pid.object_uuid)
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# FIXME temporary branch for testing
-e git+https://github.com/inspirehep/invenio-query-parser.git@invenio3-inspire#egg=invenio-query-parser==0.6.0

# INSPIRE forks of Invenio packages
-e git+https://github.com/inspirehep/invenio-pidstore.git#egg=invenio-pidstore

# Workflows and Holding Pen related dependencies
-e git+https://github.com/inveniosoftware/invenio-classifier.git#egg=invenio-classifier
-e git+https://github.com/inspirehep/invenio-matcher.git#egg=invenio-matcher
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
'invenio-logging>=1.0.0a3',
'invenio-mail>=1.0.0a4',
'invenio-oauthclient>=1.0.0a8',
'invenio-pidstore>=1.0.0a9',
'invenio-records>=1.0.0a16', # Add [versioning] in the future
'invenio-rest[cors]>=1.0.0a7',
'invenio-search>=1.0.0a7',
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/disambiguation/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from invenio_search import current_search_client as es

from inspirehep.modules.disambiguation.models import DisambiguationRecord
from inspirehep.modules.pidstore.providers import get_pid_type_for
from inspirehep.utils.record_getter import get_es_record_by_uuid


Expand All @@ -42,7 +43,7 @@ def test_count_phonetic_block_dispatched(small_app):

# Signature #1.
glashow_record_id = str(PersistentIdentifier.get(
"literature", 4328).object_uuid)
get_pid_type_for("literature"), 4328).object_uuid)
glashow_record = get_es_record_by_uuid(glashow_record_id)

# Add phonetic block to the record.
Expand All @@ -53,7 +54,7 @@ def test_count_phonetic_block_dispatched(small_app):

# Signature #2.
higgs_record_id_first = str(PersistentIdentifier.get(
"literature", 1358492).object_uuid)
get_pid_type_for("literature"), 1358492).object_uuid)
higgs_record_first = get_es_record_by_uuid(higgs_record_id_first)

# Add phonetic block to the record.
Expand All @@ -64,7 +65,7 @@ def test_count_phonetic_block_dispatched(small_app):

# Signature #3.
higgs_record_id_second = str(PersistentIdentifier.get(
"literature", 11883).object_uuid)
get_pid_type_for("literature"), 11883).object_uuid)
higgs_record_second = get_es_record_by_uuid(higgs_record_id_second)

# Add phonetic block to the record.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/disambiguation/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
from invenio_pidstore.models import PersistentIdentifier

from inspirehep.modules.disambiguation.logic import _create_distance_signature
from inspirehep.modules.pidstore.providers import get_pid_type_for


def test_create_distance_signature_method(small_app):
"""Test the method responsible for creating data in Beard format."""
pid = PersistentIdentifier.get("literature", 4328)
pid = PersistentIdentifier.get(get_pid_type_for("literature"), 4328)
publication_id = str(pid.object_uuid)

signatures_map = {
Expand Down
5 changes: 3 additions & 2 deletions tests/integration/disambiguation/test_receivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
append_new_record_to_queue,
append_updated_record_to_queue,
)
from inspirehep.modules.pidstore.providers import get_pid_type_for


class _IdDict(dict):
Expand Down Expand Up @@ -92,7 +93,7 @@ def test_append_new_record_to_queue_method_not_hep_record(small_app):

def test_append_updated_record_to_queue(small_app):
"""Test the receiver responsible for queuing updated HEP records."""
pid = PersistentIdentifier.get("literature", 4328)
pid = PersistentIdentifier.get(get_pid_type_for("literature"), 4328)
publication_id = str(pid.object_uuid)
record = Record.get_record(publication_id)

Expand Down Expand Up @@ -159,7 +160,7 @@ def test_append_updated_record_to_queue_not_hep_record(small_app):

def test_append_updated_record_to_queue_same_data(small_app):
"""Check if for the same record, the receiver will skip the publication."""
pid = PersistentIdentifier.get("literature", 11883)
pid = PersistentIdentifier.get(get_pid_type_for("literature"), 11883)
publication_id = str(pid.object_uuid)
record = Record.get_record(publication_id)

Expand Down
Loading

0 comments on commit 89a4ce8

Please sign in to comment.