Skip to content

Commit

Permalink
Merge pull request #1111 from datacite/schema-4.5-cleanup-r1
Browse files Browse the repository at this point in the history
Schema-4.5 cleanup. (DOI model)
  • Loading branch information
svogt0511 authored Feb 23, 2024
2 parents 7c7d715 + a555b30 commit d5bf268
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Doi < ApplicationRecord
PUBLISHER_JSON_SCHEMA = "#{Rails.root}/app/models/schemas/doi/publisher.json"
audited only: %i[doi url creators contributors titles publisher publisher_obj publication_year types descriptions container sizes formats version_info language dates identifiers related_identifiers related_items funding_references geo_locations rights_list subjects schema_version content_url landing_page aasm_state source reason]
audited only: %i[doi url creators contributors titles publisher_obj publication_year types descriptions container sizes formats version_info language dates identifiers related_identifiers related_items funding_references geo_locations rights_list subjects schema_version content_url landing_page aasm_state source reason]

# disable STI
self.inheritance_column = :_type_disabled
Expand Down Expand Up @@ -76,6 +76,7 @@ class Doi < ApplicationRecord
attribute :regenerate, :boolean, default: false
attribute :only_validate, :boolean, default: false
attribute :should_validate, :boolean, default: false
attribute :publisher, :string, default: nil

belongs_to :client, foreign_key: :datacentre, optional: true
has_many :media, -> { order "created DESC" }, foreign_key: :dataset, dependent: :destroy, inverse_of: :doi
Expand Down Expand Up @@ -110,7 +111,7 @@ class Doi < ApplicationRecord
}

def validate_publisher_obj?(doi)
doi.validatable? && doi.publisher_obj? && !(doi.publisher.blank? || doi.publisher.all?(nil))
doi.validatable? && doi.publisher_obj? && !(doi.publisher_obj.blank? || doi.publisher_obj.all?(nil))
end

validates :publisher_obj, if: ->(doi) { validate_publisher_obj?(doi) }, json: json_schema_validation
Expand All @@ -129,7 +130,6 @@ def validate_publisher_obj?(doi)
validate :check_descriptions, if: :descriptions?
validate :check_types, if: :types?
validate :check_container, if: :container?
validate :check_publisher, if: :publisher?
validate :check_subjects, if: :subjects?
validate :check_creators, if: :creators?
validate :check_contributors, if: :contributors?
Expand Down Expand Up @@ -2002,10 +2002,6 @@ def check_container
errors.add(:container, "Container '#{container}' should be an object instead of a string.") unless container.is_a?(Hash)
end

def check_publisher
errors.add(:publisher, "Publisher '#{publisher}' should be an object instead of a string.") unless publisher.is_a?(Hash)
end

def check_language
errors.add(:language, "Language #{language} is in an invalid format.") if !language.match?(/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/)
end
Expand Down Expand Up @@ -2347,16 +2343,7 @@ def update_publisher
end

def publisher
pub = read_attribute("publisher")
pub_obj = read_attribute("publisher_obj")

return nil if pub.nil? && pub_obj.nil?

if !(pub_obj.nil? || pub_obj.empty?)
pub_obj
else
{ "name" => pub || "" }
end
read_attribute("publisher_obj")
end

def self.repair_landing_page(id: nil)
Expand Down Expand Up @@ -2517,19 +2504,16 @@ def update_publisher_from_hash
publisherIdentifier: symbolized_publisher_hash.fetch(:publisherIdentifier, nil),
publisherIdentifierScheme: symbolized_publisher_hash.fetch(:publisherIdentifierScheme, nil)
}.compact
self.publisher = symbolized_publisher_hash.dig(:name)
else
reset_publishers
end
end

def update_publisher_from_string
self.publisher_obj = { name: publisher_before_type_cast }
self.publisher = publisher_before_type_cast
end
end

def reset_publishers
self.publisher_obj = nil
self.publisher = nil
end
end

0 comments on commit d5bf268

Please sign in to comment.