Skip to content

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

@tgbugs

Description

@tgbugs

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,)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions