-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
32 changed files
with
506 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% if assigned? %> | ||
<p>The DOI assigned to this work is <%= doi_link %>.</p> | ||
<%= form.hidden_field :doi_option, value: 'assigned' %> | ||
<% elsif yes_doi_option? %> | ||
<p>A DOI will be assigned.</p> | ||
<%= form.hidden_field :doi_option, value: 'yes' %> | ||
<% elsif no_doi_option? %> | ||
<p>DOI assignment is turned off for this collection.</p> | ||
<%= form.hidden_field :doi_option, value: 'no' %> | ||
<% else %> | ||
<p>Getting a DOI may improve discovery of your work in web searches and will enable Altmetric reporting.</p> | ||
|
||
<fieldset class="row"> | ||
<legend class="form-label col-md-5">Do you want a DOI assigned to this work?</legend> | ||
<div class="form-check col-md-2"> | ||
<%= form.radio_button :doi_option, 'yes', class: 'form-check-input' %> | ||
<%= form.label :doi_option_yes, 'Yes', class: 'form-check-label' %> | ||
</div> | ||
<div class="form-check col-md-2"> | ||
<%= form.radio_button :doi_option, 'no', class: 'form-check-input' %> | ||
<%= form.label :doi_option_no, 'No', class: 'form-check-label' %> | ||
</div> | ||
</fieldset> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Works | ||
module Edit | ||
# Component for rendering the DOI form | ||
class DoiComponent < ApplicationComponent | ||
def initialize(form:, collection:) | ||
@form = form | ||
@collection = collection | ||
super | ||
end | ||
|
||
attr_reader :form | ||
|
||
delegate :yes_doi_option?, :no_doi_option?, to: :@collection | ||
|
||
def assigned? | ||
form.object.doi_option == 'assigned' | ||
end | ||
|
||
def doi_link | ||
link_to(nil, Doi.url(druid: form.object.druid)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# Model for DOIs | ||
class Doi | ||
def self.id(...) | ||
new(...).id | ||
end | ||
|
||
def self.url(...) | ||
new(...).url | ||
end | ||
|
||
def self.assigned?(...) | ||
new(...).assigned? | ||
end | ||
|
||
def initialize(druid:) | ||
@druid = druid | ||
end | ||
|
||
def id | ||
@id ||= "#{prefix}/#{druid.delete_prefix('druid:')}" | ||
end | ||
|
||
def url | ||
@url ||= "https://doi.org/#{id}" | ||
end | ||
|
||
def assigned? | ||
@assigned ||= client.exists?(id:) | ||
end | ||
|
||
private | ||
|
||
attr_reader :druid | ||
|
||
def prefix | ||
Settings.datacite.prefix | ||
end | ||
|
||
def client | ||
Datacite::Client.new(host: Settings.datacite.host) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# Efficiently determines if a DOI has been assigned to a work. | ||
class DoiAssignedService | ||
def self.call(...) | ||
new(...).call | ||
end | ||
|
||
def initialize(cocina_object:, work:) | ||
@cocina_object = cocina_object | ||
@work = work | ||
end | ||
|
||
# return true if the work has a DOI assigned | ||
def call | ||
# If there is no DOI in the Cocina object, then a DOI definitely has not been assigned. | ||
return false unless doi_in_cocina? | ||
|
||
# Once a DOI is assigned (as determined by checking Datacite), | ||
# the Work record's doi_assigned attribute is set to true. | ||
# This is done to avoid checking Datacite every time the Work is accessed (slow!). | ||
# The way DOI assignment works is: | ||
# 1. The Cocina object gets a DOI. This may be done when the object is registered or by an update. | ||
# 2. When the object is accessioned, the update DOI step registers the DOI with Datacite. | ||
# Thus, having a DOI in the Cocina object does not mean it is registered with Datacite. | ||
# The only way to know for sure is to check Datacite. | ||
return true if work.doi_assigned? | ||
|
||
# This checks Datacite. | ||
assigned = Doi.assigned?(druid: work.druid) | ||
|
||
# So that next time don't have to check Datacite. | ||
work.update!(doi_assigned: true) if assigned | ||
assigned | ||
end | ||
|
||
private | ||
|
||
attr_reader :cocina_object, :work | ||
|
||
def doi_in_cocina? | ||
CocinaSupport.doi_for(cocina_object:).present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module ToCocina | ||
module Work | ||
# Maps WorkForm to Cocina identification parameters | ||
class IdentificationMapper | ||
def self.call(...) | ||
new(...).call | ||
end | ||
|
||
# @param [WorkForm] work_form | ||
# @param [source_id] source_id | ||
def initialize(work_form:, source_id:) | ||
@work_form = work_form | ||
@source_id = source_id | ||
end | ||
|
||
# @return [Hash] the Cocina identification parameters | ||
def call | ||
{ | ||
sourceId: source_id | ||
}.tap do |params| | ||
params[:doi] = doi if doi? | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :work_form, :source_id | ||
|
||
delegate :doi, to: :work_form | ||
|
||
def doi? | ||
# If a work has not yet been registered, the DOI is assigned as part of the registration request. | ||
# If the work already has a DOI, it should continue to be added here. | ||
# If the work does not have a DOI, but one should be assigned then it should be added here. | ||
work_form.persisted? && %w[assigned yes].include?(work_form.doi_option) | ||
end | ||
|
||
def doi | ||
Doi.id(druid: work_form.druid) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.