Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documents: import HEP FR publications from RERO DOC to FOLIA #737

Merged
merged 1 commit into from
Dec 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion sonar/modules/documents/dojson/rerodoc/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from sonar.modules.collections.api import Record as CollectionRecord
from sonar.modules.documents.dojson.rerodoc.overdo import Overdo
from sonar.modules.organisations.api import OrganisationRecord
from sonar.modules.subdivisions.api import Record as SubdivisionRecord
from sonar.modules.subdivisions.api import RecordSearch, Record as SubdivisionRecord
from sonar.modules.utils import remove_trailing_punctuation

overdo = Overdo()
Expand Down Expand Up @@ -59,6 +59,8 @@
@utils.ignore_value
def marc21_to_type_and_organisation(self, key, value):
"""Get document type and organisation from 980 field."""
subdivision_name = None

# organisation
if value.get('b'):
organisation = value.get('b').lower()
Expand Down Expand Up @@ -86,6 +88,33 @@ def marc21_to_type_and_organisation(self, key, value):
if customField2:
self['customField2'] = [customField2]

# Specific transformation for `hepfr`, which should be imported as
# a faculty AND a subdivision of FOLIA/unifr
if organisation == 'hepfr':
organisation = 'unifr'
self['organisation'] = [{
'$ref':
OrganisationRecord.get_ref_link('organisations', organisation)
}]
# `hepfr` is a faculty of FOLIA/unifr
self['customField1'] = ['HEP|PH FR']
# `hepfr` is a subdivision of FOLIA/unifr
subdivision_name = 'HEP Fribourg'
# Store subdivision
# TODO: avoid possible clashes between subdivision
# names in different languages
result = RecordSearch()\
.filter('term', organisation__pid=organisation)\
.filter('term', name__value__raw=subdivision_name)\
.source(includes='pid').scan()
subdivision_pid = next(result).pid
# If the subdivision exists, assign it to the record
if subdivision_pid:
self['subdivisions'] = [{
'$ref':
SubdivisionRecord.get_ref_link('subdivisions', subdivision_pid)
}]

# Specific transformation for `bpuge` and `mhnge`, because the real
# acronym is `vge`.
subdivision_name = None
Expand Down