hyrax 4.0.0 → 5.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +124 -232
  3. data/.dassie/.env +8 -2
  4. data/.dassie/Gemfile +27 -42
  5. data/.dassie/Gemfile.dassie +2 -0
  6. data/.dassie/app/assets/config/manifest.js +2 -0
  7. data/.dassie/app/assets/stylesheets/hyrax.scss +1 -0
  8. data/.dassie/config/environments/test.rb +1 -0
  9. data/.dassie/config/initializers/hyrax.rb +3 -1
  10. data/.dassie/config/initializers/riiif.rb +11 -7
  11. data/.dassie/config/metadata/collection_resource.yaml +3 -0
  12. data/.dassie/config/metadata/monograph.yaml +8 -0
  13. data/.dassie/config/metadata/sample_metadata.yaml +1 -0
  14. data/.dassie/config/redis.yml +2 -0
  15. data/.dassie/db/migrate/20230725222727_create_hyrax_counter_metrics.hyrax.rb +14 -0
  16. data/.dassie/db/migrate/20230803165135_change_work_id_to_string.rb +5 -0
  17. data/.dassie/db/migrate/20230808102105_add_indices_to_hyrax_counter_metrics.hyrax.rb +8 -0
  18. data/.dassie/db/migrate/20230821153635_add_fields_to_counter_metric.rb +8 -0
  19. data/.dassie/db/schema.rb +22 -3
  20. data/.dockerignore +7 -0
  21. data/.github/PULL_REQUEST_TEMPLATE.md +10 -7
  22. data/.github/release.yml +5 -2
  23. data/.gitignore +1 -1
  24. data/.koppie/.env +13 -4
  25. data/.koppie/Gemfile +10 -12
  26. data/.koppie/Gemfile.koppie +2 -0
  27. data/.koppie/Rakefile +0 -2
  28. data/.koppie/app/models/ability.rb +1 -5
  29. data/.koppie/app/models/user.rb +0 -2
  30. data/.koppie/config/application.rb +2 -1
  31. data/.koppie/config/arkivo.yml +6 -0
  32. data/.koppie/config/blacklight.yml +2 -2
  33. data/.koppie/config/environments/test.rb +1 -0
  34. data/.koppie/config/features.yml +2 -0
  35. data/.koppie/config/initializers/1_valkyrie.rb +29 -6
  36. data/.koppie/config/initializers/arkivo_constraint.rb +12 -0
  37. data/.koppie/config/initializers/hyrax.rb +10 -4
  38. data/.koppie/config/initializers/riiif.rb +11 -7
  39. data/.koppie/config/metadata/collection_resource.yaml +49 -0
  40. data/.koppie/config/metadata/generic_work.yaml +2 -0
  41. data/.koppie/config/metadata/monograph.yaml +10 -0
  42. data/.koppie/config/role_map.yml +3 -25
  43. data/.koppie/config/routes.rb +1 -2
  44. data/.koppie/config/solr.yml +1 -1
  45. data/.koppie/config/valkyrie_index.yml +4 -10
  46. data/.koppie/config/zotero.yml +6 -0
  47. data/.koppie/db/migrate/20230725222727_create_hyrax_counter_metrics.hyrax.rb +14 -0
  48. data/.koppie/db/migrate/20230803165135_change_work_id_to_string.rb +5 -0
  49. data/.koppie/db/schema.rb +12 -1
  50. data/.koppie/yarn.lock +23 -23
  51. data/.regen +1 -1
  52. data/CONTAINERS.md +1 -3
  53. data/Dockerfile +17 -13
  54. data/Gemfile +4 -21
  55. data/Gemfile.dassie +2 -0
  56. data/Gemfile.koppie +2 -0
  57. data/README.md +0 -1
  58. data/Rakefile +0 -11
  59. data/app/actors/hyrax/actors/base_actor.rb +4 -3
  60. data/app/actors/hyrax/actors/embargo_actor.rb +3 -3
  61. data/app/actors/hyrax/actors/lease_actor.rb +5 -2
  62. data/app/assets/javascripts/hyrax/batch_select_all.js +1 -1
  63. data/app/assets/javascripts/hyrax/file_manager/member.es6 +1 -1
  64. data/app/assets/javascripts/hyrax/file_manager/sorting.es6 +3 -2
  65. data/app/assets/stylesheets/hyrax/_file-listing.scss +0 -2
  66. data/app/assets/stylesheets/hyrax/_work-show.scss +19 -3
  67. data/app/assets/stylesheets/hyrax/sidebar.scss +23 -0
  68. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +8 -2
  69. data/app/controllers/concerns/hyrax/leases_controller_behavior.rb +7 -1
  70. data/app/controllers/concerns/hyrax/valkyrie_downloads_controller_behavior.rb +79 -0
  71. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +64 -14
  72. data/app/controllers/hyrax/admin/workflows_controller.rb +48 -3
  73. data/app/controllers/hyrax/api/items_controller.rb +2 -3
  74. data/app/controllers/hyrax/batch_edits_controller.rb +39 -10
  75. data/app/controllers/hyrax/batch_uploads_controller.rb +5 -1
  76. data/app/controllers/hyrax/dashboard/collections_controller.rb +4 -1
  77. data/app/controllers/hyrax/downloads_controller.rb +8 -1
  78. data/app/controllers/hyrax/file_sets_controller.rb +50 -6
  79. data/app/controllers/hyrax/my/collections_controller.rb +2 -0
  80. data/app/controllers/hyrax/single_use_links_viewer_controller.rb +16 -2
  81. data/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb +38 -0
  82. data/app/forms/hyrax/forms/collection_form.rb +0 -15
  83. data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +0 -34
  84. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  85. data/app/forms/hyrax/forms/file_set_form.rb +2 -2
  86. data/app/forms/hyrax/forms/pcdm_object_form.rb +21 -0
  87. data/app/forms/hyrax/forms/permission_template_form.rb +2 -7
  88. data/app/forms/hyrax/forms/resource_batch_edit_form.rb +118 -0
  89. data/app/forms/hyrax/forms/resource_form.rb +21 -34
  90. data/app/forms/hyrax/forms/work_embargo_form.rb +1 -0
  91. data/app/forms/hyrax/forms/work_form.rb +1 -1
  92. data/app/forms/hyrax/forms/work_lease_form.rb +1 -0
  93. data/app/helpers/hyrax/dashboard_helper_behavior.rb +30 -9
  94. data/app/helpers/hyrax/membership_helper.rb +13 -1
  95. data/app/helpers/hyrax/work_form_helper.rb +0 -107
  96. data/app/indexers/hyrax/file_set_indexer.rb +6 -0
  97. data/app/indexers/hyrax/location_indexer.rb +29 -0
  98. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +36 -5
  99. data/app/indexers/hyrax/valkyrie_work_indexer.rb +9 -2
  100. data/app/inputs/controlled_vocabulary_input.rb +1 -1
  101. data/app/jobs/characterize_job.rb +1 -1
  102. data/app/jobs/create_work_job.rb +36 -4
  103. data/app/jobs/valkyrie_characterization_job.rb +9 -0
  104. data/app/jobs/valkyrie_create_derivatives_job.rb +8 -7
  105. data/app/jobs/valkyrie_ingest_job.rb +1 -4
  106. data/app/models/admin_set.rb +1 -31
  107. data/app/models/collection_branding_info.rb +2 -9
  108. data/app/models/concerns/hyrax/ability.rb +2 -1
  109. data/app/models/concerns/hyrax/collection_behavior.rb +4 -12
  110. data/app/models/concerns/hyrax/file_set/derivatives.rb +3 -2
  111. data/app/models/concerns/hyrax/riiif_file.rb +30 -0
  112. data/app/models/concerns/hyrax/solr_document_behavior.rb +20 -3
  113. data/app/models/hyrax/collection_type.rb +5 -14
  114. data/app/models/hyrax/counter_metric.rb +7 -0
  115. data/app/models/hyrax/file_metadata.rb +9 -9
  116. data/app/models/hyrax/file_set.rb +76 -15
  117. data/app/models/hyrax/orcid_validator.rb +0 -6
  118. data/app/models/hyrax/resource.rb +30 -2
  119. data/app/models/hyrax/work.rb +2 -5
  120. data/app/presenters/hyrax/collection_presenter.rb +0 -17
  121. data/app/presenters/hyrax/embargo_presenter.rb +4 -0
  122. data/app/presenters/hyrax/file_set_presenter.rb +6 -0
  123. data/app/presenters/hyrax/iiif_manifest_presenter.rb +3 -7
  124. data/app/presenters/hyrax/pcdm_member_presenter_factory.rb +6 -4
  125. data/app/presenters/hyrax/presenter_renderer.rb +0 -7
  126. data/app/presenters/hyrax/version_list_presenter.rb +19 -10
  127. data/app/presenters/hyrax/version_presenter.rb +19 -4
  128. data/app/presenters/hyrax/work_show_presenter.rb +6 -11
  129. data/app/search_builders/hyrax/file_set_search_builder.rb +1 -1
  130. data/app/search_builders/hyrax/valkyrie_abstract_type_relation.rb +37 -0
  131. data/app/search_builders/hyrax/valkyrie_work_relation.rb +9 -0
  132. data/app/services/hyrax/admin_set_create_service.rb +0 -17
  133. data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +16 -9
  134. data/app/services/hyrax/collections/collection_member_service.rb +1 -1
  135. data/app/services/hyrax/custom_queries/find_by_date_range.rb +55 -0
  136. data/app/services/hyrax/custom_queries/find_count_by.rb +62 -0
  137. data/app/services/hyrax/custom_queries/find_file_metadata.rb +1 -1
  138. data/app/services/hyrax/custom_queries/find_models_by_access.rb +59 -0
  139. data/app/services/hyrax/derivative_bucketed_storage.rb +25 -0
  140. data/app/services/hyrax/derivative_path.rb +14 -4
  141. data/app/services/hyrax/embargo_manager.rb +106 -13
  142. data/app/services/hyrax/embargo_service.rb +12 -10
  143. data/app/services/hyrax/file_set_derivatives_service.rb +14 -13
  144. data/app/services/hyrax/fixity_check_failure_service.rb +1 -1
  145. data/app/services/hyrax/identifier/dispatcher.rb +9 -2
  146. data/app/services/hyrax/lease_manager.rb +88 -8
  147. data/app/services/hyrax/listeners/file_metadata_listener.rb +16 -8
  148. data/app/services/hyrax/listeners/member_cleanup_listener.rb +2 -28
  149. data/app/services/hyrax/listeners/metadata_index_listener.rb +11 -0
  150. data/app/services/hyrax/listeners/workflow_listener.rb +8 -11
  151. data/app/services/hyrax/lock_manager.rb +1 -2
  152. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +24 -2
  153. data/app/services/hyrax/riiif_file_resolver.rb +50 -0
  154. data/app/services/hyrax/simple_schema_loader.rb +31 -0
  155. data/app/services/hyrax/solr_query_service.rb +7 -6
  156. data/app/services/hyrax/statistics/depositors/summary.rb +1 -1
  157. data/app/services/hyrax/statistics/over_time.rb +1 -1
  158. data/app/services/hyrax/statistics/users/over_time.rb +3 -1
  159. data/app/services/hyrax/statistics/valkyrie_query_service.rb +49 -0
  160. data/app/services/hyrax/statistics/works/count.rb +1 -1
  161. data/app/services/hyrax/thumbnail_path_service.rb +5 -0
  162. data/app/services/hyrax/valkyrie_persist_derivatives.rb +16 -11
  163. data/app/services/hyrax/valkyrie_upload.rb +16 -28
  164. data/app/services/hyrax/versioning_service.rb +30 -15
  165. data/app/services/hyrax/visibility_intention.rb +1 -4
  166. data/app/services/hyrax/visibility_propagator.rb +1 -1
  167. data/app/services/hyrax/work_uploads_handler.rb +1 -1
  168. data/app/services/hyrax/workflow/actionable_objects.rb +28 -3
  169. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +1 -1
  170. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +1 -1
  171. data/app/services/hyrax/workflow/permission_query.rb +23 -2
  172. data/app/validators/hyrax/collection_membership_validator.rb +1 -1
  173. data/app/views/catalog/_search_form.html.erb +1 -1
  174. data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
  175. data/app/views/hyrax/admin/workflows/_tabs.html.erb +9 -0
  176. data/app/views/hyrax/admin/workflows/index.html.erb +53 -76
  177. data/app/views/hyrax/base/_file_manager_members.html.erb +2 -2
  178. data/app/views/hyrax/base/_file_manager_resource_form.html.erb +1 -1
  179. data/app/views/hyrax/base/_form.html.erb +0 -10
  180. data/app/views/hyrax/base/_form_permission_embargo.html.erb +1 -1
  181. data/app/views/hyrax/base/_form_permission_lease.html.erb +1 -1
  182. data/app/views/hyrax/base/_form_visibility_component.html.erb +4 -4
  183. data/app/views/hyrax/base/_items.html.erb +1 -1
  184. data/app/views/hyrax/base/_show_actions.html.erb +1 -1
  185. data/app/views/hyrax/base/_workflow_actions.html.erb +25 -23
  186. data/app/views/hyrax/base/file_manager.html.erb +1 -1
  187. data/app/views/hyrax/base/show.json.jbuilder +4 -3
  188. data/app/views/hyrax/collections/_show_document_list_row.html.erb +1 -1
  189. data/app/views/hyrax/dashboard/collections/_list_collections.html.erb +1 -1
  190. data/app/views/hyrax/dashboard/collections/_show_document_list_row.html.erb +1 -1
  191. data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +3 -3
  192. data/app/views/hyrax/file_sets/_versioning.html.erb +5 -5
  193. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +4 -4
  194. data/app/views/hyrax/file_sets/media_display/_default.html.erb +1 -1
  195. data/app/views/hyrax/file_sets/media_display/_video.html.erb +2 -2
  196. data/app/views/hyrax/file_sets/show.html.erb +5 -3
  197. data/app/views/hyrax/homepage/_explore_collections.html.erb +1 -1
  198. data/app/views/hyrax/my/_search_form.html.erb +1 -1
  199. data/app/views/hyrax/notifications/_notifications.html.erb +1 -1
  200. data/app/views/hyrax/users/_vitals.html.erb +1 -1
  201. data/bin/dev-entrypoint.sh +13 -0
  202. data/chart/hyrax/Chart.yaml +18 -14
  203. data/chart/hyrax/README.md +34 -21
  204. data/chart/hyrax/templates/_helpers.tpl +34 -1
  205. data/chart/hyrax/templates/configmap-env.yaml +12 -2
  206. data/chart/hyrax/templates/secrets.yaml +1 -1
  207. data/chart/hyrax/values.yaml +39 -14
  208. data/config/initializers/file_length_patch.rb +10 -0
  209. data/config/initializers/listeners.rb +4 -10
  210. data/config/initializers/storage_adapter_initializer.rb +1 -1
  211. data/config/locales/hyrax.en.yml +8 -0
  212. data/config/metadata/basic_metadata.yaml +52 -0
  213. data/config/metadata/core_metadata.yaml +4 -0
  214. data/config/metadata/file_set_metadata.yaml +20 -1
  215. data/config/metadata/hyrax_internal_metadata.yaml +57 -0
  216. data/docker-compose-koppie.yml +36 -22
  217. data/docker-compose-sirenia.yml +202 -0
  218. data/docker-compose.yml +42 -26
  219. data/documentation/developing-your-hyrax-based-app.md +6 -14
  220. data/documentation/legacyREADME.md +3 -1
  221. data/hyrax.gemspec +12 -13
  222. data/karma.conf.js +9 -10
  223. data/lib/generators/hyrax/collection_resource/templates/collection_metadata.yaml +2 -0
  224. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  225. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +11 -7
  226. data/lib/generators/hyrax/templates/db/migrate/20230725222727_create_hyrax_counter_metrics.rb.erb +14 -0
  227. data/lib/generators/hyrax/templates/db/migrate/20230803165135_change_work_id_to_string.rb.erb +5 -0
  228. data/lib/generators/hyrax/templates/db/migrate/20230808102105_add_indices_to_hyrax_counter_metrics.rb.erb +8 -0
  229. data/lib/generators/hyrax/templates/db/migrate/20230821153635_add_fields_to_counter_metric.rb.erb +8 -0
  230. data/lib/generators/hyrax/templates/db/seeds.rb +1 -1
  231. data/lib/generators/hyrax/work_resource/templates/form.rb.erb +1 -1
  232. data/lib/generators/hyrax/work_resource/templates/metadata.yaml +2 -0
  233. data/lib/hyrax/active_fedora_dummy_model.rb +6 -1
  234. data/lib/hyrax/configuration.rb +147 -43
  235. data/lib/hyrax/controlled_vocabularies/location.rb +7 -1
  236. data/lib/hyrax/engine.rb +2 -1
  237. data/lib/hyrax/form_fields.rb +6 -0
  238. data/lib/hyrax/publisher.rb +23 -3
  239. data/lib/hyrax/redis_event_store.rb +7 -8
  240. data/lib/hyrax/resource_name.rb +4 -0
  241. data/lib/hyrax/specs/capybara.rb +25 -37
  242. data/lib/hyrax/specs/shared_specs/hydra_works.rb +34 -7
  243. data/lib/hyrax/specs/shared_specs/indexers.rb +24 -6
  244. data/lib/hyrax/transactions/collection_destroy.rb +3 -2
  245. data/lib/hyrax/transactions/container.rb +47 -0
  246. data/lib/hyrax/transactions/file_metadata_destroy.rb +20 -0
  247. data/lib/hyrax/transactions/file_set_destroy.rb +3 -1
  248. data/lib/hyrax/transactions/file_set_update.rb +21 -0
  249. data/lib/hyrax/transactions/steps/add_file_sets.rb +6 -0
  250. data/lib/hyrax/transactions/steps/add_to_parent.rb +1 -1
  251. data/lib/hyrax/transactions/steps/apply_permission_template.rb +40 -0
  252. data/lib/hyrax/transactions/steps/delete_all_file_metadata.rb +46 -0
  253. data/lib/hyrax/transactions/steps/delete_all_file_sets.rb +46 -0
  254. data/lib/hyrax/transactions/steps/file_metadata_delete.rb +40 -0
  255. data/lib/hyrax/transactions/steps/remove_from_membership.rb +45 -0
  256. data/lib/hyrax/transactions/steps/save.rb +21 -0
  257. data/lib/hyrax/transactions/work_create.rb +1 -0
  258. data/lib/hyrax/transactions/work_destroy.rb +3 -2
  259. data/lib/hyrax/version.rb +1 -1
  260. data/lib/hyrax.rb +1 -0
  261. data/lib/tasks/collection_type_global_id.rake +9 -4
  262. data/lib/tasks/embargo_lease.rake +1 -0
  263. data/lib/valkyrie/indexing/solr/indexing_adapter.rb +2 -0
  264. data/lib/wings/active_fedora_converter/default_work.rb +7 -2
  265. data/lib/wings/active_fedora_converter/file_metadata_node.rb +1 -1
  266. data/lib/wings/active_fedora_converter.rb +53 -11
  267. data/lib/wings/attribute_transformer.rb +24 -17
  268. data/lib/wings/model_transformer.rb +23 -12
  269. data/lib/wings/orm_converter.rb +23 -18
  270. data/lib/wings/setup.rb +23 -3
  271. data/lib/wings/valkyrie/persister.rb +4 -2
  272. data/lib/wings/valkyrie/storage.rb +8 -90
  273. data/lib/wings.rb +5 -0
  274. data/package.json +3 -1
  275. data/tasks/hyrax_dev.rake +2 -33
  276. data/template.rb +1 -1
  277. metadata +104 -81
  278. data/.engine_cart.yml +0 -3
  279. data/app/forms/hyrax/forms/file_manager_form.rb +0 -35
  280. data/app/services/hyrax/collections/migration_service.rb +0 -113
  281. data/app/views/hyrax/base/_form_collections_error.html.erb +0 -1
  282. data/app/views/hyrax/base/_form_in_works_error.html.erb +0 -3
  283. data/app/views/hyrax/base/_form_ordered_members_error.html.erb +0 -3
  284. data/app/views/hyrax/base/_form_visibility_error.html.erb +0 -19
  285. data/app/views/hyrax/users/_user_util_links_extra.html.erb +0 -0
  286. data/lib/hyrax/specs/shared_specs/valkyrie_storage_versions.rb +0 -9
@@ -15,6 +15,11 @@ class Hyrax::Characterization::ValkyrieCharacterizationService
15
15
  new(metadata: metadata, file: file, **options).characterize
16
16
  saved = Hyrax.persister.save(resource: metadata)
17
17
  Hyrax.publisher.publish('file.metadata.updated', metadata: saved, user: user)
18
+
19
+ Hyrax.publisher.publish('file.characterized',
20
+ file_set: Hyrax.query_service.find_by(id: saved.file_set_id),
21
+ file_id: saved.id.to_s,
22
+ path_hint: saved.file_identifier.to_s)
18
23
  end
19
24
 
20
25
  ##
@@ -27,25 +32,27 @@ class Hyrax::Characterization::ValkyrieCharacterizationService
27
32
  # @!attribute [rw] source
28
33
  # @return [Valkyrie::StorageAdapter::StreamFile]
29
34
  # @!attribute [rw] tools
30
- # @todo clarify what this is for. it gets passed to {#characterize}
31
- # on the characterizer, but it's not clear how to customize
32
- # effectively.
35
+ # can be :fits, :fits_servlet, :ffprobe or any other service added to HydraFileCharacterization
36
+ # note that ffprope is faster but only works on AV files.
33
37
  # @return [Symbol]
34
38
  attr_accessor :mapping, :metadata, :parser, :source, :tools
35
39
 
36
40
  ##
37
41
  # @api private
38
- def initialize(metadata:, # rubocop:disable Metrics/ParameterLists
39
- file:,
40
- characterizer: Hydra::FileCharacterization,
41
- parser_mapping: Hydra::Works::Characterization.mapper,
42
- parser: Hydra::Works::Characterization::FitsDocument.new)
42
+ def initialize( # rubocop:disable Metrics/ParameterLists
43
+ metadata:,
44
+ file:,
45
+ characterizer: Hydra::FileCharacterization,
46
+ parser_mapping: Hydra::Works::Characterization.mapper,
47
+ parser: Hydra::Works::Characterization::FitsDocument.new,
48
+ ch12n_tool: :fits
49
+ )
43
50
  @characterizer = characterizer
44
51
  @metadata = metadata
45
52
  @source = file
46
53
  @mapping = parser_mapping
47
54
  @parser = parser
48
- @tools = :fits
55
+ @tools = ch12n_tool
49
56
  end
50
57
 
51
58
  ##
@@ -106,7 +106,7 @@ module Hyrax
106
106
  def add_member(collection_id:, new_member:, user:)
107
107
  message = Hyrax::MultipleMembershipChecker.new(item: new_member).check(collection_ids: [collection_id], include_current_members: true)
108
108
  raise Hyrax::SingleMembershipError, message if message.present?
109
- new_member.member_of_collection_ids << collection_id # only populate this direction
109
+ new_member.member_of_collection_ids += [collection_id] # only populate this direction
110
110
  new_member = Hyrax.persister.save(resource: new_member)
111
111
  publish_metadata_updated(new_member, user)
112
112
  new_member
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindByDateRange
7
+ def self.queries
8
+ [:find_by_date_range]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param models [Array]
26
+ # @param start_datetime [DateTime]
27
+ # @param end_datetime [DateTime]
28
+ def find_by_date_range(start_datetime:, end_datetime: nil, models: nil)
29
+ end_datetime = 1.second.since(Time.zone.now) if end_datetime.blank?
30
+ if models.present?
31
+ query_service.run_query(find_models_by_date_range_query, start_datetime.to_s, end_datetime.to_s, models)
32
+ else
33
+ query_service.run_query(find_by_date_range_query, start_datetime.to_s, end_datetime.to_s)
34
+ end
35
+ end
36
+
37
+ def find_models_by_date_range_query
38
+ <<-SQL
39
+ SELECT * FROM orm_resources
40
+ WHERE created_at >= ?
41
+ AND created_at <= ?
42
+ AND internal_resource IN (?);
43
+ SQL
44
+ end
45
+
46
+ def find_by_date_range_query
47
+ <<-SQL
48
+ SELECT * FROM orm_resources
49
+ WHERE created_at >= ?
50
+ AND created_at <= ?;
51
+ SQL
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindCountBy
7
+ def self.queries
8
+ [:find_count_by]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param hash [Hash] the hash representation of the query
26
+ def find_count_by(hash = {}, models: nil)
27
+ return nil if models.empty? && hash.blank?
28
+
29
+ internal_array = ["{ #{hash.map { |k, v| "\"#{k}\": #{v}" }.join(', ')} }"] if hash.present?
30
+ if models.empty?
31
+ query_service.orm_class.count_by_sql(([find_count_by_properties_query] + internal_array))
32
+ elsif hash.blank?
33
+ query_service.orm_class.count_by_sql([find_count_by_models_query] + [models])
34
+ else
35
+ query_service.orm_class.count_by_sql(([find_count_by_properties_and_models_query] + internal_array + [models]))
36
+ end
37
+ end
38
+
39
+ def find_count_by_properties_and_models_query
40
+ <<-SQL
41
+ SELECT count(*) FROM orm_resources
42
+ WHERE metadata @> ?
43
+ AND internal_resource IN (?);
44
+ SQL
45
+ end
46
+
47
+ def find_count_by_models_query
48
+ <<-SQL
49
+ SELECT count(*) FROM orm_resources
50
+ WHERE internal_resource IN (?);
51
+ SQL
52
+ end
53
+
54
+ def find_count_by_properties_query
55
+ <<-SQL
56
+ SELECT count(*) FROM orm_resources
57
+ WHERE metadata @> ?;
58
+ SQL
59
+ end
60
+ end
61
+ end
62
+ end
@@ -67,7 +67,7 @@ module Hyrax
67
67
  return [] unless resource.try(:file_ids)
68
68
 
69
69
  results = find_many_file_metadata_by_ids(ids: resource.file_ids)
70
- results.select { |fm| fm.type.include?(use) }
70
+ results.select { |fm| fm.pcdm_use.include?(use) }
71
71
  end
72
72
  end
73
73
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module CustomQueries
4
+ ##
5
+ # @see https://github.com/samvera/valkyrie/wiki/Queries#custom-queries
6
+ class FindModelsByAccess
7
+ def self.queries
8
+ [:find_models_by_access]
9
+ end
10
+
11
+ def initialize(query_service:)
12
+ @query_service = query_service
13
+ end
14
+
15
+ attr_reader :query_service
16
+ delegate :resource_factory, to: :query_service
17
+ delegate :orm_class, to: :resource_factory
18
+
19
+ ##
20
+ # @note this is an unoptimized default implementation of this custom
21
+ # query. it's Hyrax's policy to provide such implementations of custom
22
+ # queries in use for cross-compatibility of Valkyrie query services.
23
+ # it's advisable to provide an optimized query for the specific adapter.
24
+ #
25
+ # @param model [Class]
26
+ # @param ids [Enumerable<#to_s>, Symbol]
27
+ #
28
+ def find_models_by_access(mode:, models: nil, agent:, group: nil)
29
+ agent = "group/#{agent}" if group.present?
30
+ internal_array = "{\"permissions\": [{\"mode\": \"#{mode}\", \"agent\": \"#{agent}\"}]}"
31
+ if models.present?
32
+ query_service.run_query(find_models_by_access_query, internal_array, models)
33
+ else
34
+ query_service.run_query(find_by_access_query, internal_array)
35
+ end
36
+ end
37
+
38
+ def find_models_by_access_query
39
+ <<-SQL
40
+ SELECT * FROM orm_resources
41
+ WHERE id IN (
42
+ SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources
43
+ WHERE metadata @> ?
44
+ ) AND internal_resource IN (?);
45
+ SQL
46
+ end
47
+
48
+ def find_by_access_query
49
+ <<-SQL
50
+ SELECT * FROM orm_resources
51
+ WHERE id IN (
52
+ SELECT uuid(metadata::json#>'{access_to,0}'->>'id') FROM orm_resources
53
+ WHERE metadata @> ?
54
+ );
55
+ SQL
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this class overrides the Valkyrie::Storage::Disk::BucketStorage class so that file paths match
4
+ module Hyrax
5
+ class DerivativeBucketedStorage
6
+ attr_reader :base_path
7
+
8
+ def initialize(base_path:)
9
+ @base_path = base_path
10
+ end
11
+
12
+ # rubocop:disable Lint/UnusedMethodArgument
13
+ def generate(resource:, file:, original_filename:)
14
+ raise ArgumentError, "original_filename must be provided" unless original_filename
15
+ Pathname.new(base_path).join(*bucketed_path(resource.id)).join(original_filename)
16
+ end
17
+ # rubocop:enable Lint/UnusedMethodArgument
18
+
19
+ def bucketed_path(id)
20
+ # We want to use the same code the derivative process uses so that items end up
21
+ # stored in the place we expect them.
22
+ Hyrax::DerivativePath.new(id.to_s).pair_directory
23
+ end
24
+ end
25
+ end
@@ -35,6 +35,18 @@ module Hyrax
35
35
  end
36
36
  end
37
37
 
38
+ def pairs
39
+ @pairs ||= id.split('').each_slice(2).map(&:join)
40
+ end
41
+
42
+ def pair_directory
43
+ pairs[0..-2]
44
+ end
45
+
46
+ def pair_path
47
+ (pair_directory + pairs[-1..-1]).join('/')
48
+ end
49
+
38
50
  private
39
51
 
40
52
  # @return [String] Returns the root path where derivatives will be generated into.
@@ -47,10 +59,6 @@ module Hyrax
47
59
  Pathname.new(Hyrax.config.derivatives_path).join(pair_path)
48
60
  end
49
61
 
50
- def pair_path
51
- id.split('').each_slice(2).map(&:join).join('/')
52
- end
53
-
54
62
  def file_name
55
63
  return unless destination_name
56
64
  destination_name + extension
@@ -60,6 +68,8 @@ module Hyrax
60
68
  case destination_name
61
69
  when 'thumbnail'
62
70
  ".#{MIME::Types.type_for('jpg').first.extensions.first}"
71
+ when 'extracted_text'
72
+ ".#{MIME::Types.type_for('txt').first.extensions.first}"
63
73
  else
64
74
  ".#{destination_name}"
65
75
  end
@@ -12,11 +12,13 @@ module Hyrax
12
12
  # date is today or later.
13
13
  # - "Applied" means the embargo's pre-release visibility has been set on
14
14
  # the resource.
15
- # - "Released" means the embargo's post-release visibility has been set on
16
- # the resource.
17
15
  # - "Enforced" means the object's visibility matches the pre-release
18
16
  # visibility of the embargo; i.e. the embargo has been applied,
19
17
  # but not released.
18
+ # - "Released" means the embargo's post-release visibility has been set on
19
+ # the resource.
20
+ # - "Deactivate" means that the existing embargo will be removed, even
21
+ # if it active.
20
22
  #
21
23
  # Note that an resource may be `#under_embargo?` even if the embargo is not
22
24
  # be `#enforced?` (in this case, the application should seek to apply the
@@ -74,7 +76,7 @@ module Hyrax
74
76
  # resource.visibility # => 'open'
75
77
  # manager.enforced? => false
76
78
  #
77
- class EmbargoManager
79
+ class EmbargoManager # rubocop:disable Metrics/ClassLength
78
80
  ##
79
81
  # @!attribute [rw] resource
80
82
  # @return [Hyrax::Resource]
@@ -108,15 +110,74 @@ module Hyrax
108
110
  .embargo
109
111
  end
110
112
 
113
+ # @return [Boolean]
114
+ def deactivate_embargo_for(resource:, query_service: Hyrax.query_service)
115
+ new(resource: resource, query_service: query_service)
116
+ .deactivate
117
+ end
118
+
119
+ # @return [Boolean]
120
+ def deactivate_embargo_for!(resource:, query_service: Hyrax.query_service)
121
+ new(resource: resource, query_service: query_service)
122
+ .deactivate!
123
+ end
124
+
125
+ # @return [Boolean]
111
126
  def release_embargo_for(resource:, query_service: Hyrax.query_service)
112
127
  new(resource: resource, query_service: query_service)
113
128
  .release
114
129
  end
115
130
 
131
+ # @return [Boolean]
116
132
  def release_embargo_for!(resource:, query_service: Hyrax.query_service)
117
133
  new(resource: resource, query_service: query_service)
118
134
  .release!
119
135
  end
136
+
137
+ # Creates or updates an existing embargo on a member to match the embargo on the parent work
138
+ # @param [Array<Valkyrie::Resource>] members
139
+ # @param [Hyrax::Work] work
140
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
141
+ def create_or_update_embargo_on_members(members, work)
142
+ # TODO: account for all members and levels, not just file sets. ref: #6131
143
+
144
+ members.each do |member|
145
+ member_embargo_needs_updating = work.embargo.updated_at > member.embargo&.updated_at if member.embargo
146
+
147
+ if member.embargo && member_embargo_needs_updating
148
+ member.embargo.embargo_release_date = work.embargo['embargo_release_date']
149
+ member.embargo.visibility_during_embargo = work.embargo['visibility_during_embargo']
150
+ member.embargo.visibility_after_embargo = work.embargo['visibility_after_embargo']
151
+ member.embargo = Hyrax.persister.save(resource: member.embargo)
152
+ else
153
+ work_embargo_manager = Hyrax::EmbargoManager.new(resource: work)
154
+ work_embargo_manager.copy_embargo_to(target: member)
155
+ member = Hyrax.persister.save(resource: member)
156
+ end
157
+
158
+ user ||= ::User.find_by_user_key(member.depositor)
159
+ # the line below works in that it indexes the file set with the necessary lease properties
160
+ # I do not know however if this is the best event_id to pass
161
+ Hyrax.publisher.publish('object.metadata.updated', object: member, user: user)
162
+ end
163
+ end
164
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
165
+ end
166
+
167
+ ##
168
+ # Deactivates the embargo
169
+ # @return [Boolean]
170
+ def deactivate
171
+ release(force: true) &&
172
+ nullify(force: true)
173
+ end
174
+
175
+ ##
176
+ # Deactivates the embargo
177
+ # @return [Boolean]
178
+ def deactivate!
179
+ release!(force: true)
180
+ nullify(force: true)
120
181
  end
121
182
 
122
183
  ##
@@ -128,7 +189,7 @@ module Hyrax
128
189
  def copy_embargo_to(target:)
129
190
  return false unless under_embargo?
130
191
 
131
- target.embargo = Embargo.new(clone_attributes)
192
+ target.embargo = Hyrax.persister.save(resource: Embargo.new(clone_attributes))
132
193
  self.class.apply_embargo_for(resource: target)
133
194
  end
134
195
 
@@ -152,7 +213,8 @@ module Hyrax
152
213
  ##
153
214
  # @return [Boolean]
154
215
  def enforced?
155
- embargo.visibility_during_embargo.to_s == resource.visibility
216
+ embargo.embargo_release_date.present? &&
217
+ (embargo.visibility_during_embargo.to_s == resource.visibility)
156
218
  end
157
219
 
158
220
  ##
@@ -162,21 +224,40 @@ module Hyrax
162
224
  end
163
225
 
164
226
  ##
165
- # Drop the embargo by setting its release date to `nil`.
227
+ # Drop the embargo by setting its release date and visibility settings to `nil`.
166
228
  #
167
- # @return [void]
168
- def nullify
169
- return unless under_embargo?
229
+ # @param force [Boolean] force the nullify even when the embargo period is current
230
+ #
231
+ # @return [Boolean]
232
+ def nullify(force: false)
233
+ return false if !force && under_embargo?
234
+
170
235
  embargo.embargo_release_date = nil
236
+ embargo.visibility_during_embargo = nil
237
+ embargo.visibility_after_embargo = nil
238
+ true
171
239
  end
172
240
 
173
241
  ##
174
- # Sets the visibility of the resource to the embargo's visibility condition.
175
- # no-op if the embargo period is current.
242
+ # Sets the visibility of the resource to the embargo's after embargo visibility.
243
+ # no-op if the embargo period is current and the force flag is false.
244
+ #
245
+ # @param force [boolean] force the release even when the embargo period is current
176
246
  #
177
247
  # @return [Boolean] truthy if the embargo has been applied
178
- def release
179
- return false if under_embargo?
248
+ def release(force: false)
249
+ return false if !force && under_embargo?
250
+
251
+ embargo_state = embargo.active? ? 'active' : 'expired'
252
+ history_record = embargo_history_message(
253
+ embargo_state,
254
+ Hyrax::TimeService.time_in_utc,
255
+ embargo.embargo_release_date,
256
+ embargo.visibility_during_embargo,
257
+ embargo.visibility_after_embargo
258
+ )
259
+ embargo.embargo_history += [history_record]
260
+
180
261
  return true if embargo.visibility_after_embargo.nil?
181
262
 
182
263
  resource.visibility = embargo.visibility_after_embargo
@@ -209,5 +290,17 @@ module Hyrax
209
290
  def core_attribute_keys
210
291
  [:visibility_after_embargo, :visibility_during_embargo, :embargo_release_date]
211
292
  end
293
+
294
+ protected
295
+
296
+ # Create the log message used when releasing an embargo
297
+ def embargo_history_message(state, deactivate_date, release_date, visibility_during, visibility_after)
298
+ I18n.t 'hydra.embargo.history_message',
299
+ state: state,
300
+ deactivate_date: deactivate_date,
301
+ release_date: release_date,
302
+ visibility_during: visibility_during,
303
+ visibility_after: visibility_after
304
+ end
212
305
  end
213
306
  end
@@ -1,24 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
+ ##
4
+ # Methods for Querying Repository to find Embargoed Objects
3
5
  class EmbargoService < RestrictionService
4
6
  class << self
5
- #
6
- # Methods for Querying Repository to find Embargoed Objects
7
- #
8
-
9
7
  # Returns all assets with embargo release date set to a date in the past
10
- def assets_with_expired_embargoes
8
+ def assets_with_expired_enforced_embargoes
11
9
  builder = Hyrax::ExpiredEmbargoSearchBuilder.new(self)
12
10
  presenters(builder)
13
11
  end
12
+ alias assets_with_expired_embargoes assets_with_expired_enforced_embargoes
14
13
 
15
- # Returns all assets with embargo release date set
16
- # (assumes that when lease visibility is applied to assets
17
- # whose leases have expired, the lease expiration date will be removed from its metadata)
18
- def assets_under_embargo
14
+ ##
15
+ # Returns all assets with embargoes that are currently enforced,
16
+ # regardless of whether the embargoes are active or expired.
17
+ #
18
+ # @see Hyrax::EmbargoManager
19
+ def assets_with_enforced_embargoes
19
20
  builder = Hyrax::EmbargoSearchBuilder.new(self)
20
- presenters(builder)
21
+ presenters(builder).select(&:enforced?)
21
22
  end
23
+ alias assets_under_embargo assets_with_enforced_embargoes
22
24
 
23
25
  # Returns all assets that have had embargoes deactivated in the past.
24
26
  def assets_with_deactivated_embargoes
@@ -5,7 +5,7 @@ module Hyrax
5
5
  attr_reader :file_set
6
6
  delegate :mime_type, to: :file_set
7
7
 
8
- # @param file_set [Hyrax::FileSet] At least for this class, it must have #uri and #mime_type
8
+ # @param file_set [Hyrax::FileSet, Hyrax::FileMetadata] At least for this class, it must have #uri and #mime_type
9
9
  def initialize(file_set)
10
10
  @file_set = file_set
11
11
  end
@@ -31,11 +31,11 @@ module Hyrax
31
31
 
32
32
  def create_derivatives(filename)
33
33
  case mime_type
34
- when *file_set.class.pdf_mime_types then create_pdf_derivatives(filename)
35
- when *file_set.class.office_document_mime_types then create_office_document_derivatives(filename)
36
- when *file_set.class.audio_mime_types then create_audio_derivatives(filename)
37
- when *file_set.class.video_mime_types then create_video_derivatives(filename)
38
- when *file_set.class.image_mime_types then create_image_derivatives(filename)
34
+ when *Hyrax.config.derivative_mime_type_mappings[:pdf] then create_pdf_derivatives(filename)
35
+ when *Hyrax.config.derivative_mime_type_mappings[:office] then create_office_document_derivatives(filename)
36
+ when *Hyrax.config.derivative_mime_type_mappings[:audio] then create_audio_derivatives(filename)
37
+ when *Hyrax.config.derivative_mime_type_mappings[:video] then create_video_derivatives(filename)
38
+ when *Hyrax.config.derivative_mime_type_mappings[:image] then create_image_derivatives(filename)
39
39
  end
40
40
  end
41
41
 
@@ -75,7 +75,7 @@ module Hyrax
75
75
  url: derivative_url('thumbnail'),
76
76
  layer: 0
77
77
  }])
78
- extract_full_text(filename, uri)
78
+ extract_full_text(filename, derivative_url('extracted_text'))
79
79
  end
80
80
 
81
81
  def create_office_document_derivatives(filename)
@@ -86,20 +86,20 @@ module Hyrax
86
86
  url: derivative_url('thumbnail'),
87
87
  layer: 0
88
88
  }])
89
- extract_full_text(filename, uri)
89
+ extract_full_text(filename, derivative_url('extracted_text'))
90
90
  end
91
91
 
92
92
  def create_audio_derivatives(filename)
93
93
  Hydra::Derivatives::AudioDerivatives.create(filename,
94
- outputs: [{ label: 'mp3', format: 'mp3', url: derivative_url('mp3') },
95
- { label: 'ogg', format: 'ogg', url: derivative_url('ogg') }])
94
+ outputs: [{ label: 'mp3', format: 'mp3', url: derivative_url('mp3'), mime_type: 'audio/mpeg', container: 'service_file' },
95
+ { label: 'ogg', format: 'ogg', url: derivative_url('ogg'), mime_type: 'audio/ogg', container: 'service_file' }])
96
96
  end
97
97
 
98
98
  def create_video_derivatives(filename)
99
99
  Hydra::Derivatives::VideoDerivatives.create(filename,
100
- outputs: [{ label: :thumbnail, format: 'jpg', url: derivative_url('thumbnail') },
101
- { label: 'webm', format: 'webm', url: derivative_url('webm') },
102
- { label: 'mp4', format: 'mp4', url: derivative_url('mp4') }])
100
+ outputs: [{ label: :thumbnail, format: 'jpg', url: derivative_url('thumbnail'), mime_type: 'image/jpeg' },
101
+ { label: 'webm', format: 'webm', url: derivative_url('webm'), mime_type: 'video/webm', container: 'service_file' },
102
+ { label: 'mp4', format: 'mp4', url: derivative_url('mp4'), mime_type: 'video/mp4', container: 'service_file' }])
103
103
  end
104
104
 
105
105
  def create_image_derivatives(filename)
@@ -122,6 +122,7 @@ module Hyrax
122
122
  # @param [String] uri to the file set (deligated to file_set)
123
123
  def extract_full_text(filename, uri)
124
124
  return unless Hyrax.config.extract_full_text?
125
+
125
126
  Hydra::Derivatives::FullTextExtract.create(filename,
126
127
  outputs: [{ url: uri, container: "extracted_text" }])
127
128
  end
@@ -14,7 +14,7 @@ module Hyrax
14
14
  end
15
15
 
16
16
  def message
17
- uri = file_set.original_file.uri.to_s
17
+ uri = checksum_audit_log.checked_uri
18
18
  file_title = file_set.title.first
19
19
  I18n.t('hyrax.notifications.fixity_check_failure.message', log_date: log_date, file_title: file_title, uri: uri)
20
20
  end
@@ -53,8 +53,15 @@ module Hyrax
53
53
  #
54
54
  # @see #assign_for
55
55
  def assign_for!(object:, attribute: :identifier)
56
- assign_for(object: object, attribute: attribute).save!
57
- object
56
+ result = assign_for(object: object, attribute: attribute)
57
+
58
+ case result
59
+ when Valkyrie::Resource
60
+ Hyrax.persister.save(resource: result)
61
+ else
62
+ result.save
63
+ result
64
+ end
58
65
  end
59
66
  end
60
67
  end