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 fc8c91c commit 8a878c8
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 12 deletions.
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' aria-label='Status: Complete'></span>".html_safe if status == 'attached'
"<span class='glyphicon glyphicon-question-sign' aria-label='Status: Unknown'></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 @@ -12,5 +12,10 @@ def title
return solr_title unless solr_title.nil?
'This work\'s metadata has not been indexed yet.'
end

def status
return 'attached' unless pre_ingest_files.map(&:status).include?('preingest')
'preingest'
end
end
end
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
3 changes: 3 additions & 0 deletions app/views/zizia/csv_import_details/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<td>
<%= pre_ingest_work.created_at.strftime("%B %-d, %Y %H:%M") %>
</td>
<td>
<%= status_icon(pre_ingest_work.status) %>
</td>
</tr>
<% end %>
</table>
Expand Down
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rights_statement,another_header_2,rights statement,title,files,label,relative_path,import url,resource type,creator,contributor,abstract or summary,keyword,license,publisher,date created,subject,language,identifier,location,related url,bibliographic_citation,source,visibility
http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 1 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 2 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 3 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
deduplication_key,rights_statement,another_header_2,rights statement,title,files,label,relative_path,import url,resource type,creator,contributor,abstract or summary,keyword,license,publisher,date created,subject,language,identifier,location,related url,bibliographic_citation,source,visibility
1,http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 1 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
2,http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 2 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
3,http://rightsstatements.org/vocab/InC/1.0/,,http://rightsstatements.org/vocab/InC/1.0/,Work 3 Title,cat.jpg,,,,,creator,,,cat,,,,,,,,,,,open
4 changes: 2 additions & 2 deletions spec/dummy/spec/fixtures/csv_import/good/all_fields.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
identifier,license,deduplication_key,visibility,location,keyword,rights statement,creator,title,files
abc/123,https://creativecommons.org/licenses/by/4.0/,abc/123,PUBlic,http://www.geonames.org/5667009/montana.html|~|http://www.geonames.org/6252001/united-states.html,Clothing stores $z California $z Los Angeles|~|Interior design $z California $z Los Angeles,http://rightsstatements.org/vocab/InC/1.0/,"Connell, Will, $d 1898-1961","Interior view of The Bachelors haberdashery designed by Julius Ralph Davidson, Los Angeles, circa 1929",dog.jpg
identifier,type,license,deduplication_key,visibility,location,keyword,rights statement,creator,title,files
abc/123,work,https://creativecommons.org/licenses/by/4.0/,abc/123,PUBlic,http://www.geonames.org/5667009/montana.html|~|http://www.geonames.org/6252001/united-states.html,Clothing stores $z California $z Los Angeles|~|Interior design $z California $z Los Angeles,http://rightsstatements.org/vocab/InC/1.0/,"Connell, Will, $d 1898-1961","Interior view of The Bachelors haberdashery designed by Julius Ralph Davidson, Los Angeles, circa 1929",dog.jpg
2 changes: 2 additions & 0 deletions spec/dummy/spec/fixtures/csv_import/good/all_fields_multi.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
identifier,type,license,deduplication_key,visibility,location,keyword,rights statement,creator,title,files
abc/123,work,https://creativecommons.org/licenses/by/4.0/,abc/123,PUBlic,http://www.geonames.org/5667009/montana.html|~|http://www.geonames.org/6252001/united-states.html,Clothing stores $z California $z Los Angeles|~|Interior design $z California $z Los Angeles,http://rightsstatements.org/vocab/InC/1.0/,"Connell, Will, $d 1898-1961","Interior view of The Bachelors haberdashery designed by Julius Ralph Davidson, Los Angeles, circa 1929",dog.jpg|~|cat.jpg
1 change: 1 addition & 0 deletions spec/dummy/spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
Capybara.default_max_wait_time = 20

# Setup chrome headless driver
Capybara.server = :puma, { Silent: true }
Expand Down
95 changes: 95 additions & 0 deletions spec/dummy/spec/system/import_file_status_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true
require 'rails_helper'
include Warden::Test::Helpers

RSpec.describe 'Importing records from a CSV file', :perform_jobs, :clean, type: :system, js: true do
before do
allow(CharacterizeJob).to receive(:perform_later)
ENV['IMPORT_PATH'] = File.join(fixture_path, 'images')
end

let(:csv_file) { File.join(fixture_path, 'csv_import', 'good', 'all_fields_multi.csv') }

context 'logged in as an admin user' do
let(:collection) { FactoryBot.build(:collection, title: ['Testing Collection']) }
let(:admin_user) { FactoryBot.create(:admin) }

let(:admin_set_id) { AdminSet.find_or_create_default_admin_set_id }
let(:permission_template) { Hyrax::PermissionTemplate.find_or_create_by!(source_id: admin_set_id) }
let(:workflow) { Sipity::Workflow.create!(active: true, name: 'test-workflow', permission_template: permission_template) }

before do
# Create a single action that can be taken
Sipity::WorkflowAction.create!(name: 'submit', workflow: workflow)

# Grant the user access to deposit into the admin set.
Hyrax::PermissionTemplateAccess.create!(
permission_template_id: permission_template.id,
agent_type: 'user',
agent_id: admin_user.user_key,
access: 'deposit'
)

collection.save!
login_as admin_user
end

it 'starts the import' do
visit '/csv_imports/new'
expect(page).to have_content 'Testing Collection'
expect(page).not_to have_content '["Testing Collection"]'

# Fill in and submit the form
select 'Testing Collection', from: "csv_import[fedora_collection_id]"
select 'Update Existing Metadata, create new works', from: "csv_import[update_actor_stack]"
attach_file('csv_import[manifest]', csv_file, make_visible: true)

expect(page).to have_content('You sucessfully uploaded this CSV: all_fields_multi.csv')

click_on 'Preview Import'

# We expect to see the title of the collection on the page
expect(page).to have_content 'Testing Collection'

expect(page).to have_content 'This import will process 1 row(s).'

# There is a link so the user can cancel.
expect(page).to have_link 'Cancel', href: '/csv_imports/new?locale=en'

expect(page).not_to have_content 'deduplication_key'

# After reading the warnings, the user decides
# to continue with the import.
click_on 'Start Import'

# The show page for the CsvImport
expect(page).to have_content 'all_fields_multi.csv'
expect(page).to have_content 'Start time'

# We expect to see the title of the collection on the page
expect(page).to have_content 'Testing Collection'
expect(Work.count).to eq 1

# Ensure that all the fields got assigned as expected
work = Work.where(title: "*haberdashery*").first
expect(work.title.first).to match(/haberdashery/)
expect(Zizia::PreIngestFile.last.status).to eq('attached')

expect(Zizia::PreIngestWork.find_by(deduplication_key: work.deduplication_key).pre_ingest_files.count).to eq(2)

# Everything should have the attached status now
expect(Zizia::PreIngestWork.find_by(deduplication_key: work.deduplication_key)
.pre_ingest_files.first.status).to eq('attached')
expect(Zizia::PreIngestWork.find_by(deduplication_key: work.deduplication_key).pre_ingest_files.last.status).to eq('attached')
expect(Zizia::PreIngestWork.find_by(deduplication_key: work.deduplication_key).status).to eq('attached')
visit('/csv_import_details/index')
click_on '1'
expect(page).to have_content 'View Files'
click_on 'View Files'
expect(page.html).not_to match(/glyphicon-question-sign/)
expect(page.html).to match(/glyphicon-ok-sign/)
expect(page).to have_content('dog.jpg')
expect(page).to have_content('cat.jpg')
end
end
end
4 changes: 2 additions & 2 deletions spec/dummy/spec/system/import_from_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

RSpec.describe 'Importing records from a CSV file', :perform_jobs, :clean, type: :system, js: true do
before do
allow(CharacterizeJob).to receive(:perform_later)
ENV['IMPORT_PATH'] = File.join(fixture_path, 'images')
end

Expand Down Expand Up @@ -32,7 +33,6 @@
access: 'deposit'
)

allow(CharacterizeJob).to receive(:perform_later) # There is no fits installed on travis-ci
collection.save!
login_as admin_user
end
Expand Down Expand Up @@ -251,7 +251,7 @@
expect(page).to have_content('cat.jpg')
expect(page).to have_content('5.74 MB')
expect(page).to have_content('abc/123')
expect(page).to have_content('This work\'s metadata has not been indexed yet.')
expect(page).to have_content('haberdashery')
expect(page).to have_content('Date Created')
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/models/zizia/application_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Zizia::ApplicationJob do
let(:application_job) { described_class.new }

context 'when including Zizia' do
it 'has its own ApplicationJob class' do
expect(application_job).to be_kind_of(ActiveJob::Base)
end
end
end
3 changes: 3 additions & 0 deletions spec/support/hyrax/basic_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def self.included(work)
work.property :related_url, predicate: ::RDF::RDFS.seeAlso
work.property :bibliographic_citation, predicate: ::RDF::Vocab::DC.bibliographicCitation
work.property :source, predicate: ::RDF::Vocab::DC.source

# From Zizia
work.property :deduplication_key, predicate: 'http://metadata.example.com/vocab/predicates#deduplicationKey'
end
end
end
6 changes: 5 additions & 1 deletion spec/zizia/hyrax/hyrax_basic_metadata_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
[:visibility, :files]
end

let(:zizia_fields) do
[:deduplication_key]
end

it_behaves_like 'a Zizia::Mapper' do
let(:metadata) do
{ title: ['A Title for a Record'],
my_custom_field: ['This gets ignored'] }
end
let(:expected_fields) { core_fields + basic_fields + tenejo_fields }
let(:expected_fields) { core_fields + basic_fields + tenejo_fields + zizia_fields }
end

context 'with metadata, but some missing fields' do
Expand Down

0 comments on commit 8a878c8

Please sign in to comment.