Commit 39dcb978 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Refactor record set endpoint to read from all language endpoints by default.

parent b929bd6f
Pipeline #26079 passed with stages
in 2 minutes and 5 seconds
......@@ -41,163 +41,160 @@ class UpdateRecordSet(Resource):
result_topic_value = ''
base_url = current_app.config['drupal-api-url']
json_api_path = '/jsonapi/node/record_set/'
metadata_language_path = '/jsonapi/taxonomy_term/language_of_metadata/'
user = current_app.config['drupal-user']
password = current_app.config['drupal-password']
auth = HTTPBasicAuth(user, password)
headers = {'X-API-Key': current_app.config['drupal-api-key']}
# 1. request info from drupal with received uuid for default entity
default_request = base_url + json_api_path + record_set_id
base_response = None
# Retrieve Drupal Entities for each language.
# Returns default entity if there is a language missing.
de_drupal_url = f'{base_url}/de{json_api_path}{record_set_id}'
fr_drupal_url = f'{base_url}/fr{json_api_path}{record_set_id}'
it_drupal_url = f'{base_url}/it{json_api_path}{record_set_id}'
try:
base_response = requests.get(default_request, headers=headers, auth=auth)
drupal_record_set = base_response.json()['data']
drupal_record_set_de = \
requests.get(de_drupal_url, headers=headers, auth=auth).json()['data']
drupal_record_set_fr = \
requests.get(current_app.config['drupal-api-url'] + '/fr/jsonapi/node/' +
'record_set/' + record_set_id,
headers=headers, auth=auth).json()['data']
requests.get(fr_drupal_url, headers=headers, auth=auth).json()['data']
drupal_record_set_it = \
requests.get(current_app.config['drupal-api-url'] + '/it/jsonapi/node/' +
'record_set/' + record_set_id,
headers=headers, auth=auth).json()['data']
requests.get(it_drupal_url, headers=headers, auth=auth).json()['data']
institutions = drupal_record_set['relationships']['field_institution']['data']
institution_ids = UpdateRecordSet.get_institution_id_list(institutions,
headers, auth)
institutions = drupal_record_set_de['relationships']['field_institution']['data']
institution_ids = UpdateRecordSet.get_institution_id_list(institutions, headers, auth)
institutions = drupal_record_set['relationships']['field_resp_institution_access'][
'data']
field_resp_institution_access = UpdateRecordSet.get_institution_id_list(
institutions = \
drupal_record_set_de['relationships']['field_resp_institution_access']['data']
access_institution_ids = UpdateRecordSet.get_institution_id_list(
institutions, headers, auth)
institutions = drupal_record_set['relationships']['field_resp_institution_master'][
'data']
field_resp_institution_master = UpdateRecordSet.get_institution_id_list(
institutions = \
drupal_record_set_de['relationships']['field_resp_institution_master']['data']
master_institutions_ids = UpdateRecordSet.get_institution_id_list(
institutions, headers, auth)
institutions = \
drupal_record_set['relationships']['field_resp_institution_original']['data']
field_resp_institution_original = UpdateRecordSet.get_institution_id_list(
drupal_record_set_de['relationships']['field_resp_institution_original']['data']
original_institution_ids = UpdateRecordSet.get_institution_id_list(
institutions, headers, auth)
metadata_language_codes = []
metadata_languages = \
drupal_record_set['relationships']['field_metadata_languages']['data']
drupal_record_set_de['relationships']['field_metadata_languages']['data']
for metadataLanguage in metadata_languages:
drupal_record_set_language_code = \
requests.get(current_app.config['drupal-api-url'] + '/jsonapi/taxonomy_term/' +
'language_of_metadata/' + metadataLanguage['id'],
requests.get(f'{base_url}{metadata_language_path}{metadataLanguage["id"]}',
headers=headers, auth=auth)
metadata_language_codes.append(
drupal_record_set_language_code.json()['data']['attributes']['name']
)
field_related_record_sets = UpdateRecordSet.get_related_record_sets(
drupal_record_set)
field_related_record_sets_fr = UpdateRecordSet.get_related_record_sets(
drupal_record_set_fr)
field_related_record_sets_it = UpdateRecordSet.get_related_record_sets(
drupal_record_set_it)
related_record_sets_de = \
UpdateRecordSet.get_related_record_sets(drupal_record_set_de)
related_record_sets_fr = \
UpdateRecordSet.get_related_record_sets(drupal_record_set_fr)
related_record_sets_it = \
UpdateRecordSet.get_related_record_sets(drupal_record_set_it)
result_topic_value = {
'type': drupal_record_set['type'],
'status': drupal_record_set['attributes']['status'],
'title_de': drupal_record_set['attributes']['title'],
'type': drupal_record_set_de['type'],
'status': drupal_record_set_de['attributes']['status'],
'title_de': drupal_record_set_de['attributes']['title'],
'title_fr': drupal_record_set_fr['attributes']['title'],
'title_it': drupal_record_set_it['attributes']['title'],
'field_institution': institution_ids,
'field_metadata_language_codes': metadata_language_codes,
'computed_teaser_image_url':
drupal_record_set['attributes']['computed_teaser_image_url'],
drupal_record_set_de['attributes']['computed_teaser_image_url'],
'field_processed_teaser_text_de':
drupal_record_set['attributes']['field_processed_teaser_text'],
drupal_record_set_de['attributes']['field_processed_teaser_text'],
'field_processed_teaser_text_fr':
drupal_record_set_fr['attributes']['field_processed_teaser_text'],
'field_processed_teaser_text_it':
drupal_record_set_it['attributes']['field_processed_teaser_text'],
'field_old_memobase_id':
drupal_record_set['attributes']['field_old_memobase_id'],
'field_access_de': drupal_record_set['attributes']['field_access'],
drupal_record_set_de['attributes']['field_old_memobase_id'],
'field_access_de': drupal_record_set_de['attributes']['field_access'],
'field_access_fr': drupal_record_set_fr['attributes']['field_access'],
'field_access_it': drupal_record_set_it['attributes']['field_access'],
'field_access_memobase_de':
drupal_record_set['attributes']['field_access_memobase'],
drupal_record_set_de['attributes']['field_access_memobase'],
'field_access_memobase_fr':
drupal_record_set_fr['attributes']['field_access_memobase'],
'field_access_memobase_it':
drupal_record_set_it['attributes']['field_access_memobase'],
'field_content_de': drupal_record_set['attributes']['field_content'],
'field_content_de': drupal_record_set_de['attributes']['field_content'],
'field_content_fr': drupal_record_set_fr['attributes']['field_content'],
'field_content_it': drupal_record_set_it['attributes']['field_content'],
'field_context_de': drupal_record_set['attributes']['field_context'],
'field_context_de': drupal_record_set_de['attributes']['field_context'],
'field_context_fr': drupal_record_set_fr['attributes']['field_context'],
'field_context_it': drupal_record_set_it['attributes']['field_context'],
'field_data_transfer_de': drupal_record_set['attributes']['field_data_transfer'],
'field_data_transfer_de': drupal_record_set_de['attributes']['field_data_transfer'],
'field_data_transfer_fr': drupal_record_set_fr['attributes']['field_data_transfer'],
'field_data_transfer_it': drupal_record_set_it['attributes']['field_data_transfer'],
'field_documents_de': drupal_record_set['attributes']['field_documents'],
'field_documents_de': drupal_record_set_de['attributes']['field_documents'],
'field_documents_fr': drupal_record_set_fr['attributes']['field_documents'],
'field_documents_it': drupal_record_set_it['attributes']['field_documents'],
'field_info_on_development_de':
drupal_record_set['attributes']['field_info_on_development'],
drupal_record_set_de['attributes']['field_info_on_development'],
'field_info_on_development_fr':
drupal_record_set_fr['attributes']['field_info_on_development'],
'field_info_on_development_it':
drupal_record_set_it['attributes']['field_info_on_development'],
'field_language_de': drupal_record_set['attributes']['field_language'],
'field_language_de': drupal_record_set_de['attributes']['field_language'],
'field_language_fr': drupal_record_set_fr['attributes']['field_language'],
'field_language_it': drupal_record_set_it['attributes']['field_language'],
'field_memobase_id': drupal_record_set['attributes']['field_memobase_id'],
'field_notes': drupal_record_set['attributes']['field_notes'],
'field_memobase_id': drupal_record_set_de['attributes']['field_memobase_id'],
'field_notes': drupal_record_set_de['attributes']['field_notes'],
'field_original_description_de':
drupal_record_set['attributes']['field_original_description'],
drupal_record_set_de['attributes']['field_original_description'],
'field_original_description_fr':
drupal_record_set_fr['attributes']['field_original_description'],
'field_original_description_it':
drupal_record_set_it['attributes']['field_original_description'],
'field_original_id': drupal_record_set['attributes']['field_original_id'],
'field_original_id': drupal_record_set_de['attributes']['field_original_id'],
'field_original_shelf_mark':
drupal_record_set['attributes']['field_original_shelf_mark'],
'field_original_title_de': drupal_record_set['attributes']['field_original_title'],
drupal_record_set_de['attributes']['field_original_shelf_mark'],
'field_original_title_de': drupal_record_set_de['attributes'][
'field_original_title'],
'field_original_title_fr':
drupal_record_set_fr['attributes']['field_original_title'],
'field_original_title_it':
drupal_record_set_it['attributes']['field_original_title'],
'field_project_de': drupal_record_set['attributes']['field_project'],
'field_project_de': drupal_record_set_de['attributes']['field_project'],
'field_project_fr': drupal_record_set_fr['attributes']['field_project'],
'field_project_it': drupal_record_set_it['attributes']['field_project'],
'field_publications_de': drupal_record_set['attributes']['field_publications'],
'field_publications_de': drupal_record_set_de['attributes']['field_publications'],
'field_publications_fr': drupal_record_set_fr['attributes']['field_publications'],
'field_publications_it': drupal_record_set_it['attributes']['field_publications'],
'field_related_record_sets_de': field_related_record_sets,
'field_related_record_sets_fr': field_related_record_sets_fr,
'field_related_record_sets_it': field_related_record_sets_it,
'field_rights_de': drupal_record_set['attributes']['field_rights'],
'field_related_record_sets_de': related_record_sets_de,
'field_related_record_sets_fr': related_record_sets_fr,
'field_related_record_sets_it': related_record_sets_it,
'field_rights_de': drupal_record_set_de['attributes']['field_rights'],
'field_rights_fr': drupal_record_set_fr['attributes']['field_rights'],
'field_rights_it': drupal_record_set_it['attributes']['field_rights'],
'field_scope_de': drupal_record_set['attributes']['field_scope'],
'field_scope_de': drupal_record_set_de['attributes']['field_scope'],
'field_scope_fr': drupal_record_set_fr['attributes']['field_scope'],
'field_scope_it': drupal_record_set_it['attributes']['field_scope'],
'field_selection_de': drupal_record_set['attributes']['field_selection'],
'field_selection_de': drupal_record_set_de['attributes']['field_selection'],
'field_selection_fr': drupal_record_set_fr['attributes']['field_selection'],
'field_selection_it': drupal_record_set_it['attributes']['field_selection'],
'field_supported_by_memoriav':
drupal_record_set['attributes']['field_supported_by_memoriav'],
'field_time_period': drupal_record_set['attributes']['field_time_period'],
'field_transfer_date': drupal_record_set['attributes']['field_transfer_date'],
drupal_record_set_de['attributes']['field_supported_by_memoriav'],
'field_time_period': drupal_record_set_de['attributes']['field_time_period'],
'field_transfer_date': drupal_record_set_de['attributes']['field_transfer_date'],
'field_image_gallery':
drupal_record_set['relationships']['field_image_gallery'],
drupal_record_set_de['relationships']['field_image_gallery'],
'field_metadata_languages': metadata_language_codes,
'field_resp_institution_access': field_resp_institution_access,
'field_resp_institution_master': field_resp_institution_master,
'field_resp_institution_original': field_resp_institution_original,
'field_teaser_image': drupal_record_set['relationships']['field_teaser_image']
'field_resp_institution_access': access_institution_ids,
'field_resp_institution_master': master_institutions_ids,
'field_resp_institution_original': original_institution_ids,
'field_teaser_image': drupal_record_set_de['relationships']['field_teaser_image']
}
except LookupError as ex:
msg = 'LookupError for ' + record_set_id + ': ' + str(ex) + '\n' + \
traceback.format_exc() + '\n' + \
'baseRequest: ' + default_request + '\n' + \
'baseResponse: ' + base_response.content.decode("utf-8")
'baseRequest: ' + de_drupal_url + '\n'
current_app.logger.error(msg)
return {
'status': 'FAILURE',
......@@ -207,8 +204,7 @@ class UpdateRecordSet(Resource):
except Exception as ex:
msg = 'Exception for ' + record_set_id + ': ' + str(ex) + '\n' + \
traceback.format_exc() + '\n' + \
'baseRequest: ' + default_request + '\n' + \
'baseResponse: ' + base_response.content.decode("utf-8")
'baseRequest: ' + de_drupal_url + '\n'
current_app.logger.error(msg)
return {
'status': 'FAILURE',
......
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