Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,14 @@ def schema_file_path(schema_name)
validate :check_language, if: :language?

# JSON-SCHEMA VALIDATION
# temporarily commenting out this validation.
validates :identifier, if: proc { |doi| doi.validate_json_attribute?(:identifier) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("identifier") } }, unless: :only_validate
validates :creators, if: proc { |doi| doi.validate_json_attribute?(:creators) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("creators") } }, unless: :only_validate
validates :titles, if: proc { |doi| doi.validate_json_attribute?(:titles) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("titles") } }, unless: :only_validate
validates :publisher_obj, if: proc { |doi| doi.validate_json_attribute?(:publisher_obj) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("publisher") } }, unless: :only_validate
validates :publication_year, if: proc { |doi| doi.validate_json_attribute?(:publication_year) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("publication_year") } }, unless: :only_validate
validates :subjects, if: proc { |doi| doi.validate_json_attribute?(:subjects) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("subjects") } }, unless: :only_validate
validates :contributors, if: proc { |doi| doi.validate_json_attribute?(:contributors) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("contributors") } }, unless: :only_validate
validates :dates, if: proc { |doi| doi.validate_json_attribute?(:dates) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("dates") } }, unless: :only_validate
validates :alternate_identifiers, if: proc { |doi| doi.validate_json_attribute?(:alternate_identifiers) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("alternate_identifiers") } }, unless: :only_validate
validates :identifiers, if: proc { |doi| doi.validate_json_attribute?(:identifiers) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("alternate_identifiers") } }, unless: :only_validate
validates :related_identifiers, if: proc { |doi| doi.validate_json_attribute?(:related_identifiers) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("related_identifiers") } }, unless: :only_validate
validates :sizes, if: proc { |doi| doi.validate_json_attribute?(:sizes) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("sizes") } }, unless: :only_validate
validates :formats, if: proc { |doi| doi.validate_json_attribute?(:formats) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("formats") } }, unless: :only_validate
Expand All @@ -173,33 +171,24 @@ def schema_file_path(schema_name)
validates :geolocations, if: proc { |doi| doi.validate_json_attribute?(:geolocations) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("geolocations") } }, unless: :only_validate
validates :funding_references, if: proc { |doi| doi.validate_json_attribute?(:funding_references) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("funding_references") } }, unless: :only_validate
validates :related_items, if: proc { |doi| doi.validate_json_attribute?(:related_items) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("related_items") } }, unless: :only_validate
validates :types, if: proc { |doi| doi.validate_json_attribute?(:types) }, json: { message: ->(errors) { errors }, schema: lambda { schema_file_path("resource_type") } }, unless: :only_validate

validates :raw_language, presence: true, if: proc { |doi| doi.validate_json_attribute?(:raw_language) }, json: {
message: ->(errors) { errors },
schema: lambda { schema_file_path("language") }
}, unless: :only_validate

validates :raw_types, if: proc { |doi| doi.validate_json_attribute?(:raw_types) }, json: {
message: ->(errors) { errors },
schema: lambda { schema_file_path("resource_type") },
}, unless: :only_validate

# See https://github.com/mirego/activerecord_json_validator for an explanation of why this must be done.
def raw_language
self[:language]
end

def raw_types
self[:types]
end

after_commit :update_url, on: %i[create update]
after_commit :update_media, on: %i[create update]

before_validation :update_publisher, if: [ :will_save_change_to_publisher? ]
before_validation :update_xml, if: :regenerate
before_validation :update_agency
before_validation :update_field_of_science
before_validation :update_language, if: :language?
before_validation :update_rights_list, if: :rights_list?
before_validation :update_identifiers
Expand Down Expand Up @@ -2624,18 +2613,6 @@ def update_language
end
end

def update_field_of_science
self.subjects = Array.wrap(subjects).reduce([]) do |sum, subject|
if subject.is_a?(String)
sum += name_to_fos(subject)
elsif subject.is_a?(Hash)
sum += hsh_to_fos(subject)
end

sum
end.uniq
end

def update_rights_list
self.rights_list = Array.wrap(rights_list).map do |r|
if r.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/models/schemas/doi/affiliation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "object",
"properties": {
"name": {
"$ref": "definitions.json#/$defs/nonemptycontentStringType"
"type": "string"
},
"affiliationIdentifier": {
"type": "string"
Expand Down
9 changes: 4 additions & 5 deletions app/models/schemas/doi/alternate_identifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"description": "An identifier or identifiers other than the primary Identifier applied to the resource being registered. This may be any alphanumeric string which is unique within its domain of issue. May be used for local identifiers. AlternateIdentifier should be used for another identifier of the same instance (same location, same file).",
"type": "object",
"properties": {
"alternateIdentifier": {
"type": "string"
"identifier": {
"type": ["string", "null"]
},
"alternateIdentifierType": {
"type": "string"
"identifierType": {
"type": ["string", "null"]
}
},
"required": ["alternateIdentifierType"],
"additionalProperties": false
}
3 changes: 1 addition & 2 deletions app/models/schemas/doi/resource_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"$ref": "controlled_vocabularies/resource_type_general.json"
}
},
"additionalProperties": false,
"additionalProperties": true,
"required": [
"resourceType",
"resourceTypeGeneral"
]
}
3 changes: 0 additions & 3 deletions app/models/schemas/doi/subject.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@
"$ref": "definitions.json#/$defs/language"
}
},
"required": [
"subject"
],
"additionalProperties": false
}
5 changes: 1 addition & 4 deletions app/models/schemas/doi/title.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@
"$ref": "definitions.json#/$defs/language"
}
},
"additionalProperties": false,
"required": [
"title"
]
"additionalProperties": false
}