Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsibilla committed Aug 12, 2024
2 parents 1a3e418 + c4276f3 commit 6084b4f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
15 changes: 14 additions & 1 deletion ingest-api-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,19 @@ paths:
error:
type: string

/metadata/data-provider-groups:
get:
tags:
- metadata
summary: Returns an array of nested objects containing information pertaining to all Data Provider groups.
responses:
"200":
description: The JSON containing an array of data provider group information
"401":
description: User's token is not valid
"500":
description: An unexpected error occurred

/sources/bulk/validate:
post:
tags:
Expand Down Expand Up @@ -839,4 +852,4 @@ paths:
"401":
description: User's token is not valid
"500":
description: An unexpected error occured
description: An unexpected error occurred
25 changes: 23 additions & 2 deletions src/lib/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def bulk_update_entities(
)
results[uuid] = {
"success": res.ok,
"data": res.json() if res.ok else res.json().get("error"),
"data": res.json() if res.ok else error_msg(res.json())
}
except requests.exceptions.RequestException as e:
logger.error(f"Failed to update entity {uuid}: {e}")
Expand Down Expand Up @@ -322,7 +322,7 @@ def bulk_create_entities(
results.append(
{
"success": res.ok,
"data": res.json() if res.ok else res.json().get("error"),
"data": res.json() if res.ok else error_msg(res.json())
}
)
except requests.exceptions.RequestException as e:
Expand All @@ -336,3 +336,24 @@ def bulk_create_entities(
time.sleep(throttle)

return results


def error_msg(json_res: dict) -> str:
"""Get the error message from the json response.
Parameters
----------
json_res : dict
The json response from the request.
Returns
-------
str
The error message from the json response.
"""
if "error" in json_res:
return json_res["error"]
if "message" in json_res:
return json_res["message"]

return str(json_res)
24 changes: 23 additions & 1 deletion src/routes/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import time
from http.client import HTTPException
from uuid import uuid4

from atlas_consortia_commons.decorator import (
Expand All @@ -19,7 +20,8 @@
rest_server_err,
)
from atlas_consortia_commons.string import equals
from flask import Blueprint, jsonify
from flask import Blueprint, jsonify, Response, current_app
from hubmap_commons.hm_auth import AuthHelper
from rq.job import Job, JobStatus, NoSuchJobError

from jobs import (
Expand Down Expand Up @@ -177,6 +179,26 @@ def register_metadata_upload(body: dict, token: str, user: User):
return jsonify({"job_id": job_id, "status": display_status}), 202


# Fetch all Data Provider groups through Hubmap Commons
# Returns an Array of nested objects containing all groups
@metadata_blueprint.route('/metadata/data-provider-groups', methods=['GET'])
@require_valid_token()
def get_all_data_provider_groups(token: str, user: User):
try:
auth_helper_instance = AuthHelper.instance()
group_list = auth_helper_instance.getHuBMAPGroupInfo()
return_list = []
for group_info in group_list.keys():
if group_list[group_info]['data_provider'] == True:
return_list.append(group_list[group_info])
return jsonify({'groups': return_list}), 200
except HTTPException as hte:
return Response(hte.get_description(), hte.get_status_code())
except Exception as e:
logger.error(e, exc_info=True)
return Response("Unexpected error while fetching group list: " + str(e) + " Check the logs", 500)


def check_metadata_upload():
"""Checks the uploaded file.
Expand Down

0 comments on commit 6084b4f

Please sign in to comment.