Skip to content

Commit

Permalink
Move processing of null parameters over to update_publisher.
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Nov 9, 2023
1 parent e685e04 commit 676ded1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/datacite/bolognese
revision: ca90d2c7e33fdd76d0ee7ad00434740a324166df
revision: 714d71a4a2169d1880ccb296df3ca1331e0e1a83
branch: schema-4.5
specs:
bolognese (1.11.5)
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/datacite_dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,6 @@ def safe_params
ParamsSanitizer.sanitize_nameIdentifiers(params[:creators])
ParamsSanitizer.sanitize_nameIdentifiers(params[:contributors])

if params.dig(:data, :attributes, :publisher).present? && params.dig(:data, :attributes, :publisher).respond_to?(:to_hash)
params[:data][:attributes][:publisher].compact!
end

p =
params.require(:data).permit(
:type,
Expand Down
28 changes: 21 additions & 7 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,14 @@ class Doi < ApplicationRecord
validates_presence_of :doi
validates_presence_of :url, if: Proc.new { |doi| doi.is_registered_or_findable? }

validates :publisher_obj, if: :publisher_obj? && Proc.new { |doi| doi.validatable? },
json: {
message: ->(errors) { errors },
schema: PUBLISHER_JSON_SCHEMA
}
validates :publisher_obj, if: :publisher_obj? && Proc.new { |doi|
doi.validatable? &&
!(doi.publisher.blank? || doi.publisher.all?(nil))
},
json: {
message: ->(errors) { errors },
schema: PUBLISHER_JSON_SCHEMA
}

# from https://www.crossref.org/blog/dois-and-matching-regular-expressions/ but using uppercase
validates_format_of :doi, with: /\A10\.\d{4,5}\/[-._;()\/:a-zA-Z0-9*~$=]+\z/, on: :create
Expand Down Expand Up @@ -2297,8 +2300,19 @@ def update_types

def update_publisher
if publisher_before_type_cast.respond_to?(:to_hash)
self.publisher_obj = publisher_before_type_cast
self.publisher = publisher_before_type_cast.dig(:name)
if !(publisher_before_type_cast.blank? || publisher_before_type_cast.values.all?(nil))
self.publisher_obj = {
:name => publisher_before_type_cast.fetch(:name, nil),
:lang => publisher_before_type_cast.fetch(:lang, nil),
:schemeUri => publisher_before_type_cast.fetch(:schemeUri, nil),
:publisherIdentifier => publisher_before_type_cast.fetch(:publisherIdentifier, nil),
:publisherIdentifierScheme => publisher_before_type_cast.fetch(:publisherIdentifierScheme, nil)
}.compact
self.publisher = publisher_before_type_cast.dig(:name)
else
self.publisher_obj = nil
self.publisher = nil
end
elsif publisher_before_type_cast.respond_to?(:to_str)
self.publisher_obj = { :name => publisher_before_type_cast }
self.publisher = publisher_before_type_cast
Expand Down

0 comments on commit 676ded1

Please sign in to comment.