Skip to content

Commit

Permalink
Merge pull request #212 from EOSC-synergy/release/3.0.0
Browse files Browse the repository at this point in the history
New release 3.0.0: FAIR report in DT-GEO's D4.1v2
  • Loading branch information
orviz authored Oct 15, 2024
2 parents f7db793 + 0187a5e commit 29e2cb5
Show file tree
Hide file tree
Showing 21 changed files with 16,800 additions and 952 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# - id: check-added-large-files
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
hooks:
Expand Down
518 changes: 419 additions & 99 deletions api/evaluator.py

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions api/rda.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
)
logger = logging.getLogger("api")

config = load_config()


def load_evaluator(wrapped_func):
@wraps(wrapped_func)
Expand All @@ -35,9 +33,9 @@ def wrapper(body, **kwargs):
msg = "Neither the identifier nor the pattern to query was provided. Exiting.."
logger.error(msg)
return msg, 400

# Get the identifiers through a search query
ids = [item_id]

# FIXME oai-pmh should be no different
downstream_logger = evaluator.logger
if repo not in ["oai-pmh"]:
Expand All @@ -61,15 +59,18 @@ def wrapper(body, **kwargs):
evaluator_handler = ut.EvaluatorLogHandler()
downstream_logger.addHandler(evaluator_handler)

# Load configuration
config_data = load_config(plugin=repo)

# Collect FAIR checks per metadata identifier
result = {}
exit_code = 200
for item_id in ids:
# FIXME oai-pmh should be no different
if repo in ["oai-pmh"]:
eva = evaluator.Evaluator(item_id, oai_base, lang)
eva = evaluator.Evaluator(item_id, oai_base, lang, config=config_data)
else:
eva = plugin.Plugin(item_id, oai_base, lang)
eva = plugin.Plugin(item_id, oai_base, lang, config=config_data)
_result, _exit_code = wrapped_func(body, eva=eva)
logger.debug(
"Raw result returned for indicator ID '%s': %s" % (item_id, _result)
Expand Down Expand Up @@ -99,8 +100,8 @@ def endpoints(plugin=None, plugins_path="plugins"):

# Obtain endpoint from each plugin's config
for plug in plugins_list:
config = load_config(plugin=plug, fail_if_no_config=False)
endpoint = config.get("Generic", "endpoint", fallback="")
_config = load_config(plugin=plug, fail_if_no_config=False)
endpoint = _config.get("Generic", "endpoint", fallback="")
if not endpoint:
logger.debug(
"Plugin's config does not contain 'Generic:endpoint' section: %s" % plug
Expand Down Expand Up @@ -1339,14 +1340,14 @@ def rda_all(body, eva):
result_points = 10
num_of_tests = 10

generic_config = config["Generic"]
generic_config = eva.config["Generic"]
api_config = os.path.join(
app_dirname, generic_config.get("api_config", "fair-api.yaml")
)
try:
with open(api_config, "r") as f:
documents = yaml.full_load(f)
logging.debug("API configuration successfully loaded: %s" % api_config)
logger.debug("API configuration successfully loaded: %s" % api_config)
except Exception as e:
message = "Could not find API config file: %s" % api_config
logger.error(message)
Expand All @@ -1360,7 +1361,7 @@ def rda_all(body, eva):
if documents["paths"][e]["x-indicator"]:
indi_code = e.split("/")
indi_code = indi_code[len(indi_code) - 1]
logger.debug("Running - %s" % indi_code)
logger.info("Running - %s" % indi_code)
points, msg = getattr(eva, indi_code)()
x_principle = documents["paths"][e]["x-principle"]
if "Findable" in x_principle:
Expand Down
84 changes: 10 additions & 74 deletions api/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import os
import re
import sys
import urllib
Expand Down Expand Up @@ -704,12 +705,15 @@ def orcid_basic_info(orcid):
"Authorization": "Bearer a354d82e-37fa-47de-b4a2-740dbe90f355",
}
try:
if not idutils.is_orcid(orcid):
raise Exception("Malformed ORCID value: %s" % orcid)
url = "https://pub.orcid.org/v3.0/" + orcid
r = requests.get(url, verify=False, headers=headers) # GET with headers
xmlTree = ET.fromstring(r.text)
item = xmlTree.findall(
".//{http://www.orcid.org/ns/common}assertion-origin-name"
)
for prop in ["assertion-origin-name", "source-name"]:
item = xmlTree.findall(".//{http://www.orcid.org/ns/common}%s" % prop)
if item:
break
except Exception as e:
logging.error(e)
return basic_info
Expand Down Expand Up @@ -883,9 +887,11 @@ def resolve_handle(handle_id):
return resolves, msg, values


def check_link(address):
def check_link(address, return_http_code=False):
req = urllib.request.Request(url=address)
resp = urllib.request.urlopen(req)
if return_http_code:
return resp.status
if resp.status in [400, 404, 403, 408, 409, 501, 502, 503]:
return False
else:
Expand Down Expand Up @@ -918,76 +924,6 @@ def make_http_request(url, request_type="GET", verify=False):
return payload


def get_fairsharing_metadata(offline=True, username="", password="", path=""):
if offline == True:
f = open(path)
fairlist = json.load(f)
f.close()

else:
url = "https://api.fairsharing.org/users/sign_in"
payload = {"user": {"login": username, "password": password}}
headers = {"Accept": "application/json", "Content-Type": "application/json"}

response = requests.request(
"POST", url, headers=headers, data=json.dumps(payload)
)

# Get the JWT from the response.text to use in the next part.
data = response.json()
jwt = data["jwt"]

url = "https://api.fairsharing.org/search/fairsharing_records?page[size]=2500&fairsharing_registry=standard&user_defined_tags=metadata standardization"

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer {0}".format(jwt),
}

response = requests.request("POST", url, headers=headers)
fairlist = response.json()
user = open(path, "w")
json.dump(fairlist, user)
user.close()
return fairlist


def get_fairsharing_formats(offline=True, username="", password="", path=""):
if offline == True:
f = open(path)
fairlist = json.load(f)
f.close()

else:
url = "https://api.fairsharing.org/users/sign_in"
payload = {"user": {"login": username, "password": password}}
headers = {"Accept": "application/json", "Content-Type": "application/json"}

response = requests.request(
"POST", url, headers=headers, data=json.dumps(payload)
)

# Get the JWT from the response.text to use in the next part.
data = response.json()
jwt = data["jwt"]

url = "https://api.fairsharing.org/search/fairsharing_records?page[size]=2500&user_defined_tags=Geospatial data"

headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": "Bearer {0}".format(jwt),
}

response = requests.request("POST", url, headers=headers)
fairlist = response.json()
user = open(path, "w")
json.dump(fairlist, user)
user.close()
return fairlist


def check_fairsharing_abbreviation(fairlist, abreviation):
for standard in fairlist["data"]:
if abreviation == standard["attributes"]["abbreviation"]:
Expand Down
Loading

0 comments on commit 29e2cb5

Please sign in to comment.