Skip to content

Commit

Permalink
Merge pull request #497 from datacite/alternate-identifiers
Browse files Browse the repository at this point in the history
proper support for alternate identifiers
  • Loading branch information
Martin Fenner authored May 4, 2020
2 parents 7aa74d7 + 2d06d92 commit 817e561
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 11 deletions.
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ GEM
audited (4.9.0)
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.1.0)
aws-partitions (1.305.0)
aws-partitions (1.308.0)
aws-sdk-core (3.94.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
Expand Down Expand Up @@ -102,7 +102,7 @@ GEM
latex-decode (~> 0.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bolognese (1.5.17)
bolognese (1.5.21)
activesupport (>= 4.2.5)
benchmark_methods (~> 0.7)
bibtex-ruby (>= 5.1.0)
Expand Down Expand Up @@ -355,7 +355,7 @@ GEM
optimist (3.0.1)
pandoc-ruby (2.1.4)
parallel (1.19.1)
parser (2.7.1.1)
parser (2.7.1.2)
ast (~> 2.4.0)
postrank-uri (1.0.24)
addressable (>= 2.4.0)
Expand Down Expand Up @@ -405,7 +405,7 @@ GEM
thor (>= 0.19.0, < 2.0)
rainbow (3.0.0)
rake (12.3.3)
rb-fsevent (0.10.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rchardet (1.8.0)
Expand Down Expand Up @@ -445,8 +445,8 @@ GEM
benchmark-perf (~> 0.4.0)
benchmark-trend (~> 0.2.0)
rspec (>= 3.0.0, < 4.0.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
Expand All @@ -463,7 +463,7 @@ GEM
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rspec-support (3.9.3)
rubocop (0.77.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand Down
15 changes: 13 additions & 2 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def safe_params
{ contributors: [:nameType, { nameIdentifiers: [:nameIdentifier, :nameIdentifierScheme, :schemeUri] }, :name, :givenName, :familyName, { affiliation: [:name, :affiliationIdentifier, :affiliationIdentifierScheme, :schemeUri] }, :contributorType, :lang] },
:identifiers,
{ identifiers: [:identifier, :identifierType] },
:alternateIdentifiers,
{ alternateIdentifiers: [:alternateIdentifier, :alternateIdentifierType] },
:relatedIdentifiers,
{ relatedIdentifiers: [:relatedIdentifier, :relatedIdentifierType, :relationType, :relatedMetadataScheme, :schemeUri, :schemeType, :resourceTypeGeneral, :relatedMetadataScheme, :schemeUri, :schemeType] },
:fundingReferences,
Expand Down Expand Up @@ -680,7 +682,7 @@ def safe_params

read_attrs_keys = [:url, :creators, :contributors, :titles, :publisher,
:publicationYear, :types, :descriptions, :container, :sizes,
:formats, :language, :dates, :identifiers, :relatedIdentifiers,
:formats, :language, :dates, :identifiers, :alternateIdentifiers, :relatedIdentifiers,
:fundingReferences, :geoLocations, :rightsList, :agency,
:subjects, :contentUrl, :schemaVersion]

Expand All @@ -689,14 +691,23 @@ def safe_params
read_attrs_keys.each do |attr|
p.merge!(attr.to_s.underscore => p[attr] || meta[attr.to_s.underscore] || p[attr]) if p.has_key?(attr) || meta.has_key?(attr.to_s.underscore)
end

# handle alternate_identifiers
p[:identifiers] = Array.wrap(p[:alternate_identifiers]).map do |a|
{ "identifierType" => a["alternateIdentifierType"], "identifier" => a["alternateIdentifier"] }
end.compact

# handle version metadata
p[:version_info] = p[:version] || meta["version_info"] if p.has_key?(:version) || meta["version_info"].present?

# only update landing_page info if something is received via API to not overwrite existing data
p.merge!(landing_page: p[:landingPage]) if p[:landingPage].present?

p.merge(
regenerate: p[:regenerate] || regenerate
).except(
:confirmDoi, :prefix, :suffix, :publicationYear,
# ignore camelCase keys, read-only keys and alternate_identifiers
:confirmDoi, :prefix, :suffix, :publicationYear, :alternateIdentifiers, :alternate_identifiers,
:rightsList, :relatedIdentifiers, :fundingReferences, :geoLocations,
:metadataVersion, :schemaVersion, :state, :mode, :isActive, :landingPage,
:created, :registered, :updated, :published, :lastLandingPage, :version,
Expand Down
8 changes: 7 additions & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DoiSerializer
set_id :uid
# don't cache dois, as works are cached using the doi model

attributes :doi, :prefix, :suffix, :identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :views_over_time, :download_count, :downloads_over_time, :reference_count, :citation_count, :citations_over_time, :part_count, :part_of_count, :version_count, :version_of_count, :created, :registered, :published, :updated
attributes :doi, :prefix, :suffix, :identifiers, :alternate_identifiers, :creators, :titles, :publisher, :container, :publication_year, :subjects, :contributors, :dates, :language, :types, :related_identifiers, :sizes, :formats, :version, :rights_list, :descriptions, :geo_locations, :funding_references, :xml, :url, :content_url, :metadata_version, :schema_version, :source, :is_active, :state, :reason, :landing_page, :view_count, :views_over_time, :download_count, :downloads_over_time, :reference_count, :citation_count, :citations_over_time, :part_count, :part_of_count, :version_count, :version_of_count, :created, :registered, :published, :updated
attributes :prefix, :suffix, :views_over_time, :downloads_over_time, :citations_over_time, if: Proc.new { |object, params| params && params[:detail] }

belongs_to :client, record_type: :clients
Expand Down Expand Up @@ -72,6 +72,12 @@ class DoiSerializer
Array.wrap(object.identifiers)
end

attribute :alternate_identifiers, if: Proc.new { |object, params| params && params[:detail] } do |object|
Array.wrap(object.identifiers).select { |r| r["identifierType"] != "DOI" }.map do |a|
{ "alternateIdentifierType" => a["identifierType"], "alternateIdentifier" => a["identifier"] }
end.compact
end

attribute :related_identifiers, if: Proc.new { |object, params| params && params[:composite].blank? } do |object|
Array.wrap(object.related_identifiers)
end
Expand Down
Loading

0 comments on commit 817e561

Please sign in to comment.