コード例 #1
0
ファイル: api.py プロジェクト: turtle321/inspire-next
 def _get_ref(self):
     """Returns full url to this object (as in $ref)"""
     pid_value = self.get('control_number')
     pid_type = get_pid_type_from_schema(self.get('$schema'))
     endpoint = get_endpoint_from_pid_type(pid_type)
     return absolute_url(u'/api/{endpoint}/{control_number}'.format(
         endpoint=endpoint, control_number=pid_value))
コード例 #2
0
ファイル: api.py プロジェクト: harunurhan/inspire-next
 def _get_ref(self):
     """Returns full url to this object (as in $ref)"""
     pid_value = self.get('control_number')
     pid_type = get_pid_type_from_schema(self.get('$schema'))
     endpoint = get_endpoint_from_pid_type(pid_type)
     return absolute_url(u'/api/{endpoint}/{control_number}'.format(endpoint=endpoint,
                                                                    control_number=pid_value))
コード例 #3
0
def get_es_record_by_uuid(uuid):
    pid = PersistentIdentifier.query.filter_by(object_uuid=uuid).one()

    endpoint = get_endpoint_from_pid_type(pid.pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.get_source(uuid)
コード例 #4
0
def get_es_record_by_uuid(uuid):
    pid = PersistentIdentifier.query.filter_by(object_uuid=uuid).one()

    endpoint = get_endpoint_from_pid_type(pid.pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.get_source(uuid)
コード例 #5
0
ファイル: api.py プロジェクト: harunurhan/inspire-next
 def _get_index_ref(self):
     """Return shorten version of pid_value/pid_type for proper querying with index"""
     pid_value = self.get('control_number')
     pid_type = get_pid_type_from_schema(self.get('$schema'))
     endpoint = get_endpoint_from_pid_type(pid_type)
     shorten_endpoint = endpoint[:3]
     return "{pid_value}{shorten_endpoint}".format(pid_value=pid_value,
                                                   shorten_endpoint=shorten_endpoint)
コード例 #6
0
def get_es_record(pid_type, recid, **kwargs):
    pid = PersistentIdentifier.get(pid_type, recid)

    endpoint = get_endpoint_from_pid_type(pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.get_source(pid.object_uuid, **kwargs)
コード例 #7
0
ファイル: api.py プロジェクト: turtle321/inspire-next
 def _get_index_ref(self):
     """Return shorten version of pid_value/pid_type for proper querying with index"""
     pid_value = self.get('control_number')
     pid_type = get_pid_type_from_schema(self.get('$schema'))
     endpoint = get_endpoint_from_pid_type(pid_type)
     shorten_endpoint = endpoint[:3]
     return "{pid_value}{shorten_endpoint}".format(
         pid_value=pid_value, shorten_endpoint=shorten_endpoint)
コード例 #8
0
def get_es_record(pid_type, recid, **kwargs):
    pid = PersistentIdentifier.get(pid_type, recid)

    endpoint = get_endpoint_from_pid_type(pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.get_source(pid.object_uuid, **kwargs)
コード例 #9
0
ファイル: views.py プロジェクト: harunurhan/inspire-next
def record(control_number):
    try:
        pid = PersistentIdentifier.query.filter_by(
            pid_value=control_number).one()
    except NoResultFound:
        abort(404)

    return redirect('/{endpoint}/{control_number}'.format(
        endpoint=get_endpoint_from_pid_type(pid.pid_type),
        control_number=control_number)), 301
コード例 #10
0
ファイル: views.py プロジェクト: Kjili/inspire-next
def record(control_number):
    try:
        pid = PersistentIdentifier.query.filter_by(
            pid_value=control_number).one()
    except NoResultFound:
        abort(404)

    return redirect('/{endpoint}/{control_number}'.format(
        endpoint=get_endpoint_from_pid_type(pid.pid_type),
        control_number=control_number)), 301
コード例 #11
0
ファイル: __init__.py プロジェクト: pazembrz/inspire-next
def post_record_to_hep(pid_type, data=None):
    if not data:
        raise InspirehepMissingDataError
    endpoint = get_endpoint_from_pid_type(pid_type)
    inspirehep_url = current_app.config.get("INSPIREHEP_URL")
    response = requests.post("{inspirehep_url}/{endpoint}".format(
        inspirehep_url=inspirehep_url,
        endpoint=endpoint,
    ),
                             headers=_get_headers_for_hep(),
                             json=data or {})
    response.raise_for_status()
    return response.json()
コード例 #12
0
ファイル: __init__.py プロジェクト: pazembrz/inspire-next
def get_record_from_hep(pid_type, pid_value):
    endpoint = get_endpoint_from_pid_type(pid_type)
    inspirehep_url = current_app.config.get("INSPIREHEP_URL")
    headers = _get_headers_for_hep()
    response = requests.get(
        "{inspirehep_url}/{endpoint}/{control_number}".format(
            inspirehep_url=inspirehep_url,
            endpoint=endpoint,
            control_number=pid_value),
        headers=headers,
    )
    response.raise_for_status()
    return response.json()
コード例 #13
0
def get_es_records(pid_type, recids, **kwargs):
    """Get a list of recids from ElasticSearch."""
    recids = [str(recid) for recid in recids]
    uuids = PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_value.in_(recids),
        PersistentIdentifier.pid_type == pid_type).all()
    uuids = [str(uuid.object_uuid) for uuid in uuids]

    endpoint = get_endpoint_from_pid_type(pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.mget(uuids, **kwargs)
コード例 #14
0
def get_es_records(pid_type, recids, **kwargs):
    """Get a list of recids from ElasticSearch."""
    recids = [str(recid) for recid in recids]
    uuids = PersistentIdentifier.query.filter(
        PersistentIdentifier.pid_value.in_(recids),
        PersistentIdentifier.pid_type == pid_type
    ).all()
    uuids = [str(uuid.object_uuid) for uuid in uuids]

    endpoint = get_endpoint_from_pid_type(pid_type)
    search_conf = current_app.config['RECORDS_REST_ENDPOINTS'][endpoint]
    search_class = import_string(search_conf['search_class'])()

    return search_class.mget(uuids, **kwargs)
コード例 #15
0
ファイル: utils.py プロジェクト: fschwenn/inspire-next
def get_endpoint_from_record(record):
    """Return the endpoint corresponding to a record."""
    pid_type = get_pid_type_from_schema(record['$schema'])
    endpoint = get_endpoint_from_pid_type(pid_type)

    return endpoint
コード例 #16
0
def test_get_endpoint_from_pid_type():
    expected = 'literature'
    result = get_endpoint_from_pid_type('lit')

    assert expected == result
コード例 #17
0
def test_get_endpoint_from_pid_type():
    expected = 'literature'
    result = get_endpoint_from_pid_type('lit')

    assert expected == result
コード例 #18
0
ファイル: utils.py プロジェクト: rikirenz/inspire-next
def get_endpoint_from_record(record):
    """Return the endpoint corresponding to a record."""
    pid_type = get_pid_type_from_schema(record['$schema'])
    endpoint = get_endpoint_from_pid_type(pid_type)

    return endpoint