From cb9edd2fa603b9ff8328dd877c75bce2e0dd174c Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Tue, 9 Nov 2021 11:13:12 +0100 Subject: [PATCH] deposit: improve document type detection. If field 502 is available in the record, it is analyzed to determine the type of document. Co-Authored-by: Bertrand Zuchuat --- sonar/modules/documents/dojson/sru/model.py | 27 ++++++++++--------- .../api/swisscovery/test_swisscovery_rest.py | 14 ++++++++++ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/sonar/modules/documents/dojson/sru/model.py b/sonar/modules/documents/dojson/sru/model.py index 4f395f81..7dcc33c4 100644 --- a/sonar/modules/documents/dojson/sru/model.py +++ b/sonar/modules/documents/dojson/sru/model.py @@ -507,23 +507,22 @@ def determine_type(field): """Determine type of document.""" # Bachelor thesis if 'bachelor' in field.get( - 'a', '') or 'bachelor' in field.get('b', ''): + 'a', '').lower() or 'bachelor' in field.get('b', '').lower(): return 'coar:c_7a1f' # Master thesis - if 'master' in field.get('a', '') or 'master' in field.get( - 'b', ''): + if 'master' in field.get('a', '').lower() or 'master' in field.get( + 'b', '').lower(): 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', ''): + 'a', '').lower() or 'dissertation' in field.get( + 'b', '').lower() or 'thèse' in field.get( + 'a', '').lower() or 'thèse' in field.get('b', '')\ + .lower(): return 'coar:c_db06' - # Thesis - return 'coar:c_46ec' leader_06 = value[6] @@ -570,11 +569,15 @@ def determine_type(field): if field_502: if type(field_502) == tuple: for fld502 in field_502: - # Bachelor thesis - return determine_type(fld502) + doctype = determine_type(fld502) + if doctype: + return doctype else: - # Bachelor thesis - return determine_type(field_502) + doctype = determine_type(field_502) + if doctype: + return doctype + # Thesis + return 'coar:c_46ec' # Book if leader_07 == 'm': return 'coar:c_2f33' diff --git a/tests/api/swisscovery/test_swisscovery_rest.py b/tests/api/swisscovery/test_swisscovery_rest.py index 9a68308a..70d9adf2 100644 --- a/tests/api/swisscovery/test_swisscovery_rest.py +++ b/tests/api/swisscovery/test_swisscovery_rest.py @@ -22,6 +22,7 @@ def test_get_record(client, user, submitter): + """Test get record on swisscovery.""" url = url_for('swisscovery.get_record') # Not logged @@ -184,3 +185,16 @@ def test_get_record(client, user, submitter): } } } + + +def test_document_type(client, submitter): + """Test of the document type with the content of field 502.""" + login_user_via_session(client, email=submitter['email']) + res = client.get( + url_for('swisscovery.get_record', + query='991050676859705501', + type='mms_id', + format='deposit')) + assert res.status_code == 200 + data = res.json + assert data['metadata']['documentType'] == 'coar:c_db06'