Skip to content

Commit

Permalink
Reingest collection (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadel committed Oct 6, 2021
1 parent afb0b4a commit dc956c0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/zizia/hyrax/hyrax_record_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,32 @@ def find_file_path(filename)

private

def update_for(existing_record:, update_record:)
if update_record.object_type == :collection
collection_updater(existing_record: existing_record, update_record: update_record)
else
curation_concern_updater(existing_record: existing_record, update_record: update_record)
end
end

def collection_updater(existing_record:, update_record:)
attrs = process_collection_attrs(record: update_record)

case csv_import_detail.update_actor_stack
when 'HyraxMetadataOnly', 'HyraxDelete'
# Update Existing Metadata, create new works
existing_record.update(attrs)
when 'HyraxOnlyNew'
return unless existing_record[deduplication_field] != update_record.try(deduplication_field)
# Ignore Existing Works, new works only
raise "This has not been implemented yet"
end
end

# Update an existing object using the Hyrax actor stack
# We assume the object was created as expected if the actor stack returns true.
# Note that for now the update stack will only update metadata and update collection membership, it will not re-import files.
def update_for(existing_record:, update_record:)
def curation_concern_updater(existing_record:, update_record:)
updater = case csv_import_detail.update_actor_stack
when 'HyraxMetadataOnly'
Zizia::HyraxMetadataOnlyUpdater.new(csv_import_detail: csv_import_detail,
Expand Down
47 changes: 47 additions & 0 deletions spec/zizia/hyrax/hyrax_record_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,51 @@
expect(work_two.file_sets.second.label).to eq('zizia_4.png')
end
end
context "reingesting a collection" do
around do |example|
orig_import_path = ENV['IMPORT_PATH']
ENV['IMPORT_PATH'] = File.join(fixture_path, 'images')
example.run
ENV['IMPORT_PATH'] = orig_import_path
end

before do
allow(CharacterizeJob).to receive(:perform_later)
permission_template
end

let(:collection) { FactoryBot.create(:collection, identifier: ['MINNESOTA_POSTCARDS'], deduplication_key: 'MINNESOTA_POSTCARDS', title: ['Awesome Minnesota Postcard Collection'], visibility: 'open') }
let(:permission_template) { Hyrax::PermissionTemplate.find_or_create_by!(source_id: collection.id) }

let(:parser) { Zizia::CsvParser.new(file: file) }
let(:file) { File.open('spec/dummy/spec/fixtures/csv_import/good/Postcards_-_Minneapolis_UNPACKED.csv') }
let(:importer) do
Zizia::Importer.new(
parser: parser,
record_importer: hyrax_record_importer
)
end

it "can import a csv with an existing collection" do
expect do
importer.import
collection.reload
end.to change { collection.title }.from(['Awesome Minnesota Postcard Collection']).to(['Minnesota Postcard Collection'])
end

context "only changing new objects" do
let(:csv_import_detail) do
Zizia::CsvImportDetail.create(csv_import_id: 1, collection_id: collection.id, depositor_id: user.id,
batch_id: 1, deduplication_field: 'identifier', update_actor_stack: 'HyraxOnlyNew')
end

it "can import a csv with an existing collection" do
expect do
importer.import
collection.reload
# note: this says it changes, but it keeps the same string value inside the array
end.to change { collection.title }.from(['Awesome Minnesota Postcard Collection']).to(['Awesome Minnesota Postcard Collection'])
end
end
end
end

0 comments on commit dc956c0

Please sign in to comment.