Skip to content

Commit

Permalink
resource_type meta for researcher, provider, repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 25, 2019
1 parent b296062 commit 9508252
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
24 changes: 18 additions & 6 deletions app/controllers/concerns/countable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ def doi_count(client_id: nil, provider_id: nil, consortium_id: nil, researcher_i
else
response = Doi.query(nil, page: { number: 1, size: 0 })
end

if researcher_id
response.results.total > 0 ? facet_by_cumulative_year(response.response.aggregations.created.buckets) : []
else
response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : []
end

response.results.total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : []
end

# cumulative count clients by year
Expand Down Expand Up @@ -56,5 +52,21 @@ def provider_count(consortium_id: nil)
response.results.total > 0 ? facet_by_cumulative_year(response.response.aggregations.cumulative_years.buckets) : []
end
end

def resource_type_count(client_id: nil, provider_id: nil, consortium_id: nil, researcher_id: nil, state: nil)
if client_id
response = Doi.query(nil, client_id: client_id, page: { number: 1, size: 0 })
elsif provider_id
response = Doi.query(nil, provider_id: provider_id, page: { number: 1, size: 0 })
elsif consortium_id
response = Doi.query(nil, consortium_id: consortium_id, page: { number: 1, size: 0 })
elsif researcher_id
response = Doi.query(nil, researcher_id: researcher_id, state: state, page: { number: 1, size: 0 })
else
response = Doi.query(nil, page: { number: 1, size: 0 })
end

response.results.total > 0 ? facet_by_resource_type(response.response.aggregations.resource_types.buckets) : []
end
end
end
6 changes: 5 additions & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,25 @@ def show
providers = provider_count(consortium_id: nil)
clients = client_count(provider_id: nil)
dois = doi_count(provider_id: nil)
resource_types = resource_type_count(provider_id: nil)
elsif @provider.member_type == "consortium_member"
providers = provider_count(consortium_id: params[:id])
clients = client_count(consortium_id: params[:id])
dois = doi_count(consortium_id: params[:id])
resource_types = resource_type_count(consortium_id: params[:id])
else
providers = nil
clients = client_count(provider_id: params[:id])
dois = doi_count(provider_id: params[:id])
resource_types = resource_type_count(provider_id: params[:id])
end

options = {}
options[:meta] = {
providers: providers,
clients: clients,
dois: dois }.compact
dois: dois,
"resourceTypes" => resource_types }.compact
options[:include] = @include
options[:is_collection] = false
options[:params] = { current_ability: current_ability }
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def show
fail ActiveRecord::RecordNotFound unless repository.present?

options = {}
options[:meta] = { dois: doi_count(client_id: params[:id]) }
options[:meta] = {
dois: doi_count(client_id: params[:id]),
"resourceTypes" => resource_type_count(client_id: params[:id]) }.compact
options[:include] = @include
options[:is_collection] = false
options[:params] = { current_ability: current_ability }
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/researchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def show
state = current_user.nil? || current_user.role_id == "user" ? "findable" : nil

options = {}
options[:meta] = { dois: doi_count(researcher_id: params[:id], state: state) }
options[:meta] = {
dois: doi_count(researcher_id: params[:id], state: state),
"resourceTypes" => resource_type_count(researcher_id: params[:id], state: state) }.compact
options[:is_collection] = false
render json: ResearcherSerializer.new(@researcher, options).serialized_json, status: :ok
end
Expand Down

0 comments on commit 9508252

Please sign in to comment.