hermes.commands.deposit.invenio
Contents
hermes.commands.deposit.invenio
Module Contents
Functions
|
Prepare the deposition on an Invenio-based platform. |
|
Map the harvested metadata onto the Invenio schema. |
|
Create an initial version of a publication. |
|
Create a new version of an existing publication. |
|
Update the metadata of a draft. |
|
Delete existing file artifacts. |
|
Upload file artifacts to the deposit. |
|
Publish the deposited record. |
|
Using the given configuration and metadata, figure out the latest record id. |
|
Resolve an DOI to a Invenio URL and extract the record id. |
|
Find the latest version of a given record. |
|
The mapping logic. |
|
Get Invenio license representation from CodeMeta. |
|
Get Invenio community identifiers from config. |
|
Get access right, embargo date and access conditions based on configuration and given license. |
Attributes
- hermes.commands.deposit.invenio.prepare(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Prepare the deposition on an Invenio-based platform.
In this function we do the following:
resolve the latest published version of this publication (if any)
check whether the current version (given in the CodeMeta) was already published
check whether we have a valid license identifier (if any)
check wether the communities are valid (if configured)
check access modalities (access right, access conditions, embargo data, existence of license)
check whether required configuration options are present
check whether an auth token is given
update
ctx
with metadata collected during the checks
- hermes.commands.deposit.invenio.map_metadata(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Map the harvested metadata onto the Invenio schema.
- hermes.commands.deposit.invenio.create_initial_version(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Create an initial version of a publication.
If a previous publication exists, this function does nothing, leaving the work for
create_new_version()
.
- hermes.commands.deposit.invenio.create_new_version(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Create a new version of an existing publication.
If no previous publication exists, this function does nothing because
create_initial_version()
will have done the work.
- hermes.commands.deposit.invenio.update_metadata(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Update the metadata of a draft.
If no draft is found in the context, it is assumed that no metadata has to be updated (e.g. because an initial version was created already containing the metadata).
- hermes.commands.deposit.invenio.delete_artifacts(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Delete existing file artifacts.
This is done so that files which existed in an earlier publication but don’t exist any more, are removed. Otherwise they would cause an error because the didn’t change between versions.
- hermes.commands.deposit.invenio.upload_artifacts(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Upload file artifacts to the deposit.
We’ll use the bucket API rather than the files API as it supports file sizes above 100MB. The URL to the bucket of the deposit is taken from the context at
deposit.invenio.links.bucket
.
- hermes.commands.deposit.invenio.publish(click_ctx: click.Context, ctx: hermes.model.context.CodeMetaContext)
Publish the deposited record.
This is done by doing a POST request to the publication URL stored in the context at
deposit.invenio.links.publish
.
- hermes.commands.deposit.invenio._resolve_latest_invenio_id(ctx: hermes.model.context.CodeMetaContext) Tuple[str, dict]
Using the given configuration and metadata, figure out the latest record id.
If a record id is present as configuration
deposit.invenio.record_id
this one will be used to identify the latest version of the record. Otherwise, if there is a doi present (either as configuration with keydeposit.invenio.doi
or as a codemeta identifier, the DOI will be used to resolve the base record id.Anyway, the record id will always be used to resolve the latest version.
If any of the resolution steps fail or produce an unexpected result, a ValueError will be thrown.
- Parameters
ctx – The context for which the record id should be resolved.
- Returns
The Invenio record id and the metadata of the record
- hermes.commands.deposit.invenio._invenio_resolve_doi(site_url, doi) str
Resolve an DOI to a Invenio URL and extract the record id.
- Parameters
site_url – Root URL for the Invenio instance to use.
doi – The DOI to be resolved (only the identifier without the
https://doi.org/
prefix).
- Returns
The record ID on the respective instance.
- hermes.commands.deposit.invenio._invenio_resolve_record_id(site_url: str, record_id: str) Tuple[str, dict]
Find the latest version of a given record.
- Parameters
site_url – Root URL for the Invenio instance to use.
record_id – The record that sould be resolved.
- Returns
The record id of the latest version for the requested record.
- hermes.commands.deposit.invenio._codemeta_to_invenio_deposition(ctx: hermes.model.context.CodeMetaContext) dict
The mapping logic.
Functionality similar to this exists in the
convert_codemeta
package which uses the crosswalk tables to do the mapping:invenio_metadata = convert_codemeta.crosswalk( metadata, "codemeta", "Zenodo" )
Unfortunately, this doesn’t work well with additional metadata in the same dict, so it is safer to provide our own implementation.
Currently, this function handles a lot of cases which we want to be able to configure. A simple mapping from one JSON path to another is not enough.
The metadata expected by Zenodo is described in the Zenodo Developers guide. Unfortunately, there doesn’t seem to be a schema one can download in order to validate these metadata. There might be differences between Invenio-based platforms.
- hermes.commands.deposit.invenio._get_license_identifier(ctx: hermes.model.context.CodeMetaContext, license_api_url: str)
Get Invenio license representation from CodeMeta.
The license to use is extracted from the
license
field in theCodeMetaContext
and converted into an appropiate license identifier to be passed to an Invenio instance.A license according to CodeMeta may be a URL (text) or a CreativeWork. This function only handles URLs. If a
license
field is present in the CodeMeta and it is not of typestr
, aRuntimeError
is raised.Invenio instances take a license string which refers to a license identifier. Typically, Invenio instances offer licenses from https://opendefinition.org and https://spdx.org. However, it is possible to mint PIDs for custom licenses.
An API endpoint (usually
/api/licenses
) can be used to check whether a given license is supported by the Invenio instance. This function tries to retrieve the license by the identifier at the end of the license URL path. If this identifier does not exist on the Invenio instance, aRuntimeError
is raised. If no license is given in the CodeMeta,None
is returned.
- hermes.commands.deposit.invenio._get_community_identifiers(ctx: hermes.model.context.CodeMetaContext, communities_api_url: str)
Get Invenio community identifiers from config.
This function gets the communities to be used for the deposition on an Invenio-based site from the config and checks their validity against the site’s API. If one of the identifiers can not be found on the site, a
MisconfigurationError
is raised.
- hermes.commands.deposit.invenio._get_access_modalities(license)
Get access right, embargo date and access conditions based on configuration and given license.
This function implements the rules laid out in the Zenodo developer documentation:
access_right
is a controlled vocabularyembargoed access depositions need an embargo date
restricted access depositions need access conditions
open and embargoed access depositions need a license
closed access depositions have no further requirements
This function also makes sure that the given embargo date can be parsed as an ISO 8601 string representation and that the access rights are given as a string.