Skip to content

Commit

Permalink
trigger dois missing report via api
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Nov 27, 2020
1 parent 656e35b commit 23791d1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ def stats
render json: meta, status: :ok
end

def check_links
csv = Client.export_doi_counts
filename = "repositories-not-fully-indexed-#{Date.today}.csv"

send_data csv, filename: filename
end

protected
def set_include
if params[:include].present?
Expand Down
7 changes: 6 additions & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def self.export_doi_counts(query: nil)
"DOIs missing",
]

dois_by_client = DataciteDoi.where(type: "DataciteDoi").group(:datacentre).count
dois_by_client = DataciteDoi.group(:datacentre).count
rows =
clients.reduce([]) do |sum, client|
db_total = dois_by_client[client.id.to_i].to_i
Expand Down Expand Up @@ -695,6 +695,11 @@ def self.export_doi_counts(query: nil)
sum
end

if rows.blank?
logger.warn "Found 0 repositories with missing DOIs."
return nil
end

csv = [CSV.generate_line(headers)] + rows

logger.warn "Found #{csv.size} repositories with missing DOIs."
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
get "export/repositories",
to: "exports#repositories", defaults: { format: :csv }
get "export/contacts", to: "exports#contacts", defaults: { format: :csv }
get "repositories/check-links", to: "repositories#check_links"

resources :heartbeat, only: %i[index]

Expand Down
52 changes: 52 additions & 0 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,56 @@
# expect(Doi.query(nil, client_id: target.symbol.downcase).results.total).to eq(3)
end
end

describe "GET /repositories/check-links", elasticsearch: true do
let(:admin_bearer) { User.generate_token }
let(:admin_headers) do
{
"HTTP_ACCEPT" => "text/csv",
"HTTP_AUTHORIZATION" => "Bearer " + admin_bearer,
}
end
let(:consortium) do
create(
:provider,
role_name: "ROLE_CONSORTIUM",
name: "Virtual Library of Virginia",
symbol: "VIVA",
)
end
let!(:provider) do
create(
:provider,
role_name: "ROLE_CONSORTIUM_ORGANIZATION",
name: "University of Virginia",
symbol: "UVA",
consortium: consortium,
)
end
let(:client) do
create(
:client,
provider: provider,
symbol: "UVA.LIBRARY",
name: "University of Virginia Library",
)
end
let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") }

before do
DataciteDoi.import
Client.import
sleep 2
end

it "returns repositories with dois not indexed", vcr: false do
get "/repositories/check-links",
nil, admin_headers
puts last_response.body
expect(last_response.status).to eq(200)
csv = last_response.body.lines
expect(csv.length).to eq(1)
expect(csv[0].strip).to be_blank
end
end
end

0 comments on commit 23791d1

Please sign in to comment.