Skip to content

Commit

Permalink
More detailed file status
Browse files Browse the repository at this point in the history
This adds a status field to `PreIngestFile`s that
defaults to 'preingest'.

The `AttachFilesToWorkJob` class is preprended with
logic that updates the status to 'attached'.

The logic requires that `deduplication_key` is present in the
CSV so that field is added to the default mapper and validator.

There is a helper which outputs a success icon (a green checkmark) if
the `PreIngestFile` has an 'attached' status. This is used for the
`PreIngestWork` if all the statuses for the `PreIngestFile` are 'attached'.
  • Loading branch information
little9 committed Dec 10, 2019
1 parent 472df2b commit 18eed87
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 268 deletions.
254 changes: 0 additions & 254 deletions CHANGELOG.md

This file was deleted.

6 changes: 6 additions & 0 deletions app/helpers/zizia/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ def collections_for_select
def collections?
!ActiveFedora::SolrService.query('has_model_ssim:Collection').empty?
end

def status_icon(status)
# rubocop:disable Rails/OutputSafety
return "<span class='glyphicon glyphicon-ok-sign text-success'></span>".html_safe if status == 'attached'
"<span class='glyphicon glyphicon-question-sign'></span>".html_safe
end
end
end
5 changes: 5 additions & 0 deletions app/models/zizia/pre_ingest_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def title
'This work\'s metadata has not been indexed yet.'
end

def status
return 'attached' unless pre_ingest_files.map(&:status).include?('preingest')
'preingest'
end

# Returns thumbnail urls based on the work's deduplication_key
# @return [Array<String>] the work's thumbnail urls
def thumbnails
Expand Down
4 changes: 2 additions & 2 deletions app/uploaders/zizia/csv_manifest_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def valid_headers
'publisher', 'date created', 'subject',
'language', 'identifier', 'location',
'related url', 'bibliographic_citation',
'source', 'visibility']
'source', 'visibility', 'deduplication_key', 'type']
end

def parse_csv
Expand All @@ -82,7 +82,7 @@ def missing_headers
end

def required_headers
['title', 'creator', 'keyword', 'rights statement', 'visibility', 'files']
['title', 'creator', 'keyword', 'rights statement', 'visibility', 'files', 'deduplication_key']
end

def duplicate_headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th>Size</th>
<th>Row Number</th>
<th>Date Created</th>
<th>Status</th>
</tr>
<% pre_ingest_work.pre_ingest_files.each do |pre_ingest_file| %>
<tr>
Expand All @@ -23,6 +24,9 @@
<td>
<%= pre_ingest_file.created_at.strftime("%B %-d, %Y %H:%M") %>
</td>
<td>
<%= status_icon(pre_ingest_file.status) %>
</td>
</tr>
<% end %>
</table>
Expand Down
9 changes: 2 additions & 7 deletions app/views/zizia/csv_import_details/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@
<td>
<%= pre_ingest_work.created_at.strftime("%B %-d, %Y %H:%M") %>
</td>
<td id="<%= "work-status-#{pre_ingest_work.deduplication_key}" %>">
<span class="glyphicon glyphicon-question-sign status-unknown"></span>
<td>
<%= status_icon(pre_ingest_work.status) %>
</td>
</tr>
<% end %>
</table>
<%= paginate @pre_ingest_works %>
</div>
<script>
$(document).on('turbolinks:load', function() {
Zizia.displayWorkStatus()
})
</script>
17 changes: 17 additions & 0 deletions config/initializers/attach_files_to_work_job_prepends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module AttachFilesToWorkJobPrepends
# @param [ActiveFedora::Base] work - the work object
# @param [Array<Hyrax::UploadedFile>] uploaded_files - an array of files to attach
def perform(work, uploaded_files, **work_attributes)
super
if work.deduplication_key
uploaded_files.each do |uploaded_file|
# Remove existing PreIngestFile for this FileSet
pre_ingest_work = Zizia::PreIngestWork.find_by(deduplication_key: work.deduplication_key)
pre_ingest_file = pre_ingest_work.pre_ingest_files.where('status != "attached"')
.find_by(filename: File.basename(uploaded_file.file.path))
pre_ingest_file.status = 'attached'
pre_ingest_file.save
end
end
end
end
1 change: 1 addition & 0 deletions config/initializers/prepends.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AttachFilesToWorkJob.prepend(AttachFilesToWorkJobPrepends)
5 changes: 5 additions & 0 deletions db/migrate/20191114021032_add_status_to_pre_ingest_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStatusToPreIngestFile < ActiveRecord::Migration[5.1]
def change
add_column :zizia_pre_ingest_files, :status, :string, default: 'preingest'
end
end
11 changes: 10 additions & 1 deletion lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HyraxBasicMetadataMapper < HashMapper
##
# @return [Enumerable<Symbol>] The fields the mapper can process.
def fields
core_fields + basic_fields + [:visibility, :files]
core_fields + basic_fields + [:visibility, :files] + zizia_fields
end

# Properties defined with `multiple: false` in
Expand All @@ -57,6 +57,10 @@ def import_url
single_value('import_url')
end

def deduplication_key
single_value('deduplication_key')
end

# We should accept visibility values that match the UI and transform them into
# the controlled vocabulary term expected by Hyrax
def visibility
Expand Down Expand Up @@ -152,5 +156,10 @@ def basic_fields
:based_near, :related_url,
:bibliographic_citation, :source]
end

# Properties requires for zizia
def zizia_fields
[:deduplication_key]
end
end
end
1 change: 1 addition & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@
t.integer "pre_ingest_work_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "status", default: "preingest"
t.index ["pre_ingest_work_id"], name: "index_zizia_pre_ingest_files_on_pre_ingest_work_id"
end

Expand Down
Loading

0 comments on commit 18eed87

Please sign in to comment.