From bfde155659518643484731e1212dc3ebda5bb47e Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Thu, 29 Jun 2023 17:49:44 +0200 Subject: [PATCH] Closes https://github.com/CDL-Dryad/dryad-product-roadmap/issues/2585 --- .../MetadataEntry/PrelimArticle.jsx | 2 +- .../resource/dataset_validations.rb | 41 +++++++++++-------- .../dataset_validations_spec.rb | 35 +++++++++++++--- spec/support/helpers/dataset_helper.rb | 1 + 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/app/javascript/react/components/MetadataEntry/PrelimArticle.jsx b/app/javascript/react/components/MetadataEntry/PrelimArticle.jsx index 5e7387c4a3..a4ce928027 100644 --- a/app/javascript/react/components/MetadataEntry/PrelimArticle.jsx +++ b/app/javascript/react/components/MetadataEntry/PrelimArticle.jsx @@ -94,7 +94,7 @@ function PrelimArticle({ { htmlId: 'publication', labelText: 'Journal name', - isRequired: false, + isRequired: true, } } /> diff --git a/app/models/stash_datacite/resource/dataset_validations.rb b/app/models/stash_datacite/resource/dataset_validations.rb index 7ac1b52d9e..00d4e5a5e0 100644 --- a/app/models/stash_datacite/resource/dataset_validations.rb +++ b/app/models/stash_datacite/resource/dataset_validations.rb @@ -88,6 +88,30 @@ def loose_errors err.flatten end + def article_id + err = [] + + if @resource.identifier.import_info != 'other' && @resource.identifier.publication_name.blank? + err << ErrorItem.new(message: 'Fill in the {journal of the related publication}', + page: metadata_page(@resource), + ids: ['publication']) + end + + journal = " from #{@resource.identifier.publication_name}" if @resource.identifier.publication_name.present? + + if @resource.identifier.import_info == 'published' && + (@resource.identifier.publication_article_doi.blank? || @resource.related_identifiers.where(work_type: 'primary_article').count.positive?) + err << ErrorItem.new(message: "Fill in {a correctly formatted DOI} for the article#{journal}", + page: metadata_page(@resource), + ids: %w[primary_article_doi]) + elsif @resource.identifier.import_info == 'manuscript' && @resource.identifier.manuscript_number.blank? + err << ErrorItem.new(message: "Fill in the {manuscript number} for the article#{journal}", + page: metadata_page(@resource), + ids: ['msId']) + end + err + end + def title if @resource.title.blank? return ErrorItem.new(message: 'Fill in a {dataset title}', @@ -167,23 +191,6 @@ def abstract [] end - def article_id - return [] unless @resource.identifier.publication_name.present? && - @resource.identifier.manuscript_number.blank? && - @resource.identifier.publication_article_doi.blank? - - if @resource.related_identifiers.where(work_type: 'primary_article').count.positive? # has primary, but not doi - ErrorItem.new(message: "Fill in {a correctly formatted DOI} for your article from #{@resource.identifier - .publication_name}", - page: metadata_page(@resource), - ids: %w[primary_article_doi]) - else - ErrorItem.new(message: "Fill in a {manuscript number or DOI} for the article from #{@resource.identifier.publication_name}", - page: metadata_page(@resource), - ids: %w[msid primary_article_doi]) - end - end - def s3_error_uploads return [] if @resource.submitted? diff --git a/spec/models/stash_datacite/dataset_validations_spec.rb b/spec/models/stash_datacite/dataset_validations_spec.rb index a21b3f3ad6..84bf2b1180 100644 --- a/spec/models/stash_datacite/dataset_validations_spec.rb +++ b/spec/models/stash_datacite/dataset_validations_spec.rb @@ -97,26 +97,51 @@ module Resource end describe :article_id do - it 'gives error for unfilled manuscript number or publication doi if publication' do + it 'gives error for unfilled publication' do + @resource.identifier.update(import_info: 'published') + + validations = DatasetValidations.new(resource: @resource) + error = validations.article_id.first + + expect(error.message).to include('journal of the related publication') + expect(error.ids).to eq(%w[publication]) + end + + it 'gives error for unfilled publication doi if publication' do + @resource.identifier.update(import_info: 'published') + StashEngine::InternalDatum.create(data_type: 'publicationName', + value: 'Barrel of Monkeys: the Primate Journal', + identifier_id: @resource.identifier_id) + + validations = DatasetValidations.new(resource: @resource) + error = validations.article_id.first + + expect(error.message).to include('formatted DOI') + expect(error.ids).to eq(%w[primary_article_doi]) + end + + it 'gives error for unfilled manuscript number if manuscript' do + @resource.identifier.update(import_info: 'manuscript') StashEngine::InternalDatum.create(data_type: 'publicationName', value: 'Barrel of Monkeys: the Primate Journal', identifier_id: @resource.identifier_id) validations = DatasetValidations.new(resource: @resource) - error = validations.article_id + error = validations.article_id.first - expect(error.message).to include('manuscript number or DOI') - expect(error.ids).to eq(%w[msid primary_article_doi]) + expect(error.message).to include('manuscript number') + expect(error.ids).to eq(%w[msId]) end it 'gives a formatting error when someone puts in a URL instead of a DOI' do + @resource.identifier.update(import_info: 'published') StashEngine::InternalDatum.create(data_type: 'publicationName', value: 'Barrel of Monkeys: the Primate Journal', identifier_id: @resource.identifier_id) create(:related_identifier, resource_id: @resource.id, related_identifier_type: 'url', work_type: 'primary_article') validations = DatasetValidations.new(resource: @resource) - error = validations.article_id + error = validations.article_id.first expect(error.message).to include('formatted DOI') expect(error.ids).to eq(%w[primary_article_doi]) diff --git a/spec/support/helpers/dataset_helper.rb b/spec/support/helpers/dataset_helper.rb index 7ff23de3d1..39e1be1272 100644 --- a/spec/support/helpers/dataset_helper.rb +++ b/spec/support/helpers/dataset_helper.rb @@ -45,6 +45,7 @@ def fill_required_metadata # make sure we're on the right page navigate_to_metadata + choose('choose_other') fill_in 'title', with: Faker::Lorem.sentence fill_in_author fill_in_research_domain