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,24 @@
|
|
1
|
+
{
|
2
|
+
"description": "Contains metrics about a day, metrics that do not fall into a specific subcategory",
|
3
|
+
"type": "object",
|
4
|
+
"required": [
|
5
|
+
"day",
|
6
|
+
"total_active_records",
|
7
|
+
"total_new_records"
|
8
|
+
],
|
9
|
+
"properties": {
|
10
|
+
"day": {
|
11
|
+
"description": "Day this metadata refers to",
|
12
|
+
"type": "string",
|
13
|
+
"format": "date"
|
14
|
+
},
|
15
|
+
"total_active_records": {
|
16
|
+
"description": "Number of active records in the system on this date",
|
17
|
+
"type": "number"
|
18
|
+
},
|
19
|
+
"total_new_records": {
|
20
|
+
"description": "Number of records harvested on this date",
|
21
|
+
"type": "number"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
{
|
2
|
+
"description": "container object for all extended metrics objects",
|
3
|
+
"type": "object",
|
4
|
+
"required": ["date"],
|
5
|
+
"properties": {
|
6
|
+
"date": {
|
7
|
+
"description": "dayDate this metric represents",
|
8
|
+
"type": "string",
|
9
|
+
"format": "date"
|
10
|
+
},
|
11
|
+
"record": {
|
12
|
+
"description": "Record metadata metric",
|
13
|
+
"type": "array",
|
14
|
+
"items": {
|
15
|
+
"$ref": "record_metadata.json"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
"view": {
|
19
|
+
"description": "Record view metadata metric",
|
20
|
+
"type": "array",
|
21
|
+
"items": {
|
22
|
+
"$ref": "view_metadata.json"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"description": "Contains metadata about the records grouped by a facet on a specific day",
|
3
|
+
"type": "object",
|
4
|
+
"required": [
|
5
|
+
"id",
|
6
|
+
"total_active_records",
|
7
|
+
"total_new_records",
|
8
|
+
"category_counts",
|
9
|
+
"copyright_counts"
|
10
|
+
],
|
11
|
+
"properties": {
|
12
|
+
"id": {
|
13
|
+
"description": "Facet name",
|
14
|
+
"type": "string"
|
15
|
+
},
|
16
|
+
"total_active_records": {
|
17
|
+
"description": "Number of active records for this facet",
|
18
|
+
"type": "number"
|
19
|
+
},
|
20
|
+
"total_new_records": {
|
21
|
+
"description": "Number of new records for this facet",
|
22
|
+
"type": "number"
|
23
|
+
},
|
24
|
+
"category_counts": {
|
25
|
+
"description": "Mapping of categories to counts, object shape is dynamic so it has no schema",
|
26
|
+
"type": "object"
|
27
|
+
},
|
28
|
+
"copyright_counts": {
|
29
|
+
"description": "Mapping of copyrights to counts, object shape is dynamic so it has no schema",
|
30
|
+
"type": "object"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
{
|
2
|
+
"description": "Contains metadata about how records in a display_collection were viewed on a specific day",
|
3
|
+
"type": "object",
|
4
|
+
"required": [
|
5
|
+
"id",
|
6
|
+
"searches",
|
7
|
+
"record_page_views",
|
8
|
+
"user_set_views",
|
9
|
+
"total_views"
|
10
|
+
],
|
11
|
+
"properties": {
|
12
|
+
"id": {
|
13
|
+
"description": "Facet name",
|
14
|
+
"type": "string"
|
15
|
+
},
|
16
|
+
"searches": {
|
17
|
+
"description": "Number of times a record from this collection was part of a search result",
|
18
|
+
"type": "number"
|
19
|
+
},
|
20
|
+
"record_page_views": {
|
21
|
+
"description": "Number of times a record page for a record from this collection was viewed",
|
22
|
+
"type": "number"
|
23
|
+
},
|
24
|
+
"user_set_views": {
|
25
|
+
"description": "Number of times a record from this collection was viewed in a user set",
|
26
|
+
"type": "number"
|
27
|
+
},
|
28
|
+
"total_views": {
|
29
|
+
"description": "Cumulative count of all record views for this collection",
|
30
|
+
"type": "number"
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'json-schema'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :match_response_schema do |schema|
|
4
|
+
match do |json|
|
5
|
+
schema_directory = "#{Dir.pwd}/spec/support/api/schemas"
|
6
|
+
schema_path = "#{schema_directory}/#{schema}.json"
|
7
|
+
|
8
|
+
errors = JSON::Validator.fully_validate(schema_path, json)
|
9
|
+
|
10
|
+
fail Exception.new(errors.join(' ----- ')) unless errors.empty?
|
11
|
+
|
12
|
+
true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include Devise::TestHelpers, type: :controller
|
10
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe DailyMetricsWorker, search: true, slow: true do
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
Sunspot.session = Sunspot.session.original_session
|
15
|
+
end
|
16
|
+
|
17
|
+
after :each do
|
18
|
+
Sunspot.remove_all
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#call" do
|
22
|
+
def build_records
|
23
|
+
10.times do
|
24
|
+
create(:record_with_fragment, display_collection: 'pc1', copyright: ['0'], category: ['0'], created_at: Date.current.midday)
|
25
|
+
create(:record_with_fragment, display_collection: 'pc2', copyright: ['1'], category: ['1'], created_at: Date.current.midday)
|
26
|
+
create(:record_with_fragment, display_collection: 'pc1', copyright: ['0', '1'], category: ['0', '1'], created_at: Date.yesterday.midday)
|
27
|
+
end
|
28
|
+
|
29
|
+
Sunspot.commit
|
30
|
+
end
|
31
|
+
|
32
|
+
def facet_metrics_query(result, expected_results, &accessor_block)
|
33
|
+
result.each_with_index do |facet, index|
|
34
|
+
expect(accessor_block.call(facet, index)).to eq(expected_results[index])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "handles records with missing categories/copyrights" do
|
39
|
+
10.times do |n|
|
40
|
+
c = n % 2 == 0 ? nil : ['0']
|
41
|
+
create(:record_with_fragment, created_at: Date.current.midday, copyright: c)
|
42
|
+
end
|
43
|
+
Sunspot.commit
|
44
|
+
|
45
|
+
DailyMetricsWorker.new.call
|
46
|
+
facet = SupplejackApi::FacetedMetrics.where(name: 'all').first
|
47
|
+
|
48
|
+
expect(facet.total_active_records).to eq(10)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "handles copyrights with periods in the name" do
|
52
|
+
create(:record_with_fragment, copyright: ['1.0'], display_collection: 'test')
|
53
|
+
Sunspot.commit
|
54
|
+
|
55
|
+
DailyMetricsWorker.new.call
|
56
|
+
expect(FacetedMetrics.created_on(Date.current).first.copyright_counts.first.first).to eq("1.0")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "correctly paginates the facet list when there are more than 150 facets" do
|
60
|
+
200.times do |n|
|
61
|
+
create(:record_with_fragment, display_collection: n.to_s)
|
62
|
+
end
|
63
|
+
Sunspot.commit
|
64
|
+
|
65
|
+
DailyMetricsWorker.new.call
|
66
|
+
|
67
|
+
expect(FacetedMetrics.count).to eq(201)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "faceted metrics" do
|
71
|
+
before do
|
72
|
+
create(:record_with_fragment, status: "deleted") # inactive, should never show in counts
|
73
|
+
build_records
|
74
|
+
|
75
|
+
DailyMetricsWorker.new.call
|
76
|
+
end
|
77
|
+
let(:faceted_metrics) {SupplejackApi::FacetedMetrics.all.where(:name.ne => 'all').to_a}
|
78
|
+
|
79
|
+
it "has metrics for each facet" do
|
80
|
+
expect(faceted_metrics.length).to eq(2)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "has active record counts for each facet" do
|
84
|
+
facet_metrics_query(faceted_metrics, [20, 10]) {|facet| facet.total_active_records}
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has new record counts for each display_collection" do
|
88
|
+
facet_metrics_query(faceted_metrics, [10, 10]) {|facet| facet.total_new_records}
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has a count of records per category in each display_collection" do
|
92
|
+
facet_metrics_query(faceted_metrics, [20, 10]) {|facet, index| facet.category_counts[index.to_s]}
|
93
|
+
end
|
94
|
+
|
95
|
+
it "has a count of records per usage type in each display_collection" do
|
96
|
+
facet_metrics_query(faceted_metrics, [20, 10]) {|facet, index| facet.copyright_counts[index.to_s]}
|
97
|
+
end
|
98
|
+
|
99
|
+
it "creates an All facet that contains the summed metrics of for all the individual facets" do
|
100
|
+
all_metric = SupplejackApi::FacetedMetrics.where(name: 'all').first
|
101
|
+
|
102
|
+
expect(all_metric.total_active_records).to eq(30)
|
103
|
+
expect(all_metric.total_new_records).to eq(20)
|
104
|
+
expect(all_metric.copyright_counts['0']).to eq(20)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "daily metrics" do
|
109
|
+
let(:metric) do
|
110
|
+
# Lazy generate metrics
|
111
|
+
DailyMetricsWorker.new.call
|
112
|
+
|
113
|
+
SupplejackApi::DailyMetrics.first
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'creates a DailyMetrics model' do
|
117
|
+
expect(metric).to be_present
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'sets the date field to the current day' do
|
121
|
+
expect(metric.date).to eq(Date.current)
|
122
|
+
end
|
123
|
+
|
124
|
+
context "set metrics" do
|
125
|
+
it 'counts the number of sets in the system' do
|
126
|
+
create(:user_set)
|
127
|
+
|
128
|
+
expect(metric.total_public_sets).to eq(1)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'does not count non-public sets' do
|
132
|
+
create(:user_set, privacy: 'private')
|
133
|
+
|
134
|
+
expect(metric.total_public_sets).to eq(0)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe FlushOldRecordsWorker do
|
12
|
+
|
13
|
+
describe "perform" do
|
14
|
+
it "should call 'flush_old_records' on Record with the given source_id & job_id" do
|
15
|
+
expect(Record).to receive(:flush_old_records).with("abc-123", "abc123")
|
16
|
+
FlushOldRecordsWorker.perform("abc-123", "abc123")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe IndexWorker do
|
12
|
+
|
13
|
+
describe "#find_all" do
|
14
|
+
let(:record1) { FactoryGirl.create(:record, record_id: 12345) }
|
15
|
+
let(:record2) { FactoryGirl.create(:record, record_id: 67890) }
|
16
|
+
|
17
|
+
it "finds all records by id" do
|
18
|
+
expect(IndexWorker.find_all("Record", [record1.id, record2.id])).to eq [record1, record2]
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns records even when some where not found" do
|
22
|
+
expect(IndexWorker.find_all("Record", ["504d333aa9b6ad1860000056", record1.id])).to eq [record1]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "handles individual records" do
|
26
|
+
expect(IndexWorker.find_all("Record", record1.id)).to eq [record1]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "perform" do
|
31
|
+
let(:record) { double(:record).as_null_object }
|
32
|
+
|
33
|
+
it "indexes all given record id's" do
|
34
|
+
expect(IndexWorker).to receive(:find_all).with("Record", ["123"]) { [record] }
|
35
|
+
expect(IndexWorker).to receive(:index).with([record])
|
36
|
+
IndexWorker.perform(:index, {class: "Record", id: ["123"]})
|
37
|
+
end
|
38
|
+
|
39
|
+
it "removes all given record id's" do
|
40
|
+
expect(IndexWorker).to receive(:find_all).with("Record", ["123"]) { [record] }
|
41
|
+
expect(IndexWorker).to receive(:remove).with([record])
|
42
|
+
IndexWorker.perform(:remove, {class: "Record", id: ["123"]})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "rescues from a RSolr::Error::Http errors when commiting SOLR" do
|
46
|
+
allow(Sunspot).to receive(:commit).and_raise(RSolr::Error::Http.new({}, {}))
|
47
|
+
IndexWorker.perform(:commit)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe IndexSourceWorker do
|
12
|
+
describe ".perform" do
|
13
|
+
let(:records) { [FactoryGirl.create(:record_with_fragment), FactoryGirl.create(:record_with_fragment)] }
|
14
|
+
|
15
|
+
before do
|
16
|
+
records.each do |r|
|
17
|
+
r.primary_fragment.source_id = 'tapuhi'
|
18
|
+
r.save
|
19
|
+
end
|
20
|
+
|
21
|
+
allow(Record).to receive(:where).with(hash_including(:'fragments.source_id' => 'tapuhi')).and_call_original
|
22
|
+
end
|
23
|
+
|
24
|
+
it "finds all active records and indexes them" do
|
25
|
+
expect(Record).to receive(:where).with(:'fragments.source_id' => 'tapuhi').and_call_original
|
26
|
+
expect(Sunspot).to receive(:index).with(records)
|
27
|
+
IndexSourceWorker.perform('tapuhi')
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it "finds all deleted records and removes them from solr" do
|
32
|
+
records.each { |r| r.update_attribute(:status, 'deleted') }
|
33
|
+
|
34
|
+
expect(Record).to receive(:where).with(:'fragments.source_id' => 'tapuhi').and_call_original
|
35
|
+
expect(Sunspot).to receive(:remove).with(records)
|
36
|
+
IndexSourceWorker.perform('tapuhi')
|
37
|
+
end
|
38
|
+
|
39
|
+
it "finds records updated more recently than the date given" do
|
40
|
+
date = Time.now
|
41
|
+
allow(Time).to receive(:parse) { date }
|
42
|
+
expect(Record).to receive(:where).with(:'fragments.source_id' => 'tapuhi', :updated_at.gt => date)
|
43
|
+
IndexSourceWorker.perform('tapuhi', date.to_s)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".in_chunks" do
|
48
|
+
let(:records) { [double(:record), double(:record)] }
|
49
|
+
|
50
|
+
it "gets a chunk of records and yields to block" do
|
51
|
+
mock_cursor = double(:cursor)
|
52
|
+
mock_cursor_2 = double(:cursor)
|
53
|
+
expect(mock_cursor).to receive(:limit).with(10000) {mock_cursor_2}
|
54
|
+
expect(mock_cursor).to receive(:count) {2}
|
55
|
+
expect(mock_cursor_2).to receive(:skip).with(0) { records }
|
56
|
+
|
57
|
+
expect{|b| IndexSourceWorker.in_chunks(mock_cursor, &b) }.to yield_with_args(records)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|