Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions articlemeta/export_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ def _transform_translations(self, data):
class XMLFundingDataPipe(plumber.Pipe):
def precond(data):
raw, _ = data
if not raw.contract and not raw.journal.sponsors:
if not raw.award_ids and not raw.project_sponsors:
raise plumber.UnmetPrecondition()

@staticmethod
Expand Down Expand Up @@ -1258,14 +1258,14 @@ def transform(self, data):
sponsors=raw.project_sponsor,
award_ids=raw.award_ids
)

for journal_article in xml.findall(".//journal_article"):
crossmark = journal_article.find("crossmark")

if crossmark is not None:
crossmark.append(program)
else:
journal_article.append(program)

publisher_item = xml.xpath(".//journal_article/publisher_item")[-1]
crossmark = publisher_item.find("../crossmark")

if crossmark is not None:
crossmark.append(program)
else:
publisher_item.addnext(program)

return data

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ thriftpy2==0.5.0
urllib3==1.26.19
venusian==1.1.0
WebOb==1.8.7
-e git+https://github.com/scieloorg/xylose.git@1.35.10#egg=xylose
-e git+https://github.com/scieloorg/xylose.git@1.35.11#egg=xylose
zope.deprecation==4.3.0
zope.interface==6.1
crossrefapi==1.3.0
71 changes: 71 additions & 0 deletions tests/test_export_crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2079,3 +2079,74 @@ def test_aop_element(self):
self.assertEqual(
b'<doi_batch><body><journal><journal_issue/></journal></body></doi_batch>',
ET.tostring(xml))

class ExportCrossRef_XMLFundingData_Tests(unittest.TestCase):
def setUp(self):
namespace_map = {
"xsi": "http://www.w3.org/2001/XMLSchema-instance",
"jats": "http://www.ncbi.nlm.nih.gov/JATS1",
"ai": "http://www.crossref.org/AccessIndicators.xsd",
"fr": "http://www.crossref.org/fundref.xsd",
}

ET.register_namespace('xsi', "http://www.w3.org/2001/XMLSchema-instance")
ET.register_namespace('jats', "http://www.ncbi.nlm.nih.gov/JATS1")
ET.register_namespace('ai', "http://www.crossref.org/AccessIndicators.xsd")
ET.register_namespace('fr', "http://www.crossref.org/fundref.xsd")

self.xmlcrossref = ET.Element(
'{http://www.crossref.org/schema/4.4.0}doi_batch',
nsmap=namespace_map,
attrib={
'{http://www.w3.org/2001/XMLSchema-instance}schemaLocation': (
"http://www.crossref.org/schema/4.4.0 "
"http://www.crossref.org/schemas/crossref4.4.0.xsd"
),
'version': '4.4.0'
}
)
journal = ET.Element('journal')
journal_article = ET.Element('journal_article')
publisher_item = ET.Element('publisher_item')
xxx = ET.Element('xxx')
body = ET.Element('body')

journal_article.append(publisher_item)
journal_article.append(xxx)
journal.append(journal_article)

body.append(journal)
self.xmlcrossref.append(body)

def test_funding_data_element(self):
_raw_json = {
'article':
{
'v58': [
{
"_": "CNPQ"
},
{
"_": "Ministério da Saúde"
}
],
'v60': [
{
"_": "nº 308051/2022-0-CNPQ"
},
{
"_": "nº 18/2020"
}
],
},
}
_article = Article(_raw_json)
data = [_article, self.xmlcrossref]

_xmlcrossref = export_crossref.XMLFundingDataPipe()
raw, xml = _xmlcrossref.transform(data)

publisher_item = xml.xpath(".//journal_article/publisher_item")[-1]

self.assertEqual(publisher_item.getnext().find("*").tag, "{http://www.crossref.org/fundref.xsd}assertion")
self.assertIn("fr:program", ET.tostring(xml).decode("utf-8"))