Skip to content

Commit

Permalink
Merge pull request #290 from softwarepub/feature/235-hermes-tracing
Browse files Browse the repository at this point in the history
Related identifier for tracing and advertising hermes usage
  • Loading branch information
zyzzyxdonta authored Dec 17, 2024
2 parents dc0f625 + a46fc19 commit c47cb79
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/hermes/commands/deposit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ def prepare(self) -> None:

@abc.abstractmethod
def map_metadata(self) -> None:
"""Map the given metadata to the target schema of the deposition platform."""
"""Map the given metadata to the target schema of the deposition platform.
When mapping metadata, make sure to add traces to the HERMES software, e.g. via
DataCite's ``relatedIdentifier`` using the ``isCompiledBy`` relation. Ideally, the value
of the relation target should be of the respective type for DOIs in your metadata
schema, with the value itself being the DOI for the version of the HERMES software
you are using.
"""
pass

def is_initial_publication(self) -> bool:
Expand Down
18 changes: 16 additions & 2 deletions src/hermes/commands/deposit/invenio.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from hermes.error import MisconfigurationError
from hermes.model.context import CodeMetaContext
from hermes.model.path import ContextPath
from hermes.utils import hermes_user_agent
from hermes.utils import hermes_doi, hermes_user_agent


_log = logging.getLogger("cli.deposit.invenio")
Expand Down Expand Up @@ -392,6 +392,20 @@ def create_new_version(self) -> None:
old_deposit = response.json()
self.links.update(old_deposit["links"])

def related_identifiers(self):
"""Return desired related identifiers.
In all cases, we add HERMES as ``isCompiledBy`` relation to be able to trace and
advertise HERMES usage across publication repositories.
"""
return [
{
"identifier": hermes_doi,
"relation": "isCompiledBy",
"scheme": "doi",
},
]

def update_metadata(self) -> None:
"""Update the metadata of a draft."""

Expand Down Expand Up @@ -570,7 +584,7 @@ def _codemeta_to_invenio_deposition(self) -> dict:
# TODO: A good source for this could be `tool.poetry.keywords` in pyproject.toml.
"keywords": None,
"notes": None,
"related_identifiers": None,
"related_identifiers": self.related_identifiers(),
# TODO: Use `contributors`. In the case of the hermes workflow itself, the
# contributors are currently all in `creators` already. So for now, we set this
# to `None`. Change this when relationship between authors and contributors can
Expand Down
45 changes: 23 additions & 22 deletions src/hermes/commands/deposit/rodare.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,35 @@ def create_initial_version(self) -> None:
f"HERMES may be used for subsequent releases. {self.robis_url}"
)

def _codemeta_to_invenio_deposition(self) -> dict:
"""Update the deposition metadata from the parent class.
Deposits on Rodare require a connection to the publication database Robis. To
make this connection, the deposit metadata has to contain the field ``pub_id``
which can be used to find the publication at
``https://www.hzdr.de/publications/Publ-{pub_id}``.
def related_identifiers(self):
"""Update the related identifiers with link to Robis.
Additionally (this is not required by Rodare), we make a connection via related
identifiers.
Add the Robis Publ-Id as a related identifier. This is additional metadata which
is not required by Rodare or Robis. It helps users find the related publication
on Robis at ``https://www.hzdr.de/publications/Publ-{pub_id}``.
An example publication on Rodare: https://rodare.hzdr.de/api/records/2
The associated Robis page: https://www.hzdr.de/publications/Publ-27151
"""
pub_id = self.config.robis_pub_id
deposition_metadata = super()._codemeta_to_invenio_deposition()

robis_identifier = {
"identifier": self.robis_publication_url.format(pub_id=pub_id),
"relation": "isIdenticalTo",
"scheme": "url",
}

related_identifiers: list = deposition_metadata.get("related_identifiers", [])
related_identifiers.append(robis_identifier)
identifiers = super().related_identifiers()
identifiers.append(
{
"identifier": self.robis_publication_url.format(
pub_id=self.config.robis_pub_id
),
"relation": "isIdenticalTo",
"scheme": "url",
}
)
return identifiers

deposition_metadata["related_identifiers"] = related_identifiers
deposition_metadata["pub_id"] = pub_id
def _codemeta_to_invenio_deposition(self) -> dict:
"""Update the deposition metadata with Robis Publ-Id.
Deposits on Rodare require a connection to the publication database Robis. To
make this connection, the deposit metadata has to contain the field ``pub_id``.
"""
deposition_metadata = super()._codemeta_to_invenio_deposition()
deposition_metadata["pub_id"] = self.config.robis_pub_id
return deposition_metadata
3 changes: 3 additions & 0 deletions src/hermes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
hermes_version = hermes_metadata["version"]
hermes_homepage = hermes_metadata["home-page"]

# TODO: Fetch this from somewhere
hermes_doi = "10.5281/zenodo.13311079" # hermes v0.8.1

hermes_user_agent = f"{hermes_name}/{hermes_version} ({hermes_homepage})"

0 comments on commit c47cb79

Please sign in to comment.