supplejack_api 1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +80 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/supplejack_api/application.js +26 -0
- data/app/assets/stylesheets/supplejack_api/application.css +30 -0
- data/app/controllers/supplejack_api/admin/base_controller.rb +24 -0
- data/app/controllers/supplejack_api/admin/sessions_controller.rb +25 -0
- data/app/controllers/supplejack_api/admin/site_activities_controller.rb +21 -0
- data/app/controllers/supplejack_api/admin/users_controller.rb +55 -0
- data/app/controllers/supplejack_api/application_controller.rb +70 -0
- data/app/controllers/supplejack_api/concepts_controller.rb +52 -0
- data/app/controllers/supplejack_api/concerns/ignore_metrics.rb +14 -0
- data/app/controllers/supplejack_api/concerns/records_controller_metrics.rb +26 -0
- data/app/controllers/supplejack_api/concerns/set_items_controller_metrics.rb +20 -0
- data/app/controllers/supplejack_api/concerns/user_sets_controller_metrics.rb +26 -0
- data/app/controllers/supplejack_api/harvester/concepts_controller.rb +41 -0
- data/app/controllers/supplejack_api/harvester/fragments_controller.rb +30 -0
- data/app/controllers/supplejack_api/harvester/records_controller.rb +68 -0
- data/app/controllers/supplejack_api/metrics_api_controller.rb +44 -0
- data/app/controllers/supplejack_api/partners_controller.rb +39 -0
- data/app/controllers/supplejack_api/records_controller.rb +71 -0
- data/app/controllers/supplejack_api/schema_controller.rb +19 -0
- data/app/controllers/supplejack_api/set_items_controller.rb +38 -0
- data/app/controllers/supplejack_api/sources_controller.rb +67 -0
- data/app/controllers/supplejack_api/status_controller.rb +67 -0
- data/app/controllers/supplejack_api/user_sets_controller.rb +97 -0
- data/app/controllers/supplejack_api/users_controller.rb +49 -0
- data/app/helpers/supplejack_api/application_helper.rb +39 -0
- data/app/helpers/supplejack_api/facets_helper.rb +30 -0
- data/app/mailers/supplejack_api/request_limit_mailer.rb +43 -0
- data/app/models/supplejack_api/api_concept/concept_fragment.rb +31 -0
- data/app/models/supplejack_api/api_record/record_fragment.rb +15 -0
- data/app/models/supplejack_api/concept.rb +46 -0
- data/app/models/supplejack_api/concept_search.rb +86 -0
- data/app/models/supplejack_api/concerns/queryable_by_date.rb +31 -0
- data/app/models/supplejack_api/concerns/record.rb +108 -0
- data/app/models/supplejack_api/concerns/record_fragmentable.rb +24 -0
- data/app/models/supplejack_api/concerns/searchable.rb +430 -0
- data/app/models/supplejack_api/concerns/user_set.rb +219 -0
- data/app/models/supplejack_api/daily_metrics.rb +20 -0
- data/app/models/supplejack_api/faceted_metrics.rb +55 -0
- data/app/models/supplejack_api/fragment.rb +82 -0
- data/app/models/supplejack_api/interaction_models/record.rb +60 -0
- data/app/models/supplejack_api/interaction_models/set.rb +13 -0
- data/app/models/supplejack_api/interaction_updaters/all_usage_metric.rb +41 -0
- data/app/models/supplejack_api/interaction_updaters/set_metrics.rb +32 -0
- data/app/models/supplejack_api/interaction_updaters/usage_metrics.rb +73 -0
- data/app/models/supplejack_api/partner.rb +24 -0
- data/app/models/supplejack_api/preview_record.rb +30 -0
- data/app/models/supplejack_api/record.rb +18 -0
- data/app/models/supplejack_api/record_search.rb +12 -0
- data/app/models/supplejack_api/schema_definition.rb +147 -0
- data/app/models/supplejack_api/search.rb +14 -0
- data/app/models/supplejack_api/set_item.rb +57 -0
- data/app/models/supplejack_api/site_activity.rb +59 -0
- data/app/models/supplejack_api/source.rb +28 -0
- data/app/models/supplejack_api/source_activity.rb +36 -0
- data/app/models/supplejack_api/source_authority.rb +42 -0
- data/app/models/supplejack_api/supplejack_schema.rb +37 -0
- data/app/models/supplejack_api/support/concept/searchable.rb +79 -0
- data/app/models/supplejack_api/support/concept/storable.rb +59 -0
- data/app/models/supplejack_api/support/fragment_helpers.rb +96 -0
- data/app/models/supplejack_api/support/harvestable.rb +105 -0
- data/app/models/supplejack_api/support/searchable.rb +115 -0
- data/app/models/supplejack_api/support/status_logger.rb +23 -0
- data/app/models/supplejack_api/support/storable.rb +49 -0
- data/app/models/supplejack_api/support/validation_logger.rb +23 -0
- data/app/models/supplejack_api/usage_metrics.rb +25 -0
- data/app/models/supplejack_api/user.rb +211 -0
- data/app/models/supplejack_api/user_activity.rb +65 -0
- data/app/models/supplejack_api/user_set.rb +17 -0
- data/app/serializers/supplejack_api/application_serializer.rb +12 -0
- data/app/serializers/supplejack_api/concept_record_serializer.rb +23 -0
- data/app/serializers/supplejack_api/concept_search_serializer.rb +12 -0
- data/app/serializers/supplejack_api/concept_serializer.rb +100 -0
- data/app/serializers/supplejack_api/concerns/record_serializable.rb +119 -0
- data/app/serializers/supplejack_api/concerns/search_serializable.rb +24 -0
- data/app/serializers/supplejack_api/record_search_serializer.rb +64 -0
- data/app/serializers/supplejack_api/record_serializer.rb +13 -0
- data/app/serializers/supplejack_api/search_serializer.rb +13 -0
- data/app/serializers/supplejack_api/source_authority_serializer.rb +23 -0
- data/app/serializers/supplejack_api/user_serializer.rb +13 -0
- data/app/serializers/supplejack_api/user_set_record_serializer.rb +14 -0
- data/app/serializers/supplejack_api/user_set_serializer.rb +77 -0
- data/app/services/metrics_api/v3/api.rb +30 -0
- data/app/services/metrics_api/v3/endpoints/facets.rb +23 -0
- data/app/services/metrics_api/v3/endpoints/global.rb +26 -0
- data/app/services/metrics_api/v3/endpoints/helpers.rb +14 -0
- data/app/services/metrics_api/v3/endpoints/root.rb +97 -0
- data/app/services/metrics_api/v3/presenters/daily_metric.rb +23 -0
- data/app/services/metrics_api/v3/presenters/extended_metadata.rb +41 -0
- data/app/services/metrics_api/v3/presenters/record.rb +26 -0
- data/app/services/metrics_api/v3/presenters/view.rb +28 -0
- data/app/views/layouts/supplejack_api/_head.html.erb +17 -0
- data/app/views/layouts/supplejack_api/_top_nav.html.erb +33 -0
- data/app/views/layouts/supplejack_api/application.html.erb +33 -0
- data/app/views/supplejack_api/admin/sessions/new.html.erb +25 -0
- data/app/views/supplejack_api/admin/shared/_links.erb +34 -0
- data/app/views/supplejack_api/admin/site_activities/index.csv.erb +22 -0
- data/app/views/supplejack_api/admin/site_activities/index.html.erb +54 -0
- data/app/views/supplejack_api/admin/users/edit.html.erb +16 -0
- data/app/views/supplejack_api/admin/users/index.csv.erb +22 -0
- data/app/views/supplejack_api/admin/users/index.html.erb +57 -0
- data/app/views/supplejack_api/admin/users/show.html.erb +33 -0
- data/app/views/supplejack_api/request_limit_mailer/at100percent.text.erb +13 -0
- data/app/views/supplejack_api/request_limit_mailer/at100percent_admin.text.erb +1 -0
- data/app/views/supplejack_api/request_limit_mailer/at90percent.text.erb +13 -0
- data/app/views/supplejack_api/request_limit_mailer/at90percent_admin.text.erb +1 -0
- data/app/workers/supplejack_api/daily_metrics_worker.rb +112 -0
- data/app/workers/supplejack_api/interaction_metrics_worker.rb +45 -0
- data/config/cucumber.yml +16 -0
- data/config/initializers/force_eagerload.rb +11 -0
- data/config/initializers/interaction_updaters.rb +7 -0
- data/config/routes.rb +81 -0
- data/db/binding_records.development.json +7 -0
- data/db/binding_records.staging.json +7 -0
- data/db/concepts.json +33 -0
- data/db/concepts_data.json +569745 -0
- data/db/source_authorities.json +119 -0
- data/lib/generators/supplejack_api/install_generator.rb +124 -0
- data/lib/mongoid/paperclip.rb +53 -0
- data/lib/mongoid/string.rb +20 -0
- data/lib/sunspot/mongoid.rb +51 -0
- data/lib/sunspot/resque_session_proxy.rb +72 -0
- data/lib/sunspot/sunspot_spellcheck.rb +98 -0
- data/lib/supplejack_api.rb +13 -0
- data/lib/supplejack_api/admin/sortable.rb +40 -0
- data/lib/supplejack_api/engine.rb +46 -0
- data/lib/supplejack_api/harvester_constraint.rb +28 -0
- data/lib/supplejack_api/stylesheets.rb +36 -0
- data/lib/supplejack_api/utils.rb +75 -0
- data/lib/supplejack_api/version.rb +11 -0
- data/lib/tasks/resque.rake +22 -0
- data/lib/url_validator.rb +38 -0
- data/spec/controllers/supplejack_api/admin/base_controller_spec.rb +55 -0
- data/spec/controllers/supplejack_api/admin/site_activities_controller_spec.rb +43 -0
- data/spec/controllers/supplejack_api/admin/users_controller_spec.rb +79 -0
- data/spec/controllers/supplejack_api/application_controller_spec.rb +133 -0
- data/spec/controllers/supplejack_api/concepts_controller_spec.rb +83 -0
- data/spec/controllers/supplejack_api/concerns/records_controller_metrics_spec.rb +60 -0
- data/spec/controllers/supplejack_api/harvester/concepts_controller_spec.rb +57 -0
- data/spec/controllers/supplejack_api/harvester/records_controller_spec.rb +138 -0
- data/spec/controllers/supplejack_api/metrics_api_controller_spec.rb +71 -0
- data/spec/controllers/supplejack_api/partners_controller_spec.rb +77 -0
- data/spec/controllers/supplejack_api/records_controller_spec.rb +143 -0
- data/spec/controllers/supplejack_api/set_items_controller_spec.rb +78 -0
- data/spec/controllers/supplejack_api/sources_controller_spec.rb +161 -0
- data/spec/controllers/supplejack_api/status_controller_spec.rb +120 -0
- data/spec/controllers/supplejack_api/user_sets_controller_spec.rb +233 -0
- data/spec/controllers/supplejack_api/users_controller_spec.rb +61 -0
- data/spec/dummy/README.rdoc +268 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +23 -0
- data/spec/dummy/app/assets/stylesheets/application.css +22 -0
- data/spec/dummy/app/controllers/application_controller.rb +10 -0
- data/spec/dummy/app/helpers/application_helper.rb +9 -0
- data/spec/dummy/app/supplejack_api/concept_schema.rb +83 -0
- data/spec/dummy/app/supplejack_api/record_schema.rb +64 -0
- data/spec/dummy/app/supplejack_api/record_schema.txt +66 -0
- data/spec/dummy/app/views/layouts/application.html.erb +23 -0
- data/spec/dummy/app/workers/supplejack_api/clear_index_buffer.rb +32 -0
- data/spec/dummy/app/workers/supplejack_api/flush_old_records_worker.rb +17 -0
- data/spec/dummy/app/workers/supplejack_api/index_buffer.rb +49 -0
- data/spec/dummy/app/workers/supplejack_api/index_source_worker.rb +39 -0
- data/spec/dummy/app/workers/supplejack_api/index_worker.rb +82 -0
- data/spec/dummy/app/workers/supplejack_api/store_user_activity_worker.rb +24 -0
- data/spec/dummy/config.ru +11 -0
- data/spec/dummy/config/application.rb +76 -0
- data/spec/dummy/config/application.yml +31 -0
- data/spec/dummy/config/application.yml.example +36 -0
- data/spec/dummy/config/boot.rb +17 -0
- data/spec/dummy/config/environment.rb +12 -0
- data/spec/dummy/config/environments/development.rb +42 -0
- data/spec/dummy/config/environments/production.rb +76 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +14 -0
- data/spec/dummy/config/initializers/devise.rb +214 -0
- data/spec/dummy/config/initializers/inflections.rb +22 -0
- data/spec/dummy/config/initializers/kaminari_config.rb +17 -0
- data/spec/dummy/config/initializers/mime_types.rb +12 -0
- data/spec/dummy/config/initializers/mongoid.rb +9 -0
- data/spec/dummy/config/initializers/quiet_logger.rb +23 -0
- data/spec/dummy/config/initializers/resque.rb +18 -0
- data/spec/dummy/config/initializers/secret_token.rb +14 -0
- data/spec/dummy/config/initializers/session_store.rb +15 -0
- data/spec/dummy/config/initializers/simple_form.rb +149 -0
- data/spec/dummy/config/initializers/simple_form_foundation.rb +33 -0
- data/spec/dummy/config/initializers/state_machine.rb +8 -0
- data/spec/dummy/config/initializers/sunspot.rb +32 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
- data/spec/dummy/config/locales/devise.en.yml +63 -0
- data/spec/dummy/config/locales/en.yml +66 -0
- data/spec/dummy/config/locales/simple_form.en.yml +33 -0
- data/spec/dummy/config/mongoid.travis.yml +34 -0
- data/spec/dummy/config/mongoid.yml +36 -0
- data/spec/dummy/config/resque-pool.yml +18 -0
- data/spec/dummy/config/resque_schedule.yml +12 -0
- data/spec/dummy/config/routes.rb +11 -0
- data/spec/dummy/config/secrets.yml +8 -0
- data/spec/dummy/config/sunspot.yml +38 -0
- data/spec/dummy/db/concepts.json +37 -0
- data/spec/dummy/db/source_authorities.json +116 -0
- data/spec/dummy/public/404.html +35 -0
- data/spec/dummy/public/422.html +35 -0
- data/spec/dummy/public/500.html +34 -0
- data/spec/dummy/public/favicon.ico +8 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/solr/collection1/conf/elevate.xml +36 -0
- data/spec/dummy/solr/collection1/conf/mapping-FoldToASCII.txt +3813 -0
- data/spec/dummy/solr/collection1/conf/schema.xml +292 -0
- data/spec/dummy/solr/collection1/conf/solrconfig.xml +1780 -0
- data/spec/dummy/solr/collection1/conf/spellings.txt +2 -0
- data/spec/dummy/solr/collection1/conf/stopwords.txt +58 -0
- data/spec/dummy/solr/collection1/conf/synonyms.txt +31 -0
- data/spec/factories/concepts.rb +16 -0
- data/spec/factories/daily_metrics.rb +10 -0
- data/spec/factories/faceted_metrics.rb +25 -0
- data/spec/factories/fragment.rb +14 -0
- data/spec/factories/partners.rb +14 -0
- data/spec/factories/record_interaction.rb +17 -0
- data/spec/factories/records.rb +47 -0
- data/spec/factories/set_interaction.rb +15 -0
- data/spec/factories/source_authorities.rb +19 -0
- data/spec/factories/sources.rb +16 -0
- data/spec/factories/usage_metrics.rb +20 -0
- data/spec/factories/user_activities.rb +14 -0
- data/spec/factories/user_sets.rb +27 -0
- data/spec/factories/users.rb +23 -0
- data/spec/helpers/application_helper_spec.rb +35 -0
- data/spec/models/concept_spec.rb +163 -0
- data/spec/models/fragment_spec.rb +15 -0
- data/spec/models/site_activity_spec.rb +103 -0
- data/spec/models/source_activity_spec.rb +56 -0
- data/spec/models/source_authority_spec.rb +42 -0
- data/spec/models/supplejack_api/api_concept/concept_fragment_spec.rb +189 -0
- data/spec/models/supplejack_api/api_record/record_fragment_spec.rb +189 -0
- data/spec/models/supplejack_api/concept_spec.rb +0 -0
- data/spec/models/supplejack_api/interaction_updaters/all_usage_metric_spec.rb +41 -0
- data/spec/models/supplejack_api/interaction_updaters/set_metrics_spec.rb +32 -0
- data/spec/models/supplejack_api/interaction_updaters/usage_metrics_spec.rb +44 -0
- data/spec/models/supplejack_api/partner_spec.rb +20 -0
- data/spec/models/supplejack_api/record_search_spec.rb +429 -0
- data/spec/models/supplejack_api/record_spec.rb +280 -0
- data/spec/models/supplejack_api/schema_definition_spec.rb +272 -0
- data/spec/models/supplejack_api/search_spec.rb +243 -0
- data/spec/models/supplejack_api/set_item_spec.rb +123 -0
- data/spec/models/supplejack_api/source_spec.rb +22 -0
- data/spec/models/supplejack_api/support/fragment_helpers_spec.rb +216 -0
- data/spec/models/supplejack_api/support/harvestable_spec.rb +177 -0
- data/spec/models/supplejack_api/support/searchable_spec.rb +85 -0
- data/spec/models/supplejack_api/support/storable_spec.rb +18 -0
- data/spec/models/supplejack_api/user_activity_spec.rb +88 -0
- data/spec/models/supplejack_api/user_set_spec.rb +559 -0
- data/spec/models/supplejack_api/user_spec.rb +348 -0
- data/spec/routing/concepts_routing_spec.rb +22 -0
- data/spec/routing/harvester_constraint_spec.rb +66 -0
- data/spec/routing/harvester_routing_spec.rb +51 -0
- data/spec/routing/partner_routing_spec.rb +34 -0
- data/spec/routing/records_routing_spec.rb +26 -0
- data/spec/routing/sets_routing_spec.rb +44 -0
- data/spec/routing/source_routing_spec.rb +38 -0
- data/spec/routing/users_routing_spec.rb +18 -0
- data/spec/serializers/concept_record_serializer_spec.rb +30 -0
- data/spec/serializers/supplejack_api/application_serializer_spec.rb +14 -0
- data/spec/serializers/supplejack_api/concept_search_serializer_spec.rb +34 -0
- data/spec/serializers/supplejack_api/concept_serializer_spec.rb +92 -0
- data/spec/serializers/supplejack_api/record_search_serializer_spec.rb +34 -0
- data/spec/serializers/supplejack_api/record_serializer_spec.rb +271 -0
- data/spec/serializers/supplejack_api/search_serializer_spec.rb +90 -0
- data/spec/serializers/supplejack_api/user_serializer_spec.rb +22 -0
- data/spec/serializers/supplejack_api/user_set_serializer_spec.rb +96 -0
- data/spec/services/metrics_api/v3/api_spec.rb +23 -0
- data/spec/services/metrics_api/v3/endpoints/facets_spec.rb +25 -0
- data/spec/services/metrics_api/v3/endpoints/global_spec.rb +22 -0
- data/spec/services/metrics_api/v3/endpoints/root_spec.rb +49 -0
- data/spec/services/metrics_api/v3/presenters/extended_metadata_spec.rb +49 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/support/api/schemas/metrics/daily_metrics_metadata.json +24 -0
- data/spec/support/api/schemas/metrics/extended_metrics.json +26 -0
- data/spec/support/api/schemas/metrics/extended_response.json +6 -0
- data/spec/support/api/schemas/metrics/facets_response.json +6 -0
- data/spec/support/api/schemas/metrics/record_metadata.json +33 -0
- data/spec/support/api/schemas/metrics/top_level_response.json +6 -0
- data/spec/support/api/schemas/metrics/view_metadata.json +33 -0
- data/spec/support/api_schema_matcher.rb +14 -0
- data/spec/support/devise.rb +10 -0
- data/spec/workers/supplejack_api/daily_metrics_worker_spec.rb +140 -0
- data/spec/workers/supplejack_api/flush_old_records_worker_spec.rb +20 -0
- data/spec/workers/supplejack_api/index_worker_spec.rb +52 -0
- data/spec/workers/supplejack_api/source_index_worker_spec.rb +61 -0
- metadata +1231 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
class SourcesController < ActionController::Base
|
11
|
+
respond_to :json
|
12
|
+
|
13
|
+
def create
|
14
|
+
params[:source][:partner_id] = params[:partner_id]
|
15
|
+
if params[:source][:_id].present?
|
16
|
+
@source = Source.find_or_initialize_by(_id: params[:source][:_id])
|
17
|
+
@source.update_attributes(params[:source])
|
18
|
+
else
|
19
|
+
@source = Source.create(params[:source])
|
20
|
+
end
|
21
|
+
|
22
|
+
render json: @source
|
23
|
+
end
|
24
|
+
|
25
|
+
def index
|
26
|
+
@sources = params[:source].nil? ? Source.all : Source.where(params[:source])
|
27
|
+
render json: @sources
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
@source = Source.find(params[:id])
|
32
|
+
render json: @source
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@source = Source.find(params[:id])
|
37
|
+
@source.update_attributes(params[:source])
|
38
|
+
render json: @source
|
39
|
+
end
|
40
|
+
|
41
|
+
def reindex
|
42
|
+
@source = Source.find(params[:id])
|
43
|
+
Resque.enqueue(IndexSourceWorker, @source.source_id, params[:date])
|
44
|
+
|
45
|
+
render nothing: true
|
46
|
+
end
|
47
|
+
|
48
|
+
def link_check_records
|
49
|
+
@source = Source.find(params[:id])
|
50
|
+
@records = []
|
51
|
+
|
52
|
+
@records += first_two_records(@source.source_id, :oldest).map(&:source_url)
|
53
|
+
@records += first_two_records(@source.source_id, :latest).map(&:source_url)
|
54
|
+
|
55
|
+
render json: @records.to_json
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def first_two_records(source_id, direction)
|
61
|
+
sort = direction == :latest ? -1 : 1
|
62
|
+
records = Record.where('fragments.source_id' => source_id, :status => 'active')
|
63
|
+
.sort('fragments.syndication_date' => sort)
|
64
|
+
records.limit(2).to_a
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
# rubocop:disable Metrics/LineLength
|
11
|
+
# FIXME: make log lines smaller
|
12
|
+
class StatusController < ApplicationController
|
13
|
+
skip_before_filter :authenticate_user!, only: [:show]
|
14
|
+
skip_before_filter :verify_limits!, only: [:show]
|
15
|
+
around_filter :handle_timeout, only: :show
|
16
|
+
|
17
|
+
newrelic_ignore if defined? NewRelic
|
18
|
+
|
19
|
+
TIMEOUT = 10.seconds
|
20
|
+
|
21
|
+
def show
|
22
|
+
both_ok = Timeout.timeout(TIMEOUT) do
|
23
|
+
solr_ok = solr_up?
|
24
|
+
mongo_ok = mongod_up?
|
25
|
+
solr_ok && mongo_ok
|
26
|
+
end
|
27
|
+
|
28
|
+
if both_ok
|
29
|
+
render status: 200, nothing: true
|
30
|
+
else
|
31
|
+
render status: 500, nothing: true
|
32
|
+
end
|
33
|
+
rescue Timeout::Error => e
|
34
|
+
Support::StatusLogger.logger.error("Solr or MongoDB is down or took longer than #{TIMEOUT} seconds to respond. Exception is #{e}.\nBacktrace #{e.backtrace[0..2].join("\n")}")
|
35
|
+
|
36
|
+
render status: 500, nothing: true
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def handle_timeout
|
42
|
+
time = Benchmark.ms { yield }
|
43
|
+
Support::StatusLogger.logger.warn("/status request took #{time.round}ms to complete") if time > 5000
|
44
|
+
end
|
45
|
+
|
46
|
+
def solr_up?
|
47
|
+
resource = RestClient.get ENV['SOLR_PING'], open_timeout: 5
|
48
|
+
success = Hash.from_xml(resource)['response']['str'] == 'OK'
|
49
|
+
Support::StatusLogger.logger.error("Solr ping command not successful. Ping output: #{Hash.from_xml(resource)['response']}") unless success
|
50
|
+
success
|
51
|
+
rescue StandardError => e
|
52
|
+
Support::StatusLogger.logger.error("Exception when attempting to ping Solr. Exception is #{e}.\nBacktrace #{e.backtrace[0..2].join("\n")}")
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def mongod_up?
|
57
|
+
session = Record.collection.database.session
|
58
|
+
success = session.command(ping: 1)['ok'] == 1
|
59
|
+
Support::StatusLogger.logger.error("MongoDB ping command not successful. Ping output: #{session.command(ping: 1)}") unless success
|
60
|
+
success
|
61
|
+
rescue StandardError => e
|
62
|
+
Support::StatusLogger.logger.error("Exception when attempting to ping MongoDB. Exception is #{e}.\nBacktrace #{e.backtrace[0..2].join("\n")}")
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
# rubocop:enable Metrics/LineLength
|
67
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
class UserSetsController < ApplicationController
|
11
|
+
include Concerns::UserSetsControllerMetrics
|
12
|
+
|
13
|
+
respond_to :json
|
14
|
+
|
15
|
+
prepend_before_filter :find_user_set, only: [:update, :destroy]
|
16
|
+
before_filter :authenticate_admin!, only: [:admin_index, :public_index]
|
17
|
+
|
18
|
+
def index
|
19
|
+
@user_sets = current_user.user_sets
|
20
|
+
render json: serializable_array(@user_sets).to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
# Endpoint for the administrator to get a list of sets for any user.
|
24
|
+
#
|
25
|
+
def admin_index
|
26
|
+
@user = User.find_by_api_key(params[:user_id])
|
27
|
+
|
28
|
+
if @user
|
29
|
+
@user_sets = @user.user_sets
|
30
|
+
render json: serializable_array(@user_sets).to_json
|
31
|
+
else
|
32
|
+
render json: { errors: "The user with api key: '#{params[:user_id]}' was not found" }, status: :not_found
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Enpoint for the administrator to fetch a list of all public sets
|
37
|
+
#
|
38
|
+
def public_index
|
39
|
+
@user_sets = UserSet.public_sets(page: params[:page])
|
40
|
+
render json: serializable_array(@user_sets, user: true, total: true).to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
def featured_sets_index
|
44
|
+
@user_sets = UserSet.featured_sets(4)
|
45
|
+
render json: serializable_array(@user_sets, user: true, featured: true).to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
def show
|
49
|
+
@user_set = UserSet.custom_find(params[:id])
|
50
|
+
if @user_set
|
51
|
+
render json: UserSetSerializer.new(@user_set, user: current_user)
|
52
|
+
else
|
53
|
+
render json: { errors: "Set with id: #{params[:id]} was not found." }, status: :not_found
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create
|
58
|
+
@user_set = current_user.user_sets.build
|
59
|
+
if @user_set.update_attributes_and_embedded(params[:set])
|
60
|
+
render json: UserSetSerializer.new(@user_set, user: true)
|
61
|
+
else
|
62
|
+
render json: { errors: @user_set.errors.to_hash }, status: :unprocessable_entity
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def update
|
67
|
+
if @user_set.update_attributes_and_embedded(params[:set], current_user)
|
68
|
+
render json: UserSetSerializer.new(@user_set, user: true)
|
69
|
+
else
|
70
|
+
render json: { errors: @user_set.errors.to_hash }, status: :unprocessable_entity
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def destroy
|
75
|
+
@user_set.destroy
|
76
|
+
respond_with(@user_set)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def serializable_array(user_sets, options = {})
|
82
|
+
options.reverse_merge!(root: false, items: false, user: false, total: false)
|
83
|
+
hash = { 'sets' => [] }
|
84
|
+
user_sets.each do |set|
|
85
|
+
hash['sets'] << UserSetSerializer.new(set, options).as_json
|
86
|
+
end
|
87
|
+
hash['total'] = UserSet.public_sets_count if options[:total]
|
88
|
+
hash
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue_from UserSet::WrongRecordsFormat do |_exception|
|
92
|
+
render json: {
|
93
|
+
errors: { records: ['The records array is not in a valid format.'] }
|
94
|
+
}, status: :unprocessable_entity
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
class UsersController < ApplicationController
|
11
|
+
respond_to :xml, :json
|
12
|
+
before_filter :authenticate_admin!, except: :show
|
13
|
+
|
14
|
+
def show
|
15
|
+
@user = User.custom_find(params[:id])
|
16
|
+
respond_with @user, serializer: UserSerializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
@user = User.create(user_params)
|
21
|
+
respond_with @user, location: user_url(@user), serializer: UserSerializer
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
@user = User.custom_find(params[:id])
|
26
|
+
@user.update_attributes(user_params)
|
27
|
+
render json: @user, serializer: UserSerializer
|
28
|
+
end
|
29
|
+
|
30
|
+
def destroy
|
31
|
+
@user = User.custom_find(params[:id])
|
32
|
+
@user.destroy
|
33
|
+
respond_with @user
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def user_params
|
39
|
+
params.require(:user).permit(
|
40
|
+
:name,
|
41
|
+
:username,
|
42
|
+
:email,
|
43
|
+
:encrypted_password,
|
44
|
+
:authentication_token,
|
45
|
+
sets: [:name, :privacy, :priority]
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
module ApplicationHelper
|
11
|
+
def flash_messages
|
12
|
+
return nil if flash.empty?
|
13
|
+
|
14
|
+
flash.map do |type, message|
|
15
|
+
type = :success if type.to_s == 'notice'
|
16
|
+
content_tag(:div, message, class: "alert-box #{type} margin-top")
|
17
|
+
end.join.html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
def sortable(klass, column)
|
21
|
+
path = "admin_#{klass.to_s.tableize}_path"
|
22
|
+
sort_column, sort_direction = extract_sort_info
|
23
|
+
direction = column == sort_column && sort_direction == 'asc' ? 'desc' : 'asc'
|
24
|
+
css_class = column == sort_column ? "current #{sort_direction}" : nil
|
25
|
+
|
26
|
+
label = safe_join([t("#{klass.to_s.tableize}.#{column}", default: column.titleize), content_tag(:span)])
|
27
|
+
link_to label, send(path, order: "#{column}_#{direction}"), class: css_class
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_sort_info
|
31
|
+
return unless params[:order].to_s =~ /^([\w\_\.]+)_(desc|asc)$/
|
32
|
+
|
33
|
+
@sort_column = Regexp.last_match(1)
|
34
|
+
@sort_direction = Regexp.last_match(2)
|
35
|
+
|
36
|
+
[@sort_column, @sort_direction]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module SupplejackApi
|
3
|
+
module FacetsHelper
|
4
|
+
# Given a facet key, returns list of facets under that key
|
5
|
+
#
|
6
|
+
# @parameter facet_key [String] facet to retrieve all values of
|
7
|
+
# @returns [Array<String>] all values for this facet
|
8
|
+
def get_list_of_facet_values(facet_key)
|
9
|
+
facets_list = []
|
10
|
+
facets_page = 1
|
11
|
+
|
12
|
+
loop do
|
13
|
+
s = RecordSearch.new(facets: facet_key, facets_per_page: 150, facets_page: facets_page)
|
14
|
+
# HACK: We override SearchSerializable#facets_list in the api_app to
|
15
|
+
# replace :display_collection with :primary_collection, this transparently fixes it
|
16
|
+
mappings = { primary_collection: :display_collection }
|
17
|
+
facets = Hash[s.facets_hash.map { |k, v| [mappings[k] || k, v] }][facet_key.to_sym]
|
18
|
+
|
19
|
+
# Gone past last page of facets
|
20
|
+
break if facets.length.zero?
|
21
|
+
|
22
|
+
facets_list << facets.keys
|
23
|
+
facets_page += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
facets_list.flatten
|
27
|
+
end
|
28
|
+
module_function :get_list_of_facet_values
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
class RequestLimitMailer < ActionMailer::Base
|
11
|
+
default from: ENV['REQUEST_LIMIT_MAILER']
|
12
|
+
|
13
|
+
def at90percent(user)
|
14
|
+
@limit = user.max_requests
|
15
|
+
|
16
|
+
mail(to: [user.email].join(', '),
|
17
|
+
subject: 'Your API key has exceeded 90% of its daily limit')
|
18
|
+
end
|
19
|
+
|
20
|
+
def at100percent(user)
|
21
|
+
@limit = user.max_requests
|
22
|
+
|
23
|
+
mail(to: [user.email].join(', '),
|
24
|
+
subject: 'Your API key exceeded its daily limit')
|
25
|
+
end
|
26
|
+
|
27
|
+
def at90percent_admin(user)
|
28
|
+
@limit = user.max_requests
|
29
|
+
@email = user.email
|
30
|
+
|
31
|
+
mail(to: ENV['REQUEST_LIMIT_MAILER'],
|
32
|
+
subject: 'A API key has exceeded 90% of its daily limit')
|
33
|
+
end
|
34
|
+
|
35
|
+
def at100percent_admin(user)
|
36
|
+
@limit = user.max_requests
|
37
|
+
@email = user.email
|
38
|
+
|
39
|
+
mail(to: ENV['REQUEST_LIMIT_MAILER'],
|
40
|
+
subject: 'A API key exceeded its daily limit')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
module ApiConcept
|
11
|
+
class ConceptFragment < SupplejackApi::Fragment
|
12
|
+
embedded_in :concept
|
13
|
+
|
14
|
+
delegate :concept_id, to: :concept
|
15
|
+
|
16
|
+
def self.schema_class
|
17
|
+
ConceptSchema
|
18
|
+
end
|
19
|
+
|
20
|
+
build_mongoid_schema
|
21
|
+
|
22
|
+
def self.mutable_fields
|
23
|
+
@@mutable_fields ||= begin
|
24
|
+
immutable_fields = %w(_id _type source_id created_at updated_at)
|
25
|
+
mutable_fields = fields.keys - immutable_fields
|
26
|
+
Hash[mutable_fields.map { |name| [name, fields[name].type] }]
|
27
|
+
end.freeze
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
3
|
+
# and is licensed under the GNU General Public License, version 3.
|
4
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
5
|
+
#
|
6
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
7
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
8
|
+
|
9
|
+
module SupplejackApi
|
10
|
+
module ApiRecord
|
11
|
+
class RecordFragment < SupplejackApi::Fragment
|
12
|
+
include SupplejackApi::Concerns::RecordFragmentable
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|