def test_name_conflict(self): # Both are called "John Doe" r1 = Researcher.get_or_create_by_orcid('0000-0002-3037-8851', instance='sandbox.orcid.org') r2 = Researcher.get_or_create_by_orcid('0000-0003-2295-9629', instance='sandbox.orcid.org') self.assertNotEqual(r1, r2)
def test_creation(self): r = Researcher.create_by_name('Marie', 'Farge') r2 = Researcher.create_by_name(' Marie', ' Farge') self.assertNotEqual(r, r2) r3 = Researcher.get_or_create_by_orcid('0000-0002-4445-8625') self.assertNotEqual(r, r3)
def test_merge(self, delete_user, django_user_model): u = django_user_model.objects.create(username='******', first_name='Stefan', last_name='Beck') r = Researcher.create_by_name('Stefan', 'Beck', email='*****@*****.**', homepage='https://becks.dissem.in', user=u) u2 = django_user_model.objects.create(username='******', first_name='Stefan', last_name='Beck') r2 = Researcher.create_by_name('Stefan', 'Beck', orcid='0000-0001-8187-9704', homepage='https://sbeck.dissem.in', user=u2) p = Paper.create_by_doi('10.17192/z2016.0217') p.set_researcher(0, r2.pk) p.save() r.merge(r2, delete_user=delete_user) p.refresh_from_db() r.refresh_from_db() assert r.name == r2.name assert r.email == '*****@*****.**' assert r.homepage == 'https://becks.dissem.in' assert r.orcid == r2.orcid assert p.authors_list[0]['researcher_id'] == r.pk with pytest.raises(Researcher.DoesNotExist): r2.refresh_from_db() if delete_user: with pytest.raises(django_user_model.DoesNotExist): u2.refresh_from_db() else: u2.refresh_from_db()
def test_empty_name(self): r = Researcher.create_by_name('', '') self.assertEqual(r, None) # this ORCID has no public name in the sandbox: r = Researcher.get_or_create_by_orcid('0000-0002-6091-2701', instance='sandbox.orcid.org') self.assertEqual(r, None)
def lod_env(request, db, book_god_of_the_labyrinth, authenticated_client, dummy_repository, uploaded_pdf): """ Everything you need for Letter of Declaration """ loc = LetterOfDeclaration.objects.create(function_key='test_pdf_generator') dummy_repository.letter_declaration = loc dummy_repository.save() user = authenticated_client.user user.first_name = 'Jose' user.last_name = 'Saramago' user.save() dr = DepositRecord.objects.create( paper=book_god_of_the_labyrinth, user=user, repository=dummy_repository, status='pending', file=uploaded_pdf, ) Researcher.create_by_name( first=user.first_name, last=user.last_name, orcid="2543-2454-2345-234X", user=user, ) request.cls.dr = dr request.cls.client = authenticated_client
def test_creation(self): r = Researcher.create_by_name('George', 'Banks') r2 = Researcher.create_by_name(' George', ' Banks') self.assertNotEqual(r, r2) r3 = Researcher.get_or_create_by_orcid('0000-0003-2306-6531', instance='sandbox.orcid.org') self.assertNotEqual(r, r3)
def test_creation(self): r = Researcher.create_by_name('George', 'Banks') r2 = Researcher.create_by_name(' George', ' Banks') assert r != r2 r3 = Researcher.get_or_create_by_orcid('0000-0003-2306-6531', instance='sandbox.orcid.org') assert r != r3
def test_write_mets_metadata_examples(self, db, upload_data, user_leibniz): """ This is not really a test. It just outputs metadata examples that the protocol generates. Ususally this test is omitted, you can run it explicetely with "-m write_mets_examples". For any subclass, make sure to set ``path_metadata_examples``. This is the place where the file will created. You can then include them in the documentation. In case of changes of the protocol or repository, you should run this function, but make sure it's up to date """ self.protocol.paper = upload_data['paper'] self.protocol.user = user_leibniz Researcher.create_by_name( user=user_leibniz, first=user_leibniz.first_name, last=user_leibniz.last_name, orcid="2543-2454-2345-234X", ) data = dict() data['email'] = user_leibniz.email if upload_data['oairecord'].description is not None: data['abstract'] = upload_data['oairecord'].description else: data['abstract'] = upload_data['abstract'] ddcs = DDC.objects.all() data['ddc'] = [ ddc for ddc in ddcs.filter(number__in=upload_data['ddc']) ] l = License.objects.get( uri="https://creativecommons.org/licenses/by/4.0/") lc = LicenseChooser.objects.create(license=l, repository=self.protocol.repository, transmit_id='cc_by-40') licenses = LicenseChooser.objects.by_repository( repository=self.protocol.repository) data['license'] = lc.pk form = SWORDMETSForm(ddcs=ddcs, licenses=licenses, data=data) valid_form = form.is_valid() if not valid_form: print(form.errors) assert valid_form == True dissemin_xml = self.protocol._get_xml_dissemin_metadata(form) metadata_xml = self.protocol._get_xml_metadata(form) mets_xml = self.protocol._get_mets(metadata_xml, dissemin_xml) # Here we write the file. We take the base path, extend with protocl specific path and write it out f_path = os.path.join(BASE_DIR, 'doc', 'sphinx', 'examples', self.path_metadata_examples) f_name = os.path.join(f_path, upload_data['load_name'] + '.xml') os.makedirs(f_path, exist_ok=True) with open(f_name, 'w') as fout: fout.write(mets_xml)
def test_refresh(self): r = Researcher.get_or_create_by_orcid('0000-0002-0022-2290', instance='sandbox.orcid.org') self.assertEqual(r.institution.name, 'Ecole Normale Superieure') r.institution = None r.name = Name.lookup_name(('John','Doe')) r.save() r = Researcher.get_or_create_by_orcid('0000-0002-0022-2290', instance='sandbox.orcid.org', update=True) self.assertEqual(r.institution.name, 'Ecole Normale Superieure')
def test_institution_match(self): # first, load a profile from someone with # a disambiguated institution (from the sandbox) # http://sandbox.orcid.org/0000-0001-7174-97 r = Researcher.get_or_create_by_orcid('0000-0001-7174-9738', instance='sandbox.orcid.org') # then, load someone else, with the same institution, but not # disambiguated, and without accents # http://sandbox.orcid.org//0000-0001-6068-024 r2 = Researcher.get_or_create_by_orcid('0000-0001-6068-0245', instance='sandbox.orcid.org') self.assertEqual(r.institution, r2.institution)
def depositing_user(db, request, user_leibniz): """ Depositing user with Researcher profile with and without ORCID """ Researcher.create_by_name( user=user_leibniz, first=user_leibniz.first_name, last=user_leibniz.last_name, orcid=request.param, ) return user_leibniz
def test_attributions_preserved_by_merge(self): p1 = Paper.create_by_doi('10.4049/jimmunol.167.12.6786') r1 = Researcher.create_by_name('Stephan', 'Hauschildt') p1.set_researcher(4, r1.id) p2 = Paper.create_by_doi('10.1016/j.chemgeo.2015.03.025') r2 = Researcher.create_by_name('Priscille', 'Lesne') p2.set_researcher(0, r2.id) # merge them ! even if they actually don't have anything # to do together p1.merge(p2) p1.check_authors() self.assertEqual(p1.researchers, [r2, r1])
def fetch_on_orcid_login(sender, **kwargs): account = kwargs['sociallogin'].account # Only prefetch if the social login refers to a valid ORCID account orcid = validate_orcid(account.uid) if not orcid: raise ImmediateHttpResponse( render(kwargs['request'], 'dissemin/error.html', {'message':_('Invalid ORCID identifier.')}) ) profile = None # disabled account.extra_data because of API version mismatches user = None if '_user_cache' in account.__dict__: user = account.user r = Researcher.get_or_create_by_orcid(orcid, profile, user) if not r: # invalid ORCID profile (e.g. no name provided) raise ImmediateHttpResponse( render(kwargs['request'], 'dissemin/error.html', {'message': _('Dissemin requires access to your ORCID name, which is marked as private in your ORCID profile.')}) ) if r.user_id is None and user is not None: r.user = user r.save(update_fields=['user']) if r.empty_orcid_profile is None: r.init_from_orcid() else: r.fetch_everything_if_outdated()
def get(self, request, *args, **kwargs): if 'researcher' in kwargs: researcher = get_object_or_404(Researcher, pk=kwargs['researcher']) elif 'orcid' in kwargs: try: researcher = Researcher.objects.get(orcid=kwargs['orcid']) except Researcher.DoesNotExist: try: orcid = validate_orcid(kwargs['orcid']) researcher = Researcher.get_or_create_by_orcid(orcid) if not researcher: raise Http404(_("Invalid ORCID profile. Please make sure it includes a public name.")) researcher.init_from_orcid() except MetadataSourceException: raise Http404(_('Invalid ORCID profile.')) if not researcher.visible: name = researcher.name.full return HttpResponsePermanentRedirect(reverse('search')+'?'+urlencode({'authors':name})) if kwargs.get('slug') != researcher.slug: view_args = {'researcher': researcher.id, 'slug': researcher.slug} url = reverse('researcher', kwargs=view_args) self.url = self.url_with_query_string(url=url) return HttpResponsePermanentRedirect(self.url) self.queryset = self.queryset.filter(researchers=researcher.id) self.researcher = researcher return super(ResearcherView, self).get(request, *args, **kwargs)
def fetch_on_orcid_login(sender, sociallogin, **kwargs): """ Here we prepare some things, i.e. create a Researcher and require that the name on the orcid profile is public """ account = sociallogin.account # Only prefetch if the social login refers to a valid ORCID account orcid = validate_orcid(account.uid) if not orcid: raise ImmediateHttpResponse( render(kwargs['request'], 'dissemin/error.html', {'message': _('Invalid ORCID identifier.')})) profile = None # disabled account.extra_data because of API version mismatches user = None if '_user_cache' in account.__dict__: user = account.user r = Researcher.get_or_create_by_orcid(orcid, profile, user) if not r: # invalid ORCID profile (e.g. no name provided) raise ImmediateHttpResponse( render( kwargs['request'], 'dissemin/error.html', { 'message': _('Dissemin requires access to your ORCID name, ' 'which is marked as private in your ORCID profile.') }))
def get(self, request, *args, **kwargs): if 'researcher' in kwargs: researcher = get_object_or_404(Researcher, pk=kwargs['researcher']) elif 'orcid' in kwargs: try: researcher = Researcher.objects.get(orcid=kwargs['orcid']) except Researcher.DoesNotExist: try: orcid = validate_orcid(kwargs['orcid']) researcher = Researcher.get_or_create_by_orcid(orcid) if not researcher: raise Http404( _("Invalid ORCID profile. Please make sure it includes a public name." )) researcher.init_from_orcid() except MetadataSourceException: raise Http404(_('Invalid ORCID profile.')) if not researcher.visible: name = researcher.name.full return HttpResponsePermanentRedirect( reverse('search') + '?' + urlencode({'authors': name})) if kwargs.get('slug') != researcher.slug: view_args = {'researcher': researcher.id, 'slug': researcher.slug} url = reverse('researcher', kwargs=view_args) self.url = self.url_with_query_string(url=url) return HttpResponsePermanentRedirect(self.url) self.queryset = self.queryset.filter(researchers=researcher.id) self.researcher = researcher return super(ResearcherView, self).get(request, *args, **kwargs)
def test_bibtex_not_ignored(self): profile = OrcidProfileStub('0000-0003-2888-1770', instance='orcid.org') adrien = Researcher.get_or_create_by_orcid('0000-0003-2888-1770', profile=profile) self.source.fetch_and_save(adrien, profile=profile) p1 = Paper.objects.get(title='A Fuzzy Take on Graded Beliefs') p2 = Paper.objects.get(title='Information quality and uncertainty') self.assertTrue(p1 != p2)
def bulk_import(self, directory, fetch_papers=True, use_doi=False): """ Bulk-imports ORCID profiles from a dmup (warning: this still uses our DOI cache). The directory should contain json versions of orcid profiles, as in the official ORCID dump. """ for root, _, fnames in os.walk(directory): for fname in fnames: #if fname == '0000-0003-1349-4524.json': # seen = True #if not seen: # continue with open(path.join(root, fname), 'r') as f: try: profile = json.load(f) orcid = profile['orcid-profile']['orcid-identifier'][ 'path'] r = Researcher.get_or_create_by_orcid(orcid, profile, update=True) if fetch_papers: papers = self.fetch_orcid_records(orcid, profile=profile, use_doi=use_doi) for p in papers: self.save_paper(p, r) except (ValueError, KeyError): print "Invalid profile: %s" % fname
def bulk_import(self, directory, fetch_papers=True, use_doi=False): """ Bulk-imports ORCID profiles from a dmup (warning: this still uses our DOI cache). The directory should contain json versions of orcid profiles, as in the official ORCID dump. """ for root, _, fnames in os.walk(directory): for fname in fnames: #if fname == '0000-0003-1349-4524.json': # seen = True #if not seen: # continue with open(path.join(root, fname), 'r') as f: try: profile = json.load(f) orcid = profile['orcid-profile'][ 'orcid-identifier'][ 'path'] r = Researcher.get_or_create_by_orcid( orcid, profile, update=True) if fetch_papers: papers = self.fetch_orcid_records(orcid, profile=OrcidProfile(json=profile), use_doi=use_doi) for p in papers: self.save_paper(p, r) except (ValueError, KeyError): logger.warning("Invalid profile: %s" % fname)
def test_link_existing_papers(self): # Fetch papers from a researcher profile_pablo = OrcidProfileStub('0000-0002-6293-3231', instance='orcid.org') pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231', profile=profile_pablo) self.source.fetch_and_save(pablo, profile=profile_pablo) papers = list(pablo.papers) nb_papers = len(papers) self.assertEqual(nb_papers, 9) # Remove the researcher_ids from the papers for paper in papers: for author in paper.authors_list: if author.get('researcher_id') == pablo.id: del author['researcher_id'] paper.save() # Now the profile has no papers anymore self.assertEqual(pablo.papers.count(), 0) # Let's fix that! self.source.link_existing_papers(pablo) # Now it's fine!! self.assertEqual(Researcher.objects.get(id=pablo.id).papers.count(), 9)
def test_unmerge_orcid_nones(self): # First, fetch a few DOIs dois = [ "10.1075/aicr.90.09ngo", "10.1075/aicr.90.04wad", ] for doi in dois: Paper.create_by_doi(doi) # Then, fetch an ORCID profile with a buggy version of the ORCID interface, which incorrectly merges papers together with patch.object(OrcidPaperSource, '_oai_id_for_doi') as mock_identifier: mock_identifier.return_value = "https://pub.orcid.org/v2.1/0000-0002-1909-134X/work/None" profile = OrcidProfileStub('0000-0002-1909-134X', instance='orcid.org') trung = Researcher.get_or_create_by_orcid('0000-0002-1909-134X', profile=profile) OrcidPaperSource().fetch_and_save(trung, profile=profile) # The two papers are incorrectly merged! papers = [Paper.get_by_doi(doi) for doi in dois] self.assertEqual(papers[0], papers[1]) # We unmerge them unmerge_orcid_nones() # The two papers are now distinct papers = [Paper.get_by_doi(doi) for doi in dois] self.assertTrue(papers[0] != papers[1])
def test_fetch_dois(self): pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833') self.source.fetch_and_save(pboesu) doi = '10.3354/meps09890' p = Paper.get_by_doi(doi) dois_in_paper = [r.doi for r in p.oairecords] self.assertTrue(doi in dois_in_paper)
def test_researcher_with_empty_slug(self): """ Researchers may have names with characters that are all ignored by slugify. """ r = Researcher.create_by_name('!@#', '$%^') self.assertEqual(r.slug, '') self.checkPage('researcher', args=[r.pk, r.slug])
def test_previously_present_papers_are_attributed(self): # Fetch papers from a researcher pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231') self.source.fetch_and_save(pablo) p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1') self.assertEqual(p.authors[2].orcid, pablo.orcid) # Now fetch a coauthor of him antoine = Researcher.get_or_create_by_orcid('0000-0002-7977-4441') self.source.fetch_and_save(antoine) # This paper should be attributed to both ORCID ids p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1') self.assertEqual(p.authors[0].orcid, antoine.orcid) self.assertEqual(p.authors[2].orcid, pablo.orcid)
def test_researcher_with_empty_slug(self, check_page): """ Researchers may have names with characters that are all ignored by slugify. """ r = Researcher.create_by_name('!@#', '$%^') assert r.slug == '' check_page(200, 'researcher', args=[r.pk, r.slug])
def test_set_researcher(self): p1 = Paper.create_by_doi('10.4049/jimmunol.167.12.6786') r1 = Researcher.create_by_name('Stephan', 'Hauschildt') # Add the researcher p1.set_researcher(4, r1.id) self.assertEqual(set(p1.researchers), {r1}) # Remove the researcher p1.set_researcher(4, None) self.assertEqual(set(p1.researchers), set())
def create_new_user_and_researcher(self, remote_user, orcid, shib_meta): """ Creates a new user and researcher and returns the user """ user = User.objects.create_user( remote_user, first_name=shib_meta.get('first_name'), last_name=shib_meta.get('last_name'), ) ShibbolethAccount.objects.create( user=user, shib_username=shib_meta.get('username')) Researcher.create_by_name( shib_meta.get('first_name'), shib_meta.get('last_name'), orcid=orcid, user=user, ) return user
def test_merge_value_error(self): r = Researcher.create_by_name('Stefan', 'Beck', email='*****@*****.**', homepage='https://becks.dissem.in') r2 = Researcher.create_by_name('Stefan', 'Beck', homepage='https://sbeck.dissem.in') with pytest.raises(ValueError): r.pk = None r.merge(r2) r.save() with pytest.raises(ValueError): r2.pk = None r.merge(r2) r.save() with pytest.raises(ValueError): r2.pk = r.pk r.merge(r2)
def test_import_with_crossref_error(self): stergios = Researcher.get_or_create_by_orcid('0000-0001-9232-4042') self.source.fetch_and_save(stergios) p = Paper.objects.get(oairecord__doi='10.1016/j.metabol.2017.10.007') # crossref claims that the ORCID should be associated to author 2 # but it should actually be associated to author 0 self.assertEqual(p.authors[0].orcid, '0000-0001-9232-4042') self.assertEqual(p.authors[2].orcid, None) self.assertEqual(p.authors[0].researcher_id, stergios.id) self.assertEqual(p.authors[2].researcher_id, None)
def test_fetch_dois(self): profile = OrcidProfileStub('0000-0001-6723-6833', instance='orcid.org') pboesu = Researcher.get_or_create_by_orcid('0000-0001-6723-6833', profile=profile) self.source.fetch_and_save(pboesu, profile=profile) doi = '10.3354/meps09890' p = Paper.get_by_doi(doi) dois_in_paper = [r.doi for r in p.oairecords] self.assertTrue(doi in dois_in_paper)
def test_previously_present_papers_are_attributed(self): # Fetch papers from a researcher profile_pablo = OrcidProfileStub('0000-0002-6293-3231', instance='orcid.org') pablo = Researcher.get_or_create_by_orcid('0000-0002-6293-3231', profile=profile_pablo) self.source.fetch_and_save(pablo, profile=profile_pablo) p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1') self.assertEqual(p.authors[2].orcid, pablo.orcid) # Now fetch a coauthor of him profile_antoine = OrcidProfileStub('0000-0002-7977-4441', instance='orcid.org') antoine = Researcher.get_or_create_by_orcid('0000-0002-7977-4441', profile=profile_antoine) self.source.fetch_and_save(antoine, profile=profile_antoine) # This paper should be attributed to both ORCID ids p = Paper.objects.get(oairecord__doi='10.1007/978-3-642-25516-8_1') self.assertEqual(p.authors[0].orcid, antoine.orcid) self.assertEqual(p.authors[2].orcid, pablo.orcid)
def preparation(self, django_user_model, shib_meta): self.shib_meta = shib_meta self.remote_user = self.shib_meta.get('username') # Adding a ShibbolethAccount and a researcher. The latter exists since the first exists self.user = django_user_model.objects.create_user('vimess') self.shib_account = ShibbolethAccount.objects.create( user=self.user, shib_username=self.shib_meta.get('username')) self.researcher = Researcher.create_by_name( self.shib_meta.get('first_name'), self.shib_meta.get('last_name'), orcid=self.shib_meta.get('orcid'), user=self.user)
def test_set_researcher(self): """ Test setting (adding and removing) the researcher """ p = Paper.create_by_doi('10.4049/jimmunol.167.12.6786') r = Researcher.create_by_name('Stephan', 'Hauschildt') # Add the researcher p.set_researcher(4, r.pk) assert set(p.researchers) == {r} # Remove the researcher p.set_researcher(4, None) assert set(p.researchers) == set()
def test_import_with_crossref_error(self): profile = OrcidProfileStub('0000-0001-9232-4042', instance='orcid.org') stergios = Researcher.get_or_create_by_orcid('0000-0001-9232-4042', profile=profile) self.source.fetch_and_save(stergios, profile=profile) p = Paper.objects.get(oairecord__doi='10.1016/j.metabol.2017.10.007') # crossref claims that the ORCID should be associated to author 2 # but it should actually be associated to author 0 self.assertEqual(p.authors[0].orcid, '0000-0001-9232-4042') self.assertEqual(p.authors[2].orcid, None) self.assertEqual(p.authors[0].researcher_id, stergios.id) self.assertEqual(p.authors[2].researcher_id, None)
def test_authenticate_researcher_without_user(self): r = Researcher.create_by_name( self.shib_meta.get('first_name'), self.shib_meta.get('last_name'), orcid=self.shib_meta.get('orcid'), ) user = auth.authenticate(remote_user=self.remote_user, shib_meta=self.shib_meta) assert user.shibboleth_account.shib_username == self.shib_meta.get( 'username') r.refresh_from_db() assert r.user == user assert r.orcid == self.shib_meta.get('orcid')
def test_bibtex_formatting_search(self): bibtex_output = """@inproceedings{Amarilli2015, author = {Amarilli, Antoine}, doi = {10.1145/2744680.2744690}, journal = {Proceedings of the 2015 ACM SIGMOD on PhD Symposium - SIGMOD '15 PhD Symposium}, month = {jan}, title = {Structurally Tractable Uncertain Data}, url = {https://oadoi.org/10.1145/2744680.2744690}, year = {2015} } @inproceedings{Amarilli2015_2, author = {Amarilli, Antoine and Benedikt, Michael}, doi = {10.1109/lics.2015.37}, journal = {2015 30th Annual ACM/IEEE Symposium on Logic in Computer Science}, month = {jul}, title = {Finite Open-World Query Answering with Number Restrictions}, url = {https://oadoi.org/10.1109/lics.2015.37}, year = {2015} }""" r1 = Researcher.create_by_name('John', 'Doe') p1 = Paper.create_by_doi('10.1109/lics.2015.37') p1.set_researcher(0, r1.id) p1.update_index() # Ensure index is updated p2 = Paper.create_by_doi('10.1145/2744680.2744690') p2.set_researcher(0, r1.id) p2.update_index() # Ensure index is updated resp = self.getPage( 'api-paper-search', getargs={'authors': 'amarilli', 'format': 'bibtex'} ) self.assertEqual(resp.status_code, 200) self.assertEqual( resp.content.decode('utf-8').strip(), bibtex_output.strip() )
def test_fetch_everything_with_orcid(self): profile = OrcidProfileStub('0000-0002-9658-1473', instance='orcid.org') r = Researcher.get_or_create_by_orcid('0000-0002-9658-1473', profile=profile) fetch_everything_for_researcher(r.pk)
def test_empty(self): emptyres = Researcher.create_by_name('Anrscuienrsc', 'Lecsrcudresies') papers = list(self.source.fetch_papers(emptyres)) self.assertEqual(papers, [])
def fetch_orcid_records(self, orcid_identifier, profile=None, use_doi=True): """ Queries ORCiD to retrieve the publications associated with a given ORCiD. It also fetches such papers from the CrossRef search interface. :param profile: The ORCID profile if it has already been fetched before (format: parsed JSON). :param use_doi: Fetch the publications by DOI when we find one (recommended, but slow) :returns: a generator, where all the papers found are yielded. (some of them could be in free form, hence not imported) """ cr_api = CrossRefAPI() # Cleanup iD: orcid_id = validate_orcid(orcid_identifier) if orcid_id is None: raise MetadataSourceException('Invalid ORCiD identifier') # Get ORCiD profile try: if profile is None: profile = OrcidProfile(orcid_id=orcid_id) except MetadataSourceException: logger.exception("ORCID Profile Error") return # As we have fetched the profile, let's update the Researcher self.researcher = Researcher.get_or_create_by_orcid(orcid_identifier, profile.json, update=True) if not self.researcher: return # Reference name ref_name = profile.name ignored_papers = [] # list of ignored papers due to incomplete metadata # Get summary publications and separate them in two classes: # - the ones with DOIs, that we will fetch with CrossRef dois_and_putcodes = [] # list of (DOIs,putcode) to fetch # - the ones without: we will fetch ORCID's metadata about them # and try to create a paper with what they provide put_codes = [] for summary in profile.work_summaries: if summary.doi and use_doi: dois_and_putcodes.append((summary.doi, summary.put_code)) else: put_codes.append(summary.put_code) # 1st attempt with DOIs and CrossRef if use_doi: # Let's grab papers with DOIs found in our ORCiD profile. dois = [doi for doi, put_code in dois_and_putcodes] for idx, (success, paper_or_metadata) in enumerate(self.fetch_metadata_from_dois(cr_api, ref_name, orcid_id, dois)): if success: yield paper_or_metadata # We know that this is a paper else: put_codes.append(dois_and_putcodes[idx][1]) # 2nd attempt with ORCID's own crappy metadata works = profile.fetch_works(put_codes) for work in works: if not work: continue # If the paper is skipped due to invalid metadata. # We first try to reconcile it with local researcher author name. # Then, we consider it missed. if work.skipped: logger.warning("Work skipped due to incorrect metadata. \n %s \n %s" % (work.reason, work.skip_reason)) ignored_papers.append(work.as_dict()) continue yield self.create_paper(work) self.warn_user_of_ignored_papers(ignored_papers) if ignored_papers: logger.warning("Total ignored papers: %d" % (len(ignored_papers)))