diff --git a/app/models/doi.rb b/app/models/doi.rb index f8aa8c560..d40b6cc41 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -154,8 +154,6 @@ 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 @@ -163,7 +161,7 @@ def schema_file_path(schema_name) 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 @@ -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 @@ -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? diff --git a/app/models/schemas/doi/affiliation.json b/app/models/schemas/doi/affiliation.json index 954b222c3..d264ecd97 100644 --- a/app/models/schemas/doi/affiliation.json +++ b/app/models/schemas/doi/affiliation.json @@ -5,7 +5,7 @@ "type": "object", "properties": { "name": { - "$ref": "definitions.json#/$defs/nonemptycontentStringType" + "type": "string" }, "affiliationIdentifier": { "type": "string" diff --git a/app/models/schemas/doi/alternate_identifier.json b/app/models/schemas/doi/alternate_identifier.json index 8a5b51bd1..413814845 100644 --- a/app/models/schemas/doi/alternate_identifier.json +++ b/app/models/schemas/doi/alternate_identifier.json @@ -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 } diff --git a/app/models/schemas/doi/resource_type.json b/app/models/schemas/doi/resource_type.json index 8e3cb8415..e81b88926 100644 --- a/app/models/schemas/doi/resource_type.json +++ b/app/models/schemas/doi/resource_type.json @@ -10,9 +10,8 @@ "$ref": "controlled_vocabularies/resource_type_general.json" } }, - "additionalProperties": false, + "additionalProperties": true, "required": [ - "resourceType", "resourceTypeGeneral" ] } diff --git a/app/models/schemas/doi/subject.json b/app/models/schemas/doi/subject.json index 4766c1f28..b1c015168 100644 --- a/app/models/schemas/doi/subject.json +++ b/app/models/schemas/doi/subject.json @@ -23,8 +23,5 @@ "$ref": "definitions.json#/$defs/language" } }, - "required": [ - "subject" - ], "additionalProperties": false } \ No newline at end of file diff --git a/app/models/schemas/doi/title.json b/app/models/schemas/doi/title.json index 0fafa05df..cb200ce73 100644 --- a/app/models/schemas/doi/title.json +++ b/app/models/schemas/doi/title.json @@ -14,8 +14,5 @@ "$ref": "definitions.json#/$defs/language" } }, - "additionalProperties": false, - "required": [ - "title" - ] + "additionalProperties": false } \ No newline at end of file