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 3, 2023
1 parent 6a0f55c commit 122ec12
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/components/contents/file_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<td><%= width %></td>
<% end %>
<td><%= role %></td>
<td><%= file_language %></td>
<td class="ps-4"><%= tag.span(class: 'bi-check') if publish %></td>
<td class="ps-4"><%= tag.span(class: 'bi-check') if shelve %></td>
<td class="ps-4"><%= tag.span(class: 'bi-check') if sdrPreserve %></td>
Expand Down
10 changes: 8 additions & 2 deletions app/components/contents/file_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def image?
@image
end

delegate :access, :administrative, :filename, :hasMimeType, :size, :externalIdentifier, :use, :presentation,
to: :file
delegate :access, :administrative, :filename, :hasMimeType, :size, :externalIdentifier, :use,
:presentation, :languageTag, to: :file
delegate :publish, :shelve, :sdrPreserve, to: :administrative

def view_access
Expand All @@ -45,6 +45,12 @@ def role
use.capitalize
end

def file_language
return 'No language specified' if languageTag.blank?

languageTag
end

def link_attrs
{ item_id: object_id, id: filename }
end
Expand Down
1 change: 1 addition & 0 deletions app/components/contents/resource_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<th>Width</th>
<% end %>
<th>Role</th>
<th>Language</th>
<th>Publish</th>
<th>Shelve</th>
<th>Preserve</th>
Expand Down
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
1 change: 1 addition & 0 deletions app/services/structure_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def update_file(existing_file, row)
)
}
attributes[:use] = row['role'] if row['role'] # nil is not permitted
attributes[:languageTag] = row['file_language'] if row['file_language'] # nil is not permitted
existing_file.new(**attributes)
end

Expand Down
15 changes: 13 additions & 2 deletions spec/components/contents/file_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
access:,
administrative: admin,
presentation:,
use:)
use:,
languageTag: language_tag)
end

let(:access) { instance_double(Cocina::Models::FileAccess, view: 'world', download: 'stanford') }
let(:admin) { instance_double(Cocina::Models::FileAdministrative, sdrPreserve: true, publish: true, shelve: true) }
let(:presentation) { instance_double(Cocina::Models::Presentation, height: 11_839, width: 19_380) }
let(:use) { 'transcription' }
let(:language_tag) { 'en-US' }

context 'with an image fileset' do
it 'renders the component' do
Expand All @@ -30,6 +32,7 @@
expect(rendered.to_html).to include 'Stanford'
expect(rendered.to_html).to include 'Transcription'
expect(rendered.to_html).to include '11839 px'
expect(rendered.to_html).to include language_tag
end
end

Expand All @@ -41,6 +44,14 @@
end
end

context 'with no file language set' do
let(:language_tag) { nil }

it 'renders the component' do
expect(rendered.to_html).to include 'No language specified'
end
end

context 'with no presentation' do
let(:presentation) { nil }

Expand Down Expand Up @@ -74,7 +85,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
1 change: 1 addition & 0 deletions spec/components/contents/resource_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
expect(rendered.to_html).to include 'Type'
expect(rendered.to_html).to include 'Height'
expect(rendered.to_html).to include 'Width'
expect(rendered.to_html).to include 'Language'
end
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
8 changes: 4 additions & 4 deletions spec/services/structure_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@
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,
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,
Expand Down Expand Up @@ -237,8 +237,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 122ec12

Please sign in to comment.