Skip to content

Commit

Permalink
Merge pull request #227 from EOSC-synergy/release/3.0.3
Browse files Browse the repository at this point in the history
Fix: gather 'start_date' and 'end_date' as part of temporal coverage …
  • Loading branch information
orviz authored Oct 16, 2024
2 parents 6619716 + d0c24ef commit 0115207
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
20 changes: 14 additions & 6 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,22 @@ def resolve_handle(handle_id):


def check_link(address, return_http_code=False):
resolves = 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
try:
resp = urllib.request.urlopen(req, timeout=15)
except urllib.error.URLError as e:
logging.warning("Timeout reached while trying to connect to '%s'" % address)
except urllib.error.HTTPError as e:
logging.warning("Could not access to resource: %s" % address)
else:
return True
http_code = resp.status
logging.debug("Returned HTTP status from '%s': %s" % (address, http_code))
if return_http_code:
return http_code
if http_code not in ["400", "404", "403", "408", "409", "501", "502", "503"]:
resolves = True
return resolves


def get_protocol_scheme(url):
Expand Down
24 changes: 15 additions & 9 deletions plugins/epos/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def _get_temporal_coverage(cls, element_values):
"start_date": value_data.get("startDate", ""),
"end_date": value_data.get("endDate", ""),
}
for value_data in element_values
]

@classmethod
Expand Down Expand Up @@ -826,17 +827,22 @@ def rda_a1_03d(self, **kwargs):
for uri in data_access_uri:
resolves = False
schemes = idutils.detect_identifier_schemes(uri)
logger.debug("Identifier schemes found: %s" % schemes)
if "doi" in schemes or "handle" in schemes:
resolves = ut.resolve_handle(uri)[0]
elif "url" in schemes:
resolves = ut.check_link(uri)
if not schemes:
logger.warning("Could not get the scheme/s from the value: %s" % uri)
else:
logger.warning(
"Scheme/s used by the identifier not known: %s" % schemes
logger.debug(
"Identifier schemes found for the value '%s': %s" % (uri, schemes)
)
if resolves:
resolvable_uris.append(uri)
if "doi" in schemes or "handle" in schemes:
resolves = ut.resolve_handle(uri)[0]
elif "url" in schemes:
resolves = ut.check_link(uri)
else:
logger.warning(
"Scheme/s used by the identifier not known: %s" % schemes
)
if resolves:
resolvable_uris.append(uri)

resolvable_uris_num = len(resolvable_uris)
if resolvable_uris:
Expand Down

0 comments on commit 0115207

Please sign in to comment.