def test_record_responsify(app):
    """Test JSON serialize."""
    rec_serializer = record_responsify(
        TestSerializer(), 'application/x-custom')

    pid = PersistentIdentifier(pid_type='rec', pid_value='1')
    rec = Record({'title': 'test'})
    resp = rec_serializer(pid, rec, headers=[('X-Test', 'test')])
    assert resp.status_code == 200
    assert resp.content_type == 'application/x-custom'
    assert resp.get_data(as_text=True) == "1:test"
    assert resp.headers['X-Test'] == 'test'

    resp = rec_serializer(pid, rec, code=201)
    assert resp.status_code == 201
def test_record_responsify(app):
    """Test JSON serialize."""
    rec_serializer = record_responsify(TestSerializer(),
                                       'application/x-custom')

    pid = PersistentIdentifier(pid_type='rec', pid_value='1')
    rec = Record({'title': 'test'})
    resp = rec_serializer(pid, rec, headers=[('X-Test', 'test')])
    assert resp.status_code == 200
    assert resp.content_type == 'application/x-custom'
    assert resp.get_data(as_text=True) == "1:test"
    assert resp.headers['X-Test'] == 'test'

    resp = rec_serializer(pid, rec, code=201)
    assert resp.status_code == 201
def test_get_record(test_custom_endpoints_app, test_records):
    """Test the creation of a custom endpoint using RecordResource."""
    test_records = test_records
    """Test creation of a RecordResource view."""
    blueprint = Blueprint(
        'test_invenio_records_rest',
        __name__,
    )

    json_v1 = JSONSerializer(RecordSchemaJSONV1)

    blueprint.add_url_rule(
        '/records/<pid(recid):pid_value>',
        view_func=RecordResource.as_view(
            'recid_item',
            serializers={
                'application/json': record_responsify(
                    json_v1, 'application/json'
                )
            },
            default_media_type='application/json',
            read_permission_factory=allow_all,
            update_permission_factory=allow_all,
            delete_permission_factory=allow_all,
        )
    )

    test_custom_endpoints_app.register_blueprint(blueprint)

    with test_custom_endpoints_app.app_context():
        pid, record = test_records[0]
        url = url_for('test_invenio_records_rest.recid_item',
                      pid_value=pid.pid_value, user=1)
        with test_custom_endpoints_app.test_client() as client:
            res = client.get(url)
            assert res.status_code == 200

            # Check metadata
            data = get_json(res)
            assert record == data['metadata']
Пример #4
0
def test_get_record(test_custom_endpoints_app, test_records):
    """Test the creation of a custom endpoint using RecordResource."""
    test_records = test_records
    """Test creation of a RecordResource view."""
    blueprint = Blueprint(
        'test_invenio_records_rest',
        __name__,
    )

    json_v1 = JSONSerializer(RecordSchemaJSONV1)

    blueprint.add_url_rule(
        '/records/<pid(recid):pid_value>',
        view_func=RecordResource.as_view(
            'recid_item',
            serializers={
                'application/json': record_responsify(
                    json_v1, 'application/json'
                )
            },
            default_media_type='application/json',
            read_permission_factory=allow_all,
            update_permission_factory=allow_all,
            delete_permission_factory=allow_all,
        )
    )

    test_custom_endpoints_app.register_blueprint(blueprint)

    with test_custom_endpoints_app.app_context():
        pid, record = test_records[0]
        url = url_for('test_invenio_records_rest.recid_item',
                      pid_value=pid.pid_value, user=1)
        with test_custom_endpoints_app.test_client() as client:
            res = client.get(url)
            assert res.status_code == 200

            # Check metadata
            data = get_json(res)
            assert record == data['metadata']
Пример #5
0
                'RERO_ILS_APP_CONFIG_FACETS', {}
            )
            if search_result['hits']['hits']:
                index_name = \
                    search_result['hits']['hits'][0]['_index'].split('-')[0]
                facet_config = facet_config.get(index_name, {})
                results['aggregations']['_settings'] = facet_config

        return json.dumps(results, **self._format_args())


json_v1 = ReroIlsSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""

json_v1_search = search_responsify(json_v1, 'application/json')
json_v1_response = record_responsify(json_v1, 'application/json')


class ReroIlsCanDeleteSerializer(ReroIlsSerializer):
    """Mixin serializing records as JSON."""

    def serialize(self, pid, record, links_factory=None, **kwargs):
        """Serialize a single record and persistent identifier.

        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for record links.
        """
        if request and request.args.get('resolve'):
            record = record.replace_refs()
        if not record.can_delete:
Пример #6
0
from __future__ import absolute_import, print_function

from invenio_records_rest.serializers.citeproc import CiteprocSerializer
from invenio_records_rest.serializers.json import JSONSerializer
from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify

from ..marshmallow import RecordSchemaV1

# Serializers
# ===========
#: JSON serializer definition.
from ..marshmallow.json import CitationSchemaV1

json_v1 = JSONSerializer(RecordSchemaV1, replace_refs=True)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')

# Citation serializers
csl_v1 = JSONSerializer(CitationSchemaV1, replace_refs=True)
citeproc_v1 = CiteprocSerializer(csl_v1)
citeproc_v1_response = record_responsify(citeproc_v1, 'text/x-bibliography')

__all__ = ('json_v1', 'json_v1_response', 'json_v1_search', 'csl_v1',
           'citeproc_v1', 'citeproc_v1_response')
Пример #7
0
            for key in keys:
                value = es_hit.get(key)
                if value is not None:
                    record[key] = value
        except StopIteration:
            # Should not happens... the account should always be indexed
            pass

        return super().preprocess_record(pid=pid,
                                         record=record,
                                         links_factory=links_factory,
                                         kwargs=kwargs)

    def post_process_serialize_search(self, results, pid_fetcher):
        """Post process the search results."""
        # Add library name
        for lib_term in results.get('aggregations',
                                    {}).get('library', {}).get('buckets', []):
            pid = lib_term.get('key')
            lib_term['name'] = Library.get_record_by_pid(pid).get('name')
        return super().post_process_serialize_search(results, pid_fetcher)


json_acq_account = AcqAccountJSONSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""

json_acq_account_search = search_responsify(json_acq_account,
                                            'application/rero+json')
json_acq_account_response = record_responsify(json_acq_account,
                                              'application/rero+json')
Пример #8
0
        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for record links.
        """
        return self.format_record(record)

    def serialize_search(self,
                         pid_fetcher,
                         search_result,
                         links=None,
                         item_links_factory=None):
        """Serialize a search result.

        :param pid_fetcher: Persistent identifier fetcher.
        :param search_result: Elasticsearch search result.
        :param links: Dictionary of links to add to response.
        """
        records = []
        for hit in search_result['hits']['hits']:
            records.append(self.format_record(record=hit['_source']))

        return "\n".join(records)


documents_items_csv_v1 = TextSerializer()
documents_items_csv_v1_response = record_responsify(documents_items_csv_v1,
                                                    'text/csv')
documents_items_csv_v1_search = search_responsify(documents_items_csv_v1,
                                                  'text/csv')
Пример #9
0
from .json import (BasicJSONSerializer, PermissionsJSONSerializer,
                   RecordSerializer)
from .schemas.json import (BasicDepositSchema, PermissionsDepositSchema,
                           RecordSchema, RecordFormSchema)

# Serializers
# ===========
# CAP JSON serializer version 1.0.0
record_json_v1 = RecordSerializer(RecordSchema)
record_form_json_v1 = RecordSerializer(RecordFormSchema)

basic_json_v1 = BasicJSONSerializer(BasicDepositSchema)
permissions_json_v1 = PermissionsJSONSerializer(PermissionsDepositSchema)

# Records-REST serializers
# ========================
# JSON record serializer for individual records.
record_json_v1_response = record_responsify(record_json_v1, 'application/json')
record_form_json_v1_response = record_responsify(record_form_json_v1,
                                                 'application/json')
record_json_v1_search = search_responsify(record_json_v1, 'application/json')
basic_json_v1_response = record_responsify(basic_json_v1,
                                           'application/basic+json')
permissions_json_v1_response = record_responsify(
    permissions_json_v1, 'application/permissions+json')

# JSON record serializer for search results.
basic_json_v1_search = search_responsify(basic_json_v1,
                                         'application/basic+json')
Пример #10
0
        return super(DocumentJSONSerializer,
                     self).post_process_serialize_search(results, pid_fetcher)

    @classmethod
    def _process_library_buckets(cls, org, lib_buckets):
        """Process library buckets.

        Add library names
        :param org: current organisation
        :param lib_buckets: library buckets

        :return processed buckets
        """
        processed_buckets = []
        lib_pids = list(org.get_libraries_pids())
        for bucket in lib_buckets:
            if bucket.get('key') in lib_pids:
                bucket['name'] = Library.get_record_by_pid(
                    bucket.get('key')).get('name')
                processed_buckets.append(bucket)

        return processed_buckets


json_doc = DocumentJSONSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""

json_doc_search = search_responsify(json_doc, 'application/rero+json')
json_doc_response = record_responsify(json_doc, 'application/rero+json')
from .json import CAPSchemaSerializer as JSONSerializer, \
    BasicJSONSerializer, PermissionsJSONSerializer
from .schemas.json import RecordSchemaJSONV1, BasicDepositSchema, \
    PermissionsDepositSchema
from invenio_deposit.serializers import json_file_response

# Serializers
# ===========
# CAP JSON serializer version 1.0.0
json_v1 = JSONSerializer(RecordSchemaJSONV1)
basic_json_v1 = BasicJSONSerializer(BasicDepositSchema)
permissions_json_v1 = PermissionsJSONSerializer(PermissionsDepositSchema)

# Records-REST serializers
# ========================
# JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
basic_json_v1_response = record_responsify(
    basic_json_v1, 'application/basic+json')
permissions_json_v1_response = record_responsify(
    permissions_json_v1, 'application/permissions+json')

# Files-REST serializers
# JSON Files serializers for deposit files
deposit_v1_files_response = json_file_response

# JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')
basic_json_v1_search = search_responsify(
    basic_json_v1, 'application/basic+json')
Пример #12
0
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Record serialization."""

from __future__ import absolute_import, print_function

from .orcid_serializer import ORCIDSerializer

from invenio_records_rest.serializers.response import record_responsify, \
                                                      search_responsify

orcid = ORCIDSerializer()

orcid_response = record_responsify(orcid, 'application/x-orcid')

orcid_search = search_responsify(orcid, 'application/x-orcid')
# along with CERN Analysis Preservation Framework; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Record serialization."""

from __future__ import absolute_import, print_function

from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify

from .json import CAPSchemaSerializer as JSONSerializer
from .schemas.json import RecordSchemaJSONV1

# Serializers
# ===========
#: CAP JSON serializer version 1.0.0
json_v1 = JSONSerializer(RecordSchemaJSONV1)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')

#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')
Пример #14
0
        return writer.to_string(bib_data)

    def serialize(self, pid, record, links_factory=None):
        try:
            return self.create_bibliography(record)
        except Exception as e:
            LOGGER.exception(
                "Bibtex serialization error",
                recid=record.get("control_number"),
                error=e,
            )
            return f"% Bibtex generation failed for record {record.get('control_number','')}"

    def serialize_search(self,
                         pid_fetcher,
                         search_result,
                         links=None,
                         item_links_factory=None):
        records = [
            hit["_source"].get("_bibtex_display", "")
            for hit in search_result["hits"]["hits"]
        ]
        return "\n".join(records)


literature_bibtex = BibTexSerializer(BibTexCommonSchema)
literature_bibtex_response = record_responsify(literature_bibtex,
                                               "application/x-bibtex")
literature_bibtex_response_search = search_responsify(literature_bibtex,
                                                      "application/x-bibtex")
Пример #15
0
    updated = fields.Str(dump_only=True)
    links = fields.Dict(dump_only=True)
    id = PersistentIdentifier()

    # @post_dump
    # def dump_metadata(self, source, **kwargs):
    #     if source['metadata']['source_type'] == SourceType.JOURNAL.value:
    #         print('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSsss')
    #         print(source)
    #         print('SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSsss')
    #         source['metadata'] = journal_data_schema.dump(source['metadata'])
    #     return source


source_data_schema_many = SourceDataSchemaV1(many=True)
source_data_schema = SourceDataSchemaV1(many=False)

source_loader_v1 = marshmallow_loader(SourceDataSchemaV1)

# Serializers
# ===========
#: JSON serializer definition.
source_v1 = JSONSerializer(SourceSchemaV1, replace_refs=True)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
source_v1_response = record_responsify(source_v1, 'application/json')
#: JSON record serializer for search results.
source_v1_search = search_responsify(source_v1, 'application/json')
Пример #16
0
#: BibTeX serializer version 1.0.0
bibtex_v1 = BibTeXSerializer()
#: DataCite serializer
datacite_v31 = DataCite31Serializer(DataCiteSchemaJSONV1, replace_refs=True)
#: OAI DataCite serializer
oai_datacite = OAIDataCiteSerializer(
    v31=datacite_v31,
    datacentre='CERN.ZENODO',
)
#: Dublin Core serializer
dc_v1 = DublinCoreSerializer(DublinCoreJSONV1, replace_refs=True)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: MARCXML record serializer for individual records.
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX record serializer for individual records.
bibtex_v1_response = record_responsify(bibtex_v1, 'application/x-bibtex')
#: DataCite v3.1 record serializer for individual records.
datacite_v31_response = record_responsify(
    datacite_v31, 'application/x-datacite+xml')
#: DublinCore record serializer for individual records.
dc_v1_response = record_responsify(dc_v1, 'application/x-dc+xml')

#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')
#: MARCXML record serializer for search records.
marcxml_v1_search = search_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX serializer for search records.
Пример #17
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import (
    record_responsify,
    search_responsify,
)

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.journals import JournalsPublicSchema
from inspirehep.serializers import JSONSerializer

journals_json = JSONSerializer(
    wrap_schema_class_with_metadata(JournalsPublicSchema),
    index_name="records-journals")

journals_json_response = record_responsify(journals_json, "application/json")

journals_json_response_search = search_responsify(journals_json,
                                                  "application/json")
Пример #18
0
#
# invenio-app-ils is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Loan serializers."""

from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify

from invenio_app_ils.records.schemas.json import ILSRecordSchemaJSONV1

from .csv import LoanCSVSerializer
from .json import LoanJSONSerializer

csv_v1 = LoanCSVSerializer(ILSRecordSchemaJSONV1)
"""CSV serializer"""

csv_v1_response = record_responsify(csv_v1, "text/csv")
"""CSV response builder that uses the CSV serializer"""

csv_v1_search = search_responsify(csv_v1, "text/csv")
"""CSV search response builder that uses the CSV serializer"""

json_v1 = LoanJSONSerializer(ILSRecordSchemaJSONV1, replace_refs=True)
"""JSON serializer."""

json_v1_response = record_responsify(json_v1, "application/json")
"""JSON response builder decorates loan."""

json_v1_search = search_responsify(json_v1, "application/json")
"""JSON response builder decorates loan."""
Also, there are different serializers defined for output of individual record
requests (json_v1_response) and search results (json_v1_search), as the
internal objects may not have indentical structures.
For more information on serializers please see
https://invenio-records-rest.readthedocs.io/en/latest/usage.html#serialization/
.
"""

from invenio_records_rest.serializers.json import JSONSerializer
from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify

from ..marshmallow import RecordSchemaV1

# Serializers
# ===========
json_v1 = JSONSerializer(RecordSchemaV1, replace_refs=True)

# Records-REST serializers
# ========================
# JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
# JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')

__all__ = (
    'json_v1',
    'json_v1_response',
    'json_v1_search',
)
Пример #20
0
)

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.jobs import JobsPublicListSchema, JobsPublicSchema
from inspirehep.records.marshmallow.jobs.ui import JobsDetailSchema, JobsListSchema
from inspirehep.serializers import JSONSerializer

jobs_json = JSONSerializer(
    wrap_schema_class_with_metadata(JobsPublicSchema), index_name="records-jobs"
)

jobs_json_search = JSONSerializer(
    wrap_schema_class_with_metadata(JobsPublicListSchema), index_name="records-jobs"
)


jobs_json_response = record_responsify(jobs_json, "application/json")

jobs_json_response_search = search_responsify(jobs_json_search, "application/json")

jobs_json_detail = JSONSerializer(wrap_schema_class_with_metadata(JobsDetailSchema))
jobs_json_detail_response = record_responsify(
    jobs_json_detail, "application/vnd+inspire.record.ui+json"
)
jobs_json_list = JSONSerializer(
    wrap_schema_class_with_metadata(JobsListSchema), index_name="records-jobs"
)
jobs_json_list_response = search_responsify(
    jobs_json_list, "application/vnd+inspire.record.ui+json"
)
Пример #21
0
        links['viaf.org'] = 'http://www.viaf.org/viaf/' + str(viaf_pid)
    except Exception:
        pass

    link_factory = default_links_factory_with_additional(links)
    return link_factory(pid)


class ReroMefSerializer(JSONSerializer):
    """Mixin serializing records as JSON."""

    def serialize(self, pid, record, links_factory=None, **kwargs):
        """Serialize a single record and persistent identifier.

        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for record links.
        """
        if request and request.args.get('resolve'):
            record = record.replace_refs()

        return super(ReroMefSerializer, self).serialize(
            pid, record, links_factory=add_links, **kwargs
        )


json_v1 = ReroMefSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""

json_v1_agent_response = record_responsify(json_v1, 'application/rero+json')
Пример #22
0
                dict(hits=dict(hits=to_return, total=total)))
            return native_json.dumps(to_return, indent=2)

        graph = Graph().parse(data=native_json.dumps(to_return, indent=2),
                              format="json-ld")
        # out = ''
        if self.output_format == 'xml':
            out = '<!--  Search-Engine-Total-Number-Of-Results: %s  -->\n' \
                  % total
        if self.output_format == 'turtle':
            out = '# Search-Engine-Total-Number-Of-Results: %s\n' % total
        return out + graph.serialize(format=self.output_format).decode('utf-8')


marcxml_v1 = MARCXMLSerializer(book2marc, schema_class=None, replace_refs=True)
marcxml_v1_search = search_responsify(marcxml_v1, 'application/marcxml+xml')
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')

ld_json_v1 = LDSerializer(RecordSchemaJSONV1, output_format='json-ld')
ld_turtle_v1 = LDSerializer(RecordSchemaJSONV1, output_format='turtle')
ld_xml_v1 = LDSerializer(RecordSchemaJSONV1, output_format='xml')

ld_json_v1_response = record_responsify(ld_json_v1, 'application/ld+json')
ld_json_v1_search = search_responsify(ld_json_v1, 'application/ld+json')

ld_turtle_v1_response = record_responsify(ld_turtle_v1, 'text/tutle')
ld_turtle_v1_search = search_responsify(ld_turtle_v1, 'text/turtle')

ld_xml_v1_response = record_responsify(ld_xml_v1, 'application/rdf+xml')
ld_xml_v1_search = search_responsify(ld_xml_v1, 'application/rdf+xml')
Пример #23
0
                         search_result,
                         links=None,
                         item_links_factory=None):
        """Serialize search result(s).

        Args:
            pid_fetcher: Persistent identifier fetcher.
            search_result: Elasticsearch search result.
            links: Dictionary of links to add to response.

        Returns:
            str: serialized search result(s)
        """
        records = [
            hit["_source"].get(f"_latex_{self.format.lower()}_display", "")
            for hit in search_result["hits"]["hits"]
        ]
        return "\n\n".join(records)


latex_EU = LatexSerializer("EU", schema_class=LatexSchema)
latex_US = LatexSerializer("US", schema_class=LatexSchema)
latex_response_eu = record_responsify(
    latex_EU, "application/vnd+inspire.latex.eu+x-latex")
latex_response_us = record_responsify(
    latex_US, "application/vnd+inspire.latex.us+x-latex")
literature_latex_eu_response_search = search_responsify(
    latex_EU, "application/vnd+inspire.latex.eu+x-latex")
literature_latex_us_response_search = search_responsify(
    latex_US, "application/vnd+inspire.latex.us+x-latex")
Пример #24
0
from pkg_resources import resource_filename

from .marcxml import MARCXMLSerializer

xslt_dublincore_oai = resource_filename(
    'invenio_marc21', 'xslts/MARC21slim2OAIDC.xsl')
xslt_dublincore_rdf = resource_filename(
    'invenio_marc21', 'xslts/MARC21slim2RDFDC.xsl')
xslt_dublincore_SRW = resource_filename(
    'invenio_marc21', 'xslts/MARC21slim2SRWDC.xsl')
xslt_mods = resource_filename('invenio_marc21', 'xslts/MARC21slim2MODS3-6.xsl')

#: MARCXML serializer.
marcxml_v1 = MARCXMLSerializer(to_marc21)
#: MARCXML record serializer
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: MARCXML search serializer
marcxml_v1_search = search_responsify(marcxml_v1, 'application/marcxml+xml')

#: DublinCore serializer.
dublincore_v1 = MARCXMLSerializer(to_marc21, xslt_filename=xslt_dublincore_oai)
#: DublinCore record serializer.
dublincore_v1_response = record_responsify(
    dublincore_v1, 'application/xml')
#: DublinCore search serializer.
dublincore_v1_search = search_responsify(
    dublincore_v1, 'application/xml')

#: MODS serializer.
mods_v1 = MARCXMLSerializer(to_marc21, xslt_filename=xslt_mods)
#: DublinCore record serializer.
Пример #25
0
        :param pid: Persistent identifier instance.
        :param record: Record instance.
        :param links_factory: Factory function for record links.
        """
        if request and request.args.get('resolve'):
            record = record.replace_refs()
        if request and request.args.get('sources'):
            sources = []
            # TODO: add the list of sources into the current_app.config
            if 'rero' in record:
                sources.append('rero')
            record['sources'] = sources

        concept_classes = get_entity_classes()
        for concept, concept_classe in concept_classes.items():
            if concept in ['corero']:
                local_link(concept, concept_classe.name, record)

        return super(ReroMefSerializer,
                     self).serialize(pid,
                                     record,
                                     links_factory=add_links,
                                     **kwargs)


json_v1 = ReroMefSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""

json_v1_concept_mef_response = record_responsify(json_v1,
                                                 'application/rero+json')
Пример #26
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.


from invenio_records_rest.serializers.response import record_responsify

from inspirehep.accounts.api import is_superuser_or_cataloger_logged_in
from inspirehep.records.marshmallow.base import EnvelopeSchema, ForbiddenSchema
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer

records_raw_json = ConditionalMultiSchemaJSONSerializer(
    [
        (
            lambda _: is_superuser_or_cataloger_logged_in(),
            EnvelopeSchema,
        ),
        (None, ForbiddenSchema),
    ]
)
raw_json_detail_response = record_responsify(
    records_raw_json,
    "application/vnd+inspire.record.raw+json",
)
Пример #27
0
csl_v1 = JSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(csl_v1)
#: OpenAIRE JSON serializer
openaire_json_v1 = JSONSerializer(RecordSchemaOpenAIREJSON, replace_refs=True)
#: JSON-LD serializer
schemaorg_jsonld_v1 = ZenodoSchemaOrgSerializer(replace_refs=True)
#: Extra formats serializer
extra_formats_v1 = ExtraFormatsSerializer()
#: GeoJSON serializer
geojson_v1 = GeoJSONSerializer(replace_refs=False)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record legacy serializer for individual records.
legacyjson_v1_response = record_responsify(legacyjson_v1, 'application/json')
#: MARCXML record serializer for individual records.
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX record serializer for individual records.
bibtex_v1_response = record_responsify(bibtex_v1, 'application/x-bibtex')
#: DataCite v3.1 record serializer for individual records.
datacite_v31_response = record_responsify(
    datacite_v31, 'application/x-datacite+xml')
#: DataCite v4.1 record serializer for individual records.
datacite_v41_response = record_responsify(
    datacite_v41, 'application/x-datacite-v41+xml')
#: DCAT v4.1 record serializer for individual records.
dcat_response = record_responsify(
    dcat_v1, 'application/rdf+xml')
Пример #28
0
#
# You should have received a copy of the GNU General Public License
# along with CERN Open Data Portal; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
"""Record serialization."""

from .basic_json import BasicJSONSerializer, RecordSchemaV1, CODJSONSerializer
from .schemaorg import CODSchemaorgSerializer

from invenio_records_rest.serializers.response import (
    record_responsify,
    search_responsify,
)
from invenio_records_rest.schemas import RecordSchemaJSONV1

json = BasicJSONSerializer(RecordSchemaV1)

schemaorg_jsonld = CODSchemaorgSerializer(replace_refs=True)

schemaorg_jsonld_response = record_responsify(schemaorg_jsonld,
                                              'application/ld+json')

json_search = CODJSONSerializer(RecordSchemaJSONV1)

json_v1_search = search_responsify(json_search, 'application/json')
Пример #29
0
from .cvformathtml_serializer import CVFORMATHTMLSerializer
from .cvformattext_serializer import CVFORMATTEXTSerializer
from .schemas.json import RecordSchemaJSONBRIEFV1

json_brief_v1 = JSONBriefSerializer(RecordSchemaJSONBRIEFV1)
json_brief_v1_search = search_responsify(json_brief_v1,
                                         'application/vnd+inspire.brief+json')

bibtex_v1 = BIBTEXSerializer()
latexeu_v1 = LATEXEUSerializer()
latexus_v1 = LATEXUSSerializer()
cvformatlatex_v1 = CVFORMATLATEXSerializer()
cvformathtml_v1 = CVFORMATHTMLSerializer()
cvformattext_v1 = CVFORMATTEXTSerializer()

bibtex_v1_response = record_responsify(bibtex_v1, 'application/x-bibtex')
latexeu_v1_response = record_responsify(latexeu_v1, 'application/x-latexeu')
latexus_v1_response = record_responsify(latexus_v1, 'application/x-latexus')
cvformatlatex_v1_response = record_responsify(cvformatlatex_v1,
                                              'application/x-cvformatlatex')
cvformathtml_v1_response = record_responsify(cvformathtml_v1,
                                             'application/x-cvformathtml')
cvformattext_v1_response = record_responsify(cvformattext_v1,
                                             'application/x-cvformattext')


bibtex_v1_search = search_responsify(bibtex_v1, 'application/x-bibtex')
latexeu_v1_search = search_responsify(latexeu_v1, 'application/x-latexeu')
latexus_v1_search = search_responsify(latexus_v1, 'application/x-latexus')
cvformatlatex_v1_search = search_responsify(cvformatlatex_v1,
                                            'application/x-cvformatlatex')
Пример #30
0
"""Acquisition receipt serialization."""

from invenio_records_rest.serializers.response import record_responsify

from ..acq_receipt_lines.dumpers import AcqReceiptLineESDumper
from ..serializers import JSONSerializer, RecordSchemaJSONV1


class AcqReceiptReroJSONSerializer(JSONSerializer):
    """Mixin serializing records as JSON."""
    def preprocess_record(self, pid, record, links_factory=None, **kwargs):
        """Prepare a record and persistent identifier for serialization."""
        # add some dynamic key related to the record.
        record['total_amount'] = record.total_amount
        record['quantity'] = record.total_item_quantity
        record['receipt_lines'] = [
            receipt_line.dumps(dumper=AcqReceiptLineESDumper())
            for receipt_line in record.get_receipt_lines()
        ]
        # add currency to avoid to load related order_line->order to get it
        record['currency'] = record.order.get('currency')
        return super().preprocess_record(pid=pid,
                                         record=record,
                                         links_factory=links_factory,
                                         kwargs=kwargs)


json_acre = AcqReceiptReroJSONSerializer(RecordSchemaJSONV1)

json_acre_record = record_responsify(json_acre, 'application/rero+json')
Пример #31
0
from invenio_records_rest.serializers.json import JSONSerializer
from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify
from invenio_records_rest.serializers.schemas.json import RecordSchemaJSONV1
from pkg_resources import resource_filename

from .depositschema import DepositSchemaV1
from .json import WekoJSONSerializer
from .opensearchresponse import oepnsearch_responsify
from .opensearchserializer import OpenSearchSerializer
from .schemas.csl import RecordSchemaCSLJSON
from .searchserializer import SearchSerializer

deposit_json_v1 = JSONSerializer(DepositSchemaV1, replace_refs=True)
#: JSON record serializer for individual records.
deposit_json_v1_response = record_responsify(deposit_json_v1,
                                             'application/json')

# For search result list
json_v1 = SearchSerializer(RecordSchemaJSONV1)
json_v1_search = search_responsify(json_v1, 'application/json')

# For opensearch serialize
opensearch_v1 = OpenSearchSerializer(RecordSchemaJSONV1)
opensearch_v1_search = oepnsearch_responsify(opensearch_v1)

#: CSL-JSON serializer
csl_v1 = WekoJSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(csl_v1)

#: CSL-JSON record serializer for individual records.
Пример #32
0
        #     xml_links = element.links()
        #     self_link = links.get('self')
        #     if self_link:
        #         xml_links.append(element.self(f'{self_link}&format=dc'))
        #     next_link = links.get('next')
        #     if next_link:
        #         xml_links.append(element.next(f'{next_link}&format=dc'))
        #     xml_root.append(xml_links)
        return etree.tostring(xml_root,
                              encoding='utf-8',
                              method='xml',
                              pretty_print=True)


json_doc = DocumentJSONSerializer(RecordSchemaJSONV1)
"""JSON v1 serializer."""
xml_dc = DublinCoreSerializer(RecordSchemaJSONV1)
"""XML DUBLIN CORE v1 serializer."""
xml_marcxml = DocumentMARCXMLSerializer()
"""XML MARCXML v1 serializer."""
xml_marcxmlsru = DocumentMARCXMLSRUSerializer()
"""XML MARCXML SRU v1 serializer."""

json_doc_search = search_responsify(json_doc, 'application/rero+json')
json_doc_response = record_responsify(json_doc, 'application/rero+json')
xml_dc_search = search_responsify(xml_dc, 'application/xml')
xml_dc_response = record_responsify(xml_dc, 'application/xml')
xml_marcxml_search = search_responsify(xml_marcxml, 'application/xml')
xml_marcxml_response = record_responsify(xml_marcxml, 'application/xml')
xml_marcxmlsru_search = search_responsify(xml_marcxmlsru, 'application/xml')
Пример #33
0
    search_responsify

from rero_ils.modules.items.serializers.response import search_responsify_csv
from rero_ils.modules.serializers import JSONSerializer, RecordSchemaJSONV1

from .csv import ItemCSVSerializer
from .json import ItemsJSONSerializer

csv_item = ItemCSVSerializer(
    JSONSerializer,
    csv_included_fields=[
        'pid', 'document_pid', 'document_title', 'document_creator',
        'document_main_type', 'document_sub_type', 'library_name',
        'location_name', 'barcode', 'call_number', 'second_call_number',
        'enumerationAndChronology', 'item_type', 'temporary_item_type',
        'temporary_item_type_end_date', 'general_note', 'staff_note',
        'checkin_note', 'checkout_note', 'loans_count', 'checkout_date',
        'due_date', 'last_transaction_date', 'status', 'created',
        'issue_status', 'issue_status_date', 'issue_claims_count',
        'issue_expected_date', 'issue_regular'
    ])
csv_item_response = record_responsify(csv_item, "text/csv")
csv_item_search = search_responsify_csv(csv_item, "text/csv")
"""CSV serializer."""

json_item = ItemsJSONSerializer(RecordSchemaJSONV1)
"""JSON serializer."""

json_item_search = search_responsify(json_item, 'application/rero+json')
json_item_response = record_responsify(json_item, 'application/rero+json')
Пример #34
0
        data = self.transform_record(pid, record, links_factory, **kwargs)
        return self.cv_template().render(
            record=data, host=current_app.config["SERVER_NAME"]
        )

    def serialize(self, pid, record, links_factory=None, **kwargs):
        body = self.serialize_inner(pid, record, links_factory=links_factory, **kwargs)
        return self.wrapping_html.format(body=body)

    def preprocess_record(self, pid, record, links_factory=None, **kwargs):
        return record

    def serialize_search(
        self, pid_fetcher, search_result, links=None, item_links_factory=None
    ):
        records = (
            hit["_source"].get("_cv_format", "")
            for hit in search_result["hits"]["hits"]
        )
        body = "\n  ".join(records)
        return self.wrapping_html.format(body=body)


literature_cv_html = CVHTMLSerializer(schema_class=CVSchema)
literature_cv_html_response = record_responsify(
    literature_cv_html, "text/vnd+inspire.html+html"
)
literature_cv_html_response_search = search_responsify(
    literature_cv_html, "text/vnd+inspire.html+html"
)
Пример #35
0
"""Record serializers."""

from __future__ import absolute_import, print_function

from invenio_records_rest.serializers.json import JSONSerializer
from invenio_records_rest.serializers.response import record_responsify, \
    search_responsify

from ..marshmallow import RecordSchemaV1

# Serializers
# ===========
#: JSON serializer definition.
json_v1 = JSONSerializer(RecordSchemaV1, replace_refs=True)

# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')

custom_v1_response = record_responsify(json_v1, 'application/x-custom')

__all__ = (
    'json_v1',
    'json_v1_response',
    'json_v1_search',
    'custom_v1_response',
)
Пример #36
0
    record_responsify,
    search_responsify,
)
from pkg_resources import resource_filename

from .marcxml import MARCXMLSerializer

xslt_dublincore_oai = resource_filename("invenio_marc21", "xslts/MARC21slim2OAIDC.xsl")
xslt_dublincore_rdf = resource_filename("invenio_marc21", "xslts/MARC21slim2RDFDC.xsl")
xslt_dublincore_SRW = resource_filename("invenio_marc21", "xslts/MARC21slim2SRWDC.xsl")
xslt_mods = resource_filename("invenio_marc21", "xslts/MARC21slim2MODS3-6.xsl")

#: MARCXML serializer.
marcxml_v1 = MARCXMLSerializer(to_marc21)
#: MARCXML record serializer
marcxml_v1_response = record_responsify(marcxml_v1, "application/marcxml+xml")
#: MARCXML search serializer
marcxml_v1_search = search_responsify(marcxml_v1, "application/marcxml+xml")

#: DublinCore serializer.
dublincore_v1 = MARCXMLSerializer(to_marc21, xslt_filename=xslt_dublincore_oai)
#: DublinCore record serializer.
dublincore_v1_response = record_responsify(dublincore_v1, "application/xml")
#: DublinCore search serializer.
dublincore_v1_search = search_responsify(dublincore_v1, "application/xml")

#: MODS serializer.
mods_v1 = MARCXMLSerializer(to_marc21, xslt_filename=xslt_mods)
#: DublinCore record serializer.
mods_v1_response = record_responsify(mods_v1, "application/mods+xml")
#: DublinCore search serializer.
Пример #37
0
#: Dublin Core serializer
dc_v1 = ZenodoDublinCoreSerializer(DublinCoreV1, replace_refs=True)
#: CSL-JSON serializer
csl_v1 = JSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(csl_v1)
#: OpenAIRE JSON serializer
openaire_json_v1 = JSONSerializer(RecordSchemaOpenAIREJSON, replace_refs=True)
#: JSON-LD serializer
schemaorg_jsonld_v1 = ZenodoSchemaOrgSerializer(replace_refs=True)


# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record legacy serializer for individual records.
legacyjson_v1_response = record_responsify(legacyjson_v1, 'application/json')
#: MARCXML record serializer for individual records.
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX record serializer for individual records.
bibtex_v1_response = record_responsify(bibtex_v1, 'application/x-bibtex')
#: DataCite v3.1 record serializer for individual records.
datacite_v31_response = record_responsify(
    datacite_v31, 'application/x-datacite+xml')
#: DublinCore record serializer for individual records.
dc_v1_response = record_responsify(dc_v1, 'application/x-dc+xml')
#: CSL-JSON record serializer for individual records.
csl_v1_response = record_responsify(
    csl_v1, 'application/vnd.citationstyles.csl+json')
#: CSL Citation Formatter serializer for individual records.
Пример #38
0
)
from inspirehep.records.marshmallow.experiments.ui import (
    ExperimentsDetailSchema,
    ExperimentsListSchema,
)
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

experiments_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(ExperimentsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(ExperimentsPublicSchema)),
])

experiments_json_response = record_responsify(experiments_json,
                                              "application/json")

experiments_json_response_search = search_responsify(experiments_json,
                                                     "application/json")

experiments_json_detail = JSONSerializer(
    wrap_schema_class_with_metadata(ExperimentsDetailSchema))
experiments_json_detail_response = record_responsify(
    experiments_json_detail, "application/vnd+inspire.record.ui+json")

experiments_json_list = JSONSerializer(
    wrap_schema_class_with_metadata(ExperimentsListSchema),
    index_name="records-experiments",
)
experiments_json_list_response = search_responsify(
    experiments_json_list, "application/vnd+inspire.record.ui+json")
Пример #39
0
oai_datacite = OAIDataCiteSerializer(
    v31=datacite_v31,
    datacentre='CERN.ZENODO',
)
#: Dublin Core serializer
dc_v1 = ZenodoDublinCoreSerializer(DublinCoreV1, replace_refs=True)
#: CSL-JSON serializer
csl_v1 = JSONSerializer(RecordSchemaCSLJSON, replace_refs=True)
#: CSL Citation Formatter serializer
citeproc_v1 = CiteprocSerializer(csl_v1)


# Records-REST serializers
# ========================
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record legacy serializer for individual records.
legacyjson_v1_response = record_responsify(legacyjson_v1, 'application/json')
#: MARCXML record serializer for individual records.
marcxml_v1_response = record_responsify(marcxml_v1, 'application/marcxml+xml')
#: BibTeX record serializer for individual records.
bibtex_v1_response = record_responsify(bibtex_v1, 'application/x-bibtex')
#: DataCite v3.1 record serializer for individual records.
datacite_v31_response = record_responsify(
    datacite_v31, 'application/x-datacite+xml')
#: DublinCore record serializer for individual records.
dc_v1_response = record_responsify(dc_v1, 'application/x-dc+xml')
#: CSL-JSON record serializer for individual records.
csl_v1_response = record_responsify(
    csl_v1, 'application/vnd.citationstyles.csl+json')
#: CSL Citation Formatter serializer for individual records.
Пример #40
0
# CERN Open Data Portal is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CERN Open Data Portal; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Record serialization."""

from __future__ import absolute_import, print_function

from .basic_json import BasicJSONSerializer, RecordSchemaV1
from .schemaorg import CODSchemaorgSerializer

from invenio_records_rest.serializers.response import record_responsify


json = BasicJSONSerializer(RecordSchemaV1)

schemaorg_jsonld = CODSchemaorgSerializer(replace_refs=True)

schemaorg_jsonld_response = record_responsify(schemaorg_jsonld,
                                              'application/ld+json')