Unverified Commit 99b57fc0 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

better logging for access_status


Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent 98fa99f6
Pipeline #16774 failed with stages
in 1 minute and 5 seconds
......@@ -209,16 +209,24 @@ def _get_values_from_digital_object(msg, access_status):
return return_values
def _get_access_status(graph):
def _get_access_status(graph, record_id):
for resource in graph:
if 'type' in resource and resource['type'] == 'access' and \
'regulates' in resource and \
resource['regulates'].startswith('https://memobase.ch/digital/') and \
'name' in resource:
if resource['name'] == 'public':
logging.debug(f'{record_id}: Setting access for digital object to `public`')
return 'public'
elif resource['name'] == 'private':
logging.debug(f'{record_id}: Setting access for digital object to `closed`')
return 'closed'
else:
logging.info(f'Digital object of record {record_id} has access type ' +
f'`{resource["name"]}`. This makes the media resource unavailable.')
else:
logging.info(f'Digital object of record {record_id} has no related access information!'
+ 'Media resource is therefore unavailable')
return 'unavailable'
......@@ -318,7 +326,7 @@ class MediametadataToDB:
records_json_data = recordsJson.value['@graph']
record_id = _get_record_id(records_json_data)
logging.debug(f'Processing record {record_id}')
access_status = _get_access_status(records_json_data)
access_status = _get_access_status(records_json_data, record_id)
if access_status == 'public' or access_status == 'closed':
for recordJsonData in records_json_data:
if 'type' in recordJsonData and \
......
......@@ -69,8 +69,8 @@ class Reporter:
key_bytes = bytes(identifier, encoding='utf-8')
now = datetime.datetime.now()
# //@formatter:off
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S.') + \
str(round(int(now.strftime('%f')) / 1000))
timestamp = now.strftime('%Y-%m-%dT%H:%M:%S.') +\
str(round(int(now.strftime('%f')) / 1000))
# //@formatter:on
report = {
'id': identifier,
......
......@@ -74,3 +74,42 @@ class Test(TestCase):
Test._get_digital_object)
dig_obj_val = MediametadataToDB._get_values_from_digital_object(digital_object, 'public')
self.assertDictEqual(dig_obj_val, res)
def test__get_values_from_thumbnail(self):
res = {
'uri': 'file:///data/Tanzarchiv-34695-35298-1-poster.jp2',
'access': 'public',
'mimetype': 'image/jp2',
'type': 'image',
'proto': 'file',
'sig': 'Tanzarchiv-34695-35298-1-poster'
}
thumbnail = Test._load_file_and_get_res('Tanzarchiv-34695-35298.json', Test._get_thumbnail)
thumbnail_val = MediametadataToDB._get_values_from_thumbnail_object(thumbnail, 'public')
self.assertDictEqual(thumbnail_val, res)
def test__has_no_audio_snippet(self):
record_values_for_db = []
for recordJsonData in \
Test._load_file_and_get_res('SRF-UMusik-BE_MG_DUR_B62276.json', lambda x: x):
if 'type' in recordJsonData and \
recordJsonData['type'] == 'digitalObject':
MediametadataToDB._try_fetch_from_json_object(recordJsonData, record_values_for_db,
MediametadataToDB.
_get_values_from_digital_object,
'public')
self.assertFalse([MediametadataToDB._has_audio_snippet(record)
for record in record_values_for_db][0])
# def test__has_audio_snippet(self):
# record_values_for_db = []
# for recordJsonData \
# in Test._load_file_and_get_res('Tanzarchiv-34695-35298.json', lambda x: x):
# if 'type' in recordJsonData and \
# recordJsonData['type'] == 'digitalObject':
# MediametadataToDB._try_fetch_from_json_object(recordJsonData, record_values_for_db,
# MediametadataToDB.
# _get_values_from_digital_object,
# 'public')
# self.assertTrue([MediametadataToDB._has_audio_snippet(record)
# for record in record_values_for_db][0])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment