supplejack_api 1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +80 -0
  3. data/Rakefile +42 -0
  4. data/app/assets/javascripts/supplejack_api/application.js +26 -0
  5. data/app/assets/stylesheets/supplejack_api/application.css +30 -0
  6. data/app/controllers/supplejack_api/admin/base_controller.rb +24 -0
  7. data/app/controllers/supplejack_api/admin/sessions_controller.rb +25 -0
  8. data/app/controllers/supplejack_api/admin/site_activities_controller.rb +21 -0
  9. data/app/controllers/supplejack_api/admin/users_controller.rb +55 -0
  10. data/app/controllers/supplejack_api/application_controller.rb +70 -0
  11. data/app/controllers/supplejack_api/concepts_controller.rb +52 -0
  12. data/app/controllers/supplejack_api/concerns/ignore_metrics.rb +14 -0
  13. data/app/controllers/supplejack_api/concerns/records_controller_metrics.rb +26 -0
  14. data/app/controllers/supplejack_api/concerns/set_items_controller_metrics.rb +20 -0
  15. data/app/controllers/supplejack_api/concerns/user_sets_controller_metrics.rb +26 -0
  16. data/app/controllers/supplejack_api/harvester/concepts_controller.rb +41 -0
  17. data/app/controllers/supplejack_api/harvester/fragments_controller.rb +30 -0
  18. data/app/controllers/supplejack_api/harvester/records_controller.rb +68 -0
  19. data/app/controllers/supplejack_api/metrics_api_controller.rb +44 -0
  20. data/app/controllers/supplejack_api/partners_controller.rb +39 -0
  21. data/app/controllers/supplejack_api/records_controller.rb +71 -0
  22. data/app/controllers/supplejack_api/schema_controller.rb +19 -0
  23. data/app/controllers/supplejack_api/set_items_controller.rb +38 -0
  24. data/app/controllers/supplejack_api/sources_controller.rb +67 -0
  25. data/app/controllers/supplejack_api/status_controller.rb +67 -0
  26. data/app/controllers/supplejack_api/user_sets_controller.rb +97 -0
  27. data/app/controllers/supplejack_api/users_controller.rb +49 -0
  28. data/app/helpers/supplejack_api/application_helper.rb +39 -0
  29. data/app/helpers/supplejack_api/facets_helper.rb +30 -0
  30. data/app/mailers/supplejack_api/request_limit_mailer.rb +43 -0
  31. data/app/models/supplejack_api/api_concept/concept_fragment.rb +31 -0
  32. data/app/models/supplejack_api/api_record/record_fragment.rb +15 -0
  33. data/app/models/supplejack_api/concept.rb +46 -0
  34. data/app/models/supplejack_api/concept_search.rb +86 -0
  35. data/app/models/supplejack_api/concerns/queryable_by_date.rb +31 -0
  36. data/app/models/supplejack_api/concerns/record.rb +108 -0
  37. data/app/models/supplejack_api/concerns/record_fragmentable.rb +24 -0
  38. data/app/models/supplejack_api/concerns/searchable.rb +430 -0
  39. data/app/models/supplejack_api/concerns/user_set.rb +219 -0
  40. data/app/models/supplejack_api/daily_metrics.rb +20 -0
  41. data/app/models/supplejack_api/faceted_metrics.rb +55 -0
  42. data/app/models/supplejack_api/fragment.rb +82 -0
  43. data/app/models/supplejack_api/interaction_models/record.rb +60 -0
  44. data/app/models/supplejack_api/interaction_models/set.rb +13 -0
  45. data/app/models/supplejack_api/interaction_updaters/all_usage_metric.rb +41 -0
  46. data/app/models/supplejack_api/interaction_updaters/set_metrics.rb +32 -0
  47. data/app/models/supplejack_api/interaction_updaters/usage_metrics.rb +73 -0
  48. data/app/models/supplejack_api/partner.rb +24 -0
  49. data/app/models/supplejack_api/preview_record.rb +30 -0
  50. data/app/models/supplejack_api/record.rb +18 -0
  51. data/app/models/supplejack_api/record_search.rb +12 -0
  52. data/app/models/supplejack_api/schema_definition.rb +147 -0
  53. data/app/models/supplejack_api/search.rb +14 -0
  54. data/app/models/supplejack_api/set_item.rb +57 -0
  55. data/app/models/supplejack_api/site_activity.rb +59 -0
  56. data/app/models/supplejack_api/source.rb +28 -0
  57. data/app/models/supplejack_api/source_activity.rb +36 -0
  58. data/app/models/supplejack_api/source_authority.rb +42 -0
  59. data/app/models/supplejack_api/supplejack_schema.rb +37 -0
  60. data/app/models/supplejack_api/support/concept/searchable.rb +79 -0
  61. data/app/models/supplejack_api/support/concept/storable.rb +59 -0
  62. data/app/models/supplejack_api/support/fragment_helpers.rb +96 -0
  63. data/app/models/supplejack_api/support/harvestable.rb +105 -0
  64. data/app/models/supplejack_api/support/searchable.rb +115 -0
  65. data/app/models/supplejack_api/support/status_logger.rb +23 -0
  66. data/app/models/supplejack_api/support/storable.rb +49 -0
  67. data/app/models/supplejack_api/support/validation_logger.rb +23 -0
  68. data/app/models/supplejack_api/usage_metrics.rb +25 -0
  69. data/app/models/supplejack_api/user.rb +211 -0
  70. data/app/models/supplejack_api/user_activity.rb +65 -0
  71. data/app/models/supplejack_api/user_set.rb +17 -0
  72. data/app/serializers/supplejack_api/application_serializer.rb +12 -0
  73. data/app/serializers/supplejack_api/concept_record_serializer.rb +23 -0
  74. data/app/serializers/supplejack_api/concept_search_serializer.rb +12 -0
  75. data/app/serializers/supplejack_api/concept_serializer.rb +100 -0
  76. data/app/serializers/supplejack_api/concerns/record_serializable.rb +119 -0
  77. data/app/serializers/supplejack_api/concerns/search_serializable.rb +24 -0
  78. data/app/serializers/supplejack_api/record_search_serializer.rb +64 -0
  79. data/app/serializers/supplejack_api/record_serializer.rb +13 -0
  80. data/app/serializers/supplejack_api/search_serializer.rb +13 -0
  81. data/app/serializers/supplejack_api/source_authority_serializer.rb +23 -0
  82. data/app/serializers/supplejack_api/user_serializer.rb +13 -0
  83. data/app/serializers/supplejack_api/user_set_record_serializer.rb +14 -0
  84. data/app/serializers/supplejack_api/user_set_serializer.rb +77 -0
  85. data/app/services/metrics_api/v3/api.rb +30 -0
  86. data/app/services/metrics_api/v3/endpoints/facets.rb +23 -0
  87. data/app/services/metrics_api/v3/endpoints/global.rb +26 -0
  88. data/app/services/metrics_api/v3/endpoints/helpers.rb +14 -0
  89. data/app/services/metrics_api/v3/endpoints/root.rb +97 -0
  90. data/app/services/metrics_api/v3/presenters/daily_metric.rb +23 -0
  91. data/app/services/metrics_api/v3/presenters/extended_metadata.rb +41 -0
  92. data/app/services/metrics_api/v3/presenters/record.rb +26 -0
  93. data/app/services/metrics_api/v3/presenters/view.rb +28 -0
  94. data/app/views/layouts/supplejack_api/_head.html.erb +17 -0
  95. data/app/views/layouts/supplejack_api/_top_nav.html.erb +33 -0
  96. data/app/views/layouts/supplejack_api/application.html.erb +33 -0
  97. data/app/views/supplejack_api/admin/sessions/new.html.erb +25 -0
  98. data/app/views/supplejack_api/admin/shared/_links.erb +34 -0
  99. data/app/views/supplejack_api/admin/site_activities/index.csv.erb +22 -0
  100. data/app/views/supplejack_api/admin/site_activities/index.html.erb +54 -0
  101. data/app/views/supplejack_api/admin/users/edit.html.erb +16 -0
  102. data/app/views/supplejack_api/admin/users/index.csv.erb +22 -0
  103. data/app/views/supplejack_api/admin/users/index.html.erb +57 -0
  104. data/app/views/supplejack_api/admin/users/show.html.erb +33 -0
  105. data/app/views/supplejack_api/request_limit_mailer/at100percent.text.erb +13 -0
  106. data/app/views/supplejack_api/request_limit_mailer/at100percent_admin.text.erb +1 -0
  107. data/app/views/supplejack_api/request_limit_mailer/at90percent.text.erb +13 -0
  108. data/app/views/supplejack_api/request_limit_mailer/at90percent_admin.text.erb +1 -0
  109. data/app/workers/supplejack_api/daily_metrics_worker.rb +112 -0
  110. data/app/workers/supplejack_api/interaction_metrics_worker.rb +45 -0
  111. data/config/cucumber.yml +16 -0
  112. data/config/initializers/force_eagerload.rb +11 -0
  113. data/config/initializers/interaction_updaters.rb +7 -0
  114. data/config/routes.rb +81 -0
  115. data/db/binding_records.development.json +7 -0
  116. data/db/binding_records.staging.json +7 -0
  117. data/db/concepts.json +33 -0
  118. data/db/concepts_data.json +569745 -0
  119. data/db/source_authorities.json +119 -0
  120. data/lib/generators/supplejack_api/install_generator.rb +124 -0
  121. data/lib/mongoid/paperclip.rb +53 -0
  122. data/lib/mongoid/string.rb +20 -0
  123. data/lib/sunspot/mongoid.rb +51 -0
  124. data/lib/sunspot/resque_session_proxy.rb +72 -0
  125. data/lib/sunspot/sunspot_spellcheck.rb +98 -0
  126. data/lib/supplejack_api.rb +13 -0
  127. data/lib/supplejack_api/admin/sortable.rb +40 -0
  128. data/lib/supplejack_api/engine.rb +46 -0
  129. data/lib/supplejack_api/harvester_constraint.rb +28 -0
  130. data/lib/supplejack_api/stylesheets.rb +36 -0
  131. data/lib/supplejack_api/utils.rb +75 -0
  132. data/lib/supplejack_api/version.rb +11 -0
  133. data/lib/tasks/resque.rake +22 -0
  134. data/lib/url_validator.rb +38 -0
  135. data/spec/controllers/supplejack_api/admin/base_controller_spec.rb +55 -0
  136. data/spec/controllers/supplejack_api/admin/site_activities_controller_spec.rb +43 -0
  137. data/spec/controllers/supplejack_api/admin/users_controller_spec.rb +79 -0
  138. data/spec/controllers/supplejack_api/application_controller_spec.rb +133 -0
  139. data/spec/controllers/supplejack_api/concepts_controller_spec.rb +83 -0
  140. data/spec/controllers/supplejack_api/concerns/records_controller_metrics_spec.rb +60 -0
  141. data/spec/controllers/supplejack_api/harvester/concepts_controller_spec.rb +57 -0
  142. data/spec/controllers/supplejack_api/harvester/records_controller_spec.rb +138 -0
  143. data/spec/controllers/supplejack_api/metrics_api_controller_spec.rb +71 -0
  144. data/spec/controllers/supplejack_api/partners_controller_spec.rb +77 -0
  145. data/spec/controllers/supplejack_api/records_controller_spec.rb +143 -0
  146. data/spec/controllers/supplejack_api/set_items_controller_spec.rb +78 -0
  147. data/spec/controllers/supplejack_api/sources_controller_spec.rb +161 -0
  148. data/spec/controllers/supplejack_api/status_controller_spec.rb +120 -0
  149. data/spec/controllers/supplejack_api/user_sets_controller_spec.rb +233 -0
  150. data/spec/controllers/supplejack_api/users_controller_spec.rb +61 -0
  151. data/spec/dummy/README.rdoc +268 -0
  152. data/spec/dummy/Rakefile +7 -0
  153. data/spec/dummy/app/assets/javascripts/application.js +23 -0
  154. data/spec/dummy/app/assets/stylesheets/application.css +22 -0
  155. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  156. data/spec/dummy/app/helpers/application_helper.rb +9 -0
  157. data/spec/dummy/app/supplejack_api/concept_schema.rb +83 -0
  158. data/spec/dummy/app/supplejack_api/record_schema.rb +64 -0
  159. data/spec/dummy/app/supplejack_api/record_schema.txt +66 -0
  160. data/spec/dummy/app/views/layouts/application.html.erb +23 -0
  161. data/spec/dummy/app/workers/supplejack_api/clear_index_buffer.rb +32 -0
  162. data/spec/dummy/app/workers/supplejack_api/flush_old_records_worker.rb +17 -0
  163. data/spec/dummy/app/workers/supplejack_api/index_buffer.rb +49 -0
  164. data/spec/dummy/app/workers/supplejack_api/index_source_worker.rb +39 -0
  165. data/spec/dummy/app/workers/supplejack_api/index_worker.rb +82 -0
  166. data/spec/dummy/app/workers/supplejack_api/store_user_activity_worker.rb +24 -0
  167. data/spec/dummy/config.ru +11 -0
  168. data/spec/dummy/config/application.rb +76 -0
  169. data/spec/dummy/config/application.yml +31 -0
  170. data/spec/dummy/config/application.yml.example +36 -0
  171. data/spec/dummy/config/boot.rb +17 -0
  172. data/spec/dummy/config/environment.rb +12 -0
  173. data/spec/dummy/config/environments/development.rb +42 -0
  174. data/spec/dummy/config/environments/production.rb +76 -0
  175. data/spec/dummy/config/environments/test.rb +46 -0
  176. data/spec/dummy/config/initializers/backtrace_silencers.rb +14 -0
  177. data/spec/dummy/config/initializers/devise.rb +214 -0
  178. data/spec/dummy/config/initializers/inflections.rb +22 -0
  179. data/spec/dummy/config/initializers/kaminari_config.rb +17 -0
  180. data/spec/dummy/config/initializers/mime_types.rb +12 -0
  181. data/spec/dummy/config/initializers/mongoid.rb +9 -0
  182. data/spec/dummy/config/initializers/quiet_logger.rb +23 -0
  183. data/spec/dummy/config/initializers/resque.rb +18 -0
  184. data/spec/dummy/config/initializers/secret_token.rb +14 -0
  185. data/spec/dummy/config/initializers/session_store.rb +15 -0
  186. data/spec/dummy/config/initializers/simple_form.rb +149 -0
  187. data/spec/dummy/config/initializers/simple_form_foundation.rb +33 -0
  188. data/spec/dummy/config/initializers/state_machine.rb +8 -0
  189. data/spec/dummy/config/initializers/sunspot.rb +32 -0
  190. data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
  191. data/spec/dummy/config/locales/devise.en.yml +63 -0
  192. data/spec/dummy/config/locales/en.yml +66 -0
  193. data/spec/dummy/config/locales/simple_form.en.yml +33 -0
  194. data/spec/dummy/config/mongoid.travis.yml +34 -0
  195. data/spec/dummy/config/mongoid.yml +36 -0
  196. data/spec/dummy/config/resque-pool.yml +18 -0
  197. data/spec/dummy/config/resque_schedule.yml +12 -0
  198. data/spec/dummy/config/routes.rb +11 -0
  199. data/spec/dummy/config/secrets.yml +8 -0
  200. data/spec/dummy/config/sunspot.yml +38 -0
  201. data/spec/dummy/db/concepts.json +37 -0
  202. data/spec/dummy/db/source_authorities.json +116 -0
  203. data/spec/dummy/public/404.html +35 -0
  204. data/spec/dummy/public/422.html +35 -0
  205. data/spec/dummy/public/500.html +34 -0
  206. data/spec/dummy/public/favicon.ico +8 -0
  207. data/spec/dummy/script/rails +6 -0
  208. data/spec/dummy/solr/collection1/conf/elevate.xml +36 -0
  209. data/spec/dummy/solr/collection1/conf/mapping-FoldToASCII.txt +3813 -0
  210. data/spec/dummy/solr/collection1/conf/schema.xml +292 -0
  211. data/spec/dummy/solr/collection1/conf/solrconfig.xml +1780 -0
  212. data/spec/dummy/solr/collection1/conf/spellings.txt +2 -0
  213. data/spec/dummy/solr/collection1/conf/stopwords.txt +58 -0
  214. data/spec/dummy/solr/collection1/conf/synonyms.txt +31 -0
  215. data/spec/factories/concepts.rb +16 -0
  216. data/spec/factories/daily_metrics.rb +10 -0
  217. data/spec/factories/faceted_metrics.rb +25 -0
  218. data/spec/factories/fragment.rb +14 -0
  219. data/spec/factories/partners.rb +14 -0
  220. data/spec/factories/record_interaction.rb +17 -0
  221. data/spec/factories/records.rb +47 -0
  222. data/spec/factories/set_interaction.rb +15 -0
  223. data/spec/factories/source_authorities.rb +19 -0
  224. data/spec/factories/sources.rb +16 -0
  225. data/spec/factories/usage_metrics.rb +20 -0
  226. data/spec/factories/user_activities.rb +14 -0
  227. data/spec/factories/user_sets.rb +27 -0
  228. data/spec/factories/users.rb +23 -0
  229. data/spec/helpers/application_helper_spec.rb +35 -0
  230. data/spec/models/concept_spec.rb +163 -0
  231. data/spec/models/fragment_spec.rb +15 -0
  232. data/spec/models/site_activity_spec.rb +103 -0
  233. data/spec/models/source_activity_spec.rb +56 -0
  234. data/spec/models/source_authority_spec.rb +42 -0
  235. data/spec/models/supplejack_api/api_concept/concept_fragment_spec.rb +189 -0
  236. data/spec/models/supplejack_api/api_record/record_fragment_spec.rb +189 -0
  237. data/spec/models/supplejack_api/concept_spec.rb +0 -0
  238. data/spec/models/supplejack_api/interaction_updaters/all_usage_metric_spec.rb +41 -0
  239. data/spec/models/supplejack_api/interaction_updaters/set_metrics_spec.rb +32 -0
  240. data/spec/models/supplejack_api/interaction_updaters/usage_metrics_spec.rb +44 -0
  241. data/spec/models/supplejack_api/partner_spec.rb +20 -0
  242. data/spec/models/supplejack_api/record_search_spec.rb +429 -0
  243. data/spec/models/supplejack_api/record_spec.rb +280 -0
  244. data/spec/models/supplejack_api/schema_definition_spec.rb +272 -0
  245. data/spec/models/supplejack_api/search_spec.rb +243 -0
  246. data/spec/models/supplejack_api/set_item_spec.rb +123 -0
  247. data/spec/models/supplejack_api/source_spec.rb +22 -0
  248. data/spec/models/supplejack_api/support/fragment_helpers_spec.rb +216 -0
  249. data/spec/models/supplejack_api/support/harvestable_spec.rb +177 -0
  250. data/spec/models/supplejack_api/support/searchable_spec.rb +85 -0
  251. data/spec/models/supplejack_api/support/storable_spec.rb +18 -0
  252. data/spec/models/supplejack_api/user_activity_spec.rb +88 -0
  253. data/spec/models/supplejack_api/user_set_spec.rb +559 -0
  254. data/spec/models/supplejack_api/user_spec.rb +348 -0
  255. data/spec/routing/concepts_routing_spec.rb +22 -0
  256. data/spec/routing/harvester_constraint_spec.rb +66 -0
  257. data/spec/routing/harvester_routing_spec.rb +51 -0
  258. data/spec/routing/partner_routing_spec.rb +34 -0
  259. data/spec/routing/records_routing_spec.rb +26 -0
  260. data/spec/routing/sets_routing_spec.rb +44 -0
  261. data/spec/routing/source_routing_spec.rb +38 -0
  262. data/spec/routing/users_routing_spec.rb +18 -0
  263. data/spec/serializers/concept_record_serializer_spec.rb +30 -0
  264. data/spec/serializers/supplejack_api/application_serializer_spec.rb +14 -0
  265. data/spec/serializers/supplejack_api/concept_search_serializer_spec.rb +34 -0
  266. data/spec/serializers/supplejack_api/concept_serializer_spec.rb +92 -0
  267. data/spec/serializers/supplejack_api/record_search_serializer_spec.rb +34 -0
  268. data/spec/serializers/supplejack_api/record_serializer_spec.rb +271 -0
  269. data/spec/serializers/supplejack_api/search_serializer_spec.rb +90 -0
  270. data/spec/serializers/supplejack_api/user_serializer_spec.rb +22 -0
  271. data/spec/serializers/supplejack_api/user_set_serializer_spec.rb +96 -0
  272. data/spec/services/metrics_api/v3/api_spec.rb +23 -0
  273. data/spec/services/metrics_api/v3/endpoints/facets_spec.rb +25 -0
  274. data/spec/services/metrics_api/v3/endpoints/global_spec.rb +22 -0
  275. data/spec/services/metrics_api/v3/endpoints/root_spec.rb +49 -0
  276. data/spec/services/metrics_api/v3/presenters/extended_metadata_spec.rb +49 -0
  277. data/spec/spec_helper.rb +70 -0
  278. data/spec/support/api/schemas/metrics/daily_metrics_metadata.json +24 -0
  279. data/spec/support/api/schemas/metrics/extended_metrics.json +26 -0
  280. data/spec/support/api/schemas/metrics/extended_response.json +6 -0
  281. data/spec/support/api/schemas/metrics/facets_response.json +6 -0
  282. data/spec/support/api/schemas/metrics/record_metadata.json +33 -0
  283. data/spec/support/api/schemas/metrics/top_level_response.json +6 -0
  284. data/spec/support/api/schemas/metrics/view_metadata.json +33 -0
  285. data/spec/support/api_schema_matcher.rb +14 -0
  286. data/spec/support/devise.rb +10 -0
  287. data/spec/workers/supplejack_api/daily_metrics_worker_spec.rb +140 -0
  288. data/spec/workers/supplejack_api/flush_old_records_worker_spec.rb +20 -0
  289. data/spec/workers/supplejack_api/index_worker_spec.rb +52 -0
  290. data/spec/workers/supplejack_api/source_index_worker_spec.rb +61 -0
  291. metadata +1231 -0
@@ -0,0 +1,119 @@
1
+ [
2
+ {
3
+ "name": "Colin McCahon",
4
+ "prefLabel": "Colin McCahon",
5
+ "altLabel": [],
6
+ "dateOfBirth": "1919-12-03T00:00:00",
7
+ "dateOfDeath": "1987-01-27T00:00:00",
8
+ "biographicalInformation": "Colin McCahon (12 March 1919 – 25 January 1987), known as Colin McKenzie after 1941, was a New Zealand painter. Along with Colin McCahon and Toss Woollaston, she is credited as one of the leading figures in twentieth century New Zealand art.",
9
+ "source_id": "tepapa",
10
+ "source_name": "Te Papa - Museum of New Zealand",
11
+ "url": "http://collections.tepapa.govt.nz/Person/1502",
12
+ "sameAs": [
13
+ "http://en.wikipedia.org/wiki/Colin_McCahon"
14
+ ],
15
+ "concept_type": "edm:Agent",
16
+ "givenName": "Colin",
17
+ "familyName": "McCahon",
18
+ "_mn_given_name": "KLN",
19
+ "_mn_family_name": "MKHN",
20
+ "birthYear": 1919,
21
+ "deathYear": 1987,
22
+ "internal_identifier": "tepapa:1502",
23
+ "concept_id": 1,
24
+ "concept_score": 50
25
+ },
26
+ {
27
+ "name": "Colin McCahon",
28
+ "prefLabel": "Colin McCahon",
29
+ "altLabel": [],
30
+ "dateOfBirth": "1919-12-03T00:00:00",
31
+ "dateOfDeath": "1987-01-27T00:00:00",
32
+ "biographicalInformation": "",
33
+ "source_id": "aklart",
34
+ "source_name": "Auckland Art Gallery",
35
+ "url": "http://www.aucklandartgallery.com/the-collection/browse-artists/461",
36
+ "sameAs": [],
37
+ "concept_type": "edm:Agent",
38
+ "givenName": "Colin",
39
+ "familyName": "McCahon",
40
+ "_mn_given_name": "KLN",
41
+ "_mn_family_name": "MKHN",
42
+ "birthYear": 1919,
43
+ "deathYear": 1987,
44
+ "internal_identifier": "aklart:867",
45
+ "concept_id": 1,
46
+ "concept_score": 50
47
+ },
48
+ {
49
+ "name": "Colin McCahon",
50
+ "prefLabel": "Colin McCahon",
51
+ "altLabel": [],
52
+ "dateOfBirth": "1919-12-03T00:00:00",
53
+ "dateOfDeath": "1987-01-27T00:00:00",
54
+ "biographicalInformation": "",
55
+ "source_id": "teara:5m4",
56
+ "source_name": "Te Ara",
57
+ "url": "http://www.teara.govt.nz/en/biographies/5m4/mccahon-colin-john",
58
+ "sameAs": [],
59
+ "concept_type": "edm:Agent",
60
+ "givenName": "Colin",
61
+ "familyName": "McCahon",
62
+ "_mn_given_name": "KLN",
63
+ "_mn_family_name": "MKHN",
64
+ "birthYear": 1919,
65
+ "deathYear": 1987,
66
+ "internal_identifier": "teara:5m4",
67
+ "concept_id": 1,
68
+ "concept_score": 50
69
+ },
70
+ {
71
+ "name": "Rita Angus",
72
+ "prefLabel": "Rita Angus",
73
+ "altLabel": [
74
+ "Henrietta Catherine Angus",
75
+ "Rita McKenzie"
76
+ ],
77
+ "dateOfBirth": "1908-12-03T00:00:00",
78
+ "dateOfDeath": "1970-01-27T00:00:00",
79
+ "biographicalInformation": "Rita Angus (12 March 1908 – 25 January 1970), known as Rita McKenzie after 1941, was a New Zealand painter. Along with Colin McCahon and Toss Woollaston, she is credited as one of the leading figures in twentieth century New Zealand art.",
80
+ "source_id": "tepapa",
81
+ "source_name": "Te Papa - Museum of New Zealand",
82
+ "url": "http://collections.tepapa.govt.nz/Person/74",
83
+ "sameAs": [
84
+ "http://en.wikipedia.org/wiki/Rita_Angus"
85
+ ],
86
+ "concept_type": "edm:Agent",
87
+ "givenName": "Rita",
88
+ "familyName": "Angus",
89
+ "_mn_given_name": "RT",
90
+ "_mn_family_name": "ANKS",
91
+ "birthYear": 1908,
92
+ "deathYear": 1970,
93
+ "internal_identifier": "tepapa:74",
94
+ "concept_id": 2,
95
+ "concept_score": 50
96
+ },
97
+ {
98
+ "name": "Rita Angus",
99
+ "prefLabel": "Rita Angus",
100
+ "altLabel": [],
101
+ "dateOfBirth": "1908-12-03T00:00:00",
102
+ "dateOfDeath": "1970-01-27T00:00:00",
103
+ "biographicalInformation": "Rita Angus (12 March 1908 – 25 January 1970), known as Rita McKenzie after 1941, was a New Zealand painter. Along with Colin McCahon and Toss Woollaston, she is credited as one of the leading figures in twentieth century New Zealand art.",
104
+ "source_id": "aklart",
105
+ "source_name": "Auckland Art Gallery",
106
+ "url": "http://www.aucklandartgallery.com/the-collection/browse-artists/461",
107
+ "sameAs": [],
108
+ "concept_type": "edm:Agent",
109
+ "givenName": "Rita",
110
+ "familyName": "Angus",
111
+ "_mn_given_name": "RT",
112
+ "_mn_family_name": "ANKS",
113
+ "birthYear": 1908,
114
+ "deathYear": 1970,
115
+ "internal_identifier": "aklart:461",
116
+ "concept_id": 2,
117
+ "concept_score": 50
118
+ }
119
+ ]
@@ -0,0 +1,124 @@
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 'rails/generators'
9
+
10
+ module SupplejackApi
11
+ module Generators
12
+ class InstallGenerator < Rails::Generators::Base
13
+ desc 'Used to install SupplejackApi'
14
+ class_option :documentation, type: :boolean, default: true, desc: 'Displays documentation after installation'
15
+
16
+ source_root(File.expand_path('../../../../spec/dummy/', __FILE__))
17
+
18
+ def config_files
19
+ puts "\nInstalling config files into config/"
20
+
21
+ copy_file('config/application.yml.example', 'config/application.yml')
22
+ copy_file 'config/mongoid.yml'
23
+ copy_file 'config/resque-pool.yml'
24
+ copy_file 'config/resque_schedule.yml'
25
+ copy_file 'config/sunspot.yml'
26
+
27
+ puts "\nGenerating secret token"
28
+
29
+ inject_into_file('config/application.yml', before: /^\sdevelopment:/) do
30
+ " SECRET_TOKEN: '#{Digest::SHA1.hexdigest([Time.now, rand].join)}'\n"
31
+ end
32
+ end
33
+
34
+ def workers
35
+ directory 'app/workers'
36
+ end
37
+
38
+ def initializers
39
+ puts "\nInstalling initializers into config/initializers/"
40
+
41
+ copy_file 'config/initializers/devise.rb'
42
+ copy_file 'config/initializers/kaminari_config.rb'
43
+ copy_file 'config/initializers/quiet_logger.rb'
44
+ copy_file 'config/initializers/resque.rb'
45
+ copy_file 'config/initializers/simple_form.rb'
46
+ copy_file 'config/initializers/simple_form_foundation.rb'
47
+ copy_file 'config/initializers/state_machine.rb'
48
+ copy_file 'config/initializers/sunspot.rb'
49
+ copy_file 'config/initializers/mongoid.rb'
50
+
51
+ directory 'config/locales'
52
+ end
53
+
54
+ def environment_files
55
+ puts "\nInstalling environment files into config/environments/"
56
+
57
+ copy_file 'config/environments/production.rb'
58
+ gsub_file('config/environments/production.rb', 'Dummy::Application', Rails.application.class.to_s)
59
+ end
60
+
61
+ def solr_config_files
62
+ puts "\nInstalling Solr config files into solr/"
63
+ directory 'solr'
64
+ end
65
+
66
+ def mount_engine
67
+ puts "\nMounting SupplejackApi::Engine at / in config/routes.rb"
68
+
69
+ inject_into_file('config/routes.rb', "\n mount SupplejackApi::Engine => '/', as: 'supplejack_api'\n\n", :before => /^end/)
70
+ end
71
+
72
+ def update_gemfile
73
+ puts "\nAdding dependencies into Gemfile"
74
+
75
+ inject_into_file('Gemfile', after: /^gem.*supplejack_api.*/) do
76
+ string = [""]
77
+ string << "gem 'sunspot_rails', '~> 2.2.0'"
78
+ string << "gem 'active_model_serializers', git: 'https://github.com/boost/active_model_serializers.git'"
79
+ string << "gem 'mongoid_auto_inc', git: 'https://github.com/boost/mongoid_auto_inc.git'"
80
+
81
+ string.join("\n")
82
+ end
83
+ end
84
+
85
+ def create_schema
86
+ puts "\nCreating Schemas in app/supplejack_api/"
87
+
88
+ empty_directory 'app/supplejack_api'
89
+ copy_file 'app/supplejack_api/record_schema.txt', 'app/supplejack_api/record_schema.rb'
90
+ copy_file 'app/supplejack_api/concept_schema.rb'
91
+ end
92
+
93
+ def add_assets
94
+ insert_into_file "app/assets/javascripts/application.js", "//= require highcharts/highcharts\n", :after => "jquery_ujs\n"
95
+ insert_into_file "app/assets/javascripts/application.js", "//= require highcharts/highcharts-more\n", :after => "jquery_ujs\n"
96
+ insert_into_file "app/assets/javascripts/application.js", "//= require highcharts/highstock\n", :after => "jquery_ujs\n"
97
+ insert_into_file "app/assets/stylesheets/application.css", "\n *= require supplejack_api/application", :after => "require_self"
98
+ end
99
+
100
+ def documentation
101
+ if options.documentation?
102
+ string = []
103
+ string << 'Welcome to Supplejack API.'
104
+ string << "Installation process is complete.\n"
105
+ string << 'In order to have have a working API, follow the steps below:'
106
+ string << '1. Implement your data schema in app/supplejack_api/schema.rb. See comments for DSL documentation'
107
+ string << '2. Edit config/application.yml and set all the keys to the correct values for your environments'
108
+ string << "3. Start Solr via via `bundle exec rake sunspot:solr:start|stop`. Ensure it's working by going to http://localhost:8983/solr/, you should see the Solr dashboard"
109
+ string << "4. Start the rails console via `bundle exec rails console`. Perform the next commands in the rails console"
110
+ string << "5. Use a local Solr session so updates are immediate via `Sunspot.session = Sunspot::Rails.build_session`"
111
+ string << "6. Create a user via `user = SupplejackApi::User.create(email: 'test@example.com', name: 'Test User')`"
112
+ string << "7. Create a record via `record = SupplejackApi::Record.create(internal_identifier: 'abc123', status: 'active', source_url: 'http://boost.co.nz/')`"
113
+ string << "8. Add your custom data (from schema.rb) to the record's primary fragment via `record.primary_fragment.<field_name>=<value>`. Then `record.save!`"
114
+ string << "9. Start the rails server via `bundle exec rails server -p 3000`"
115
+ string << "10. Retrieve a specific record by going to http://localhost:3000/records/<record.record_id>.json?api_key=<user.api_key>"
116
+ string << "11. Perform a search by going to http://localhost:3000/records.json?api_key=<user.api_key>"
117
+ string << "12. You now have a working API!"
118
+
119
+ puts string.join("\n")
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,53 @@
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
+ #
10
+ # Save this into your `lib/mongoid/paperclip.rb` file
11
+ #
12
+ #
13
+ require 'paperclip'
14
+
15
+ module Paperclip
16
+ class << self
17
+ def logger
18
+ Rails.logger
19
+ end
20
+ end
21
+ end
22
+
23
+ ##
24
+ # the id of mongoid is not integer, correct the id_partitioin.
25
+ Paperclip.interpolates :id_partition do |attachment, _style|
26
+ attachment.instance.id.to_s.scan(/.{4}/).join('/')
27
+ end
28
+
29
+ module Mongoid
30
+ module Paperclip
31
+ def self.included(base)
32
+ base.instance_eval do
33
+ include ::Paperclip
34
+ include ::Paperclip::Glue
35
+
36
+ alias :__mongoid_has_attached_file :has_attached_file
37
+
38
+ extend ClassMethods
39
+ end
40
+ end
41
+
42
+ module ClassMethods
43
+ def has_attached_file(field, options = {})
44
+ field(:"#{field}_file_name", type: String)
45
+ field(:"#{field}_content_type", type: String)
46
+ field(:"#{field}_file_size", type: Integer)
47
+ field(:"#{field}_updated_at", type: DateTime)
48
+
49
+ __mongoid_has_attached_file(field, options)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
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
+ # method String#to_a was removed in Mongoid 4
10
+ # reference: https://github.com/mongoid/mongoid/commit/db84c0972bf4f01019cdfc2e9ab647fb814d3224
11
+
12
+ module Mongoid
13
+ module Extensions
14
+ module String
15
+ def to_a
16
+ [self]
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,51 @@
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
+ require 'sunspot'
10
+ require 'mongoid'
11
+ require 'sunspot/rails'
12
+
13
+ # == Examples:
14
+ #
15
+ # class Post
16
+ # include Mongoid::Document
17
+ # field :title
18
+ #
19
+ # include Sunspot::Mongoid
20
+ # searchable do
21
+ # text :title
22
+ # end
23
+ # end
24
+ #
25
+ module Sunspot
26
+ module Mongoid
27
+ def self.included(base)
28
+ base.class_eval do
29
+ extend Sunspot::Rails::Searchable::ActsAsMethods
30
+ Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
31
+ Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
32
+ end
33
+ end
34
+
35
+ class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
36
+ def id
37
+ @instance.id
38
+ end
39
+ end
40
+
41
+ class DataAccessor < Sunspot::Adapters::DataAccessor
42
+ def load(id)
43
+ @clazz.where(id: id).first
44
+ end
45
+
46
+ def load_all(ids)
47
+ @clazz.where(:id.in => ids)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ # This was authored by HeyZap (http://www.heyzap.com/) and is available at http://stdout.heyzap.com/2011/08/17/sunspot-resque-session-proxy/
3
+
4
+ module Sunspot
5
+ class ResqueSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy
6
+ attr_reader :original_session, :batch_size
7
+
8
+ delegate :config, :delete_dirty?, :dirty?,
9
+ :new_search, :search,
10
+ :new_more_like_this, :more_like_this,
11
+ :batch, to: :session
12
+
13
+ def initialize(session, batch_size = 1000)
14
+ @original_session = session
15
+ @batch_size = batch_size
16
+ end
17
+
18
+ alias session original_session
19
+
20
+ [:index, :index!, :remove, :remove!].each do |method|
21
+ define_method(method) do |*objects|
22
+ @buffer = SupplejackApi::IndexBuffer.new
23
+ method = method.to_s.delete('!').to_sym
24
+
25
+ start = 0
26
+ objects = objects.flatten.compact
27
+ object_ids = objects.map { |o| o.id.to_s }.compact
28
+ total_ids = object_ids + @buffer.pop_record_ids(method)
29
+
30
+ if total_ids.size < 100
31
+ @buffer.send("#{method}_record_ids=", total_ids)
32
+ else
33
+ batch_object_ids = total_ids[start..(batch_size - 1)]
34
+ class_name = objects.first.class.name
35
+
36
+ while batch_object_ids do
37
+ index_worker_args = { class: class_name, id: batch_object_ids }
38
+ Resque.enqueue(SupplejackApi::IndexWorker, method, index_worker_args) if batch_object_ids.try(:any?)
39
+ start += batch_size
40
+ batch_object_ids = total_ids[start..(start + batch_size - 1)]
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ [:remove_by_id, :remove_by_id!].each do |method|
47
+ define_method(method) do |clazz, id|
48
+ Resque.enqueue(SupplejackApi::IndexWorker, method, class: clazz, id: id.to_s)
49
+ end
50
+ end
51
+
52
+ def remove_all(clazz = nil)
53
+ Resque.enqueue SupplejackApi::IndexWorker, :remove_all, clazz.to_s
54
+ end
55
+
56
+ def remove_all!(clazz = nil)
57
+ Resque.enqueue SupplejackApi::IndexWorker, :remove_all, clazz.to_s
58
+ end
59
+
60
+ def commit(_soft_commit = false)
61
+ Resque.enqueue(SupplejackApi::IndexWorker, :commit)
62
+ end
63
+
64
+ def commit_if_dirty(soft_commit = false)
65
+ # no-op
66
+ end
67
+
68
+ def commit_if_delete_dirty(soft_commit = false)
69
+ # no-op
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,98 @@
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 Sunspot
10
+ module Query
11
+ class Spellcheck < Connective::Conjunction
12
+ attr_accessor :options
13
+
14
+ def initialize(options = {})
15
+ @options = options
16
+ end
17
+
18
+ def to_params
19
+ options = {}
20
+ @options.each do |key, val|
21
+ options['spellcheck.' + Sunspot::Util.method_case(key)] = val
22
+ end
23
+ { spellcheck: true }.merge(options)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ module Sunspot
30
+ module Query
31
+ class CommonQuery
32
+ def spellcheck(options = {})
33
+ @components << Spellcheck.new(options)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ module Sunspot
40
+ module Search
41
+ class AbstractSearch
42
+ attr_accessor :solr_result
43
+
44
+ def raw_suggestions
45
+ %w(spellcheck suggestions).inject(@solr_result) { |h, k| h && h[k] }
46
+ end
47
+
48
+ def suggestions
49
+ suggestions = %w(spellcheck suggestions).inject(@solr_result) { |h, k| h && h[k] }
50
+ return nil unless suggestions.is_a?(Array)
51
+
52
+ suggestions_hash = {}
53
+ index = -1
54
+ suggestions.each do |sug|
55
+ index += 1
56
+ next unless sug.is_a?(String)
57
+ break unless suggestions.count > index + 1
58
+ suggestions_hash[sug] = suggestions[index + 1].try(:[], 'suggestion') || suggestions[index + 1]
59
+ end
60
+ suggestions_hash
61
+ end
62
+
63
+ def all_suggestions
64
+ suggestions.inject([]) { |all, current| all += current }
65
+ end
66
+
67
+ def collation
68
+ suggestions.try(:[], 'collation')
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ module Sunspot
75
+ module DSL
76
+ class StandardQuery
77
+ def spellcheck(options = {})
78
+ @query.spellcheck(options)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ module Sunspot
85
+ module Util
86
+ class<<self
87
+ def method_case(string_or_symbol)
88
+ string = string_or_symbol.to_s
89
+ first = true
90
+ string.split('_').map! do |word|
91
+ word = first ? word : word.capitalize
92
+ first = false
93
+ word
94
+ end.join
95
+ end
96
+ end
97
+ end
98
+ end