Skip to content

Commit

Permalink
updating a file import translation (#757)
Browse files Browse the repository at this point in the history
ksierks authored Sep 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 753edde commit b4a071e
Showing 4 changed files with 22 additions and 8 deletions.
12 changes: 9 additions & 3 deletions app/services/samples/metadata/file_import_service.rb
Original file line number Diff line number Diff line change
@@ -111,13 +111,19 @@ def perform_file_import
metadata_changes = process_sample_metadata_row(sample_id, metadata)
response[sample_id] = metadata_changes if metadata_changes
rescue ActiveRecord::RecordNotFound
@namespace.errors.add(:sample,
I18n.t('services.samples.metadata.import_file.sample_not_found',
sample_name: sample_id, namespace_type: @namespace.type.downcase))
@namespace.errors.add(:sample, error_message(sample_id))
end
response
end

def error_message(sample_id)
if @namespace.type == 'Group'
I18n.t('services.samples.metadata.import_file.sample_not_found_within_group', sample_puid: sample_id)
else
I18n.t('services.samples.metadata.import_file.sample_not_found_within_project', sample_puid: sample_id)
end
end

def process_sample_metadata_row(sample_id, metadata)
sample = find_sample(sample_id)
metadata_changes = UpdateService.new(sample.project, sample, current_user, { 'metadata' => metadata }).execute
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1485,7 +1485,8 @@ en:
missing_metadata_row: The file does not have any metadata rows. Please add some rows of metadata to the file and retry uploading.
missing_sample_id_column: The file is missing the sample id column. Please make sure the sample id column exists and retry uploading.
sample_metadata_fields_not_updated: Sample '%{sample_name}' with field(s) '%{metadata_fields}' cannot be updated.
sample_not_found: Sample '%{sample_name}' is not found within this project
sample_not_found_within_group: Could not find sample with puid '%{sample_puid}' in this group.
sample_not_found_within_project: Could not find sample with puid or name '%{sample_puid}' in this project.
sample_does_not_belong_to_project: Sample '%{sample_name}'' does not belong to project '%{project_name}'
update_fields:
key_exists: Sample already contains metadata field '%{key}'.
3 changes: 2 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1485,7 +1485,8 @@ fr:
missing_metadata_row: The file does not have any metadata rows. Please add some rows of metadata to the file and retry uploading.
missing_sample_id_column: The file is missing the sample id column. Please make sure the sample id column exists and retry uploading.
sample_metadata_fields_not_updated: Sample '%{sample_name}' with field(s) '%{metadata_fields}' cannot be updated.
sample_not_found: Sample '%{sample_name}' is not found within this project
sample_not_found_within_group: Could not find sample with puid '%{sample_puid}' in this group.
sample_not_found_within_project: Could not find sample with puid or name '%{sample_puid}' in this project.
sample_does_not_belong_to_project: Sample '%{sample_name}'' does not belong to project '%{project_name}'
update_fields:
key_exists: Sample already contains metadata field '%{key}'.
12 changes: 9 additions & 3 deletions test/services/samples/metadata/file_import_service_test.rb
Original file line number Diff line number Diff line change
@@ -110,8 +110,10 @@ def setup
assert_empty Samples::Metadata::FileImportService.new(@group, @john_doe,
params).execute
assert_equal(@group.errors.messages_for(:sample).first,
I18n.t('services.samples.metadata.import_file.sample_not_found',
sample_name: @sample1.name, namespace_type: @group.type.downcase))
I18n.t(
'services.samples.metadata.import_file.sample_not_found_within_group',
sample_puid: @sample1.name
))
end

test 'import sample metadata via csv file using sample puids for group' do
@@ -272,7 +274,11 @@ def setup
response = Samples::Metadata::FileImportService.new(@project.namespace, @john_doe, params).execute
assert_equal({ @sample1.name => { added: %w[metadatafield1 metadatafield2 metadatafield3],
updated: [], deleted: [], not_updated: [], unchanged: [] } }, response)
assert_equal("Sample 'Project 2 Sample 3' is not found within this project",

assert_equal(I18n.t(
'services.samples.metadata.import_file.sample_not_found_within_project',
sample_puid: 'Project 2 Sample 3'
),
@project.namespace.errors.messages_for(:sample).first)
assert_equal({ 'metadatafield1' => '10', 'metadatafield2' => '20', 'metadatafield3' => '30' },
@sample1.reload.metadata)

0 comments on commit b4a071e

Please sign in to comment.