Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Provide patterns and infrastructure for assigning remote identifiers (DOI, Handle, etc.) #4465

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

cjcolvar
Copy link
Member

@cjcolvar cjcolvar commented Jul 21, 2020

There are three patterns provided: dispatcher, registrar, and builder
Dispatcher - assigns registered identifer to a given object
Registrar - handles communication with external identifier service
Builder - constructs identifier to submit to external identifier service

Registrar implementations just need to implement the registrar!
method. They can be tested with the provided shared spec and then
registered with Hyrax by the identifier_registrars configuration (which
is generated commented out in the hyrax initializer).
identifier_registrars should be a Hash with Symbol keys and Class values.

A custom builder implementation can be injected into your registrar by
overriding the registrar's initialize method setting the custom builder
as the default value for the builder keyword argument.

def initialize(builder: MyCustomBuilder.new)
super(builder: builder)
end

With this infrastructure in place, a new remote identifier can be
assigned to a work by calling the dispatcher with the work object.
Assuming a :datacite registrar has been registered in Hyrax's
configuration then this would look like:

Hyrax::Identifier::Dispatcher.for(:datacite).assign_for!(object: work)

This will set the remote identifier in the work's identifier attribute
and save the work. To avoid saving the object use assign_for instead.
If a different attribute is desired the pass the attribute as a symbol
in the :attribute keyword argument to assign_for!.

This work is ported from mahonia (which had parts ported from epigaea).
Both of those implementations were done by @no-reply.

Backport of #4458

@samvera/hyrax-code-reviewers

@cjcolvar cjcolvar changed the title [Backport] Provide patterns and infrastructure for assigning remote identifiers … [Backport] Provide patterns and infrastructure for assigning remote identifiers (DOI, Handle, etc.) Jul 21, 2020
jeremyf
jeremyf previously approved these changes Jul 21, 2020
…(DOI, Handle, etc.)

There are three patterns provided: dispatcher, registrar, and builder
Dispatcher - assigns registered identifer to a given object
Registrar - handles communication with external identifier service
Builder - constructs identifier to submit to external identifier service

Registrar implementations just need to implement the `registrar!`
method.  They can be tested with the provided shared spec and then
registered with Hyrax by the identifier_registrars configuration (which
is generated commented out in the hyrax initializer).
identifier_registrars should be a Hash with Symbol keys and Class values.

A custom builder implementation can be injected into your registrar by
overriding the registrar's initialize method setting the custom builder
as the default value for the builder keyword argument.

def initialize(builder: MyCustomBuilder.new)
  super(builder: builder)
end

With this infrastructure in place, a new remote identifier can be
assigned to a work by calling the dispatcher with the work object.
Assuming a :datacite registrar has been registered in Hyrax's
configuration then this would look like:

Hyrax::Identifier::Dispatcher.for(:datacite).assign_for!(object: work)

This will set the remote identifier in the work's identifier attribute
and save the work.  To avoid saving the object use `assign_for` instead.
If a different attribute is desired the pass the attribute as a symbol
in the :attribute keyword argument to `assign_for!`.

This work is ported from mahonia (which had parts ported from epigaea).
Both of those implementations were done by @no-reply.

Co-authored-by: Tom Johnson <johnson.tom@gmail.com>
@cjcolvar
Copy link
Member Author

Sorry @jeremyf I had a rubocop issue so I had to repush. I wonder why it flagged here but not on the default branch?

Copy link
Contributor

@jeremyf jeremyf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries.

@jeremyf jeremyf merged commit 338197a into 2.x-stable Jul 21, 2020
@jeremyf jeremyf deleted the ident_backport branch July 21, 2020 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants