diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 8b3b814cf..e45838e33 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -372,6 +372,24 @@ def repositories } end + draft_response = + DataciteDoi.query( + nil, + state: "draft", + page: { size: 0, number: 1 }, + totals_agg: "client_export", + ) + + draft_client_totals = {} + draft_totals_buckets = draft_response.aggregations.clients_totals.buckets + draft_totals_buckets.each do |totals| + draft_client_totals[totals["key"]] = { + "count" => totals["doc_count"], + "this_year" => totals.this_year.buckets[0]["doc_count"], + "last_year" => totals.last_year.buckets[0]["doc_count"], + } + end + headers = [ "Repository Name", "Repository ID", @@ -389,6 +407,7 @@ def repositories "doisCurrentYear", "doisPreviousYear", "doisTotal", + "doisDraftTotal", "doisDbTotal", "doisMissing" ] @@ -396,7 +415,7 @@ def repositories csv = headers.to_csv # get doi counts from database - dois_by_client = DataciteDoi.where.not(aasm_state: "draft").group(:datacentre).count + dois_by_client = DataciteDoi.group(:datacentre).count clients.each do |client| # Limit for salesforce default of max 80 chars @@ -407,6 +426,7 @@ def repositories db_total = dois_by_client[client.id.to_i].to_i es_total = client_totals[client.uid] ? client_totals[client.uid]["count"] : 0 + es_draft_total = draft_client_totals[client.uid] ? draft_client_totals[client.uid]["count"] : 0 row = { accountName: name, @@ -444,8 +464,9 @@ def repositories 0 end, doisCountTotal: es_total, + doisCountDraftTotal: es_draft_total, doisDbTotal: db_total, - doisMissing: db_total - es_total, + doisMissing: db_total - (es_total + es_draft_total), }.values csv += CSV.generate_line row diff --git a/spec/requests/exports_spec.rb b/spec/requests/exports_spec.rb index f5fa908d9..a4471e5d8 100644 --- a/spec/requests/exports_spec.rb +++ b/spec/requests/exports_spec.rb @@ -94,7 +94,7 @@ ) dois_total = csv[1].strip.split(",")[15].to_i expect(dois_total).to eq(3) - dois_missing = csv[1].strip.split(",")[17].to_i + dois_missing = csv[1].strip.split(",")[18].to_i expect(dois_missing).to eq(0) end @@ -113,7 +113,7 @@ ) dois_total = csv[1].strip.split(",")[15].to_i expect(dois_total).to eq(3) - dois_missing = csv[1].strip.split(",")[17].to_i + dois_missing = csv[1].strip.split(",")[18].to_i expect(dois_missing).to eq(0) end end