hyrax 3.0.0.pre.beta2 → 3.0.0.pre.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (441) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +118 -181
  3. data/.gitignore +3 -0
  4. data/.regen +1 -0
  5. data/.rubocop_fixme.yml +1 -1
  6. data/README.md +11 -15
  7. data/app/actors/hyrax/actors/active_fedora_to_valkyrie.rb +59 -0
  8. data/app/actors/hyrax/actors/add_to_work_actor.rb +28 -5
  9. data/app/actors/hyrax/actors/apply_order_actor.rb +2 -2
  10. data/app/actors/hyrax/actors/attach_members_actor.rb +50 -28
  11. data/app/actors/hyrax/actors/base_actor.rb +17 -2
  12. data/app/actors/hyrax/actors/cleanup_file_sets_actor.rb +1 -1
  13. data/app/actors/hyrax/actors/collections_membership_actor.rb +2 -8
  14. data/app/actors/hyrax/actors/create_with_files_actor.rb +16 -6
  15. data/app/actors/hyrax/actors/create_with_files_ordered_members_actor.rb +2 -2
  16. data/app/actors/hyrax/actors/create_with_remote_files_actor.rb +2 -1
  17. data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +8 -6
  18. data/app/actors/hyrax/actors/environment.rb +8 -16
  19. data/app/actors/hyrax/actors/file_actor.rb +75 -13
  20. data/app/actors/hyrax/actors/interpret_visibility_actor.rb +6 -8
  21. data/app/actors/hyrax/actors/valkyrie_to_active_fedora.rb +60 -0
  22. data/app/assets/javascripts/hyrax/collections.js +5 -4
  23. data/app/assets/javascripts/hyrax/nav_safety.js +4 -2
  24. data/app/assets/javascripts/hyrax/proxy_rights.js +8 -0
  25. data/app/assets/stylesheets/fileupload/jquery.fileupload-ui.scss +1 -15
  26. data/app/assets/stylesheets/hyrax/_collections.scss +1 -1
  27. data/app/assets/stylesheets/hyrax/_home-page.scss +6 -0
  28. data/app/assets/stylesheets/hyrax/_users.scss +11 -0
  29. data/app/assets/stylesheets/hyrax/_viewer.scss +14 -3
  30. data/app/controllers/concerns/hyrax/breadcrumbs.rb +2 -0
  31. data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +1 -1
  32. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +2 -1
  33. data/app/controllers/concerns/hyrax/leases_controller_behavior.rb +2 -1
  34. data/app/controllers/concerns/hyrax/local_file_downloads_controller_behavior.rb +2 -1
  35. data/app/controllers/hyrax/batch_edits_controller.rb +3 -3
  36. data/app/controllers/hyrax/dashboard/collections_controller.rb +16 -5
  37. data/app/controllers/hyrax/dashboard_controller.rb +9 -0
  38. data/app/controllers/hyrax/depositors_controller.rb +4 -6
  39. data/app/controllers/hyrax/downloads_controller.rb +1 -1
  40. data/app/controllers/hyrax/file_sets_controller.rb +3 -2
  41. data/app/controllers/hyrax/homepage_controller.rb +1 -1
  42. data/app/controllers/hyrax/my/works_controller.rb +2 -2
  43. data/app/controllers/hyrax/my_controller.rb +2 -2
  44. data/app/controllers/hyrax/permissions_controller.rb +1 -1
  45. data/app/controllers/hyrax/single_use_links_viewer_controller.rb +1 -1
  46. data/app/controllers/hyrax/workflow_actions_controller.rb +1 -1
  47. data/app/forms/hyrax/forms/admin_set_form.rb +8 -0
  48. data/app/forms/hyrax/forms/batch_edit_form.rb +1 -1
  49. data/app/forms/hyrax/forms/collection_form.rb +34 -3
  50. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  51. data/app/forms/hyrax/forms/work_form.rb +34 -7
  52. data/app/forms/hyrax/forms/workflow_responsibility_form.rb +0 -4
  53. data/app/helpers/hyrax/hyrax_helper_behavior.rb +3 -4
  54. data/app/helpers/hyrax/iiif_helper.rb +8 -0
  55. data/app/indexers/hyrax/admin_set_indexer.rb +1 -1
  56. data/app/indexers/hyrax/basic_metadata_indexer.rb +1 -1
  57. data/app/indexers/hyrax/collection_indexer.rb +2 -2
  58. data/app/indexers/hyrax/file_set_indexer.rb +7 -0
  59. data/app/indexers/hyrax/indexes_workflow.rb +3 -5
  60. data/app/indexers/hyrax/valkyrie_indexers/base_indexer.rb +19 -0
  61. data/app/indexers/hyrax/work_indexer.rb +1 -1
  62. data/app/jobs/attach_files_to_work_job.rb +9 -1
  63. data/app/jobs/characterize_job.rb +20 -5
  64. data/app/jobs/import_url_job.rb +9 -16
  65. data/app/jobs/ingest_local_file_job.rb +4 -0
  66. data/app/jobs/visibility_copy_job.rb +3 -17
  67. data/app/models/admin_set.rb +5 -0
  68. data/app/models/concerns/hyrax/ability.rb +3 -3
  69. data/app/models/concerns/hyrax/basic_metadata.rb +6 -2
  70. data/app/models/concerns/hyrax/collection_behavior.rb +22 -12
  71. data/app/models/concerns/hyrax/collection_nesting.rb +1 -1
  72. data/app/models/concerns/hyrax/file_set/characterization.rb +8 -1
  73. data/app/models/concerns/hyrax/file_set/querying.rb +1 -1
  74. data/app/models/concerns/hyrax/file_set_behavior.rb +1 -1
  75. data/app/models/concerns/hyrax/human_readable_type.rb +2 -2
  76. data/app/models/concerns/hyrax/solr_document/characterization.rb +27 -23
  77. data/app/models/concerns/hyrax/solr_document/metadata.rb +37 -39
  78. data/app/models/concerns/hyrax/solr_document_behavior.rb +4 -8
  79. data/app/models/concerns/hyrax/virus_check.rb +20 -0
  80. data/app/models/concerns/hyrax/work_behavior.rb +3 -1
  81. data/app/models/file_download_stat.rb +2 -1
  82. data/app/models/hyrax/active_job_proxy.rb +43 -0
  83. data/app/models/hyrax/embargo.rb +21 -0
  84. data/app/models/hyrax/file_metadata.rb +109 -0
  85. data/app/models/hyrax/lease.rb +21 -0
  86. data/app/models/hyrax/permission_template.rb +8 -8
  87. data/app/models/hyrax/resource.rb +31 -0
  88. data/app/models/hyrax/statistic.rb +5 -1
  89. data/app/models/hyrax/uploaded_file.rb +0 -2
  90. data/app/models/hyrax/virus_scanner.rb +56 -0
  91. data/app/models/job_io_wrapper.rb +24 -9
  92. data/app/models/proxy_deposit_request.rb +1 -1
  93. data/app/models/solr_hit.rb +23 -0
  94. data/app/presenters/hyrax/admin_set_presenter.rb +1 -1
  95. data/app/presenters/hyrax/characterization_behavior.rb +2 -2
  96. data/app/presenters/hyrax/displays_image.rb +25 -7
  97. data/app/presenters/hyrax/file_set_presenter.rb +3 -3
  98. data/app/presenters/hyrax/member_presenter_factory.rb +9 -9
  99. data/app/presenters/hyrax/presenter_factory.rb +1 -4
  100. data/app/presenters/hyrax/trophy_presenter.rb +1 -1
  101. data/app/presenters/hyrax/work_show_presenter.rb +3 -3
  102. data/app/renderers/hyrax/renderers/faceted_attribute_renderer.rb +1 -1
  103. data/app/search_builders/hyrax/catalog_search_builder.rb +1 -1
  104. data/app/search_builders/hyrax/collection_search_builder.rb +1 -1
  105. data/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +2 -2
  106. data/app/search_builders/hyrax/deposit_search_builder.rb +1 -1
  107. data/app/search_builders/hyrax/my/find_works_search_builder.rb +5 -9
  108. data/app/search_builders/hyrax/my/highlights_search_builder.rb +1 -3
  109. data/app/search_builders/hyrax/nested_collections_parent_search_builder.rb +1 -1
  110. data/app/search_builders/hyrax/parent_collection_search_builder.rb +1 -1
  111. data/app/services/hyrax/adapters/nesting_index_adapter.rb +6 -6
  112. data/app/services/hyrax/admin_set_service.rb +3 -11
  113. data/app/services/hyrax/analytics.rb +6 -6
  114. data/app/services/hyrax/collection_types/permissions_service.rb +5 -5
  115. data/app/services/hyrax/collections/permissions_service.rb +2 -2
  116. data/app/services/hyrax/custom_queries/navigators/child_collections_navigator.rb +39 -0
  117. data/app/services/hyrax/custom_queries/navigators/child_filesets_navigator.rb +39 -0
  118. data/app/services/hyrax/custom_queries/navigators/child_works_navigator.rb +39 -0
  119. data/app/services/hyrax/custom_queries/wings.rb +34 -0
  120. data/app/services/hyrax/database_migrator.rb +1 -0
  121. data/app/services/hyrax/derivative_path.rb +1 -1
  122. data/app/services/hyrax/embargo_manager.rb +100 -0
  123. data/app/services/hyrax/file_set_csv_service.rb +2 -0
  124. data/app/services/hyrax/file_set_visibility_propagator.rb +41 -0
  125. data/app/services/hyrax/graph_exporter.rb +1 -1
  126. data/app/services/hyrax/lease_manager.rb +71 -0
  127. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +1 -1
  128. data/app/services/hyrax/query_service.rb +0 -0
  129. data/app/services/hyrax/resource_visibility_propagator.rb +50 -0
  130. data/app/services/hyrax/solr_query_builder_service.rb +71 -0
  131. data/app/services/hyrax/solr_service.rb +144 -0
  132. data/app/services/hyrax/statistics/file_sets/by_format.rb +1 -1
  133. data/app/services/hyrax/statistics/term_query.rb +7 -12
  134. data/app/services/hyrax/statistics/works/by_resource_type.rb +1 -1
  135. data/app/services/hyrax/thumbnail_path_service.rb +4 -3
  136. data/app/services/hyrax/versioning_service.rb +74 -19
  137. data/app/services/hyrax/virus_checker_service.rb +52 -0
  138. data/app/services/hyrax/visibility_intention_applicator.rb +43 -0
  139. data/app/services/hyrax/visibility_map.rb +65 -0
  140. data/app/services/hyrax/visibility_propagator.rb +19 -0
  141. data/app/services/hyrax/visibility_reader.rb +43 -0
  142. data/app/services/hyrax/visibility_writer.rb +43 -0
  143. data/app/services/hyrax/work_query_service.rb +3 -3
  144. data/app/services/hyrax/workflow/deposited_notification.rb +1 -1
  145. data/app/services/hyrax/works/migration_service.rb +33 -0
  146. data/app/views/hyrax/admin/admin_sets/_form.html.erb +6 -5
  147. data/app/views/hyrax/admin/admin_sets/_form_visibility.html.erb +2 -1
  148. data/app/views/hyrax/admin/admin_sets/_form_workflow.erb +1 -1
  149. data/app/views/hyrax/base/_attribute_rows.html.erb +2 -0
  150. data/app/views/hyrax/base/_attributes.html.erb +3 -3
  151. data/app/views/hyrax/base/_citations.html.erb +4 -4
  152. data/app/views/hyrax/base/_file_manager_actions.html.erb +2 -2
  153. data/app/views/hyrax/base/_file_manager_member_resource_options.html.erb +2 -2
  154. data/app/views/hyrax/base/_form_child_work_relationships.html.erb +1 -1
  155. data/app/views/hyrax/base/_form_files.html.erb +11 -9
  156. data/app/views/hyrax/base/_form_member_of_collections.html.erb +1 -1
  157. data/app/views/hyrax/base/_form_permission.html.erb +1 -2
  158. data/app/views/hyrax/base/_form_progress.html.erb +2 -2
  159. data/app/views/hyrax/base/_form_share.html.erb +8 -11
  160. data/app/views/hyrax/base/_show_actions.html.erb +3 -3
  161. data/app/views/hyrax/base/_social_media.html.erb +0 -13
  162. data/app/views/hyrax/base/_work_button_row.html.erb +7 -7
  163. data/app/views/hyrax/base/_workflow_actions.html.erb +4 -4
  164. data/app/views/hyrax/base/file_manager.html.erb +2 -2
  165. data/app/views/hyrax/base/iiif_viewers/_universal_viewer.html.erb +5 -2
  166. data/app/views/hyrax/base/inspect_work.html.erb +13 -13
  167. data/app/views/hyrax/base/unauthorized.html.erb +4 -4
  168. data/app/views/hyrax/batch_edits/_check_all.html.erb +1 -1
  169. data/app/views/hyrax/batch_edits/_delete_selected.html.erb +1 -1
  170. data/app/views/hyrax/batch_edits/edit.html.erb +11 -11
  171. data/app/views/hyrax/citations/work.html.erb +1 -1
  172. data/app/views/hyrax/collections/_show_document_list.html.erb +1 -1
  173. data/app/views/hyrax/collections/_sort_and_per_page.html.erb +4 -4
  174. data/app/views/hyrax/dashboard/collections/_form.html.erb +6 -5
  175. data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +10 -10
  176. data/app/views/hyrax/dashboard/collections/_form_share.html.erb +5 -5
  177. data/app/views/hyrax/dashboard/collections/_show_descriptions.html.erb +1 -1
  178. data/app/views/hyrax/dashboard/collections/_show_document_list.html.erb +6 -6
  179. data/app/views/hyrax/dashboard/collections/_show_document_list_menu.html.erb +1 -1
  180. data/app/views/hyrax/dashboard/collections/_show_document_list_row.html.erb +3 -3
  181. data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +2 -3
  182. data/app/views/hyrax/dashboard/collections/_work_action_menu.html.erb +8 -8
  183. data/app/views/hyrax/dashboard/collections/edit.html.erb +2 -2
  184. data/app/views/hyrax/dashboard/profiles/_edit_primary.html.erb +8 -8
  185. data/app/views/hyrax/dashboard/sidebar/_activity.html.erb +2 -0
  186. data/app/views/hyrax/dashboard/sidebar/_configuration.html.erb +4 -1
  187. data/app/views/hyrax/dashboard/sidebar/_menu_partials.html.erb +3 -0
  188. data/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb +2 -0
  189. data/app/views/hyrax/dashboard/sidebar/_tasks.html.erb +2 -0
  190. data/app/views/hyrax/dashboard/works/_default_group.html.erb +4 -4
  191. data/app/views/hyrax/dashboard/works/_list_works.html.erb +1 -1
  192. data/app/views/hyrax/depositors/_modal_proxy_deny.html.erb +14 -0
  193. data/app/views/hyrax/depositors/index.html.erb +3 -0
  194. data/app/views/hyrax/embargoes/_list_expired_active_embargoes.html.erb +1 -1
  195. data/app/views/hyrax/file_sets/_actions.html.erb +1 -1
  196. data/app/views/hyrax/file_sets/_asset_deleted_flash.html.erb +1 -1
  197. data/app/views/hyrax/file_sets/_asset_saved_flash.html.erb +5 -6
  198. data/app/views/hyrax/file_sets/_asset_updated_flash.html.erb +2 -1
  199. data/app/views/hyrax/file_sets/_descriptions.html.erb +2 -2
  200. data/app/views/hyrax/file_sets/_extra_fields_modal.html.erb +3 -3
  201. data/app/views/hyrax/file_sets/_form.html.erb +1 -1
  202. data/app/views/hyrax/file_sets/_permission.html.erb +2 -1
  203. data/app/views/hyrax/file_sets/_permission_form.html.erb +9 -9
  204. data/app/views/hyrax/file_sets/_show_actions.html.erb +4 -4
  205. data/app/views/hyrax/file_sets/_show_details.html.erb +7 -7
  206. data/app/views/hyrax/file_sets/_versioning.html.erb +3 -3
  207. data/app/views/hyrax/file_sets/edit.html.erb +4 -3
  208. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +2 -2
  209. data/app/views/hyrax/file_sets/media_display/_video.html.erb +2 -2
  210. data/app/views/hyrax/file_sets/proxy.html.erb +2 -2
  211. data/app/views/hyrax/my/_sort_and_per_page.html.erb +1 -1
  212. data/app/views/hyrax/my/collections/_modal_delete_selected_collections.html.erb +4 -1
  213. data/app/views/hyrax/my/collections/index.html.erb +1 -1
  214. data/app/views/hyrax/my/index.html.erb +1 -1
  215. data/app/views/hyrax/my/works/_default_group.html.erb +4 -4
  216. data/app/views/hyrax/my/works/_list_works.html.erb +3 -3
  217. data/app/views/hyrax/my/works/index.html.erb +1 -1
  218. data/app/views/hyrax/notifications/index.html.erb +1 -1
  219. data/app/views/hyrax/operations/index.html.erb +4 -4
  220. data/app/views/hyrax/pages/_form.html.erb +61 -60
  221. data/app/views/hyrax/permissions/confirm_access.html.erb +1 -1
  222. data/app/views/hyrax/single_use_links_viewer/single_use_error.html.erb +3 -7
  223. data/app/views/hyrax/static/mendeley.html.erb +2 -4
  224. data/app/views/hyrax/static/zotero.html.erb +2 -4
  225. data/app/views/hyrax/transfers/_received.html.erb +10 -10
  226. data/app/views/hyrax/transfers/_sent.html.erb +6 -6
  227. data/app/views/hyrax/uploads/_js_templates.html.erb +7 -7
  228. data/app/views/hyrax/uploads/_js_templates_branding.html.erb +8 -8
  229. data/app/views/hyrax/users/_activity_log.html.erb +25 -22
  230. data/app/views/hyrax/users/_left_sidebar.html.erb +1 -1
  231. data/app/views/hyrax/users/_proxies.html.erb +1 -1
  232. data/app/views/hyrax/users/_search_form.html.erb +3 -3
  233. data/app/views/hyrax/users/_vitals.html.erb +1 -1
  234. data/app/views/hyrax/users/index.html.erb +6 -6
  235. data/app/views/records/edit_fields/_abstract.html.erb +5 -0
  236. data/app/views/records/edit_fields/_access_right.html.erb +5 -0
  237. data/app/views/records/edit_fields/_alt_title.html.erb +3 -0
  238. data/app/views/records/edit_fields/_title.html.erb +1 -0
  239. data/app/views/records/show_fields/_based_near.html.erb +1 -1
  240. data/app/views/records/show_fields/_creator.html.erb +1 -1
  241. data/app/views/records/show_fields/_keyword.html.erb +1 -1
  242. data/app/views/records/show_fields/_language.html.erb +1 -1
  243. data/app/views/records/show_fields/_publisher.html.erb +1 -1
  244. data/app/views/records/show_fields/_resource_type.html.erb +1 -1
  245. data/app/views/records/show_fields/_subject.html.erb +1 -1
  246. data/config/initializers/indexing_adapter_initializer.rb +16 -0
  247. data/config/initializers/samvera-nesting_indexer_initializer.rb +3 -3
  248. data/config/locales/hyrax.de.yml +303 -24
  249. data/config/locales/hyrax.en.yml +279 -0
  250. data/config/locales/hyrax.es.yml +284 -5
  251. data/config/locales/hyrax.fr.yml +280 -1
  252. data/config/locales/hyrax.it.yml +279 -0
  253. data/config/locales/hyrax.pt-BR.yml +279 -0
  254. data/config/locales/hyrax.zh.yml +279 -0
  255. data/hyrax.gemspec +10 -11
  256. data/lib/generators/hyrax/config_generator.rb +6 -0
  257. data/lib/generators/hyrax/install_generator.rb +5 -0
  258. data/lib/generators/hyrax/riiif_generator.rb +2 -2
  259. data/lib/generators/hyrax/templates/catalog_controller.rb +71 -71
  260. data/lib/generators/hyrax/templates/config/analytics.yml +5 -5
  261. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +11 -1
  262. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +3 -3
  263. data/lib/generators/hyrax/templates/config/solr_wrapper_valkyrie_test.yml +7 -0
  264. data/lib/generators/hyrax/templates/config/valkyrie_index.yml +12 -0
  265. data/lib/generators/hyrax/templates/package.json +17 -0
  266. data/lib/generators/hyrax/templates/uv-config.json +3 -0
  267. data/lib/generators/hyrax/templates/uv.html +87 -0
  268. data/lib/generators/hyrax/work/templates/feature_spec.rb.erb +0 -1
  269. data/lib/hyrax.rb +17 -1
  270. data/lib/hyrax/configuration.rb +34 -20
  271. data/lib/hyrax/engine.rb +12 -10
  272. data/lib/hyrax/errors.rb +4 -0
  273. data/lib/hyrax/transactions/container.rb +13 -0
  274. data/lib/hyrax/transactions/create_work.rb +11 -0
  275. data/lib/hyrax/transactions/steps/apply_collection_permission_template.rb +32 -0
  276. data/lib/hyrax/transactions/steps/apply_permission_template.rb +2 -1
  277. data/lib/hyrax/transactions/steps/apply_visibility.rb +39 -0
  278. data/lib/hyrax/version.rb +1 -1
  279. data/lib/tasks/migrate.rake +6 -0
  280. data/lib/tasks/universal_viewer.rake +15 -0
  281. data/lib/valkyrie/indexing/solr/indexing_adapter.rb +102 -0
  282. data/lib/valkyrie/indexing_adapter.rb +29 -0
  283. data/lib/wings.rb +13 -4
  284. data/lib/wings/active_fedora_converter.rb +129 -15
  285. data/lib/wings/converter_value_mapper.rb +111 -0
  286. data/lib/wings/hydra/pcdm/models/concerns/collection_valkyrie_behavior.rb +27 -0
  287. data/lib/wings/hydra/pcdm/models/concerns/object_valkyrie_behavior.rb +27 -0
  288. data/lib/wings/hydra/pcdm/models/concerns/pcdm_valkyrie_behavior.rb +172 -0
  289. data/lib/wings/hydra/works/models/concerns/collection_valkyrie_behavior.rb +30 -0
  290. data/lib/wings/hydra/works/models/concerns/file_set_valkyrie_behavior.rb +30 -0
  291. data/lib/wings/hydra/works/models/concerns/work_valkyrie_behavior.rb +59 -0
  292. data/lib/wings/hydra/works/services/add_file_metadata_to_file_set.rb +113 -0
  293. data/lib/wings/model_transformer.rb +172 -47
  294. data/lib/wings/models/concerns/collection_behavior.rb +38 -0
  295. data/lib/wings/models/multi_checksum.rb +18 -0
  296. data/lib/wings/services/file_metadata_builder.rb +81 -0
  297. data/lib/wings/services/id_converter_service.rb +14 -0
  298. data/lib/wings/{value_mapper.rb → transformer_value_mapper.rb} +24 -5
  299. data/lib/wings/valkyrie/persister.rb +47 -24
  300. data/lib/wings/valkyrie/query_service.rb +141 -6
  301. data/lib/wings/valkyrie/storage/active_fedora.rb +27 -0
  302. data/spec/abilities/proxies_and_transfer_abilities_spec.rb +50 -10
  303. data/spec/actors/hyrax/actors/active_fedora_to_valkyrie_spec.rb +70 -0
  304. data/spec/actors/hyrax/actors/attach_members_actor_spec.rb +55 -10
  305. data/spec/actors/hyrax/actors/create_with_remote_files_actor_spec.rb +14 -0
  306. data/spec/actors/hyrax/actors/create_with_remote_files_ordered_members_actor_spec.rb +22 -30
  307. data/spec/actors/hyrax/actors/file_actor_spec.rb +200 -84
  308. data/spec/actors/hyrax/actors/file_set_actor_spec.rb +1 -1
  309. data/spec/actors/hyrax/actors/generic_work_actor_spec.rb +2 -6
  310. data/spec/actors/hyrax/actors/interpret_visibility_actor_spec.rb +1 -1
  311. data/spec/actors/hyrax/actors/ordered_members_actor_spec.rb +1 -1
  312. data/spec/actors/hyrax/actors/valkyrie_to_active_fedora_spec.rb +70 -0
  313. data/spec/controllers/catalog_controller_spec.rb +2 -2
  314. data/spec/controllers/hyrax/api/items_controller_spec.rb +9 -15
  315. data/spec/controllers/hyrax/collections_controller_spec.rb +6 -2
  316. data/spec/controllers/hyrax/dashboard/collections_controller_spec.rb +53 -4
  317. data/spec/controllers/hyrax/depositors_controller_spec.rb +3 -3
  318. data/spec/controllers/hyrax/downloads_controller_spec.rb +11 -2
  319. data/spec/controllers/hyrax/file_sets_controller_spec.rb +40 -2
  320. data/spec/controllers/hyrax/generic_works_controller_spec.rb +13 -3
  321. data/spec/controllers/hyrax/homepage_controller_spec.rb +3 -3
  322. data/spec/controllers/hyrax/single_use_links_viewer_controller_spec.rb +1 -2
  323. data/spec/factories/admin_sets_lw.rb +1 -1
  324. data/spec/factories/collections.rb +1 -1
  325. data/spec/factories/hyrax_embargo.rb +16 -0
  326. data/spec/factories/hyrax_lease.rb +16 -0
  327. data/spec/factories/hyrax_resource.rb +16 -0
  328. data/spec/factory_tests/adminsets_factory_spec.rb +4 -4
  329. data/spec/factory_tests/collections_factory_spec.rb +3 -3
  330. data/spec/features/actor_stack_spec.rb +64 -0
  331. data/spec/features/batch_create_spec.rb +1 -2
  332. data/spec/features/collection_multi_membership_spec.rb +1 -0
  333. data/spec/features/collection_spec.rb +2 -2
  334. data/spec/features/collection_type_spec.rb +1 -0
  335. data/spec/features/create_work_spec.rb +15 -6
  336. data/spec/features/dashboard/collection_spec.rb +103 -14
  337. data/spec/features/edit_content_block_admin_spec.rb +3 -3
  338. data/spec/features/edit_pages_admin.spec.rb +62 -0
  339. data/spec/features/proxy_spec.rb +21 -0
  340. data/spec/features/static_pages_spec.rb +1 -1
  341. data/spec/features/work_show_spec.rb +7 -3
  342. data/spec/fixtures/sample-file.pdf +0 -0
  343. data/spec/fixtures/updated-file.txt +1 -0
  344. data/spec/forms/hyrax/forms/batch_upload_form_spec.rb +5 -2
  345. data/spec/forms/hyrax/forms/collection_form_spec.rb +5 -2
  346. data/spec/forms/hyrax/forms/work_form_spec.rb +18 -5
  347. data/spec/forms/hyrax/generic_work_form_spec.rb +4 -4
  348. data/spec/helpers/hyrax/collections_helper_spec.rb +8 -8
  349. data/spec/helpers/hyrax/dashboard_helper_behavior_spec.rb +7 -8
  350. data/spec/helpers/hyrax/iiif_helper_spec.rb +16 -0
  351. data/spec/helpers/hyrax_helper_spec.rb +4 -4
  352. data/spec/hyrax/transactions/create_work_spec.rb +68 -0
  353. data/spec/hyrax/transactions/steps/apply_collection_permission_template_spec.rb +59 -0
  354. data/spec/hyrax/transactions/steps/apply_visibility_spec.rb +82 -0
  355. data/spec/indexers/hyrax/admin_set_indexer_spec.rb +15 -0
  356. data/spec/indexers/hyrax/file_set_indexer_spec.rb +26 -1
  357. data/spec/indexers/hyrax/valkyrie_indexers/base_indexer_spec.rb +16 -0
  358. data/spec/jobs/import_url_job_spec.rb +49 -2
  359. data/spec/jobs/ingest_local_file_job_spec.rb +25 -1
  360. data/spec/jobs/visibility_copy_job_spec.rb +46 -0
  361. data/spec/lib/hyrax/configuration_spec.rb +17 -11
  362. data/spec/lib/hyrax/redis_event_store_spec.rb +1 -1
  363. data/spec/matcher_tests/match_valkyrie_ids_with_af_ids_spec.rb +40 -0
  364. data/spec/models/file_set_spec.rb +4 -3
  365. data/spec/models/hyrax/embargo_spec.rb +27 -0
  366. data/spec/models/hyrax/file_metadata_spec.rb +110 -0
  367. data/spec/models/hyrax/lease_spec.rb +25 -0
  368. data/spec/models/hyrax/permission_template_spec.rb +2 -2
  369. data/spec/models/hyrax/resource_spec.rb +60 -0
  370. data/spec/models/hyrax/virus_scanner_spec.rb +50 -0
  371. data/spec/models/job_io_wrapper_spec.rb +63 -0
  372. data/spec/models/solr_hit_spec.rb +9 -0
  373. data/spec/models/user_spec.rb +1 -1
  374. data/spec/presenters/hyrax/file_set_presenter_spec.rb +11 -7
  375. data/spec/presenters/hyrax/presenter_factory_spec.rb +2 -2
  376. data/spec/presenters/hyrax/work_show_presenter_spec.rb +1 -1
  377. data/spec/requests/riiif_spec.rb +2 -2
  378. data/spec/search_builders/hyrax/my/find_works_search_builder_spec.rb +3 -3
  379. data/spec/services/hyrax/adapters/nesting_index_adapter_spec.rb +5 -6
  380. data/spec/services/hyrax/admin_set_service_spec.rb +2 -2
  381. data/spec/services/hyrax/custom_queries/navigators/child_collections_navigator_spec.rb +41 -0
  382. data/spec/services/hyrax/custom_queries/navigators/child_filesets_navigator_spec.rb +41 -0
  383. data/spec/services/hyrax/custom_queries/navigators/child_works_navigator_spec.rb +79 -0
  384. data/spec/services/hyrax/custom_queries/wings.rb +52 -0
  385. data/spec/services/hyrax/embargo_manager_spec.rb +123 -0
  386. data/spec/services/hyrax/embargo_service_spec.rb +2 -2
  387. data/spec/services/hyrax/file_set_visibility_propagator_spec.rb +59 -0
  388. data/spec/services/hyrax/resource_visibility_propagator_spec.rb +71 -0
  389. data/spec/services/hyrax/solr_query_builder_service_spec.rb +17 -0
  390. data/spec/services/hyrax/solr_service_spec.rb +218 -0
  391. data/spec/services/hyrax/thumbnail_path_service_spec.rb +6 -0
  392. data/spec/services/hyrax/versioning_service_spec.rb +35 -15
  393. data/spec/services/hyrax/visibility_intention_applicator_spec.rb +69 -0
  394. data/spec/services/hyrax/visibility_reader_spec.rb +38 -0
  395. data/spec/services/hyrax/visibility_writer_spec.rb +47 -0
  396. data/spec/services/hyrax/workflow/status_list_service_spec.rb +1 -13
  397. data/spec/services/hyrax/works/migration_service_spec.rb +29 -0
  398. data/spec/spec_helper.rb +24 -23
  399. data/spec/support/clean_solr.rb +7 -0
  400. data/spec/support/create_for_repository.rb +25 -0
  401. data/spec/support/factory_helpers.rb +3 -1
  402. data/spec/support/fakes/fake_actor.rb +21 -0
  403. data/spec/support/matchers/embargo.rb +9 -0
  404. data/spec/support/matchers/lease.rb +9 -0
  405. data/spec/support/matchers/match_valkyrie_ids_with_af_ids.rb +11 -0
  406. data/spec/support/matchers/permission.rb +22 -0
  407. data/spec/support/valkyrie_indexing.rb +1 -0
  408. data/spec/test_app_templates/Gemfile.extra +0 -2
  409. data/spec/test_app_templates/lib/generators/test_app_generator.rb +5 -6
  410. data/spec/valkyrie/indexing/solr/indexing_adapter_spec.rb +41 -0
  411. data/spec/valkyrie/indexing_adapter_spec.rb +25 -0
  412. data/spec/views/hyrax/base/_attributes.html.erb_spec.rb +1 -1
  413. data/spec/views/hyrax/base/_social_media.html.erb_spec.rb +0 -1
  414. data/spec/views/hyrax/base/show.html.erb_spec.rb +2 -2
  415. data/spec/views/hyrax/collections/_sort_and_per_page.html.erb_spec.rb +1 -1
  416. data/spec/views/hyrax/dashboard/_sidebar.html.erb_spec.rb +39 -0
  417. data/spec/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb_spec.rb +1 -1
  418. data/spec/views/hyrax/file_sets/_versioning.html.erb_spec.rb +1 -0
  419. data/spec/views/hyrax/my/collections/_list_collections.html.erb_spec.rb +2 -2
  420. data/spec/views/records/edit_fields/_alt_title.html.erb_spec.rb +26 -0
  421. data/spec/views/records/edit_fields/_title.html.erb_spec.rb +24 -0
  422. data/spec/wings/active_fedora_converter_spec.rb +136 -1
  423. data/spec/wings/converter_value_mapper_spec.rb +23 -0
  424. data/spec/wings/hydra/pcdm/models/concerns/collection_valkyrie_behavior_spec.rb +41 -0
  425. data/spec/wings/hydra/pcdm/models/concerns/object_valkyrie_behavior_spec.rb +19 -0
  426. data/spec/wings/hydra/pcdm/models/concerns/pcdm_valkyrie_behavior_spec.rb +442 -0
  427. data/spec/wings/hydra/works/models/concerns/collection_valkyrie_behavior_spec.rb +22 -0
  428. data/spec/wings/hydra/works/models/concerns/file_set_valkyrie_behavior_spec.rb +90 -0
  429. data/spec/wings/hydra/works/models/concerns/work_valkyrie_behavior_spec.rb +218 -0
  430. data/spec/wings/model_transformer_spec.rb +167 -112
  431. data/spec/wings/models/concerns/collection_behavior_spec.rb +120 -0
  432. data/spec/wings/services/file_metadata_builder_spec.rb +39 -0
  433. data/spec/wings/services/id_converter_service_spec.rb +24 -0
  434. data/spec/wings/{value_mapper_spec.rb → transformer_value_mapper_spec.rb} +2 -2
  435. data/spec/wings/valkyrie/persister_spec.rb +544 -53
  436. data/spec/wings/valkyrie/query_service_spec.rb +381 -4
  437. data/spec/wings_helper.rb +4 -0
  438. data/template.rb +1 -1
  439. metadata +205 -49
  440. data/.travis.yml +0 -36
  441. data/lib/wings/resource_factory.rb +0 -8
@@ -1,20 +1,81 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'wings/value_mapper'
3
+ require 'wings/transformer_value_mapper'
4
+ require 'wings/models/concerns/collection_behavior'
5
+ require 'wings/hydra/works/models/concerns/work_valkyrie_behavior'
6
+ require 'wings/hydra/works/models/concerns/file_set_valkyrie_behavior'
4
7
 
5
8
  module Wings
9
+ ##
10
+ # Transforms ActiveFedora models or objects into Valkyrie::Resource models or
11
+ # objects
6
12
  #
7
- # This class is responsible for coordinating the transformation of a PCDM
8
- # Model (be it the class or an instance of the class) to a [Valkyrie::Resource](https://github.com/samvera-labs/valkyrie/blob/master/lib/valkyrie/resource.rb).
9
- # for the given PCDM model.
13
+ # @see https://github.com/samvera-labs/valkyrie/blob/master/lib/valkyrie/resource.rb
14
+ #
15
+ # Similar to an orm_converter class in other valkyrie persisters. Also used by
16
+ # the Valkyrizable mixin to make AF objects able to return their
17
+ # Valkyrie::Resource representation.
10
18
  #
11
19
  # @example getting a valkyrie resource
12
20
  # work = GenericWork.new(id: 'an_identifier')
13
- # resource = Wings::ModelTransformer.for(pcdm_object: work)
21
+ # resource = Wings::ModelTransformer.for(work)
14
22
  #
15
23
  # resource.alternate_ids # => [#<Valkyrie::ID:0x... id: 'an_identifier'>]
16
24
  #
25
+ # rubocop:disable Metrics/ClassLength
17
26
  class ModelTransformer
27
+ ##
28
+ # @!attribute [rw] pcdm_object
29
+ # @return [ActiveFedora::Base]
30
+ attr_accessor :pcdm_object
31
+
32
+ ##
33
+ # @param pcdm_object [ActiveFedora::Base]
34
+ def initialize(pcdm_object:)
35
+ self.pcdm_object = pcdm_object
36
+ end
37
+
38
+ ##
39
+ # Factory
40
+ #
41
+ # @param pcdm_object [ActiveFedora::Base]
42
+ #
43
+ # @return [::Valkyrie::Resource] a resource mirroiring `pcdm_object`
44
+ def self.for(pcdm_object)
45
+ new(pcdm_object: pcdm_object).build
46
+ end
47
+
48
+ ##
49
+ # @param reflections [Hash<Symbol, Object>]
50
+ #
51
+ # @return [Array<Symbol>]
52
+ def self.relationship_keys_for(reflections:)
53
+ relationships = reflections
54
+ .keys
55
+ .reject { |k| k.to_s.include?('id') }
56
+ .map { |k| k.to_s.singularize + '_ids' }
57
+ relationships.delete('member_ids') # Remove here. Members will be extracted as ordered_members in attributes method.
58
+ relationships.delete('ordered_member_proxy_ids') # This does not have a Valkyrie equivalent.
59
+ relationships
60
+ end
61
+
62
+ ##
63
+ # Builds a `Valkyrie::Resource` equivalent to the `pcdm_object`
64
+ #
65
+ # @return [::Valkyrie::Resource] a resource mirroiring `pcdm_object`
66
+ def build
67
+ klass = ResourceClassCache.instance.fetch(pcdm_object) do
68
+ self.class.to_valkyrie_resource_class(klass: pcdm_object.class)
69
+ end
70
+
71
+ mint_id unless pcdm_object.id
72
+
73
+ attrs = attributes.tap { |hash| hash[:new_record] = pcdm_object.new_record? }
74
+ attrs[:alternate_ids] = [::Valkyrie::ID.new(pcdm_object.id)] if pcdm_object.id
75
+
76
+ klass.new(**attrs)
77
+ end
78
+
18
79
  ##
19
80
  # Caches dynamically generated `Valkyrie::Resource` subclasses mapped from
20
81
  # legacy `ActiveFedora` model classes.
@@ -27,6 +88,8 @@ module Wings
27
88
  # end
28
89
  #
29
90
  class ResourceClassCache
91
+ include Singleton
92
+
30
93
  ##
31
94
  # @!attribute [r] cache
32
95
  # @return [Hash<Class, Class>]
@@ -47,14 +110,19 @@ module Wings
47
110
  end
48
111
  end
49
112
 
50
- # we really want a class var here. maybe we could use a singleton instead?
51
- # rubocop:disable Style/ClassVars
52
- @@resource_class_cache = ResourceClassCache.new
53
-
54
113
  ##
55
- # @!attribute [rw] pcdm_object
56
- # @return [ActiveFedora::Base]
57
- attr_accessor :pcdm_object
114
+ # Selects an existing base class for the generated valkyrie class
115
+ #
116
+ # @return [Class]
117
+ def self.base_for(klass:)
118
+ if klass == Hydra::AccessControls::Embargo
119
+ Hyrax::Embargo
120
+ elsif klass == Hydra::AccessControls::Lease
121
+ Hyrax::Lease
122
+ else
123
+ Hyrax::Resource
124
+ end
125
+ end
58
126
 
59
127
  ##
60
128
  # @note The method signature is to conform to Valkyrie's method signature
@@ -77,30 +145,44 @@ module Wings
77
145
  # @return [Class] a dyamically generated `Valkyrie::Resource` subclass
78
146
  # mirroring the provided `ActiveFedora` model
79
147
  #
148
+ # rubocop:disable Metrics/AbcSize
80
149
  # rubocop:disable Metrics/MethodLength because metaprogramming a class
81
150
  # results in long methods
82
151
  def self.to_valkyrie_resource_class(klass:)
83
- Class.new(ActiveFedoraResource) do
152
+ relationship_keys = klass.respond_to?(:reflections) ? relationship_keys_for(reflections: klass.reflections) : []
153
+ relationship_keys.delete('member_ids')
154
+ relationship_keys.delete('member_of_collection_ids')
155
+ reflection_id_keys = klass.respond_to?(:reflections) ? klass.reflections.keys.select { |k| k.to_s.end_with? '_id' } : []
156
+
157
+ Class.new(base_for(klass: klass)) do
158
+ include Wings::CollectionBehavior if klass.included_modules.include?(Hyrax::CollectionBehavior)
159
+ include Wings::Works::WorkValkyrieBehavior if klass.included_modules.include?(Hyrax::WorkBehavior)
160
+ include Wings::Works::FileSetValkyrieBehavior if klass.included_modules.include?(Hyrax::FileSetBehavior)
161
+
84
162
  # Based on Valkyrie implementation, we call Class.to_s to define
85
163
  # the internal resource.
86
- @internal_resource = klass
164
+ @internal_resource = klass.to_s
87
165
 
88
166
  class << self
89
167
  attr_reader :internal_resource
90
168
  end
91
169
 
92
170
  def self.to_s
93
- internal_resource.to_s
171
+ internal_resource
94
172
  end
95
173
 
96
174
  klass.properties.each_key do |property_name|
97
175
  attribute property_name.to_sym, ::Valkyrie::Types::String
98
176
  end
99
- relationship_keys = klass.reflections.keys.reject { |k| k.to_s.include?('id') }.map { |k| k.to_s.singularize + '_ids' }
177
+
100
178
  relationship_keys.each do |linked_property_name|
101
179
  attribute linked_property_name.to_sym, ::Valkyrie::Types::Set.of(::Valkyrie::Types::ID)
102
180
  end
103
181
 
182
+ reflection_id_keys.each do |property_name|
183
+ attribute property_name, ::Valkyrie::Types::ID
184
+ end
185
+
104
186
  # Defined after properties in case we have an `internal_resource` property.
105
187
  # This may not be ideal, but based on my understanding of the `internal_resource`
106
188
  # usage in Valkyrie, I'd rather keep synchronized the instance_method and class_method value for
@@ -111,48 +193,91 @@ module Wings
111
193
  end
112
194
  end
113
195
  # rubocop:enable Metrics/MethodLength
196
+ # rubocop:enable Metrics/AbcSize
114
197
 
115
- ##
116
- # @param pcdm_object [ActiveFedora::Base]
117
- def initialize(pcdm_object:)
118
- self.pcdm_object = pcdm_object
119
- end
120
-
121
- ##
122
- # @param pcdm_object [ActiveFedora::Base]
123
- #
124
- # @return [::Valkyrie::Resource] a resource mirroiring `pcdm_object`
125
- def self.for(pcdm_object)
126
- new(pcdm_object: pcdm_object).build
127
- end
128
-
129
- ##
130
- # Builds a `Valkyrie::Resource` equivalent to the `pcdm_object`
131
- #
132
- # @return [::Valkyrie::Resource] a resource mirroiring `pcdm_object`
133
- def build
134
- klass = @@resource_class_cache.fetch(pcdm_object) do
135
- self.class.to_valkyrie_resource_class(klass: pcdm_object.class)
198
+ class AttributeTransformer
199
+ def self.run(obj, keys)
200
+ # TODO: There is an open question about whether we want to treat all these relationships the same. See Issue #3904.
201
+ attrs = keys.select { |k| k.to_s.end_with? '_ids' }.each_with_object({}) do |attr_name, mem|
202
+ mem[attr_name.to_sym] =
203
+ TransformerValueMapper.for(obj.try(attr_name)).result ||
204
+ TransformerValueMapper.for(attribute_ids_for(name: attr_name.chomp('_ids'), obj: obj)).result ||
205
+ TransformerValueMapper.for(attribute_ids_for(name: attr_name.chomp('_ids').pluralize, obj: obj)).result || []
206
+ end
207
+ keys.each_with_object(attrs) do |attr_name, mem|
208
+ next unless obj.respond_to?(attr_name) && !mem.key?(attr_name.to_sym)
209
+ mem[attr_name.to_sym] = TransformerValueMapper.for(obj.public_send(attr_name)).result
210
+ end
136
211
  end
137
- klass.new(alternate_ids: [::Valkyrie::ID.new(pcdm_object.id)], **attributes)
138
- end
139
212
 
140
- class ActiveFedoraResource < ::Valkyrie::Resource
141
- attribute :alternate_ids, ::Valkyrie::Types::Array
213
+ def self.attribute_ids_for(name:, obj:)
214
+ attribute_value = obj.try(name)
215
+ return unless attribute_value.present?
216
+ Array(attribute_value).map(&:id)
217
+ end
142
218
  end
143
219
 
144
220
  private
145
221
 
222
+ def mint_id
223
+ id = pcdm_object.assign_id
224
+
225
+ pcdm_object.id = id unless id.blank?
226
+ end
227
+
146
228
  def attributes
147
- relationship_keys = pcdm_object.reflections.keys.reject { |k| k.to_s.include?('id') }.map { |k| k.to_s.singularize + '_ids' }
229
+ all_keys =
230
+ pcdm_object.attributes.keys +
231
+ self.class.relationship_keys_for(reflections: pcdm_object.reflections)
232
+
233
+ result = AttributeTransformer.run(pcdm_object, all_keys).merge(reflection_ids).merge(additional_attributes)
234
+
235
+ append_embargo(result)
236
+ append_lease(result)
148
237
 
149
- attrs_with_relationships = pcdm_object.attributes.keys + relationship_keys
238
+ result
239
+ end
150
240
 
151
- attrs_with_relationships.each_with_object({}) do |attr_name, mem|
152
- next unless pcdm_object.respond_to? attr_name
153
- mem[attr_name.to_sym] = ValueMapper.for(pcdm_object.public_send(attr_name)).result
241
+ def reflection_ids
242
+ pcdm_object.reflections.keys.select { |k| k.to_s.end_with? '_id' }.each_with_object({}) do |k, mem|
243
+ mem[k] = pcdm_object.try(k)
154
244
  end
155
245
  end
246
+
247
+ def additional_attributes
248
+ { created_at: pcdm_object.try(:create_date),
249
+ updated_at: pcdm_object.try(:modified_date),
250
+ read_groups: pcdm_object.try(:read_groups),
251
+ read_users: pcdm_object.try(:read_users),
252
+ edit_groups: pcdm_object.try(:edit_groups),
253
+ edit_users: pcdm_object.try(:edit_users),
254
+ member_ids: member_ids }
255
+ end
256
+
257
+ # Prefer ordered members, but if ordered members don't exist, use non-ordered members.
258
+ def member_ids
259
+ ordered_member_ids = pcdm_object.try(:ordered_member_ids)
260
+ return ordered_member_ids if ordered_member_ids.present?
261
+ pcdm_object.try(:member_ids)
262
+ end
263
+
264
+ def append_embargo(attrs)
265
+ return unless pcdm_object.try(:embargo)
266
+ embargo_attrs = pcdm_object.embargo.attributes.symbolize_keys
267
+ embargo_attrs[:embargo_history] = embargo_attrs[:embargo_history].to_a
268
+ embargo_attrs[:id] = ::Valkyrie::ID.new(embargo_attrs[:id]) if embargo_attrs[:id]
269
+
270
+ attrs[:embargo] = Hyrax::Embargo.new(**embargo_attrs)
271
+ end
272
+
273
+ def append_lease(attrs)
274
+ return unless pcdm_object.try(:lease)
275
+ lease_attrs = pcdm_object.lease.attributes.symbolize_keys
276
+ lease_attrs[:lease_history] = lease_attrs[:embargo_history].to_a
277
+ lease_attrs[:id] = ::Valkyrie::ID.new(lease_attrs[:id]) if lease_attrs[:id]
278
+
279
+ attrs[:lease] = Hyrax::Lease.new(**lease_attrs)
280
+ end
156
281
  end
157
- # rubocop:enable Style/ClassVars
282
+ # rubocop:enable Style/ClassVars Metrics/ClassLength
158
283
  end
@@ -0,0 +1,38 @@
1
+ require 'wings/services/id_converter_service'
2
+ require 'wings/hydra/works/models/concerns/collection_valkyrie_behavior'
3
+
4
+ module Wings
5
+ module CollectionBehavior
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include Wings::Works::CollectionValkyrieBehavior
10
+ end
11
+
12
+ # Add member objects by adding this collection to the objects' member_of_collection association.
13
+ # @param [Enumerable<String> | Enumerable<Valkyrie::ID] the ids of the new child collections and works collection ids
14
+ def add_collections_and_works(new_member_ids, valkyrie: false)
15
+ ### TODO: Change to do this through Valkyrie. Right now using existing AF method to get multi-membership check.
16
+ af_self = Wings::ActiveFedoraConverter.new(resource: self).convert
17
+ af_ids = valkyrie ? Wings::IdConverterService.convert_to_active_fedora_ids(new_member_ids) : new_member_ids
18
+ af_self.add_member_objects(af_ids)
19
+ end
20
+ alias add_member_objects add_collections_and_works
21
+
22
+ ##
23
+ # @return [Enumerable<ActiveFedora::Base> | Enumerable<Valkyrie::Resource>] an enumerable over the children of this collection
24
+ def child_collections_and_works(valkyrie: false)
25
+ af_collections_and_works = ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id.id}")
26
+ return af_collections_and_works unless valkyrie
27
+ af_collections_and_works.map(&:valkyrie_resource)
28
+ end
29
+ alias member_objects child_collections_and_works
30
+
31
+ ##
32
+ # @return [Enumerable<ActiveFedora::Base> | Enumerable<Valkyrie::Resource>] an enumerable over the children of this collection
33
+ def child_collections_and_works_ids(valkyrie: false)
34
+ child_collections_and_works(valkyrie: valkyrie).map(&:id)
35
+ end
36
+ alias member_object_ids child_collections_and_works_ids
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wings
4
+ class MultiChecksum < ::Valkyrie::Resource
5
+ attribute :sha256, ::Valkyrie::Types::SingleValuedString
6
+ attribute :md5, ::Valkyrie::Types::SingleValuedString
7
+ attribute :sha1, ::Valkyrie::Types::SingleValuedString
8
+
9
+ def self.for(file_object)
10
+ digests = file_object.checksum(digests: [::Digest::MD5.new, ::Digest::SHA256.new, ::Digest::SHA1.new])
11
+ MultiChecksum.new(
12
+ md5: digests.shift,
13
+ sha256: digests.shift,
14
+ sha1: digests.shift
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+ require 'wings/hydra/works/services/add_file_metadata_to_file_set'
3
+
4
+ # TODO: The file_metadata resource and the file_metadata_builder should be in Hyrax as they will be needed for non-wings valkyrie implementations too.
5
+
6
+ module Wings
7
+ # Stores a file and an associated Hyrax::FileMetadata
8
+ class FileMetadataBuilder
9
+ include Hyrax::Noid
10
+
11
+ attr_reader :storage_adapter, :persister
12
+ def initialize(storage_adapter:, persister:)
13
+ @storage_adapter = storage_adapter
14
+ @persister = persister
15
+ end
16
+
17
+ # @param io_wrapper [JobIOWrapper] with details about the uploaded file
18
+ # @param file_metadata [Hyrax::FileMetadata] the metadata to represent the file
19
+ # @param file_set [Valkyrie::Resouce, Hydra::Works::FileSet] the associated FileSet # TODO: WINGS - Remove Hydra::Works::FileSet as a potential type when valkyrization is complete.
20
+ # @return [Hyrax::FileMetadata] the persisted metadata file_metadata that represents the file
21
+ def create(io_wrapper:, file_metadata:, file_set:)
22
+ io_wrapper = build_file(io_wrapper, file_metadata.use)
23
+ file_set.save unless file_set.persisted?
24
+ file_metadata.id = ::Valkyrie::ID.new(assign_id)
25
+ file_metadata.file_set_id = file_set.id
26
+ stored_file = storage_adapter.upload(file: io_wrapper,
27
+ original_filename: io_wrapper.original_filename,
28
+ content_type: io_wrapper.content_type,
29
+ resource: file_metadata,
30
+ resource_uri_transformer: Hyrax.config.resource_id_to_uri_transformer)
31
+ file_metadata.file_identifiers = [stored_file.id]
32
+ attach_file_metadata(file_metadata: file_metadata, file_set: file_set)
33
+ end
34
+
35
+ # @param file_metadata [Hyrax::FileMetadata] the metadata to represent the file
36
+ # @param file_set [Valkyrie::Resouce, Hydra::Works::FileSet] the associated FileSet # TODO: WINGS - Remove Hydra::Works::FileSet as a potential type when valkyrization is complete.
37
+ # @return [Hyrax::FileMetadata] the persisted metadata file_metadata that represents the file
38
+ def attach_file_metadata(file_metadata:, file_set:)
39
+ file_set.is_a?(::Valkyrie::Resource) ? attach_file_metadata_to_valkyrie_file_set(file_metadata, file_set) : file_metadata
40
+ end
41
+
42
+ private
43
+
44
+ def attach_file_metadata_to_valkyrie_file_set(file_metadata, file_set)
45
+ # This is for storage adapters other than wings. The wings storage adapter already attached the file to the file_set.
46
+ # This process is a no-op for wings. # TODO: WINGS - May need to verify this is a no-op for wings once file_set is passed in as a resource.
47
+ # TODO: WINGS - Need to test this against other adapters once they are available for use.
48
+ existing_file_metadata = file_set.original_file || file_metadata
49
+ file_metadata = existing_file_metadata.new(file_metadata.to_h.except(:id))
50
+ saved_file_metadata = persister.save(resource: file_metadata)
51
+ file_set.file_ids = [saved_file_metadata.id]
52
+ persister.save(resource: file_set)
53
+ saved_file_metadata
54
+ end
55
+
56
+ # Class for wrapping the file being ingested
57
+ class IoDecorator < SimpleDelegator
58
+ attr_reader :original_filename, :content_type, :length, :use, :tempfile
59
+
60
+ # @param [IO] io stream for the file content
61
+ # @param [String] original_filename
62
+ # @param [String] content_type
63
+ # @param [RDF::URI] use the URI for the PCDM predicate indicating the use for this resource
64
+ def initialize(io, original_filename, content_type, content_length, use)
65
+ @original_filename = original_filename
66
+ @content_type = content_type
67
+ @length = content_length
68
+ @use = use
69
+ @tempfile = io
70
+ super(io)
71
+ end
72
+ end
73
+
74
+ # Constructs the IoDecorator for ingesting the intermediate file
75
+ # @param [JobIOWrapper] io wrapper with details about the uploaded file
76
+ # @param [RDF::URI] use the URI for the PCDM predicate indicating the use for this resource
77
+ def build_file(io_wrapper, use)
78
+ IoDecorator.new(io_wrapper.file, io_wrapper.original_name, io_wrapper.mime_type, io_wrapper.size, use)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,14 @@
1
+ # Converson service for going between valkyrie_ids and fedora_ids
2
+ # NOTE: This is pretty heavy handed since it loads objects to get the converted ids.
3
+ module Wings
4
+ class IdConverterService
5
+ def self.convert_to_active_fedora_ids(valkyrie_ids)
6
+ resources = valkyrie_ids.map { |id| Hyrax.query_service.find_by(id: id) }
7
+ resources.map { |resource| resource.id.id } # TODO: What if id.id is empty?
8
+ end
9
+
10
+ def self.convert_to_valkyrie_resource_ids(fedora_ids)
11
+ fedora_ids.map { |id| ActiveFedora::Base.find(id).valkyrie_resource.id }
12
+ end
13
+ end
14
+ end