Skip to content

Commit

Permalink
Only emit event if the citing bibcode exists in ADS
Browse files Browse the repository at this point in the history
  • Loading branch information
marblestation committed Jan 7, 2019
1 parent 1fd6ae3 commit 4f8a9fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions ADSCitationCapture/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ def task_process_new_citation(citation_change, force=False):
# Get citations from the database and transform the stored bibcodes into their canonical ones as registered in Solr.
original_citations = db.get_citations_by_bibcode(app, citation_target_bibcode)
citations = api.get_canonical_bibcodes(app, original_citations)
# Clean before adding the current citation
citations = [c for c in citations if c != citation_change.citing and c != canonical_citing_bibcode]
# Add canonical bibcode of current detected citation
if canonical_citing_bibcode:
if canonical_citing_bibcode and canonical_citing_bibcode not in citations:
citations.append(canonical_citing_bibcode)
else:
citations.append(citation_change.citing)
logger.debug("Calling 'task_output_results' with '%s'", citation_change)
task_output_results.delay(citation_change, parsed_metadata, citations)
logger.debug("Calling 'task_emit_event' with '%s'", citation_change)
Expand Down Expand Up @@ -197,8 +193,12 @@ def task_emit_event(citation_change, parsed_metadata):
is_link_alive = parsed_metadata and parsed_metadata.get("link_alive", False)
is_software = parsed_metadata and parsed_metadata.get("doctype", "").lower() == "software"
if is_software and is_link_alive:
emitted = webhook.emit_event(app.conf['ADS_WEBHOOK_URL'], app.conf['ADS_WEBHOOK_AUTH_TOKEN'], citation_change)
#emitted = True
canonical_citing_bibcode = api.get_canonical_bibcode(app, citation_change.citing)
if canonical_citing_bibcode:
# Citing source exists in ADS
citation_change.citing = canonical_citing_bibcode
emitted = webhook.emit_event(app.conf['ADS_WEBHOOK_URL'], app.conf['ADS_WEBHOOK_AUTH_TOKEN'], citation_change)
#emitted = True

if emitted:
logger.debug("Emitted '%s'", citation_change)
Expand Down
34 changes: 17 additions & 17 deletions ADSCitationCapture/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_process_new_citation_changes_doi(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_process_updated_citation_changes_doi(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand All @@ -92,7 +92,7 @@ def test_process_updated_citation_changes_doi(self):
self.assertFalse(fetch_metadata.called)
self.assertFalse(parse_metadata.called)
self.assertFalse(url_is_alive.called)
self.assertFalse(get_canonical_bibcode.called)
self.assertTrue(get_canonical_bibcode.called)
self.assertTrue(get_canonical_bibcodes.called)
self.assertTrue(get_citations_by_bibcode.called)
self.assertFalse(store_citation_target.called)
Expand All @@ -111,7 +111,7 @@ def test_process_deleted_citation_changes_doi(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand All @@ -127,7 +127,7 @@ def test_process_deleted_citation_changes_doi(self):
self.assertFalse(fetch_metadata.called)
self.assertFalse(parse_metadata.called)
self.assertFalse(url_is_alive.called)
self.assertFalse(get_canonical_bibcode.called)
self.assertTrue(get_canonical_bibcode.called)
self.assertTrue(get_canonical_bibcodes.called)
self.assertTrue(get_citations_by_bibcode.called)
self.assertFalse(store_citation_target.called)
Expand All @@ -146,7 +146,7 @@ def test_process_new_citation_changes_doi_when_target_exists_citation_doesnt(sel
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_process_updated_citation_changes_doi_when_target_exists_citation_doesnt
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_process_deleted_citation_changes_doi_when_target_exists_citation_doesnt
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_process_new_citation_changes_doi_when_target_and_citation_exist(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_process_updated_citation_changes_doi_when_citation_doesnt_exist(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_process_deleted_citation_changes_doi_when_citation_doesnt_exist(self):
patch.object(doi, 'fetch_metadata', return_value=self.mock_data[doi_id]['raw']) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value=self.mock_data[doi_id]['parsed']) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -362,7 +362,7 @@ def test_process_citation_changes_ascl(self):
patch.object(doi, 'fetch_metadata', return_value=None) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -403,7 +403,7 @@ def test_process_citation_changes_url(self):
patch.object(doi, 'fetch_metadata', return_value=None) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -445,7 +445,7 @@ def test_process_citation_changes_malformed_url(self):
patch.object(doi, 'fetch_metadata', return_value=None) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -486,7 +486,7 @@ def test_process_citation_changes_empty(self):
patch.object(doi, 'fetch_metadata', return_value=None) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -520,7 +520,7 @@ def test_process_new_citation_changes_doi_unparsable_http_response(self):
patch.object(doi, 'fetch_metadata', return_value="Unparsable response") as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down Expand Up @@ -555,7 +555,7 @@ def test_process_new_citation_changes_doi_http_error(self):
patch.object(doi, 'fetch_metadata', return_value=None) as fetch_metadata, \
patch.object(doi, 'parse_metadata', return_value={}) as parse_metadata, \
patch.object(url, 'is_alive', return_value=True) as url_is_alive, \
patch.object(api, 'get_canonical_bibcode', return_value=None) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcode', return_value=citation_changes.changes[0].citing) as get_canonical_bibcode, \
patch.object(api, 'get_canonical_bibcodes', return_value=[]) as get_canonical_bibcodes, \
patch.object(db, 'get_citations_by_bibcode', return_value=[]) as get_citations_by_bibcode, \
patch.object(db, 'store_citation_target', return_value=True) as store_citation_target, \
Expand Down

0 comments on commit 4f8a9fc

Please sign in to comment.