Skip to content

Commit

Permalink
Merge branch 'master' into feature_queries_forstats
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Jan 8, 2019
2 parents 75415b8 + 604abdc commit c8af853
Show file tree
Hide file tree
Showing 25 changed files with 702 additions and 418 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ WORKDIR /home/app/webapp
RUN mkdir -p vendor/bundle && \
chown -R app:app . && \
chmod -R 755 . && \
gem update --system && \
gem install bundler && \
/sbin/setuser app bundle install --path vendor/bundle

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ gem 'nokogiri', '~> 1.8.1'
gem 'diffy', '~> 3.2', '>= 3.2.1'
gem 'commonmarker', '~> 0.17.9'
gem 'iso8601', '~> 0.9.0'
gem 'patron', '~> 0.13.1', require: false
gem 'maremma', '>= 4.1'
gem 'bolognese', '~> 1.0'
gem 'dalli', '~> 2.7', '>= 2.7.6'
Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GEM
api-pagination (4.8.2)
arel (9.0.0)
aws-eventstream (1.0.1)
aws-partitions (1.127.0)
aws-partitions (1.128.0)
aws-sdk-core (3.44.1)
aws-eventstream (~> 1.0)
aws-partitions (~> 1.0)
Expand Down Expand Up @@ -166,7 +166,7 @@ GEM
database_cleaner (1.7.0)
debug_inspector (0.0.3)
diff-lcs (1.3)
diffy (3.2.1)
diffy (3.3.0)
docile (1.1.5)
docopt (0.6.1)
domain_name (0.5.20180417)
Expand Down Expand Up @@ -230,12 +230,12 @@ GEM
tilt
hamster (3.0.0)
concurrent-ruby (~> 1.0)
hashdiff (0.3.7)
hashdiff (0.3.8)
hashie (3.6.0)
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.3.0)
i18n (1.4.0)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
iso8601 (0.9.1)
Expand Down Expand Up @@ -318,7 +318,6 @@ GEM
oj (2.18.5)
oj_mimic_json (1.0.1)
pandoc-ruby (2.0.2)
patron (0.13.1)
postrank-uri (1.0.23)
addressable (>= 2.3.0, < 2.6)
nokogiri (>= 1.6.1, < 1.9)
Expand Down Expand Up @@ -367,7 +366,7 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
rdf (3.0.7)
rdf (3.0.9)
hamster (~> 3.0)
link_header (~> 0.0, >= 0.0.8)
rdf-aggregate-repo (2.2.1)
Expand Down Expand Up @@ -535,7 +534,6 @@ DEPENDENCIES
nokogiri (~> 1.8.1)
oj (>= 2.8.3)
oj_mimic_json (~> 1.0, >= 1.0.1)
patron (~> 0.13.1)
premailer (~> 1.11, >= 1.11.1)
pwqgen.rb (~> 0.1.0)
rack-cors (~> 1.0, >= 1.0.2)
Expand Down
70 changes: 39 additions & 31 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,51 @@ def index
elsif params[:ids].present?
response = Client.find_by_ids(params[:ids], page: page, sort: sort)
else
response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], software: params[:software], query_fields: params[:query_fields], page: page, sort: sort)
response = Client.query(params[:query], year: params[:year], provider_id: params[:provider_id], software: params[:software], page: page, sort: sort)
end

total = response.results.total
total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0
years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil
software = total > 0 ? facet_by_software(response.response.aggregations.software.buckets) : nil
begin
total = response.results.total
total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0
years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil
software = total > 0 ? facet_by_software(response.response.aggregations.software.buckets) : nil

@clients = response.results.results
@clients = response.results.results

options = {}
options[:meta] = {
total: total,
"totalPages" => total_pages,
page: page[:number],
years: years,
providers: providers,
software: software
}.compact

options[:links] = {
self: request.original_url,
next: @clients.blank? ? nil : request.base_url + "/clients?" + {
query: params[:query],
"provider-id" => params[:provider_id],
software: params[:software],
year: params[:year],
fields: params[:fields],
"page[number]" => page[:number] + 1,
"page[size]" => page[:size],
sort: params[:sort] }.compact.to_query
options = {}
options[:meta] = {
total: total,
"totalPages" => total_pages,
page: page[:number],
years: years,
providers: providers,
software: software
}.compact
options[:include] = @include
options[:is_collection] = true

render json: ClientSerializer.new(@clients, options).serialized_json, status: :ok
options[:links] = {
self: request.original_url,
next: @clients.blank? ? nil : request.base_url + "/clients?" + {
query: params[:query],
"provider-id" => params[:provider_id],
software: params[:software],
year: params[:year],
fields: params[:fields],
"page[number]" => page[:number] + 1,
"page[size]" => page[:size],
sort: params[:sort] }.compact.to_query
}.compact
options[:include] = @include
options[:is_collection] = true

render json: ClientSerializer.new(@clients, options).serialized_json, status: :ok
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => exception
Bugsnag.notify(exception)

message = JSON.parse(exception.message[6..-1]).to_h.dig("error", "root_cause", 0, "reason")

render json: { "errors" => { "title" => message }}.to_json, status: :bad_request
end
end

def show
Expand Down
64 changes: 36 additions & 28 deletions app/controllers/data_centers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,46 @@ def index
response = Client.query(params[:query], year: params[:year], provider_id: params[:member_id], fields: params[:fields], page: page, sort: sort)
end

total = response.results.total
total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0
years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil
begin
total = response.results.total
total_pages = page[:size] > 0 ? (total.to_f / page[:size]).ceil : 0
years = total > 0 ? facet_by_year(response.response.aggregations.years.buckets) : nil
providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil

@clients = response.results.results
@clients = response.results.results

options = {}
options[:meta] = {
total: total,
"total-pages" => total_pages,
page: page[:number],
years: years,
members: providers
}.compact
options = {}
options[:meta] = {
total: total,
"total-pages" => total_pages,
page: page[:number],
years: years,
members: providers
}.compact

options[:links] = {
self: request.original_url,
next: @clients.blank? ? nil : request.base_url + "/data-centers?" + {
query: params[:query],
"member-id" => params[:member_id],
year: params[:year],
fields: params[:fields],
"page[number]" => page[:number] + 1,
"page[size]" => page[:size],
sort: params[:sort] }.compact.to_query
}.compact
options[:include] = @include
options[:is_collection] = true
options[:links] = nil
options[:links] = {
self: request.original_url,
next: @clients.blank? ? nil : request.base_url + "/data-centers?" + {
query: params[:query],
"member-id" => params[:member_id],
year: params[:year],
fields: params[:fields],
"page[number]" => page[:number] + 1,
"page[size]" => page[:size],
sort: params[:sort] }.compact.to_query
}.compact
options[:include] = @include
options[:is_collection] = true
options[:links] = nil

render json: DataCenterSerializer.new(@clients, options).serialized_json, status: :ok
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => exception
Bugsnag.notify(exception)

render json: DataCenterSerializer.new(@clients, options).serialized_json, status: :ok
message = JSON.parse(exception.message[6..-1]).to_h.dig("error", "root_cause", 0, "reason")

render json: { "errors" => { "title" => message }}.to_json, status: :bad_request
end
end

def show
Expand Down
Loading

0 comments on commit c8af853

Please sign in to comment.