Skip to content

Commit

Permalink
check primarySet for oai
Browse files Browse the repository at this point in the history
  • Loading branch information
lsat12357 committed Jun 27, 2016
1 parent bc5f49c commit 2975635
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/oregon_digital/oai/model/active_fedora_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def find(selector, options = {})
query_args = {:sort => "system_modified_dtsi desc", :fl => "id,system_modified_dtsi", :rows=>1000, :start=>start}
solr_count = ActiveFedora::SolrService.query(query_pairs, query_args)
qry_total = ActiveFedora::SolrService.count(query_pairs, query_args)
solr_count = remove_children(solr_count,start, qry_total)
solr_count = remove_chaff(solr_count,start, qry_total)
return next_set(solr_count, options[:resumption_token], qry_total) if options[:resumption_token]
#possibly a partial even if results < limit if a lot of children were removed, so check
if @limit && (solr_count.count > @limit || solr_count.last['rank'] != qry_total)
Expand Down Expand Up @@ -123,15 +123,25 @@ def extract_labels(qry, field)
label_arr
end

def remove_children(items,start, numFound)
def remove_chaff(items,start, numFound)
afresults = []
return afresults if numFound == 0
uribase = "http://oregondigital.org/resource/"
rank = start
items.each do |item|
test = 0
item["rank"] = rank
pseudo = ActiveFedora::Base.load_instance_from_solr(item["id"])
if !pseudo.compounded?
#can add more tests here if necessary
#remove children
if pseudo.compounded?
test = test + 1
end
#check primarySet is not corrupt
if (!pseudo.descMetadata.primarySet.empty?) && (!pseudo.descMetadata.primarySet.first.respond_to? :id)
test = test + 1
end
if test == 0
afresults << item
end
rank = rank + 1
Expand Down
16 changes: 16 additions & 0 deletions spec/features/oai_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@
expect(page).to have_xpath('//header[@status="deleted"]')
end
end
context "when the asset's primaryset raises an error" do
let(:pset2) {GenericCollection.new(pid:"oregondigital:myset2") }
let(:asset2) {asset_class.new}
before do
asset2.title = "asset 2"
asset2.descMetadata.primarySet << pset2
asset2.save
asset2.review!
visit oai_path(:verb => "ListRecords", :metadataPrefix => parameter)
end
#pset2 not saved with title, raises a NoMethodError when asked for an id
it "shouldn't be included in the results" do
expect{asset2.descMetadata.primarySet.first.id}.to raise_error
expect(page).not_to have_content(asset2.id)
end
end

context "and they are documents" do
let(:asset_class) {Document}
Expand Down

0 comments on commit 2975635

Please sign in to comment.