Skip to content

Commit

Permalink
Add deduplication_key to Zizia::PreIngestWork model
Browse files Browse the repository at this point in the history
This will let us track the progress of the import by giving us a way to
tie a Zizia::PreIngestWork to the ActiveFedora object eventually created
by the import process.
  • Loading branch information
bess committed Oct 31, 2019
1 parent 0eb66a5 commit c6048c7
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/importers/modular_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def import
importer = Zizia::Importer.new(parser: Zizia::CsvParser.new(file: file), record_importer: Zizia::HyraxRecordImporter.new(attributes: attrs))

importer.records.each_with_index do |record, index|
pre_ingest_work = Zizia::PreIngestWork.new(csv_import_detail_id: csv_import_detail.id)
pre_ingest_work = Zizia::PreIngestWork.new(csv_import_detail_id: csv_import_detail.id, deduplication_key: record.mapper.metadata["deduplication_key"])

record.mapper.files.each do |child_file|
full_path = Dir.glob("#{ENV['IMPORT_PATH']}/**/#{child_file}").first
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddDeduplicationKeyToPreIngestWork < ActiveRecord::Migration[5.1]
def change
add_column :zizia_pre_ingest_works, :deduplication_key, :string
add_index :zizia_pre_ingest_works, :deduplication_key
end
end
2 changes: 2 additions & 0 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@
t.integer "csv_import_detail_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "deduplication_key"
t.index ["csv_import_detail_id"], name: "index_zizia_pre_ingest_works_on_csv_import_detail_id"
t.index ["deduplication_key"], name: "index_zizia_pre_ingest_works_on_deduplication_key"
end

end
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,visibility,location,keyword,rights statement,creator,title,files
abc/123,https://creativecommons.org/licenses/by/4.0/,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,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
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
identifier,license,visibility,location,keyword,rights statement,creator,title,files
abc/123,https://creativecommons.org/licenses/by/4.0/,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",cat.jpg
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",cat.jpg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
identifier,license,visibility,location,keyword,rights statement,creator,title,files
abc/123,https://creativecommons.org/licenses/by/4.0/,PUBlic,http://www.geonames.org/5667009/montana.html|~|http://www.geonames.org/6252001/united-states.html,Clothing stores $z California $z Los Angeles|~|Exterior design $z California $z Los Angeles,http://rightsstatements.org/vocab/InC/1.0/,"Connell, Will, $d 1898-1961","Exterior view of The Bachelors haberdashery designed by Julius Ralph Davidson, Los Angeles, circa 1929",dog.jpg
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|~|Exterior design $z California $z Los Angeles,http://rightsstatements.org/vocab/InC/1.0/,"Connell, Will, $d 1898-1961","Exterior view of The Bachelors haberdashery designed by Julius Ralph Davidson, Los Angeles, circa 1929",dog.jpg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
identifier,license,visibility,location,keyword,rights statement,creator,title,files
abc/123,https://creativecommons.org/licenses/by/4.0/,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
abc/456,https://creativecommons.org/licenses/by/4.0/,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 patisserie designed by Julius Ralph Davidson, Los Angeles, circa 1929",cat.jpg
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
abc/456,https://creativecommons.org/licenses/by/4.0/,abc/456,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 patisserie designed by Julius Ralph Davidson, Los Angeles, circa 1929",cat.jpg
1 change: 1 addition & 0 deletions spec/factories/pre_ingest_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
created_at { Time.current }
updated_at { Time.current }
csv_import_detail_id { 1 }
sequence(:deduplication_key) { |n| "zyx321cba#{n}" }
end
end
9 changes: 9 additions & 0 deletions spec/models/zizia/csv_import_detail_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Zizia::CsvImportDetail do
it 'can instantiate' do
cid = described_class.new
expect(cid.class).to eq described_class
end
end
9 changes: 9 additions & 0 deletions spec/models/zizia/pre_ingest_work_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe Zizia::PreIngestWork do
let(:pre_ingest_work) { FactoryBot.create(:pre_ingest_work, deduplication_key: "42") }
it 'has a deduplication_key' do
expect(pre_ingest_work.deduplication_key).to eq "42"
end
end

0 comments on commit c6048c7

Please sign in to comment.