diff --git a/app/importers/modular_importer.rb b/app/importers/modular_importer.rb index 5fda3a4..a4c1f7d 100644 --- a/app/importers/modular_importer.rb +++ b/app/importers/modular_importer.rb @@ -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 diff --git a/db/migrate/20191031131041_add_deduplication_key_to_pre_ingest_work.rb b/db/migrate/20191031131041_add_deduplication_key_to_pre_ingest_work.rb new file mode 100644 index 0000000..8bf7363 --- /dev/null +++ b/db/migrate/20191031131041_add_deduplication_key_to_pre_ingest_work.rb @@ -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 diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 9fc173c..2a13872 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -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 diff --git a/spec/dummy/spec/fixtures/csv_import/good/all_fields.csv b/spec/dummy/spec/fixtures/csv_import/good/all_fields.csv index 5e4e505..acef762 100644 --- a/spec/dummy/spec/fixtures/csv_import/good/all_fields.csv +++ b/spec/dummy/spec/fixtures/csv_import/good/all_fields.csv @@ -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 diff --git a/spec/dummy/spec/fixtures/csv_import/good/all_fields_complete_update.csv b/spec/dummy/spec/fixtures/csv_import/good/all_fields_complete_update.csv index 614e810..0c0ae5a 100644 --- a/spec/dummy/spec/fixtures/csv_import/good/all_fields_complete_update.csv +++ b/spec/dummy/spec/fixtures/csv_import/good/all_fields_complete_update.csv @@ -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 diff --git a/spec/dummy/spec/fixtures/csv_import/good/all_fields_metadata_update.csv b/spec/dummy/spec/fixtures/csv_import/good/all_fields_metadata_update.csv index da1ad47..b4af81a 100644 --- a/spec/dummy/spec/fixtures/csv_import/good/all_fields_metadata_update.csv +++ b/spec/dummy/spec/fixtures/csv_import/good/all_fields_metadata_update.csv @@ -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 diff --git a/spec/dummy/spec/fixtures/csv_import/good/all_fields_only_new.csv b/spec/dummy/spec/fixtures/csv_import/good/all_fields_only_new.csv index 3f9b4c8..6aaf299 100644 --- a/spec/dummy/spec/fixtures/csv_import/good/all_fields_only_new.csv +++ b/spec/dummy/spec/fixtures/csv_import/good/all_fields_only_new.csv @@ -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 diff --git a/spec/factories/pre_ingest_work.rb b/spec/factories/pre_ingest_work.rb index 348cad6..dab72c6 100644 --- a/spec/factories/pre_ingest_work.rb +++ b/spec/factories/pre_ingest_work.rb @@ -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 diff --git a/spec/models/zizia/csv_import_detail_spec.rb b/spec/models/zizia/csv_import_detail_spec.rb new file mode 100644 index 0000000..5ef2e94 --- /dev/null +++ b/spec/models/zizia/csv_import_detail_spec.rb @@ -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 diff --git a/spec/models/zizia/pre_ingest_work_spec.rb b/spec/models/zizia/pre_ingest_work_spec.rb new file mode 100644 index 0000000..e05cb7c --- /dev/null +++ b/spec/models/zizia/pre_ingest_work_spec.rb @@ -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