Example #1
0
def migrate_doi_identifier(data):
    """If the dataset has a doi, make identifier be based on it."""
    from renku.core.utils.doi import is_doi, extract_doi

    if is_doi(data.get('_id', '')):
        data['identifier'] = extract_doi(data.get('_id'))
        data['same_as'] = data['_id']
        if data.get('@context'):
            data['@context'].setdefault('same_as', 'schema:sameAs')
    return data
Example #2
0
    def _query(self, doi):
        """Retrieve metadata for given doi."""
        doi = extract_doi(doi)
        url = make_doi_url(doi)

        with retry() as session:
            response = session.get(url, headers=self.headers)
            if response.status_code != 200:
                raise LookupError("record not found. Status: {}".format(response.status_code))

            return response
Example #3
0
    def remote_url(self):
        """Get remote URL as ``urllib.ParseResult``."""
        if self.content_url is not None:
            return urllib.parse.urlparse(self.content_url)

        if self.identifier is None:
            return None

        doi = extract_doi(self.identifier)

        if doi is None:
            return None

        file_url = make_file_url('doi:' + doi, self.parent_url)

        return urllib.parse.urlparse(file_url)
Example #4
0
def _extract_doi(value):
    """Return either a string or the doi part of a URL."""
    value = str(value)
    if is_doi(value):
        return extract_doi(value)
    return value