Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dispatching on resolver response status inside submit is a major design flaw #30

Open
tgbugs opened this issue Aug 23, 2019 · 0 comments

Comments

@tgbugs
Copy link
Collaborator

tgbugs commented Aug 23, 2019

Passing the tuples around across function boundaries makes it extremely hard to understand what is going on and what the logic of the code actually is. Each step in the pipeline should be responsible for interpreting its own data.

scibot/scibot/submit.py

Lines 61 to 129 in dd3942e

if status_code < 300:
root = etree.fromstring(xml)
if duplicate:
# just mark the duplicate so that it will anchor in the client
# but don't add the RRID: tag and don't include the resolver metadata
r = h.create_annotation_with_target_using_only_text_quote(url=target_uri,
document=document,
prefix=prefix,
exact=exact_for_hypothesis,
suffix=suffix,
text='',
tags=new_tags,
extra=extra,)
elif root.findall('error'):
s = 'Resolver lookup failed.'
s += '<hr><p><a href="%s">resolver lookup</a></p>' % resolver_uri
r = h.create_annotation_with_target_using_only_text_quote(url=target_uri,
document=document,
prefix=prefix,
exact=exact_for_hypothesis,
suffix=suffix,
text=s,
tags=new_tags + ['RRIDCUR:Unresolved'],
extra=extra,)
log.error(f'rrid unresolved {exact}')
else:
s = ''
title = root.findall('title')[0].text
s += f'Title: {title}\n'
data_elements = root.findall('data')[0]
data_elements = [(e.find('name').text, e.find('value').text) for e in data_elements] # these shouldn't duplicate
citation = [(n, v) for n, v in data_elements if n == 'Proper Citation']
rrid = [rrid_from_citation(c) for _, c in citation] if citation else [exact]
name = [(n, v) for n, v in data_elements if n == 'Name']
data_elements = citation + name + sorted([(n, v) for n, v in
data_elements if (n != 'Proper Citation' or
n != 'Name') and v is not None])
for name, value in data_elements:
if ((name == 'Reference' or name == 'Mentioned In Literature')
and value is not None and value.startswith('<a class')):
if len(value) > 500:
continue # nif-0000-30467 fix keep those pubmed links short!
s += '<p>%s: %s</p>' % (name, value)
s += '<hr><p><a href="%s">resolver lookup</a></p>' % resolver_uri
r = h.create_annotation_with_target_using_only_text_quote(url=target_uri,
document=document,
prefix=prefix,
exact=exact_for_hypothesis,
suffix=suffix,
text=s,
tags=new_tags + rrid,
extra=extra,)
elif status_code >= 500:
s = 'Resolver lookup failed due to server error.'
s += '<hr><p><a href="%s">resolver lookup</a></p>' % resolver_uri
else:
s = 'Resolver lookup failed.'
s += '<hr><p><a href="%s">resolver lookup</a></p>' % resolver_uri
r = h.create_annotation_with_target_using_only_text_quote(url=target_uri,
document=document,
prefix=prefix,
exact=exact_for_hypothesis,
suffix=suffix,
text=s,
tags=new_tags + ['RRIDCUR:Unresolved'],
extra=extra,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant