hyrax 4.0.0 → 5.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +116 -231
  3. data/.dassie/.env +3 -1
  4. data/.dassie/config/environments/test.rb +1 -0
  5. data/.dassie/config/initializers/hyrax.rb +3 -1
  6. data/.dassie/config/initializers/riiif.rb +13 -3
  7. data/.dassie/db/schema.rb +2 -2
  8. data/.dockerignore +6 -0
  9. data/.github/PULL_REQUEST_TEMPLATE.md +10 -7
  10. data/.github/release.yml +5 -2
  11. data/.koppie/.env +3 -0
  12. data/.koppie/app/forms/collection_resource_form.rb +1 -0
  13. data/.koppie/app/indexers/collection_resource_indexer.rb +1 -0
  14. data/.koppie/app/models/collection_resource.rb +1 -0
  15. data/.koppie/config/environments/test.rb +1 -0
  16. data/.koppie/config/initializers/hyrax.rb +8 -2
  17. data/.koppie/config/initializers/riiif.rb +13 -4
  18. data/.koppie/config/metadata/collection_resource.yaml +1 -128
  19. data/.koppie/yarn.lock +23 -23
  20. data/.regen +1 -1
  21. data/CONTAINERS.md +1 -1
  22. data/Dockerfile +6 -11
  23. data/app/actors/hyrax/actors/base_actor.rb +4 -3
  24. data/app/actors/hyrax/actors/embargo_actor.rb +5 -2
  25. data/app/actors/hyrax/actors/lease_actor.rb +5 -2
  26. data/app/assets/javascripts/hyrax/file_manager/sorting.es6 +3 -2
  27. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
  28. data/app/controllers/concerns/hyrax/valkyrie_downloads_controller_behavior.rb +74 -0
  29. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +14 -5
  30. data/app/controllers/hyrax/admin/workflows_controller.rb +48 -3
  31. data/app/controllers/hyrax/batch_edits_controller.rb +33 -4
  32. data/app/controllers/hyrax/downloads_controller.rb +8 -1
  33. data/app/controllers/hyrax/file_sets_controller.rb +1 -0
  34. data/app/forms/hyrax/forms/file_set_edit_form.rb +1 -1
  35. data/app/forms/hyrax/forms/permission_template_form.rb +2 -0
  36. data/app/forms/hyrax/forms/resource_batch_edit_form.rb +90 -0
  37. data/app/forms/hyrax/forms/work_embargo_form.rb +1 -0
  38. data/app/forms/hyrax/forms/work_form.rb +1 -1
  39. data/app/forms/hyrax/forms/work_lease_form.rb +1 -0
  40. data/app/helpers/hyrax/dashboard_helper_behavior.rb +17 -9
  41. data/app/helpers/hyrax/membership_helper.rb +13 -1
  42. data/app/helpers/hyrax/work_form_helper.rb +0 -107
  43. data/app/indexers/hyrax/file_set_indexer.rb +6 -0
  44. data/app/indexers/hyrax/pcdm_collection_indexer.rb +8 -0
  45. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +41 -5
  46. data/app/indexers/hyrax/valkyrie_work_indexer.rb +8 -2
  47. data/app/jobs/valkyrie_create_derivatives_job.rb +8 -7
  48. data/app/jobs/valkyrie_ingest_job.rb +0 -1
  49. data/app/models/admin_set.rb +1 -31
  50. data/app/models/concerns/hyrax/file_set/derivatives.rb +3 -2
  51. data/app/models/concerns/hyrax/solr_document_behavior.rb +1 -1
  52. data/app/models/hyrax/collection_type.rb +5 -14
  53. data/app/models/hyrax/file_metadata.rb +6 -7
  54. data/app/models/hyrax/file_set.rb +8 -0
  55. data/app/models/hyrax/resource.rb +30 -2
  56. data/app/presenters/hyrax/file_set_presenter.rb +6 -0
  57. data/app/presenters/hyrax/iiif_manifest_presenter.rb +3 -7
  58. data/app/presenters/hyrax/presenter_renderer.rb +0 -7
  59. data/app/presenters/hyrax/work_show_presenter.rb +6 -11
  60. data/app/search_builders/hyrax/file_set_search_builder.rb +1 -1
  61. data/app/search_builders/hyrax/valkyrie_abstract_type_relation.rb +37 -0
  62. data/app/search_builders/hyrax/valkyrie_work_relation.rb +9 -0
  63. data/app/services/hyrax/characterization/valkyrie_characterization_service.rb +11 -9
  64. data/app/services/hyrax/custom_queries/find_by_date_range.rb +55 -0
  65. data/app/services/hyrax/custom_queries/find_count_by.rb +62 -0
  66. data/app/services/hyrax/custom_queries/find_file_metadata.rb +1 -1
  67. data/app/services/hyrax/custom_queries/find_models_by_access.rb +59 -0
  68. data/app/services/hyrax/derivative_bucketed_storage.rb +25 -0
  69. data/app/services/hyrax/derivative_path.rb +14 -4
  70. data/app/services/hyrax/embargo_manager.rb +76 -10
  71. data/app/services/hyrax/file_set_derivatives_service.rb +3 -2
  72. data/app/services/hyrax/lease_manager.rb +88 -8
  73. data/app/services/hyrax/listeners/file_metadata_listener.rb +2 -2
  74. data/app/services/hyrax/listeners/workflow_listener.rb +8 -11
  75. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +24 -2
  76. data/app/services/hyrax/solr_query_service.rb +7 -6
  77. data/app/services/hyrax/statistics/depositors/summary.rb +1 -1
  78. data/app/services/hyrax/statistics/over_time.rb +1 -1
  79. data/app/services/hyrax/statistics/users/over_time.rb +3 -1
  80. data/app/services/hyrax/statistics/valkyrie_query_service.rb +49 -0
  81. data/app/services/hyrax/statistics/works/count.rb +1 -1
  82. data/app/services/hyrax/thumbnail_path_service.rb +5 -0
  83. data/app/services/hyrax/valkyrie_persist_derivatives.rb +16 -11
  84. data/app/services/hyrax/valkyrie_upload.rb +5 -3
  85. data/app/services/hyrax/versioning_service.rb +1 -0
  86. data/app/services/hyrax/visibility_intention.rb +1 -4
  87. data/app/services/hyrax/visibility_propagator.rb +1 -1
  88. data/app/services/hyrax/workflow/actionable_objects.rb +28 -3
  89. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +1 -1
  90. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +1 -1
  91. data/app/services/hyrax/workflow/permission_query.rb +23 -2
  92. data/app/views/hyrax/admin/workflows/_tabs.html.erb +9 -0
  93. data/app/views/hyrax/admin/workflows/index.html.erb +53 -76
  94. data/app/views/hyrax/base/_file_manager_members.html.erb +2 -2
  95. data/app/views/hyrax/base/_form.html.erb +0 -10
  96. data/app/views/hyrax/base/_form_permission_embargo.html.erb +1 -1
  97. data/app/views/hyrax/base/_form_permission_lease.html.erb +1 -1
  98. data/app/views/hyrax/base/_form_visibility_component.html.erb +2 -2
  99. data/app/views/hyrax/base/_items.html.erb +1 -1
  100. data/app/views/hyrax/base/file_manager.html.erb +1 -1
  101. data/app/views/hyrax/base/show.json.jbuilder +2 -2
  102. data/app/views/hyrax/file_sets/show.html.erb +5 -3
  103. data/app/views/hyrax/homepage/_explore_collections.html.erb +1 -1
  104. data/chart/hyrax/Chart.yaml +18 -14
  105. data/chart/hyrax/README.md +34 -21
  106. data/chart/hyrax/templates/_helpers.tpl +26 -1
  107. data/chart/hyrax/templates/configmap-env.yaml +12 -2
  108. data/chart/hyrax/templates/secrets.yaml +1 -1
  109. data/chart/hyrax/values.yaml +36 -14
  110. data/config/initializers/listeners.rb +4 -10
  111. data/config/initializers/storage_adapter_initializer.rb +1 -1
  112. data/config/locales/hyrax.en.yml +8 -0
  113. data/config/metadata/file_set_metadata.yaml +1 -1
  114. data/docker-compose-koppie.yml +17 -4
  115. data/docker-compose.yml +19 -6
  116. data/documentation/developing-your-hyrax-based-app.md +6 -14
  117. data/documentation/legacyREADME.md +3 -1
  118. data/hyrax.gemspec +2 -2
  119. data/karma.conf.js +8 -9
  120. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  121. data/lib/generators/hyrax/templates/config/initializers/riiif.rb +15 -5
  122. data/lib/hyrax/active_fedora_dummy_model.rb +6 -1
  123. data/lib/hyrax/configuration.rb +6 -0
  124. data/lib/hyrax/engine.rb +2 -0
  125. data/lib/hyrax/publisher.rb +19 -3
  126. data/lib/hyrax/specs/capybara.rb +9 -4
  127. data/lib/hyrax/transactions/container.rb +5 -0
  128. data/lib/hyrax/transactions/steps/add_file_sets.rb +6 -0
  129. data/lib/hyrax/transactions/steps/apply_permission_template.rb +40 -0
  130. data/lib/hyrax/transactions/steps/save.rb +21 -0
  131. data/lib/hyrax/transactions/work_create.rb +1 -0
  132. data/lib/hyrax/version.rb +1 -1
  133. data/lib/hyrax.rb +1 -0
  134. data/lib/wings/active_fedora_converter/default_work.rb +7 -2
  135. data/lib/wings/active_fedora_converter/file_metadata_node.rb +1 -1
  136. data/lib/wings/active_fedora_converter.rb +47 -11
  137. data/lib/wings/model_transformer.rb +23 -4
  138. data/lib/wings/setup.rb +21 -1
  139. data/lib/wings/valkyrie/persister.rb +4 -2
  140. data/package.json +3 -1
  141. data/template.rb +1 -1
  142. metadata +17 -12
  143. data/app/forms/hyrax/forms/file_manager_form.rb +0 -35
  144. data/app/services/hyrax/collections/migration_service.rb +0 -113
  145. data/app/views/hyrax/base/_form_collections_error.html.erb +0 -1
  146. data/app/views/hyrax/base/_form_in_works_error.html.erb +0 -3
  147. data/app/views/hyrax/base/_form_ordered_members_error.html.erb +0 -3
  148. data/app/views/hyrax/base/_form_visibility_error.html.erb +0 -19
@@ -18,7 +18,6 @@ module Hyrax
18
18
  "with id #{file.id}. Initializing a new one")
19
19
 
20
20
  FileMetadata.new(file_identifier: file.id,
21
- alternative_ids: [file.id],
22
21
  original_filename: File.basename(file.io))
23
22
  end
24
23
 
@@ -67,11 +66,11 @@ module Hyrax
67
66
  attribute :label, ::Valkyrie::Types::Set
68
67
  attribute :original_filename, ::Valkyrie::Types::String
69
68
  attribute :mime_type, ::Valkyrie::Types::String.default(GENERIC_MIME_TYPE)
70
- attribute :type, ::Valkyrie::Types::Set.default([Use::ORIGINAL_FILE].freeze) # Use += to add types, not <<
69
+ attribute :pcdm_use, ::Valkyrie::Types::Set.default([Use::ORIGINAL_FILE].freeze) # Use += to add pcdm_uses, not <<
71
70
 
72
71
  # attributes set by fits
73
72
  attribute :format_label, ::Valkyrie::Types::Set
74
- attribute :size, ::Valkyrie::Types::Set
73
+ attribute :recorded_size, ::Valkyrie::Types::Set
75
74
  attribute :well_formed, ::Valkyrie::Types::Set
76
75
  attribute :valid, ::Valkyrie::Types::Set
77
76
  attribute :date_created, ::Valkyrie::Types::Set
@@ -130,19 +129,19 @@ module Hyrax
130
129
  ##
131
130
  # @return [Boolean]
132
131
  def original_file?
133
- type.include?(Use::ORIGINAL_FILE)
132
+ pcdm_use.include?(Use::ORIGINAL_FILE)
134
133
  end
135
134
 
136
135
  ##
137
136
  # @return [Boolean]
138
137
  def thumbnail_file?
139
- type.include?(Use::THUMBNAIL)
138
+ pcdm_use.include?(Use::THUMBNAIL)
140
139
  end
141
140
 
142
141
  ##
143
142
  # @return [Boolean]
144
143
  def extracted_file?
145
- type.include?(Use::EXTRACTED_TEXT)
144
+ pcdm_use.include?(Use::EXTRACTED_TEXT)
146
145
  end
147
146
 
148
147
  def title
@@ -154,7 +153,7 @@ module Hyrax
154
153
  end
155
154
 
156
155
  def valid?
157
- file.valid?(size: size.first, digests: { sha256: checksum&.first&.sha256 })
156
+ file.valid?(size: recorded_size.first, digests: { sha256: checksum&.first&.sha256 })
158
157
  end
159
158
 
160
159
  ##
@@ -51,6 +51,14 @@ module Hyrax
51
51
  id
52
52
  end
53
53
 
54
+ ##
55
+ # @return [Valkyrie::ID]
56
+ def representative_id=(_input)
57
+ # saving a file set using valkyrie would err because this method didn't exist.
58
+ Rails.logger.warn('This is not a valid method for file sets')
59
+ id
60
+ end
61
+
54
62
  ##
55
63
  # @return [Boolean] true
56
64
  def pcdm_object?
@@ -35,8 +35,8 @@ module Hyrax
35
35
  include Hyrax::WithEvents
36
36
 
37
37
  attribute :alternate_ids, Valkyrie::Types::Array.of(Valkyrie::Types::ID)
38
- attribute :embargo, Hyrax::Embargo.optional
39
- attribute :lease, Hyrax::Lease.optional
38
+ attribute :embargo_id, Valkyrie::Types::ID
39
+ attribute :lease_id, Valkyrie::Types::ID
40
40
 
41
41
  delegate :edit_groups, :edit_groups=,
42
42
  :edit_users, :edit_users=,
@@ -91,6 +91,10 @@ module Hyrax
91
91
  false
92
92
  end
93
93
 
94
+ def ==(other)
95
+ attributes.except(:created_at, :updated_at) == other.attributes.except(:created_at, :updated_at)
96
+ end
97
+
94
98
  def permission_manager
95
99
  @permission_manager ||= Hyrax::PermissionManager.new(resource: self)
96
100
  end
@@ -103,6 +107,30 @@ module Hyrax
103
107
  visibility_reader.read
104
108
  end
105
109
 
110
+ def embargo=(value)
111
+ raise TypeError "can't convert #{value.class} into Hyrax::Embargo" unless value.is_a? Hyrax::Embargo
112
+
113
+ @embargo = value
114
+ self.embargo_id = @embargo.id
115
+ end
116
+
117
+ def embargo
118
+ return @embargo if @embargo
119
+ @embargo = Hyrax.query_service.find_by(id: embargo_id) if embargo_id.present?
120
+ end
121
+
122
+ def lease=(value)
123
+ raise TypeError "can't convert #{value.class} into Hyrax::Lease" unless value.is_a? Hyrax::Lease
124
+
125
+ @lease = value
126
+ self.lease_id = @lease.id
127
+ end
128
+
129
+ def lease
130
+ return @lease if @lease
131
+ @lease = Hyrax.query_service.find_by(id: lease_id) if lease_id.present?
132
+ end
133
+
106
134
  protected
107
135
 
108
136
  def visibility_writer
@@ -105,6 +105,12 @@ module Hyrax
105
105
  current_ability.can?(:edit, id) || current_ability.can?(:destroy, id) || current_ability.can?(:download, id)
106
106
  end
107
107
 
108
+ ##
109
+ # @return [Array<String>]
110
+ def show_partials
111
+ ['show_details']
112
+ end
113
+
108
114
  private
109
115
 
110
116
  def link_presenter_class
@@ -56,7 +56,7 @@ module Hyrax
56
56
  ##
57
57
  # @return [Boolean]
58
58
  def file_set?
59
- model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet')
59
+ model.try(:file_set?) || Array(model[:has_model_ssim]).include?('FileSet') || Array(model[:has_model_ssim]).include?('Hyrax::FileSet')
60
60
  end
61
61
 
62
62
  ##
@@ -93,12 +93,8 @@ module Hyrax
93
93
  ##
94
94
  # @return [Array<#to_s>]
95
95
  def member_ids
96
- case model
97
- when Valkyrie::Resource
98
- Array(model.try(:member_ids))
99
- else
100
- Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids
101
- end
96
+ m = model.is_a?(::SolrDocument) ? model.hydra_model : model.class
97
+ m < Hyrax::Resource ? Array(model.member_ids) : Hyrax::SolrDocument::OrderedMembers.decorate(model).ordered_member_ids
102
98
  end
103
99
 
104
100
  ##
@@ -22,13 +22,6 @@ module Hyrax
22
22
  default: [:"defaults.#{field}", field.to_s.humanize]).presence
23
23
  end
24
24
 
25
- ##
26
- # @deprecated
27
- def fields(terms, &_block)
28
- Deprecation.warn("Fields is deprecated for removal in Hyrax 4.0.0. use #value and #label directly instead.")
29
- @view_context.safe_join(terms.map { |term| yield self, term })
30
- end
31
-
32
25
  private
33
26
 
34
27
  def render_show_field_partial(field_name, locals)
@@ -190,16 +190,6 @@ module Hyrax
190
190
  paginated_item_list(page_array: authorized_item_ids)
191
191
  end
192
192
 
193
- ##
194
- # @deprecated use `#member_presenters(ids)` instead
195
- #
196
- # @param [Array<String>] ids a list of ids to build presenters for
197
- # @return [Array<presenter_class>] presenters for the array of ids (not filtered by class)
198
- def member_presenters_for(an_array_of_ids)
199
- Deprecation.warn("Use `#member_presenters` instead.")
200
- member_presenters(an_array_of_ids)
201
- end
202
-
203
193
  # @return [Integer] total number of pages of viewable items
204
194
  def total_pages
205
195
  (total_items.to_f / rows_from_params.to_f).ceil
@@ -262,6 +252,11 @@ module Hyrax
262
252
  Hyrax::ChildTypes.for(parent: solr_document.hydra_model).to_a
263
253
  end
264
254
 
255
+ # @return [Boolean]
256
+ def valkyrie_presenter?
257
+ solr_document.hydra_model < Valkyrie::Resource
258
+ end
259
+
265
260
  private
266
261
 
267
262
  # list of item ids to display is based on ordered_ids
@@ -308,7 +303,7 @@ module Hyrax
308
303
 
309
304
  def member_presenter_factory
310
305
  @member_presenter_factory ||=
311
- if solr_document.hydra_model < Valkyrie::Resource
306
+ if valkyrie_presenter?
312
307
  PcdmMemberPresenterFactory.new(solr_document, current_ability)
313
308
  else
314
309
  self.class
@@ -5,7 +5,7 @@ module Hyrax
5
5
 
6
6
  # This overrides the models in FilterByType
7
7
  def models
8
- [::FileSet]
8
+ [::FileSet, ::Hyrax::FileSet]
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ class ValkyrieAbstractTypeRelation
5
+ def initialize(allowable_types: nil, _opts: {})
6
+ @allowable_types = allowable_types
7
+ end
8
+
9
+ def allowable_types
10
+ @allowable_types.present? ||
11
+ raise(NotImplementedException, "Implement allowable_types in a subclass")
12
+ end
13
+
14
+ def equivalent_class?(klass)
15
+ allowable_types.include?(klass)
16
+ end
17
+
18
+ def count
19
+ Hyrax.query_service.custom_queries.find_count_by(models: allowable_types)
20
+ end
21
+
22
+ def where(hash)
23
+ Hyrax.query_service.find_references_by(resource: hash.values.first, property: hash.keys.first)
24
+ end
25
+
26
+ def ==(other)
27
+ case other
28
+ when Relation
29
+ other.where_values == where_values
30
+ when Array
31
+ to_a == other
32
+ end
33
+ end
34
+
35
+ delegate :inspect, to: :to_a
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hyrax
4
+ class ValkyrieWorkRelation < ValkyrieAbstractTypeRelation
5
+ def allowable_types
6
+ Hyrax.config.curation_concerns
7
+ end
8
+ end
9
+ end
@@ -27,25 +27,27 @@ class Hyrax::Characterization::ValkyrieCharacterizationService
27
27
  # @!attribute [rw] source
28
28
  # @return [Valkyrie::StorageAdapter::StreamFile]
29
29
  # @!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.
30
+ # can be :fits, :fits_servlet, :ffprobe or any other service added to HydraFileCharacterization
31
+ # note that ffprope is faster but only works on AV files.
33
32
  # @return [Symbol]
34
33
  attr_accessor :mapping, :metadata, :parser, :source, :tools
35
34
 
36
35
  ##
37
36
  # @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)
37
+ def initialize( # rubocop:disable Metrics/ParameterLists
38
+ metadata:,
39
+ file:,
40
+ characterizer: Hydra::FileCharacterization,
41
+ parser_mapping: Hydra::Works::Characterization.mapper,
42
+ parser: Hydra::Works::Characterization::FitsDocument.new,
43
+ ch12n_tool: :fits
44
+ )
43
45
  @characterizer = characterizer
44
46
  @metadata = metadata
45
47
  @source = file
46
48
  @mapping = parser_mapping
47
49
  @parser = parser
48
- @tools = :fits
50
+ @tools = ch12n_tool
49
51
  end
50
52
 
51
53
  ##
@@ -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