Skip to content

Commit

Permalink
CAL-871 Require Title for Californica import (#798)
Browse files Browse the repository at this point in the history
* Rebuild gem file lock

* No csv ingest for missing title and ark
  • Loading branch information
pghorpade authored Mar 11, 2020
1 parent be1f155 commit b7e90ef
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
16 changes: 15 additions & 1 deletion app/uploaders/csv_manifest_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ def validate_records
controlled_column_numbers = CONTROLLED_VOCABULARIES.keys.map { |header| @headers.find_index(header) }.compact
object_type_column = @headers.find_index('Object Type')
row_warnings = Hash.new { |hash, key| hash[key] = [] }
row_errors = Hash.new { |hash, key| hash[key] = [] }

@rows.each_with_index do |row, i|
@mapper.metadata = row
this_row_warnings = []
this_row_errors = []

# If there's no "Object Type" header, assume everything's a Work
# so we so we can validate other required fields
Expand All @@ -223,13 +225,15 @@ def validate_records
# Row missing reqired field values
required_column_numbers.each_with_index do |column_number, j|
field_label, types_that_require = REQUIRED_VALUES[j]
next this_row_errors << "Rows missing required value for \"#{REQUIRED_VALUES[j][0]}\". Your spreadsheet must have this value." if field_label == 'Title' && row[column_number].blank?
next this_row_errors << "Rows missing required value for \"#{REQUIRED_VALUES[j][0]}\". Your spreadsheet must have this value." if field_label == 'Item ARK' && row[column_number].blank?
next unless types_that_require.include?(object_type)
next unless row[column_number].blank?
this_row_warnings << if field_label == 'Rights.copyrightStatus'
'Rows missing "Rights.copyrightStatus" will have the value set to "unknown".'
elsif field_label == 'File Name'
'Rows missing "File Name" will import metadata-only.'
else
elsif field_label != 'Title' || field_label != 'Item ARK'
"Rows missing \"#{REQUIRED_VALUES[j][0]}\" cannot be imported."
end
end
Expand All @@ -253,11 +257,21 @@ def validate_records
# +1 for 0-based indexing, +1 for skipped headers
row_warnings[warning] << i + 2
end

this_row_errors.each do |row_error|
# +1 for 0-based indexing, +1 for skipped headers
row_errors[row_error] << i + 2
end
end

row_warnings.each do |warning, rows|
rows = rows[0, N_ROWS_TO_WARN] + ['...'] if rows.length > N_ROWS_TO_WARN
@warnings << "Row #{rows.join(', ')}: #{warning}"
end

row_errors.each do |row_error, rows|
rows = rows[0, N_ROWS_TO_WARN] + ['...'] if rows.length > N_ROWS_TO_WARN
@errors << "Row #{rows.join(', ')}: #{row_error}"
end
end
end
32 changes: 19 additions & 13 deletions app/views/csv_imports/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
<%= File.basename(@csv_import.manifest.to_s) %>
<% end %>
</div>

<% if @csv_import.manifest_errors.empty? %>
<%= render 'record_count', locals: { csv_import: @csv_import } %>
<% unless @csv_import.manifest_errors.empty? %>
<div id='csv_errors'>
The CSV file has the following errors:
<ul>
<% @csv_import.manifest_errors.each do |error| %>
<li> <%= error %> </li>
<% end %>
</ul>
<% else %>
<div class="row">
<div class="col-md-8">
<div class="alert alert-danger">
<p> This import cannot proceed. </p>
<div id='csv_errors'>
The CSV file has the following errors:
<ul>
<% @csv_import.manifest_errors.each do |error| %>
<li> <%= error %> </li>
<% end %>
</ul>
</div>
<p> You will need to correct the errors with the CSV file before you can continue. </p>
<%= link_to 'Try Again', new_csv_import_path %>
</div>
</div>
</div>

<% end %>
<% unless @csv_import.manifest_warnings.empty? %>
Expand All @@ -35,7 +44,4 @@
<%= link_to 'Cancel', new_csv_import_path %>
<br />
<%= render 'start_import_form', csv_import: @csv_import %>
<% else %>
<p> You will need to correct the errors with the CSV file before you can continue. </p>
<%= link_to 'Try Again', new_csv_import_path %>
<% end %>
12 changes: 10 additions & 2 deletions spec/uploaders/csv_manifest_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,22 @@
it 'has warnings' do
validator.validate
expect(validator.warnings).to contain_exactly(
'Row 3: Rows missing "Item ARK" cannot be imported.',
'Row 4: Rows missing "Title" cannot be imported.',
# 'Row 3: Rows missing "Item ARK" cannot be imported.',
# 'Row 4: Rows missing "Title" cannot be imported.',
'Row 5: Rows missing "Object Type" cannot be imported.',
'Row 6: Rows missing "Parent ARK" cannot be imported.',
'Row 7: Rows missing "Rights.copyrightStatus" will have the value set to "unknown".',
'Row 8: Rows missing "File Name" will import metadata-only.'
)
end

it 'has errors' do
validator.validate
expect(validator.errors).to contain_exactly(
'Row 3: Rows missing required value for "Item ARK". Your spreadsheet must have this value.',
'Row 4: Rows missing required value for "Title". Your spreadsheet must have this value.'
)
end
end

context 'a CSV that has extra headers' do
Expand Down

0 comments on commit b7e90ef

Please sign in to comment.