Skip to content

Commit

Permalink
only return offers with ids not already imported
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun committed Jun 15, 2024
1 parent d7c50c8 commit f3608df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/controllers/reftracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ArchivesSpaceService < Sinatra::Base
.permissions([])
.returns([200, "[offers]"]) \
do
RefTrackerClient.closed_offers(params[:page])
json_response(RefTrackerClient.manuscript_offers(params[:page]))
end

Endpoint.get('/plugins/reftracker/offer/:ono')
Expand Down
15 changes: 14 additions & 1 deletion backend/model/reftracker_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.get_question(question_no)
end


def self.closed_offers(page = 1)
def self.manuscript_offers(page = 1)
columns = [
'question_no',
'question_text',
Expand Down Expand Up @@ -62,6 +62,19 @@ def self.closed_offers(page = 1)
:pagesize => 20,
}
self.get('search', {:parameters => search_params.to_json})

# here's how accession.identifier looks in the db :(
# ["moo",null,null,null]
# NLA only uses id_0 so this works
offer_ids = offers.map{|offer| offer['bib_udf_tb03']}.select{|id| !id.empty?}.map{|id| '["' + id + '",null,null,null]'}.compact


# find out which of the offer_ids already exist in AS
found_ids = nil
DB.open{ |db| found_ids = db[:accession].filter(:identifier => offer_ids).select(:identifier).map{|i| ASUtils.json_parse(i[:identifier]).first}}

# then filter out the found ids, and any offers without an id
offers.select{|offer| !offer['bib_udf_tb03'].empty? && !found_ids.include?(offer['bib_udf_tb03'])}
end


Expand Down

0 comments on commit f3608df

Please sign in to comment.