Skip to content

Commit 079418c

Browse files
committed
Abstract Class EvaluatorBase
1 parent 7ddf874 commit 079418c

File tree

6 files changed

+2128
-152
lines changed

6 files changed

+2128
-152
lines changed

api/evaluator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,11 +1347,12 @@ def rda_i3_01m(self, **kwargs):
13471347
term_metadata = term_data["metadata"]
13481348
id_list = []
13491349
for index, row in term_metadata.iterrows():
1350-
logging.debug(self.item_id)
1350+
logger.debug(self.item_id)
13511351

13521352
if row["text_value"].split("/")[-1] not in self.item_id:
13531353
id_list.append(row["text_value"])
13541354
points, msg_list = self.eval_persistency(id_list)
1355+
return (points, msg_list)
13551356

13561357
def rda_i3_01d(self):
13571358
"""Indicator RDA-A1-01M.

api/rda.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,22 @@ def wrapper(body, **kwargs):
3636
# Get the identifiers through a search query
3737
ids = [item_id]
3838

39-
# FIXME oai-pmh should be no different
4039
downstream_logger = evaluator.logger
41-
if repo not in ["oai-pmh"]:
40+
try:
41+
logger.debug("Trying to import plugin from plugins.%s.plugin" % (repo))
42+
plugin = importlib.import_module("plugins.%s.plugin" % (repo), ".")
43+
downstream_logger = plugin.logger
44+
except Exception as e:
45+
logger.error(str(e))
46+
return str(e), 400
47+
if pattern_to_query:
4248
try:
43-
logger.debug("Trying to import plugin from plugins.%s.plugin" % (repo))
44-
plugin = importlib.import_module("plugins.%s.plugin" % (repo), ".")
45-
downstream_logger = plugin.logger
49+
ids = plugin.Plugin.get_ids(
50+
oai_base=oai_base, pattern_to_query=pattern_to_query
51+
)
4652
except Exception as e:
4753
logger.error(str(e))
4854
return str(e), 400
49-
if pattern_to_query:
50-
try:
51-
ids = plugin.Plugin.get_ids(
52-
oai_base=oai_base, pattern_to_query=pattern_to_query
53-
)
54-
except Exception as e:
55-
logger.error(str(e))
56-
return str(e), 400
5755

5856
# Set handler for evaluator logs
5957
evaluator_handler = ut.EvaluatorLogHandler()
@@ -66,11 +64,7 @@ def wrapper(body, **kwargs):
6664
result = {}
6765
exit_code = 200
6866
for item_id in ids:
69-
# FIXME oai-pmh should be no different
70-
if repo in ["oai-pmh"]:
71-
eva = evaluator.Evaluator(item_id, oai_base, lang, config=config_data)
72-
else:
73-
eva = plugin.Plugin(item_id, oai_base, lang, config=config_data)
67+
eva = plugin.Plugin(item_id, oai_base, lang, config=config_data)
7468
_result, _exit_code = wrapped_func(body, eva=eva)
7569
logger.debug(
7670
"Raw result returned for indicator ID '%s': %s" % (item_id, _result)

api/utils.py

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,6 @@ def test_status(points):
128128
return test_status
129129

130130

131-
def oai_identify(oai_base):
132-
action = "?verb=Identify"
133-
return oai_request(oai_base, action)
134-
135-
136-
def oai_metadataFormats(oai_base):
137-
action = "?verb=ListMetadataFormats"
138-
xmlTree = oai_request(oai_base, action)
139-
metadataFormats = {}
140-
for e in xmlTree.findall(".//{http://www.openarchives.org/OAI/2.0/}metadataFormat"):
141-
metadataPrefix = e.find(
142-
"{http://www.openarchives.org/OAI/2.0/}metadataPrefix"
143-
).text
144-
namespace = e.find(
145-
"{http://www.openarchives.org/OAI/2.0/}metadataNamespace"
146-
).text
147-
metadataFormats[metadataPrefix] = namespace
148-
return metadataFormats
149-
150-
151131
def is_persistent_id(item_id):
152132
"""Returns boolean if the item id is or not a persistent identifier.
153133
@@ -448,119 +428,6 @@ def check_metadata_terms_with_values(metadata, terms):
448428
return df_access
449429

450430

451-
def oai_check_record_url(oai_base, metadata_prefix, pid):
452-
endpoint_root = urllib.parse.urlparse(oai_base).netloc
453-
try:
454-
pid_type = idutils.detect_identifier_schemes(pid)[0]
455-
except Exception as e:
456-
pid_type = "internal"
457-
logging.error(e)
458-
if pid_type != "internal":
459-
oai_pid = idutils.normalize_pid(pid, pid_type)
460-
else:
461-
oai_pid = pid
462-
action = "?verb=GetRecord"
463-
464-
test_id = "oai:%s:%s" % (endpoint_root, oai_pid)
465-
params = "&metadataPrefix=%s&identifier=%s" % (metadata_prefix, test_id)
466-
url_final = ""
467-
url = oai_base + action + params
468-
response = requests.get(url, verify=False, allow_redirects=True)
469-
logging.debug("Trying ID v1: url: %s | status: %i" % (url, response.status_code))
470-
error = 0
471-
for tags in ET.fromstring(response.text).findall(
472-
".//{http://www.openarchives.org/OAI/2.0/}error"
473-
):
474-
error = error + 1
475-
if error == 0:
476-
url_final = url
477-
478-
test_id = "%s" % (oai_pid)
479-
params = "&metadataPrefix=%s&identifier=%s" % (metadata_prefix, test_id)
480-
481-
url = oai_base + action + params
482-
logging.debug("Trying: " + url)
483-
response = requests.get(url, verify=False)
484-
error = 0
485-
for tags in ET.fromstring(response.text).findall(
486-
".//{http://www.openarchives.org/OAI/2.0/}error"
487-
):
488-
error = error + 1
489-
if error == 0:
490-
url_final = url
491-
492-
test_id = "%s:%s" % (pid_type, oai_pid)
493-
params = "&metadataPrefix=%s&identifier=%s" % (metadata_prefix, test_id)
494-
495-
url = oai_base + action + params
496-
logging.debug("Trying: " + url)
497-
response = requests.get(url, verify=False)
498-
error = 0
499-
for tags in ET.fromstring(response.text).findall(
500-
".//{http://www.openarchives.org/OAI/2.0/}error"
501-
):
502-
error = error + 1
503-
if error == 0:
504-
url_final = url
505-
506-
test_id = "oai:%s:%s" % (
507-
endpoint_root,
508-
oai_pid[oai_pid.rfind(".") + 1 : len(oai_pid)],
509-
)
510-
params = "&metadataPrefix=%s&identifier=%s" % (metadata_prefix, test_id)
511-
512-
url = oai_base + action + params
513-
logging.debug("Trying: " + url)
514-
response = requests.get(url, verify=False)
515-
error = 0
516-
for tags in ET.fromstring(response.text).findall(
517-
".//{http://www.openarchives.org/OAI/2.0/}error"
518-
):
519-
error = error + 1
520-
if error == 0:
521-
url_final = url
522-
523-
test_id = "oai:%s:b2rec/%s" % (
524-
endpoint_root,
525-
oai_pid[oai_pid.rfind(".") + 1 : len(oai_pid)],
526-
)
527-
params = "&metadataPrefix=%s&identifier=%s" % (metadata_prefix, test_id)
528-
529-
url = oai_base + action + params
530-
logging.debug("Trying: " + url)
531-
response = requests.get(url, verify=False)
532-
error = 0
533-
for tags in ET.fromstring(response.text).findall(
534-
".//{http://www.openarchives.org/OAI/2.0/}error"
535-
):
536-
error = error + 1
537-
if error == 0:
538-
url_final = url
539-
540-
return url_final
541-
542-
543-
def oai_get_metadata(url):
544-
logging.debug("Metadata from: %s" % url)
545-
oai = requests.get(url, verify=False, allow_redirects=True)
546-
try:
547-
xmlTree = ET.fromstring(oai.text)
548-
except Exception as e:
549-
logging.error("OAI_RQUEST: %s" % e)
550-
xmlTree = None
551-
return xmlTree
552-
553-
554-
def oai_request(oai_base, action):
555-
oai = requests.get(oai_base + action, verify=False) # Peticion al servidor
556-
try:
557-
xmlTree = ET.fromstring(oai.text)
558-
except Exception as e:
559-
logging.error("OAI_RQUEST: %s" % e)
560-
xmlTree = ET.fromstring("<OAI-PMH></OAI-PMH>")
561-
return xmlTree
562-
563-
564431
def find_dataset_file(metadata, url, data_formats):
565432
headers = {
566433
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"

0 commit comments

Comments
 (0)