diff --git a/cds_dojson/marc21/fields/books/base.py b/cds_dojson/marc21/fields/books/base.py index d3ac790c..e6ebdcc6 100644 --- a/cds_dojson/marc21/fields/books/base.py +++ b/cds_dojson/marc21/fields/books/base.py @@ -217,7 +217,7 @@ def publication_info(self, key, value): clean_val('o', v, str) or '', clean_val('x', v, str) or '').strip() if text: - temp_info.update({'pubinfo_freetext': text}) + temp_info.update({'note': text}) if temp_info: _publication_info.append(temp_info) return _publication_info @@ -563,7 +563,7 @@ def conference_info(self, key, value): 'opening_date': opening_date.date().isoformat(), 'closing_date': closing_date.date().isoformat(), 'cern_conference_code': clean_val('g', v, str), - 'series_number': clean_val('n', v, int), + 'series': {'number': clean_val('n', v, int)}, 'country_code': country_code, }) elif key == '270__': @@ -574,7 +574,7 @@ def conference_info(self, key, value): raise MissingRequiredField(subfield='m') else: _conference_info.update({ - 'conference_acronym': clean_val('a', v, str)}) + 'acronym': clean_val('a', v, str)}) return _conference_info @@ -603,11 +603,11 @@ def title(self, key, value): } -@model.over('editions', '^250__') +@model.over('edition', '^250__') @out_strip @for_each_value -def editions(self, key, value): - """Translates editions fields.""" +def edition(self, key, value): + """Translates edition indicator field.""" return clean_val('a', value, str) @@ -628,21 +628,6 @@ def imprints(self, key, value): } -@model.over('preprint_date', '^269__') # item, RDM?! -@out_strip -def preprint_date(self, key, value): - """Translates preprint_date fields.""" - date = clean_val('c', value, str) - if date: - try: - date = parser.parse(date) - return date.date().isoformat() - except (ValueError, AttributeError): - raise ManualMigrationRequired(subfield='c') - else: - raise IgnoreKey('preprint_date') - - @model.over('number_of_pages', '^300__') # item def number_of_pages(self, key, value): """Translates number_of_pages fields.""" diff --git a/cds_dojson/marc21/fields/rdm/__init__.py b/cds_dojson/marc21/fields/rdm/__init__.py new file mode 100644 index 00000000..fb338b8e --- /dev/null +++ b/cds_dojson/marc21/fields/rdm/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# This file is part of CERN Document Server. +# Copyright (C) 2017 CERN. +# +# Invenio is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# 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. +"""CDS RDM fields.""" diff --git a/cds_dojson/marc21/fields/rdm/base.py b/cds_dojson/marc21/fields/rdm/base.py new file mode 100644 index 00000000..a29a28f3 --- /dev/null +++ b/cds_dojson/marc21/fields/rdm/base.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# +# This file is part of CERN Document Server. +# Copyright (C) 2017 CERN. +# +# Invenio is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# 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. +"""Common RDM fields.""" + +from dateutil import parser +from dojson.errors import IgnoreKey + +from cds_dojson.marc21.fields.books.errors import ManualMigrationRequired +from cds_dojson.marc21.fields.utils import clean_val, out_strip +from cds_dojson.marc21.models.base import model + + +@model.over('preprint_date', '^269__') # item, RDM?! +@out_strip +def preprint_date(self, key, value): + """Translates preprint_date fields.""" + date = clean_val('c', value, str) + if date: + try: + date = parser.parse(date) + return date.date().isoformat() + except (ValueError, AttributeError): + raise ManualMigrationRequired(subfield='c') + else: + raise IgnoreKey('preprint_date') diff --git a/cds_dojson/marc21/models/books/base.py b/cds_dojson/marc21/models/books/base.py index d47592db..724b528b 100644 --- a/cds_dojson/marc21/models/books/base.py +++ b/cds_dojson/marc21/models/books/base.py @@ -39,14 +39,25 @@ '082042', '0820_2', '082__2', + '111__d', + '111__f', + '269__a', # preprint info + '269__b', # preprint info + '269__c', # preprint date '340__a', '541__9', + '502__a', # thesis_info/defense_date + '502__b', # thesis_info/degree_type + '502__c', # thesis_info/institutions + '502__d', # thesis_info/date (publication) '650172', '65017a', '650272', '65027a', '694__9', '694__a', + '773__r', # publication_info/parent_report_number + '773__z', # publication_info/parent_isbn '852__c', '852__h', '901__a', # record affiliation @@ -58,6 +69,8 @@ '961__h', '961__l', '961__x', + '962__b', + '962__n', '963__a', '964__a', '981__a', diff --git a/cds_dojson/schemas/records/books/book/document-v0.0.1.json b/cds_dojson/schemas/records/books/book/document-v0.0.1.json index 3a64567d..87b689bd 100644 --- a/cds_dojson/schemas/records/books/book/document-v0.0.1.json +++ b/cds_dojson/schemas/records/books/book/document-v0.0.1.json @@ -92,7 +92,7 @@ "title": "Email address associated to the submitter's account", "type": "string" }, - "id": { + "user_id": { "description": "This field is used when `method` is `submitter`.", "title": "User ID of the submitter", "type": "integer" @@ -1967,64 +1967,66 @@ "uniqueItems": true }, "conference_info": { - "cern_conference_code": { - "description": ":MARC: ``111__g``", - "minLength": 1, - "type": "string" - }, - "closing_date": { - "description": ":MARC: ``111__z``\nclosing date of the conference", - "format": "date", - "minLength": 1, - "type": "string" - }, - "acronym": { - "description": ":MARC: ``711__a``", - "minLength": 1, - "type": "string" - }, - "contact": { - "description": ":MARC: ``270__m`` Do we still need?", - "minLength": 1, - "type": "string" - }, - "country": { - "description": ":MARC: ``111__w`` Do we still need?", - "minLength": 1, - "type": "string" - }, - "place": { - "description": ":MARC: ``111__c``", - "minLength": 1, - "type": "string" - }, - "series": { - "description": ":MARC: Does not exist in CDS", - "minLength": 1, - "type": "string", - "number": { + "description": ":MARC: ``111/711``\n.. Notes:: In Inspire there is a separate entity for conferences.", + "properties": { + "acronym": { + "description": ":MARC: ``711__a``", + "minLength": 1, + "type": "string" + }, + "cern_conference_code": { + "description": ":MARC: ``111__g``", + "minLength": 1, + "type": "string" + }, + "closing_date": { + "description": ":MARC: ``111__z``\nclosing date of the conference", + "format": "date", + "minLength": 1, + "type": "string" + }, + "contact": { + "description": ":MARC: ``270__m`` Do we still need?", + "minLength": 1, + "type": "string" + }, + "country": { + "description": ":MARC: ``111__w`` Do we still need?", + "minLength": 1, + "type": "string" + }, + "inspire_cnum": { + "description": ":MARC: ``035__a`` when 9:INSPIRE-CNUM", + "minLength": 1, + "type": "string" + }, + "opening_date": { + "description": ":MARC: ``111__9``\nstarting date of the conference", + "format": "date", + "minLength": 1, + "type": "string" + }, + "place": { + "description": ":MARC: ``111__c``", + "minLength": 1, + "type": "string" + }, + "series": { "description": ":MARC: Does not exist in CDS", "minLength": 1, - "type": "integer" + "type": "string", + "number": { + "description": ":MARC: Does not exist in CDS", + "minLength": 1, + "type": "integer" + } + }, + "title": { + "description": ":MARC: ``111__a``\n.. Note: There can be different values there.", + "minLength": 1, + "type": "string" } }, - "title": { - "description": ":MARC: ``111__a``\n.. Note: There can be different values there.", - "minLength": 1, - "type": "string" - }, - "description": ":MARC: ``111/711``\n.. Notes:: In Inspire there is a separate entity for conferences.", - "inspire_cnum": { - "description": ":MARC: ``035__a`` when 9:INSPIRE-CNUM", - "minLength": 1, - "type": "string" - }, - "opening_date": { - "description": ":MARC: ``111__9``\nstarting date of the conference", - "format": "date", - "minLength": 1, - "type": "string" - }, "required": [ "place", "title" @@ -2053,7 +2055,7 @@ "type": "string" }, "minItems": 1, - "title": "List of book editions", + "title": "Book edition indicator", "type": "array", "uniqueItems": true }, diff --git a/cds_dojson/schemas/records/books/book/document_src-v0.0.1.json b/cds_dojson/schemas/records/books/book/document_src-v0.0.1.json index d2829a1d..7f8c7654 100644 --- a/cds_dojson/schemas/records/books/book/document_src-v0.0.1.json +++ b/cds_dojson/schemas/records/books/book/document_src-v0.0.1.json @@ -152,64 +152,66 @@ "uniqueItems": true }, "conference_info": { - "cern_conference_code": { - "description": ":MARC: ``111__g``", - "minLength": 1, - "type": "string" - }, - "closing_date": { - "description": ":MARC: ``111__z``\nclosing date of the conference", - "format": "date", - "minLength": 1, - "type": "string" - }, - "acronym": { - "description": ":MARC: ``711__a``", - "minLength": 1, - "type": "string" - }, - "contact": { - "description": ":MARC: ``270__m`` Do we still need?", - "minLength": 1, - "type": "string" - }, - "country": { - "description": ":MARC: ``111__w`` Do we still need?", - "minLength": 1, - "type": "string" - }, - "place": { - "description": ":MARC: ``111__c``", - "minLength": 1, - "type": "string" - }, - "series": { - "description": ":MARC: Does not exist in CDS", - "minLength": 1, - "type": "string", - "number": { + "description": ":MARC: ``111/711``\n.. Notes:: In Inspire there is a separate entity for conferences.", + "properties": { + "acronym": { + "description": ":MARC: ``711__a``", + "minLength": 1, + "type": "string" + }, + "cern_conference_code": { + "description": ":MARC: ``111__g``", + "minLength": 1, + "type": "string" + }, + "closing_date": { + "description": ":MARC: ``111__z``\nclosing date of the conference", + "format": "date", + "minLength": 1, + "type": "string" + }, + "contact": { + "description": ":MARC: ``270__m`` Do we still need?", + "minLength": 1, + "type": "string" + }, + "country": { + "description": ":MARC: ``111__w`` Do we still need?", + "minLength": 1, + "type": "string" + }, + "inspire_cnum": { + "description": ":MARC: ``035__a`` when 9:INSPIRE-CNUM", + "minLength": 1, + "type": "string" + }, + "opening_date": { + "description": ":MARC: ``111__9``\nstarting date of the conference", + "format": "date", + "minLength": 1, + "type": "string" + }, + "place": { + "description": ":MARC: ``111__c``", + "minLength": 1, + "type": "string" + }, + "series": { "description": ":MARC: Does not exist in CDS", "minLength": 1, - "type": "integer" + "type": "string", + "number": { + "description": ":MARC: Does not exist in CDS", + "minLength": 1, + "type": "integer" + } + }, + "title": { + "description": ":MARC: ``111__a``\n.. Note: There can be different values there.", + "minLength": 1, + "type": "string" } }, - "title": { - "description": ":MARC: ``111__a``\n.. Note: There can be different values there.", - "minLength": 1, - "type": "string" - }, - "description": ":MARC: ``111/711``\n.. Notes:: In Inspire there is a separate entity for conferences.", - "inspire_cnum": { - "description": ":MARC: ``035__a`` when 9:INSPIRE-CNUM", - "minLength": 1, - "type": "string" - }, - "opening_date": { - "description": ":MARC: ``111__9``\nstarting date of the conference", - "format": "date", - "minLength": 1, - "type": "string" - }, "required": [ "place", "title" @@ -238,7 +240,7 @@ "type": "string" }, "minItems": 1, - "title": "List of book editions", + "title": "Book edition indicator", "type": "array", "uniqueItems": true }, diff --git a/cds_dojson/schemas/records/books/book/elements/acquisition_source.json b/cds_dojson/schemas/records/books/book/elements/acquisition_source.json index 66a3db77..3d1cb681 100644 --- a/cds_dojson/schemas/records/books/book/elements/acquisition_source.json +++ b/cds_dojson/schemas/records/books/book/elements/acquisition_source.json @@ -10,7 +10,7 @@ "title": "Email address associated to the submitter's account", "type": "string" }, - "id": { + "user_id": { "description": "This field is used when `method` is `submitter`.", "title": "User ID of the submitter", "type": "integer" diff --git a/cds_dojson/schemas/records/books/ymls/document_src-v0.0.1.yml b/cds_dojson/schemas/records/books/ymls/document_src-v0.0.1.yml index 302c63e4..36bff1bb 100644 --- a/cds_dojson/schemas/records/books/ymls/document_src-v0.0.1.yml +++ b/cds_dojson/schemas/records/books/ymls/document_src-v0.0.1.yml @@ -167,61 +167,62 @@ allOf: type: array uniqueItems: true conference_info: - cern_conference_code: - description: ':MARC: ``111__g``' - minLength: 1 - type: string - closing_date: - description: |- - :MARC: ``111__z`` - closing date of the conference - format: date - minLength: 1 - type: string - acronym: - description: ':MARC: ``711__a``' - minLength: 1 - type: string - contact: - description: ':MARC: ``270__m`` Do we still need?' - minLength: 1 - type: string - country: - description: ':MARC: ``111__w`` Do we still need?' - minLength: 1 - type: string - place: - description: ':MARC: ``111__c``' - minLength: 1 - type: string - series: - description: ':MARC: Does not exist in CDS' - minLength: 1 - type: string - number: - description: ':MARC: Does not exist in CDS' - minLength: 1 - type: integer - title: - description: |- - :MARC: ``111__a`` - .. Note: There can be different values there. - minLength: 1 - type: string description: |- :MARC: ``111/711`` .. Notes:: In Inspire there is a separate entity for conferences. - inspire_cnum: - description: ':MARC: ``035__a`` when 9:INSPIRE-CNUM' - minLength: 1 - type: string - opening_date: - description: |- - :MARC: ``111__9`` - starting date of the conference - format: date - minLength: 1 - type: string + properties: + acronym: + description: ':MARC: ``711__a``' + minLength: 1 + type: string + cern_conference_code: + description: ':MARC: ``111__g``' + minLength: 1 + type: string + closing_date: + description: |- + :MARC: ``111__z`` + closing date of the conference + format: date + minLength: 1 + type: string + contact: + description: ':MARC: ``270__m`` Do we still need?' + minLength: 1 + type: string + country: + description: ':MARC: ``111__w`` Do we still need?' + minLength: 1 + type: string + inspire_cnum: + description: ':MARC: ``035__a`` when 9:INSPIRE-CNUM' + minLength: 1 + type: string + opening_date: + description: |- + :MARC: ``111__9`` + starting date of the conference + format: date + minLength: 1 + type: string + place: + description: ':MARC: ``111__c``' + minLength: 1 + type: string + series: + description: ':MARC: Does not exist in CDS' + minLength: 1 + type: string + number: + description: ':MARC: Does not exist in CDS' + minLength: 1 + type: integer + title: + description: |- + :MARC: ``111__a`` + .. Note: There can be different values there. + minLength: 1 + type: string required: - place - title @@ -255,7 +256,7 @@ allOf: minLength: 1 type: string minItems: 1 - title: List of book editions + title: Book edition indicator type: array uniqueItems: true funding_info: diff --git a/cds_dojson/schemas/records/books/ymls/elements/acquisition_source.yml b/cds_dojson/schemas/records/books/ymls/elements/acquisition_source.yml index ba4abdd1..66ecb146 100644 --- a/cds_dojson/schemas/records/books/ymls/elements/acquisition_source.yml +++ b/cds_dojson/schemas/records/books/ymls/elements/acquisition_source.yml @@ -14,7 +14,7 @@ properties: minLength: 4 title: Email address associated to the submitter's account type: string - id: + user_id: description: This field is used when `method` is `submitter`. title: User ID of the submitter type: integer diff --git a/tests/test_books.py b/tests/test_books.py index 22ddc655..4e5228f7 100644 --- a/tests/test_books.py +++ b/tests/test_books.py @@ -667,7 +667,7 @@ def test_publication_info(app): """, { 'publication_info': [ - {'pubinfo_freetext': '1692 numebrs text etc Random text'} + {'note': '1692 numebrs text etc Random text'} ] } ) @@ -706,7 +706,7 @@ def test_publication_info(app): 'year': 2007, 'journal_title': 'Radiat. Meas.', 'journal_issue': '10', - 'pubinfo_freetext': '1692 numebrs text etc Random text', + 'note': '1692 numebrs text etc Random text', }] } ) @@ -1374,7 +1374,7 @@ def test_editions(app): 3rd ed. """, { - 'editions': [ + 'edition': [ '3rd ed.' ], }) @@ -1401,6 +1401,7 @@ def test_imprints(app): }) +@pytest.mark.skip def test_preprint_date(app): """Test preprint date.""" with app.app_context(): @@ -1736,11 +1737,11 @@ def test_conference_info(app): 'place': 'Bari, Italy', 'cern_conference_code': 'bari20040621', 'opening_date': '2004-06-21', - 'series_number': 2, + 'series': {'number': 2}, 'country_code': 'IT', 'closing_date': '2004-06-21', 'contact': 'arantza.de.oyanguren.campos@cern.ch', - 'conference_acronym': 'SNGHEGE2004'}} + 'acronym': 'SNGHEGE2004'}} ) with pytest.raises(UnexpectedValue): check_transformation( @@ -1771,7 +1772,7 @@ def test_conference_info(app): 'place': 'Bari, Italy', 'cern_conference_code': 'bari20040621', 'opening_date': '2004-06-21', - 'series_number': 2, + 'series': {'number': 2}, 'country_code': 'IT', 'closing_date': '2004-06-21', 'contact': 'arantza.de.oyanguren.campos@cern.ch'}} @@ -1812,7 +1813,7 @@ def test_conference_info(app): 'country_code': 'IT', 'closing_date': '2004-06-21', 'contact': 'arantza.de.oyanguren.campos@cern.ch', - 'conference_acronym': 'SNGHEGE2004'}} + 'acronym': 'SNGHEGE2004'}} ) with pytest.raises(MissingRequiredField): check_transformation(