Skip to main content

A CKAN extension for assigning a digital object identifier (DOI) to datasets, using the DataCite DOI service.

Project description

ckanext-doi

Tests Coveralls CKAN Python

A CKAN extension for assigning a digital object identifier (DOI) to datasets, using the DataCite DOI service.

Overview

This extension assigns a digital object identifier (DOI) to datasets, using the DataCite DOI service.

When a new dataset is created it is assigned a new DOI. This DOI will be in the format:

https://doi.org/[prefix]/[8 random alphanumeric characters]

If the new dataset is active and public, the DOI and metadata will be registered with DataCite.

If the dataset is draft or private, the DOI will not be registered with DataCite. When the dataset is made active & public, the DOI will be submitted. This allows datasets to be embargoed, but still provides a DOI to be referenced in publications.

You will need an account with a DataCite DOI service provider to use this extension.

DOI Metadata

Uses DataCite Metadata Schema v4.2.

Dataset package fields and CKAN config settings are mapped to the DataCite Schema with default values, but these can be overwritten by implementing IDoi interface methods.

Required fields

CKAN Field DataCite Schema
dataset:title title
dataset:author creator
config:ckanext.doi.publisher publisher
dataset:metadata_created.year publicationYear
dataset:type resourceType

See metadata.py for full mapping details.

Installation

Path variables used below:

  • $INSTALL_FOLDER (i.e. where CKAN is installed), e.g. /usr/lib/ckan/default
  • $CONFIG_FILE, e.g. /etc/ckan/default/development.ini
  1. Clone the repository into the src folder:
cd $INSTALL_FOLDER/src
git clone https://github.com/NaturalHistoryMuseum/ckanext-doi.git
  1. Activate the virtual env:
. $INSTALL_FOLDER/bin/activate
  1. Install the requirements from requirements.txt:
cd $INSTALL_FOLDER/src/ckanext-doi
pip install -r requirements.txt
  1. Run setup.py:
cd $INSTALL_FOLDER/src/ckanext-doi
python setup.py develop
  1. Add 'doi' to the list of plugins in your $CONFIG_FILE:
ckan.plugins = ... doi
  1. Initialize the database
ckan -c $CONFIG_FILE doi initdb

Configuration

There are a number of options that can be specified in your .ini config file.

DateCite Credentials [REQUIRED]

These will be given to you by your DataCite provider.

ckanext.doi.account_name = DATACITE-ACCOUNT-NAME
ckanext.doi.account_password = DATACITE-ACCOUNT-PASSWORD
ckanext.doi.prefix = DATACITE-PREFIX

Institution Name [REQUIRED]

You also need to provide the name of the institution publishing the DOIs (e.g. Natural History Museum).

ckanext.doi.publisher = PUBLISHING-INSTITUTION

Test/Debug Mode [REQUIRED]

If test mode is set to true, the DOIs will use the DataCite test prefix 10.5072.

ckanext.doi.test_mode = True or False

Other options

Name Description Default
ckanext.doi.site_url Used to build the link back to the dataset ckan.site_url
ckanext.doi.site_title Site title to use in the citation

Further Setup

This extension will only work if you have signed up for an account with DataCite.

You will need a development/test account to use this plugin in test mode, and a live account to mint active DOIs.

Usage

Commands

doi

  1. delete-dois: delete all DOIs from the database (not datacite).

    ckan -c $CONFIG_FILE doi delete-dois
    
  2. update-doi: update the datacite metadata for one or all packages.

    ckan -c $CONFIG_FILE doi update-doi [PACKAGE_ID]
    

Interfaces

The IDoi interface allows plugins to extend the build_metadata_dict and build_xml_dict methods.

build_metadata_dict(pkg_dict, metadata_dict, errors)

Breaking changes from v1:

  1. previously called build_metadata
  2. new parameter: errors
  3. new return value: tuple of metadata_dict, errors

Extracts metadata from a pkg_dict for use in generating datacite DOIs. The base method from this extension is run first, then the metadata dict is passed through all the implementations of this method. After running these, if any of the required values (see above) are still in the errors dict (i.e. they still could not be handled by any other extension), a DOIMetadataException will be thrown.

Parameter Description
pkg_dict The original package dictionary from which the metadata were extracted.
metadata_dict The current metadata dict, created by the ckanext-doi extension and any previous plugins implementing IDoi.
errors A dictionary of metadata keys and errors generated by previous plugins; this method should remove any keys that it successfully processes and overwrites.

build_xml_dict(metadata_dict, xml_dict)

Breaking changes from v1:

  1. previously called metadata_to_xml
  2. parameters rearranged (previously xml_dict, metadata)

Converts the metadata_dict into an xml_dict that can be passed to the datacite library's schema42.tostring() and schema42.validate() methods. The base method from this extension is run first, then the xml dict is passed through all the implementations of this method.

Parameter Description
metadata_dict The original metadata dictionary from which the xml attributes are extracted.
xml_dict The current xml dict, created by the ckanext-doi extension and any previous plugins implementing IDoi.

Templates

Package citation snippet

{% snippet "doi/snippets/package_citation.html", pkg_dict=g.pkg_dict %}

Resource citation snippet

{% snippet "doi/snippets/resource_citation.html", pkg_dict=g.pkg_dict, res=res %}

Testing

Test coverage is currently extremely limited.

To run the tests in this extension, there is a Docker compose configuration available in this repository to make it easy.

To run the tests against ckan 2.9.x on Python3:

  1. Build the required images
# first build the containers
docker-compose build
  1. Then run the tests. The root of the repository is mounted into the ckan container as a volume by the Docker compose configuration, so you should only need to rebuild the ckan image if you change the extension's dependencies.
docker-compose run ckan

The ckan image uses the Dockerfile in the docker/ folder which is based on openknowledge/ckan-dev:2.9.

Note that currently the tests mock the Datacite API and therefore don't require an internet connection nor your Datacite credentials to run.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ckanext-doi-3.0.7.tar.gz (31.5 kB view details)

Uploaded Source

Built Distributions

ckanext_doi-3.0.7-py3.10.egg (21.6 kB view details)

Uploaded Source

ckanext_doi-3.0.7-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file ckanext-doi-3.0.7.tar.gz.

File metadata

  • Download URL: ckanext-doi-3.0.7.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for ckanext-doi-3.0.7.tar.gz
Algorithm Hash digest
SHA256 426328c40fcbf4bacd8efecc9fd30719ff366751f30b24a085d5f7cb707bc37b
MD5 8c5bb6185941c957f8b16ac3a92f6fa1
BLAKE2b-256 68ef20f7f6152c08a81c2bfa6f7f1ecc4979a98da3605b6b9f87c6bdcff852d8

See more details on using hashes here.

File details

Details for the file ckanext_doi-3.0.7-py3.10.egg.

File metadata

  • Download URL: ckanext_doi-3.0.7-py3.10.egg
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for ckanext_doi-3.0.7-py3.10.egg
Algorithm Hash digest
SHA256 d15f113adeacfe0539b3720cbe3368a293a07b68d7da0022715cec8741628a1e
MD5 067df469e9c6fa52214cee44eca9373b
BLAKE2b-256 da4d87f7408240f445126b067039f2e277bf658921b22b029e798a9bcaf2e36a

See more details on using hashes here.

File details

Details for the file ckanext_doi-3.0.7-py3-none-any.whl.

File metadata

  • Download URL: ckanext_doi-3.0.7-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for ckanext_doi-3.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e719fa6402049366450db4a0869c48be3600cb668f147676801a40dcc2e99a
MD5 3c667d3cc1167f6bb7a8a606198a8f2b
BLAKE2b-256 c973fee1fed2fba59253cf4242a254409749d69733018a138c98fdbffd497bec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page