Skip to content

Commit

Permalink
Add file language to upload/download spreadsheets
Browse files Browse the repository at this point in the history
Fixes #4258
  • Loading branch information
mjgiarlo committed Nov 10, 2023
1 parent b722f7f commit da104cb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
6 changes: 4 additions & 2 deletions app/services/structure_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class StructureSerializer
HEADERS = %w[druid resource_label resource_type sequence filename file_label publish
shelve preserve rights_view rights_download rights_location mimetype role].freeze
shelve preserve rights_view rights_download rights_location mimetype
role file_language].freeze

def self.as_csv(druid, structural)
new(druid, structural).as_csv
Expand All @@ -28,7 +29,8 @@ def rows
yield [@druid, resource.label, type(resource), n, file.filename, file.label,
to_yes_no(file.administrative.publish), to_yes_no(file.administrative.shelve),
to_yes_no(file.administrative.sdrPreserve), file.access.view,
file.access.download, file.access.location, file.hasMimeType, file.use]
file.access.download, file.access.location, file.hasMimeType, file.use,
file.languageTag]
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions app/services/structure_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def existing_files_by_filename

def update_file(existing_file, row)
attributes = {
hasMimeType: row['mimetype'],
label: row['file_label'],
hasMimeType: row['mimetype'],
use: row['role'],
languageTag: row['file_language'],
administrative: existing_file.administrative.new(
publish: row['publish'] == 'yes',
shelve: row['shelve'] == 'yes',
Expand All @@ -89,7 +91,7 @@ def update_file(existing_file, row)
}.compact
)
}
attributes[:use] = row['role'] if row['role'] # nil is not permitted

existing_file.new(**attributes)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/components/contents/file_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
instance_double(Cocina::Models::FileAccess, view: 'stanford', location: 'hoover', download: 'location-based')
end

it 'renders the donwload location' do
it 'renders the download location' do
expect(rendered.to_html).to include 'Stanford'
expect(rendered.to_html).to include 'hoover'
end
Expand Down
12 changes: 6 additions & 6 deletions spec/services/structure_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

it 'serializes to CSV' do
expect(csv).to eq <<~CSV
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role,file_language
CSV
end
end
Expand Down Expand Up @@ -251,11 +251,11 @@

it 'serializes to CSV' do
expect(csv).to eq <<~CSV
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role
#{bare_druid},Image 1,image,1,bb045jk9908_0001.tiff,bb045jk9908_0001.tiff,no,no,yes,world,world,,image/tiff,
#{bare_druid},Image 1,image,1,bb045jk9908_0001.jp2,bb045jk9908_0001.jp2,yes,yes,no,world,world,,image/jp2,
#{bare_druid},Image 2,image,2,bb045jk9908_0002.tiff,bb045jk9908_0002.tiff,no,no,yes,world,world,,image/tiff,
#{bare_druid},Image 2,image,2,bb045jk9908_0002.jp2,bb045jk9908_0002.jp2,yes,yes,no,location-based,location-based,music,image/jp2,
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role,file_language
#{bare_druid},Image 1,image,1,bb045jk9908_0001.tiff,bb045jk9908_0001.tiff,no,no,yes,world,world,,image/tiff,,
#{bare_druid},Image 1,image,1,bb045jk9908_0001.jp2,bb045jk9908_0001.jp2,yes,yes,no,world,world,,image/jp2,,
#{bare_druid},Image 2,image,2,bb045jk9908_0002.tiff,bb045jk9908_0002.tiff,no,no,yes,world,world,,image/tiff,,
#{bare_druid},Image 2,image,2,bb045jk9908_0002.jp2,bb045jk9908_0002.jp2,yes,yes,no,location-based,location-based,music,image/jp2,,
CSV
end
end
Expand Down
16 changes: 9 additions & 7 deletions spec/services/structure_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"label": "bb045jk9908_0001.tiff",
"filename": "bb045jk9908_0001.tiff",
"size": 22454748,
"use": "master",
"version": 1,
"hasMimeType": "image/tiff",
"hasMessageDigests": [
Expand Down Expand Up @@ -134,6 +135,7 @@
"size": 19962338,
"version": 1,
"hasMimeType": "image/tiff",
"languageTag": "it-IT",
"hasMessageDigests": [
{
"type": "sha1",
Expand Down Expand Up @@ -206,11 +208,11 @@
context 'with valid csv that has file properties changed' do
let(:csv) do
<<~CSV
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role
#{bare_druid},Image 1,image,1,bb045jk9908_0001.tiff,bb045jk9908_0001.tiff,yes,yes,yes,stanford,stanford,,image/one,
#{bare_druid},Image 1,image,1,bb045jk9908_0001.jp2,bb045jk9908_0001.jp2,yes,yes,no,world,world,,image/two,transcription
#{bare_druid},Image 2,image,2,bb045jk9908_0002.tiff,bb045jk9908_0002.tiff,yes,yes,yes,stanford,none,,image/three,
#{bare_druid},Image 2,image,2,CCTV新闻联播文本数据-20060615-20220630-Stanford University.xlsx,CCTV新闻联播文本数据-20060615-20220630-Stanford University.xlsx,yes,yes,no,location-based,location-based,music,image/four,
druid,resource_label,resource_type,sequence,filename,file_label,publish,shelve,preserve,rights_view,rights_download,rights_location,mimetype,role,file_language
#{bare_druid},Image 1,image,1,bb045jk9908_0001.tiff,bb045jk9908_0001.tiff,yes,yes,yes,stanford,stanford,,image/one,,en-US
#{bare_druid},Image 1,image,1,bb045jk9908_0001.jp2,bb045jk9908_0001.jp2,yes,yes,no,world,world,,image/two,transcription,
#{bare_druid},Image 2,image,2,bb045jk9908_0002.tiff,bb045jk9908_0002.tiff,yes,yes,yes,stanford,none,,image/three,,
#{bare_druid},Image 2,image,2,CCTV新闻联播文本数据-20060615-20220630-Stanford University.xlsx,CCTV新闻联播文本数据-20060615-20220630-Stanford University.xlsx,yes,yes,no,location-based,location-based,music,image/four,,
CSV
end

Expand All @@ -237,8 +239,8 @@
nil], ['world', 'world', nil], ['stanford', 'none', nil], %w[location-based location-based music]
]

use = new_files.map(&:use)
expect(use).to eq [nil, 'transcription', nil, nil]
expect(new_files.map(&:use)).to eq [nil, 'transcription', nil, nil]
expect(new_files.map(&:languageTag)).to eq ['en-US', nil, nil, nil]
end

it 'produces valid cocina' do
Expand Down

0 comments on commit da104cb

Please sign in to comment.