Skip to content

Commit

Permalink
deposits: fix swisscovery import
Browse files Browse the repository at this point in the history
* Fixes error on 502 fields on leader function.
* Fixes extract date on 100 or 700 field.
* Closes rero#674.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
Garfield-fr and rerowep committed Nov 4, 2021
1 parent 91b26f1 commit 4868d9a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@
},
"publisher": {
"title": "Publication statement",
"definition": "Place, publisher and date of the host document. For example: Paris : PUF, 2016)",
"definition": "Place, publisher and date of the host document. For example: Paris : PUF, 2016",
"type": "string",
"minLength": 1
},
Expand Down
56 changes: 35 additions & 21 deletions sonar/modules/documents/dojson/sru/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ def marc21_to_contribution_from_100_700(self, key, value):
data = {'agent': {'type': type, 'preferred_name': name}, 'role': [role]}

if is_100_or_700 and value.get('d'):
date_of_birth, date_of_death = overdo.extract_date(value['d'][:9])
date_of_birth = date_of_death = None
try:
date_of_birth, date_of_death = overdo.extract_date(value['d'][:9])
except Exception:
pass

if date_of_birth:
data['agent']['date_of_birth'] = date_of_birth
Expand Down Expand Up @@ -498,6 +502,29 @@ def marc21_to_edition_statement_from_250(self, key, value):
@utils.ignore_value
def marc21_to_document_type_from_leader(self, key, value):
"""Get document type from leader."""

def determine_type(field):
"""Determine type of document."""
# Bachelor thesis
if 'bachelor' in field.get(
'a', '') or 'bachelor' in field.get('b', ''):
return 'coar:c_7a1f'

# Master thesis
if 'master' in field.get('a', '') or 'master' in field.get(
'b', ''):
return 'coar:c_bdcc'

# Doctoral thesis
if 'dissertation' in field.get(
'a', '') or 'dissertation' in field.get(
'b', '') or 'thèse' in field.get(
'a', '') or 'thèse' in field.get('b', ''):
return 'coar:c_db06'

# Thesis
return 'coar:c_46ec'

leader_06 = value[6]

# Still image
Expand Down Expand Up @@ -541,26 +568,13 @@ def marc21_to_document_type_from_leader(self, key, value):

field_502 = overdo.blob_record.get('502__')
if field_502:
# Bachelor thesis
if 'bachelor' in field_502.get(
'a', '') or 'bachelor' in field_502.get('b', ''):
return 'coar:c_7a1f'

# Master thesis
if 'master' in field_502.get('a', '') or 'master' in field_502.get(
'b', ''):
return 'coar:c_bdcc'

# Doctoral thesis
if 'dissertation' in field_502.get(
'a', '') or 'dissertation' in field_502.get(
'b', '') or 'thèse' in field_502.get(
'a', '') or 'thèse' in field_502.get('b', ''):
return 'coar:c_db06'

# Thesis
return 'coar:c_46ec'

if type(field_502) == tuple:
for fld502 in field_502:
# Bachelor thesis
return determine_type(fld502)
else:
# Bachelor thesis
return determine_type(field_502)
# Book
if leader_07 == 'm':
return 'coar:c_2f33'
Expand Down

0 comments on commit 4868d9a

Please sign in to comment.