Commit 3259f1e4 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update factory.get_conference_data

parent f871c52c
......@@ -14,7 +14,7 @@ from .base import (is_conference,
REG_OAI)
from .exception import CdsException
from .inveniostore import InvenioStore
from .inveniostore import CDS, INS, InvenioStore
from .recordconf import RecordConf
from .recordinst import RecordInst
from .recordpubli import RecordPubli
......@@ -182,7 +182,8 @@ def get_conference_data(host, conf_id=None, key=None):
Args:
host (str):
possible values are ``cds.cern.ch`` or ``inspirehep.net``.
possible values are ``cds``, ``cds.cern.ch``, ``inspirehep``
or ``inspirehep.net``.
conf_id (int):
the conference identifier in the store.
......@@ -200,13 +201,13 @@ def get_conference_data(host, conf_id=None, key=None):
- conference not found
"""
cds = InvenioStore(host)
cds = InvenioStore(host, shelf="conferences")
# ........................................................................
#
# search by id
# search by id in cds.cern.ch
#
if conf_id is not None:
if conf_id is not None and host in CDS:
recjson = cds.get_record(conf_id)
if recjson["recid"] != conf_id:
raise CdsException(MSG_INV_CONF)
......@@ -216,7 +217,7 @@ def get_conference_data(host, conf_id=None, key=None):
#
# search by key in cds.cern.ch
#
if key is not None and host == "cds.cern.ch":
if key is not None and host in CDS:
ids = cds.get_ids(p=key)
for conf_id in ids:
......@@ -227,25 +228,38 @@ def get_conference_data(host, conf_id=None, key=None):
raise CdsException(MSG_NO_CONF)
# ........................................................................
#
# search by id in inspirehep.net
#
if conf_id is not None and host in INS:
obj = cds.get_record(conf_id)
if obj["id"] != str(conf_id):
raise CdsException(MSG_INV_CONF)
return obj["metadata"]
# ........................................................................
#
# search by key in inspirehep.net
#
if key is not None and host == "inspirehep.net":
key = key.replace("/", "-")
if key is not None and host in INS:
key = key.replace("/", "-")
if not REG_CONF.match(key):
raise CdsException(MSG_INV_CONF_KEY)
ids = cds.get_ids(cc="Conferences", p="111__g:%s" % key)
obj = cds.search(f"cnum:{key}")
for conf_id in ids:
recjson = cds.get_record(conf_id)
try:
recjson = obj[0]["metadata"]
if match_conference_key(recjson, key):
return recjson
except (KeyError, TypeError):
raise CdsException(MSG_NO_CONF)
raise CdsException(MSG_NO_CONF)
if recjson["cnum"] != key:
raise CdsException(MSG_NO_CONF)
return recjson
def match_conference_key(recjson, conf_key):
......
......@@ -66,7 +66,7 @@ class InvenioStore(object):
self._url = None
# base url for the API
if host in CDS and shelf is None:
if host in CDS:
api_search = "https://cds.cern.ch/search"
api_record = "https://cds.cern.ch/record"
host = "cds.cern.ch"
......
......@@ -67,15 +67,14 @@ def test_get_conference_data_ins_02002():
"""
# by id
recjson3 = get_conference_data("inspirehep.net", conf_id=980401)
assert recjson3["recid"] == 980401
assert recjson3["meeting_name"][0]["coference_code"] == "C10-12-06"
recjson1 = get_conference_data("inspirehep.net", conf_id=980401)
assert recjson1["control_number"] == 980401
assert recjson1["cnum"] == "C10-12-06"
# by key
recjson4 = get_conference_data("inspirehep.net", key="C10-12-06")
assert recjson4["recid"] == 980401
assert recjson4["meeting_name"][0]["coference_code"] == "C10-12-06"
assert recjson3 == recjson4
recjson2 = get_conference_data("inspirehep.net", key="C10-12-06")
assert recjson2["control_number"] == 980401
assert recjson2["cnum"] == "C10-12-06"
def test_add_conference_data_cds_02003():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment