Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PUDL3 support to IngestMETS #121

Merged
merged 1 commit into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/models/mets_document/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ def initialize(mets)
end

def new
mets
if pudl3_mvw?
Pudl3MVWMetsDocument.new(mets.source_file)
else
mets
end
end

private

def pudl3_mvw?
mets.collection_slugs == "pudl0003" && mets.mets.xpath("/mets:mets/mets:structMap[@type='Physical']").empty?
end
end
end
22 changes: 22 additions & 0 deletions app/models/pudl3_mvw_mets_document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
class Pudl3MVWMetsDocument < METSDocument
def multi_volume?
true
end

def volume_ids
files.map { |x| x[:path].split("/")[-2] }.uniq
end

def label_for_volume(volume_id)
volume_id.gsub("vol", "")
end

def files_for_volume(volume_id)
files.select { |x| x[:path].include?(volume_id) }
end

def structureless?
true
end
end
21 changes: 21 additions & 0 deletions spec/jobs/ingest_mets_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,26 @@
expect(child_books[1].title).to eq ["second volume"]
end
end
context "when given a pudl0003 MVW with no structmap" do
let(:mets_file) { Rails.root.join("spec", "fixtures", "mets", "pudl0003-tc85_2621.mets") }
before do
allow(File).to receive(:open).with("/mnt/diglibdata/pudl/pudl0003/tc85_2621/vol01/00000001.tif").and_return(File.open(tiff_file))
allow(File).to receive(:open).with("/mnt/diglibdata/pudl/pudl0003/tc85_2621/vol01/00000002.tif").and_return(File.open(tiff_file))
allow(File).to receive(:open).with("/mnt/diglibdata/pudl/pudl0003/tc85_2621/vol02/00000001.tif").and_return(File.open(tiff_file))
end
it "hacks together a MVW from the path" do
described_class.perform_now(mets_file, user)

books = adapter.query_service.find_all_of_model(model: ScannedResource)
parent_book = books.find { |x| x.source_metadata_identifier.present? }
expect(parent_book).not_to be_nil
expect(parent_book.member_ids).not_to be_blank
children = adapter.query_service.find_members(resource: parent_book).to_a

expect(children.map(&:class)).to eq [ScannedResource, ScannedResource]
expect(children[0].member_ids.length).to eq 2
expect(children[1].member_ids.length).to eq 1
end
end
end
end