Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 20, 2019
2 parents b137c3a + 76407c0 commit 7c2913e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def destroy

def totals
page = { size: 0, number: 1}
response = Doi.query(nil, provider_id: params[:provider_id], page: page)
response = Doi.query(nil, provider_id: params[:provider_id], page: page, totals_agg: true)
total = response.results.total

registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/prefixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def update

def totals
page = { size: 0, number: 1}
response = Doi.query("", client_id: params[:client_id],page: page)
response = Doi.query("", client_id: params[:client_id],page: page, totals_agg: true)
total = response.results.total

registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ def update

def totals
page = { size: 0, number: 1}
response = Doi.query("", page: page)

response = Doi.query("", page: page, totals_agg: true)

total = response.results.total

registrant = total > 0 ? providers_totals(response.response.aggregations.providers_totals.buckets) : nil
Expand Down
6 changes: 5 additions & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def find_by_ids(ids, options={})
end

def query(query, options={})
aggregations = query_aggregations
aggregations = options[:totals_agg] == true ? totals_aggregations : query_aggregations
options[:page] ||= { size: 25, number: 1 }

# enable cursor-based pagination for DOIs
Expand Down Expand Up @@ -243,6 +243,10 @@ def recreate_index(options={})
client.indices.create index: index_name, body: { settings: {"index.requests.cache.enable": true }}
end

def count
Elasticsearch::Model.client.count(index: index_name)['count']
end

def create_alias(index: nil)
return nil unless index.present?

Expand Down
13 changes: 9 additions & 4 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,25 @@ def self.query_aggregations
link_checks_citation_doi: { value_count: { field: "landing_page.citationDoi" } },
links_checked: { value_count: { field: "landing_page.checked" } },
sources: { terms: { field: 'source', size: 15, min_doc_count: 1 } },
providers_totals: { terms: { field: 'provider_id', size: 500, min_doc_count: 1 }, aggs: sub_aggregations},
clients_totals: { terms: { field: 'client_id', size: 2000, min_doc_count: 1 }, aggs: sub_aggregations },
prefixes_totals: { terms: { field: 'prefix', size: 2000, min_doc_count: 1 }, aggs: sub_aggregations },
subjects: { terms: { field: 'subjects.subject', size: 15, min_doc_count: 1 } }
}
end

def self.totals_aggregations
{
providers_totals: { terms: { field: 'provider_id', size: ::Provider.count, min_doc_count: 1 }, aggs: sub_aggregations},
clients_totals: { terms: { field: 'client_id', size: ::Client.count, min_doc_count: 1 }, aggs: sub_aggregations },
prefixes_totals: { terms: { field: 'prefix', size: ::Prefix.count, min_doc_count: 1 }, aggs: sub_aggregations },
}
end

def self.sub_aggregations
beginning_of_year = DateTime.current.beginning_of_year.strftime('%Y-%m-%d')
beginning_of_last_year = DateTime.current.beginning_of_year.last_year.strftime('%Y-%m-%d')
beginning_of_month = DateTime.current.beginning_of_month.strftime('%Y-%m-%d')

{
states: { terms: { field: 'aasm_state', size: 15, min_doc_count: 1 } },
states: { terms: { field: 'aasm_state', size: 4, min_doc_count: 1 } },
this_month:{ date_range:{ field: 'created', time_zone: "CET", ranges: {from: beginning_of_month, to: "now/d"} } },
this_year: { date_range: { field: 'created', time_zone: "CET", ranges: {from: beginning_of_year, to: "now/d"} } },
last_year: { date_range: { field: 'created', time_zone: "CET", ranges: {from: beginning_of_last_year, to: beginning_of_year} } }
Expand Down
31 changes: 24 additions & 7 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,10 @@ components:
type: string
created:
type: string
readOnly: true
updated:
type: string
readOnly: true
required:
- id
- attributes - name - symbol - contactName - contactEmail
Expand All @@ -852,11 +854,14 @@ components:
properties:
created:
type: string
readOnly: true
updated:
type: string
readOnly: true
required:
- id
Doi:
description: Represents a DOI and provides access to metadata attributes, further schema specific information can be found at https://schema.datacite.org
type: object
properties:
data:
Expand All @@ -875,6 +880,11 @@ components:
type: string
suffix:
type: string
event:
description: Can be set to trigger a DOI state change.
type: string
enum: [publish, register, hide]
writeOnly: true
identifiers:
type: array
items:
Expand Down Expand Up @@ -1101,10 +1111,12 @@ components:
isActive:
type: boolean
state:
readOnly: true
type: string
reason:
type: string
landingPage:
description: Data describing the landing page, used by link checking.
type: object
properties:
checked:
Expand Down Expand Up @@ -1135,10 +1147,13 @@ components:
type: boolean
created:
type: string
readOnly: true
registered:
type: string
readOnly: true
updated:
type: string
readOnly: true
required:
- id
- attributes - doi - creators - titles - publisher - publicationYear
Expand Down Expand Up @@ -1226,8 +1241,10 @@ components:
properties:
created:
type: string
readOnly: true
updated:
type: string
readOnly: true
required:
- id
Provider:
Expand Down Expand Up @@ -1269,8 +1286,8 @@ components:
report-id:
type: string
description: >-
The report ID or code or shortname. Typically this will be the same
code provided in the Report parameter of the request.
The report ID or code or shortname. Typically this will be the
same code provided in the Report parameter of the request.
example: DSR
release:
type: string
Expand All @@ -1290,14 +1307,14 @@ components:
report-filters:
type: string
description: >-
Zero or more report filters used for this report. Typically reflect
filters provided on the Request. Filters limit the data to be
reported on.
Zero or more report filters used for this report. Typically
reflect filters provided on the Request. Filters limit the data
to be reported on.
report-attributes:
type: string
description: >-
Zero or more additional attributes applied to the report. Attributes
inform the level of detail in the report.
Zero or more additional attributes applied to the report.
Attributes inform the level of detail in the report.
reporting-period:
type: string
description: Time the report was prepared.
Expand Down

0 comments on commit 7c2913e

Please sign in to comment.