コード例 #1
0
 def _get_putcodes_and_recids_iter(self, putcodes):
     for putcode, url in self._get_urls_for_putcodes_iter(putcodes):
         # Filter out putcodes that do not belong to Inspire.
         if INSPIRE_WORK_URL_REGEX.match(url):
             recid = get_pid_from_record_uri(url)[1]
             if not recid:
                 logger.error('OrcidPutcodeGetter: cannot parse recid from url={} for orcid={}'.format(
                     url, self.orcid))
                 continue
             yield putcode, recid
コード例 #2
0
 def resolve_conference_record_as_root(self, pub_info_item):
     conference_record = pub_info_item.get('conference_record')
     if conference_record is None:
         return {}
     _, recid = get_pid_from_record_uri(conference_record.get('$ref'))
     conference = get_db_record('con', recid).dumps()
     titles = conference.get('titles')
     if titles is None:
         return {}
     return conference
コード例 #3
0
 def _get_putcodes_and_recids_iter(self, putcodes):
     for putcode, url in self._get_urls_for_putcodes_iter(putcodes):
         # Filter out putcodes that do not belong to Inspire.
         if INSPIRE_WORK_URL_REGEX.match(url):
             recid = get_pid_from_record_uri(url)[1]
             if not recid:
                 logger.error(
                     'OrcidPutcodeGetter: cannot parse recid from url={} for orcid={}'
                     .format(url, self.orcid))
                 continue
             yield putcode, recid
コード例 #4
0
    def resolve_conference_record_as_root(self, pub_info_item):
        conference_record = pub_info_item.get('conference_record')
        if conference_record is None:
            return {}

        _, recid = get_pid_from_record_uri(conference_record.get('$ref'))
        try:
            conference = get_db_record('con', recid)
        except RecordGetterError:
            return {}

        titles = conference.get('titles')
        if titles is None:
            return {}
        return conference.to_dict()
コード例 #5
0
    def _cache_all_author_putcodes(self):
        logger.info(
            'New OrcidPusher cache all author putcodes for orcid={}'.format(
                self.orcid))
        putcode_getter = OrcidPutcodeGetter(self.orcid, self.oauth_token)
        putcodes_urls = list(putcode_getter.get_all_inspire_putcodes(
        ))  # Can raise exceptions.InputDataInvalidException.

        putcode = None
        for fetched_putcode, fetched_url in putcodes_urls:
            fetched_recid = get_pid_from_record_uri(fetched_url)[1]

            if not fetched_recid:
                logger.error(
                    'OrcidPusher cache all author putcodes: cannot parse recid from url={} for orcid={}'
                    .format(fetched_url, self.orcid))
                continue

            if fetched_recid == str(self.recid):
                putcode = fetched_putcode
            cache = OrcidCache(self.orcid, fetched_recid)
            cache.write_work_putcode(fetched_putcode)

        if not putcode:
            raise exceptions.PutcodeNotFoundInOrcidException(
                'No putcode was found in ORCID API for orcid={} and recid={}.'
                ' And the POST has previously failed for the same recid because'
                ' the work had already existed'.format(self.orcid, self.recid))

        # Ensure the putcode is actually in cache.
        # Note: this step is not really necessary and it can be skipped, but
        # at this moment it helps isolate a potential issue.
        if not self.cache.read_work_putcode():
            raise exceptions.PutcodeNotFoundInCacheAfterCachingAllPutcodes(
                'No putcode={} found in cache for recid={} after having'
                ' cached all author putcodes for orcid={}'.format(
                    self.putcode, self.recid, self.orcid))

        return putcode
コード例 #6
0
ファイル: api.py プロジェクト: harunurhan/inspire-next
 def _get_ids_from_refs(references):
     return set([
         get_pid_from_record_uri(ref['record']['$ref'])
         for ref in references
         if 'record' in ref
     ])
コード例 #7
0
def test_get_pid_from_record_uri_non_url():
    record_uri = 'non-url-string'
    assert not get_pid_from_record_uri(record_uri)
コード例 #8
0
def test_get_pid_from_record_uri_ending_slash():
    record_uri = 'http://labs.inspirehep.net/api/literature/1273685/'
    assert get_pid_from_record_uri(record_uri) == ('lit', '1273685')
コード例 #9
0
def test_get_pid_from_record_uri_happy_flow():
    record_uri = 'http://labs.inspirehep.net/api/literature/1273685'
    assert get_pid_from_record_uri(record_uri) == ('lit', '1273685')
コード例 #10
0
ファイル: api.py プロジェクト: turtle321/inspire-next
 def _get_ids_from_refs(references):
     return set([
         get_pid_from_record_uri(ref['record']['$ref'])
         for ref in references if 'record' in ref
     ])
コード例 #11
0
def test_get_pid_from_record_uri_non_url():
    record_uri = 'non-url-string'
    assert not get_pid_from_record_uri(record_uri)
コード例 #12
0
def test_get_pid_from_record_uri_ending_slash():
    record_uri = 'http://labs.inspirehep.net/api/literature/1273685/'
    assert get_pid_from_record_uri(record_uri) == ('lit', '1273685')
コード例 #13
0
def test_get_pid_from_record_uri_happy_flow():
    record_uri = 'http://labs.inspirehep.net/api/literature/1273685'
    assert get_pid_from_record_uri(record_uri) == ('lit', '1273685')