Commit 0af48d11 authored by Matthias's avatar Matthias
Browse files

Merge remote-tracking branch 'origin/master'

parents 1109c0fc b4384122
Pipeline #24482 passed with stages
in 2 minutes and 14 seconds
......@@ -46,16 +46,16 @@ class WriteTypeReportToDrupal(Resource):
"""
try:
node_type = request.json[0]['node_type']
identifier = request.json[0]['id']
status = request.json[0]['status']
report = request.json[0]['report']
node_type = request.json['node_type']
identifier = request.json['id']
status = request.json['status']
report = request.json['report']
except KeyError as er:
return {
'message': f'Missing a element in input body: {er}'
}, 400
try:
node_id = get_node_id(identifier)
node_id = get_node_id(identifier, node_type)
return write_results(node_type, node_id, status, report)
except ImportApiError as e:
current_app.logger.error(
......@@ -65,7 +65,7 @@ class WriteTypeReportToDrupal(Resource):
f"{e.message}"}, 500
def get_node_id(memobase_id: str):
def get_node_id(memobase_id: str, node_type: str):
current_app.logger.debug(
f'Retrieve node id from durpal json api with memobase id {memobase_id}.')
headers = {
......@@ -74,12 +74,22 @@ def get_node_id(memobase_id: str):
'X-API-Key': current_app.config['drupal-cms-admin-key'],
'Authorization': 'Basic bWVtb2Jhc2U6MjAyMA=='
}
url = f'{current_app.config["drupal-api-url"]}/jsonapi/node/institution?filter[' \
f'field_memobase_id]={memobase_id} '
url = f'{current_app.config["drupal-api-url"]}/jsonapi/node/{node_type}?filter['\
f'field_memobase_id]={memobase_id}'
response = requests.get(url, headers=headers)
if response.ok:
return response.json()['data'][0]['attributes']['id']
try:
return response.json()['data'][0]['attributes']['id']
except KeyError as er:
current_app.logger.error(f"Could not find the key {er} in data: {response.text}.")
raise ImportApiError(f"Could not find the key {er} in data (url={url}): "
f"{response.text}.")
except IndexError:
current_app.logger.error(f"Data field does not contain a list (url={url}): "
f"{response.text}.")
raise ImportApiError(f"Data field does not contain a list (url={url}): "
f"{response.text}.")
else:
raise ImportApiError(f"Could not find element for report: {response.text}.")
......
Supports Markdown
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