Skip to content

Commit

Permalink
More appropriate bulk task compound syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Jan 26, 2015
1 parent 01b4d26 commit ac03fee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions app/models/bulk_task_child.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,20 @@ def build_bag_asset(ingester)
end

def adjust_compound(asset)
uris = asset.od_content.map{|x| x.rdf_subject}
replace_uris = uris.map{|x| asset.query([x, RDF::DC.replaces, nil]).first.object}
replace_uris = asset.od_content_uris
replace_pids = replace_uris.map{|x| ActiveFedora::SolrService.query("desc_metadata__replacesUrl_ssim:#{RSolr.escape(x.to_s)}", :rows => 10000).map{|y| y["id"]}.first}.compact
raise "Unable to set compound object - child objects not ingested" if replace_uris.length != replace_pids.length
replace_pids.map!{|x| RDF::URI.new("http://oregondigital.org/resource/#{x}")}
replace_uris.each_with_index do |uri, idx|
asset.resource.statements.each do |s|
next unless s.subject == uri || s.object == uri
new_uri = RDF::URI.new("http://oregondigital.org/resource/#{replace_pids[idx]}")
subject = s.subject == uri ? new_uri : s.subject
object = s.object == uri ? new_uri : s.object
asset.resource << [subject, s.predicate, object]
asset.resource.delete(s)
end
end
asset.descMetadata.od_content = replace_pids
end

Expand Down
6 changes: 5 additions & 1 deletion app/models/generic_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def self.destroyed
delegate :od_content, :to => :descMetadata, :allow_nil => true

def compound?
od_content.length > 0
od_content_uris.length > 0
end

def od_content_uris
resource.query([resource.rdf_subject, OregonDigital::Vocabularies::OREGONDIGITAL.contents, nil]).map{|x| x.object}
end

def compounded?
Expand Down
11 changes: 7 additions & 4 deletions spec/fixtures/compound_bags/120/descMetadata.nt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<http://example.org/ns/120> <http://purl.org/dc/terms/modified> "2011-06-22" .
<http://example.org/ns/120> <http://purl.org/dc/terms/replaces> <http://oregondigital.org/u?/gwilliams,120> .
<http://example.org/ns/120> <http://opaquenamespace.org/ns/set> <http://oregondigital.org/resource/oregondigital:gwilliams> .
<http://example.org/ns/120> <http://opaquenamespace.org/ns/contents> _:g70255837180160 .
<http://example.org/ns/120> <http://opaquenamespace.org/ns/contents> _:g70255837200400 .
_:g70255837180160 <http://purl.org/dc/terms/replaces> <http://oregondigital.org/u?/gwilliams,11> .
_:g70255837200400 <http://purl.org/dc/terms/replaces> <http://oregondigital.org/u?/gwilliams,117> .
<http://example.org/ns/120> <http://opaquenamespace.org/ns/contents> <http://oregondigital.org/u?/gwilliams,11> .
<http://example.org/ns/120> <http://opaquenamespace.org/ns/contents> <http://oregondigital.org/u?/gwilliams,117> .
<http://example.org/ns/120> <http://www.iana.org/assignments/relation/first> _:1 .
<http://example.org/ns/120> <http://www.iana.org/assignments/relation/last> _:2 .
_:1 <http://www.openarchives.org/ore/1.0/datamodel#proxyFor> <http://oregondigital.org/u?/gwilliams,11> .
_:1 <http://www.iana.org/assignments/relation/next> _:2 .
_:2 <http://www.openarchives.org/ore/1.0/datamodel#proxyFor> <http://oregondigital.org/u?/gwilliams,117> .
1 change: 1 addition & 0 deletions spec/models/bulk_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
it "should create a compound object" do
last_asset = GenericAsset.all.find{|x| x.compound?}
expect(last_asset.od_content.first).to be_kind_of(ActiveFedora::Base)
expect(last_asset.query([nil, OregonDigital::Vocabularies::ORE.proxyFor, RDF::URI.new("http://oregondigital.org/u?/gwilliams,11")]).to_a.length).to eq 0
end
context "and the compound object is first" do
let(:setup) do
Expand Down

0 comments on commit ac03fee

Please sign in to comment.