hyrax 3.0.0.pre.rc4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.dassie/config/cable.yml +1 -1
  3. data/.dassie/config/environments/development.rb +2 -0
  4. data/.dassie/config/environments/production.rb +1 -1
  5. data/.dassie/config/redis.yml +1 -0
  6. data/.dassie/db/seeds.rb +8 -0
  7. data/.dockerignore +1 -0
  8. data/Dockerfile +7 -4
  9. data/app/actors/hyrax/actors/create_with_remote_files_actor.rb +27 -1
  10. data/app/actors/hyrax/actors/file_actor.rb +4 -2
  11. data/app/actors/hyrax/actors/file_set_actor.rb +8 -6
  12. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +16 -5
  13. data/app/forms/hyrax/forms/resource_form.rb +15 -0
  14. data/app/helpers/hyrax/hyrax_helper_behavior.rb +8 -0
  15. data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +116 -0
  16. data/app/indexers/hyrax/valkyrie_indexer.rb +6 -1
  17. data/app/indexers/hyrax/valkyrie_work_indexer.rb +2 -0
  18. data/app/jobs/embargo_expiry_job.rb +7 -5
  19. data/app/jobs/file_set_attached_event_job.rb +6 -1
  20. data/app/jobs/lease_expiry_job.rb +6 -4
  21. data/app/models/concerns/hyrax/ability.rb +11 -0
  22. data/app/models/concerns/hyrax/solr_document_behavior.rb +7 -1
  23. data/app/models/hyrax/file_set.rb +1 -0
  24. data/app/models/hyrax/work.rb +2 -0
  25. data/app/models/job_io_wrapper.rb +1 -1
  26. data/app/services/hyrax/access_control_list.rb +1 -1
  27. data/app/services/hyrax/adapters/nesting_index_adapter.rb +1 -1
  28. data/app/services/hyrax/embargo_manager.rb +1 -1
  29. data/app/services/hyrax/graph_exporter.rb +1 -1
  30. data/app/services/hyrax/listeners/metadata_index_listener.rb +18 -1
  31. data/app/services/hyrax/versioning_service.rb +1 -1
  32. data/app/services/hyrax/work_uploads_handler.rb +5 -2
  33. data/app/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb +1 -1
  34. data/app/views/hyrax/base/_form_share.html.erb +1 -5
  35. data/app/views/hyrax/base/_workflow_actions.html.erb +1 -1
  36. data/app/views/hyrax/batch_edits/edit.html.erb +2 -2
  37. data/app/views/hyrax/collections/_list_collections.html.erb +1 -1
  38. data/app/views/hyrax/collections/_search_form.html.erb +1 -1
  39. data/app/views/hyrax/stats/file.html.erb +1 -1
  40. data/app/views/hyrax/stats/work.html.erb +1 -1
  41. data/app/views/hyrax/uploads/_js_templates.html.erb +4 -4
  42. data/app/views/hyrax/uploads/_js_templates_versioning.html.erb +4 -4
  43. data/app/views/hyrax/users/_contributions.html.erb +1 -1
  44. data/app/views/hyrax/users/_profile_tabs.html.erb +2 -2
  45. data/app/views/hyrax/users/_search_form.html.erb +1 -1
  46. data/app/views/hyrax/users/_user.html.erb +1 -1
  47. data/app/views/hyrax/users/_user_info.html.erb +9 -9
  48. data/bin/db-migrate-seed.sh +3 -1
  49. data/bin/solrcloud-assign-configset.sh +27 -0
  50. data/bin/solrcloud-upload-configset.sh +31 -0
  51. data/chart/hyrax/Chart.yaml +8 -8
  52. data/chart/hyrax/README.md +42 -6
  53. data/chart/hyrax/templates/NOTES.txt +1 -1
  54. data/chart/hyrax/templates/_helpers.tpl +76 -0
  55. data/chart/hyrax/templates/configmap-env.yaml +10 -11
  56. data/chart/hyrax/templates/cron-embargo.yaml +24 -0
  57. data/chart/hyrax/templates/cron-lease.yaml +24 -0
  58. data/chart/hyrax/templates/deployment.yaml +36 -4
  59. data/chart/hyrax/templates/secrets.yaml +3 -2
  60. data/chart/hyrax/values.yaml +72 -1
  61. data/config/initializers/listeners.rb +2 -0
  62. data/documentation/developing-your-hyrax-based-app.md +3 -3
  63. data/lib/hyrax/transactions/container.rb +11 -1
  64. data/lib/hyrax/transactions/steps/delete_resource.rb +38 -0
  65. data/lib/hyrax/transactions/steps/destroy_work.rb +1 -0
  66. data/lib/hyrax/transactions/work_destroy.rb +20 -0
  67. data/lib/hyrax/version.rb +1 -1
  68. data/lib/tasks/embargo_lease.rake +27 -0
  69. data/lib/wings/active_fedora_converter/default_work.rb +4 -0
  70. data/lib/wings/attribute_transformer.rb +29 -19
  71. data/lib/wings/model_transformer.rb +4 -19
  72. data/lib/wings/orm_converter.rb +24 -21
  73. data/lib/wings/valkyrie/persister.rb +1 -0
  74. data/lib/wings/valkyrie/query_service.rb +36 -24
  75. data/template.rb +1 -1
  76. metadata +14 -20
  77. data/chart/fcrepo/.gitignore +0 -2
  78. data/chart/fcrepo/.helmignore +0 -23
  79. data/chart/fcrepo/Chart.yaml +0 -11
  80. data/chart/fcrepo/README.md +0 -50
  81. data/chart/fcrepo/templates/NOTES.txt +0 -21
  82. data/chart/fcrepo/templates/_helpers.tpl +0 -68
  83. data/chart/fcrepo/templates/configmap-env.yaml +0 -19
  84. data/chart/fcrepo/templates/deployment.yaml +0 -109
  85. data/chart/fcrepo/templates/ingress.yaml +0 -41
  86. data/chart/fcrepo/templates/pvc.yaml +0 -20
  87. data/chart/fcrepo/templates/secret.yaml +0 -12
  88. data/chart/fcrepo/templates/service.yaml +0 -15
  89. data/chart/fcrepo/templates/serviceaccount.yaml +0 -12
  90. data/chart/fcrepo/templates/tests/test-connection.yaml +0 -15
  91. data/chart/fcrepo/values.yaml +0 -79
  92. data/chart/hyrax/templates/fcrepo-secret.yaml +0 -13
@@ -19,10 +19,12 @@ end
19
19
 
20
20
  Hyrax.config.callback.set(:after_create_fileset, warn: false) do |file_set, user|
21
21
  Hyrax.publisher.publish('file.set.attached', file_set: file_set, user: user)
22
+ Hyrax.publisher.publish('object.metadata.updated', object: file_set, user: user)
22
23
  end
23
24
 
24
25
  Hyrax.config.callback.set(:after_revert_content, warn: false) do |file_set, user, revision|
25
26
  Hyrax.publisher.publish('file.set.restored', file_set: file_set, user: user, revision: revision)
27
+ Hyrax.publisher.publish('object.metadata.updated', object: file_set, user: user)
26
28
  end
27
29
 
28
30
  Hyrax.config.callback.set(:after_update_metadata, warn: false) do |curation_concern, user|
@@ -30,7 +30,7 @@ A Hyrax-based application includes lots of dependencies. We provide a [Docker im
30
30
  You can also try [Running Hyrax-based application in local VM](https://github.com/samvera/hyrax/wiki/Hyrax-Development-Guide#running-hyrax-based-application-in-local-vm) which uses Ubuntu.
31
31
 
32
32
  This document contains instructions specific to setting up an app with __Hyrax
33
- v3.0.0-rc4__. If you are looking for instructions on installing a different
33
+ v3.0.0__. If you are looking for instructions on installing a different
34
34
  version, be sure to select the appropriate branch or tag from the drop-down
35
35
  menu above.
36
36
 
@@ -48,7 +48,7 @@ Hyrax requires the following software to work:
48
48
  1. A SQL RDBMS (MySQL, PostgreSQL), though **note** that SQLite will be used by default if you're looking to get up and running quickly
49
49
  1. [Redis](http://redis.io/), a key-value store
50
50
  1. [ImageMagick](http://www.imagemagick.org/) with JPEG-2000 support
51
- 1. [FITS](#characterization) version 1.0.x (1.0.5 is known to be good, 1.1.0 is known to be bad: https://github.com/harvard-lts/fits/issues/140)
51
+ 1. [FITS](#characterization) (tested up to version 1.5.0 -- avoid version 1.1.0)
52
52
  1. [LibreOffice](#derivatives)
53
53
  1. [ffmpeg](#transcoding)
54
54
 
@@ -125,7 +125,7 @@ NOTE: The steps need to be done in order to create a new Hyrax based app.
125
125
  Generate a new Rails application using the template.
126
126
 
127
127
  ```
128
- rails _5.2.4.4_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v3.0.0-rc4/template.rb
128
+ rails _5.2.4.4_ new my_app -m https://raw.githubusercontent.com/samvera/hyrax/v3.0.0/template.rb
129
129
  ```
130
130
 
131
131
  Generating a new Rails application using Hyrax's template above takes cares of a number of steps for you, including:
@@ -17,17 +17,19 @@ module Hyrax
17
17
  # @since 2.4.0
18
18
  #
19
19
  # @see https://dry-rb.org/gems/dry-container/
20
- class Container
20
+ class Container # rubocop:disable Metrics/ClassLength
21
21
  require 'hyrax/transactions/apply_change_set'
22
22
  require 'hyrax/transactions/create_work'
23
23
  require 'hyrax/transactions/destroy_work'
24
24
  require 'hyrax/transactions/work_create'
25
+ require 'hyrax/transactions/work_destroy'
25
26
  require 'hyrax/transactions/update_work'
26
27
  require 'hyrax/transactions/steps/add_file_sets'
27
28
  require 'hyrax/transactions/steps/add_to_collections'
28
29
  require 'hyrax/transactions/steps/apply_collection_permission_template'
29
30
  require 'hyrax/transactions/steps/apply_permission_template'
30
31
  require 'hyrax/transactions/steps/apply_visibility'
32
+ require 'hyrax/transactions/steps/delete_resource'
31
33
  require 'hyrax/transactions/steps/destroy_work'
32
34
  require 'hyrax/transactions/steps/ensure_admin_set'
33
35
  require 'hyrax/transactions/steps/ensure_permission_template'
@@ -95,6 +97,14 @@ module Hyrax
95
97
  Steps::AddFileSets.new
96
98
  end
97
99
 
100
+ ops.register 'delete' do
101
+ Steps::DeleteResource.new
102
+ end
103
+
104
+ ops.register 'destroy' do
105
+ WorkDestroy.new
106
+ end
107
+
98
108
  ops.register 'save_acl' do
99
109
  Steps::SaveAccessControl.new
100
110
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ require 'dry/monads'
3
+
4
+ module Hyrax
5
+ module Transactions
6
+ module Steps
7
+ ##
8
+ # Deletes a resource from the persister, returning a `Dry::Monads::Result`
9
+ # (`Success`|`Failure`).
10
+ #
11
+ # @see https://dry-rb.org/gems/dry-monads/1.0/result/
12
+ class DeleteResource
13
+ include Dry::Monads[:result]
14
+
15
+ ##
16
+ # @params [#save] persister
17
+ def initialize(persister: Hyrax.persister)
18
+ @persister = persister
19
+ end
20
+
21
+ ##
22
+ # @param [Valkyrie::Resource] resource
23
+ # @param [::User] the user resposible for the delete action
24
+ #
25
+ # @return [Dry::Monads::Result]
26
+ def call(resource, user: nil)
27
+ return Failure(:resource_not_persisted) unless resource.persisted?
28
+
29
+ @persister.delete(resource: resource)
30
+ Hyrax.publisher
31
+ .publish('object.deleted', object: resource, id: resource.id.id, user: user)
32
+
33
+ Success(resource)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -6,6 +6,7 @@ module Hyrax
6
6
  # A `dry-transcation` step that destroys a Work.
7
7
  #
8
8
  # @since 3.0.0
9
+ # @deprecated
9
10
  class DestroyWork
10
11
  include Dry::Transaction::Operation
11
12
 
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'hyrax/transactions/transaction'
3
+
4
+ module Hyrax
5
+ module Transactions
6
+ ##
7
+ # Destroys a work resource
8
+ #
9
+ # @since 3.0.0
10
+ class WorkDestroy < Transaction
11
+ DEFAULT_STEPS = ['work_resource.delete'].freeze
12
+
13
+ ##
14
+ # @see Hyrax::Transactions::Transaction
15
+ def initialize(container: Container, steps: DEFAULT_STEPS)
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
data/lib/hyrax/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
- VERSION = '3.0.0-rc4'
3
+ VERSION = '3.0.0'
4
4
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :hyrax do
4
+ namespace :embargo do
5
+ desc 'Deactivate embargoes for which the lift date has past'
6
+ task deactivate_expired: :environment do
7
+ ids = Hyrax::EmbargoService.assets_with_expired_embargoes.map(&:id)
8
+
9
+ Hyrax.query_service.find_many_by_ids(ids: ids).each do |resource|
10
+ Hyrax::EmbargoManager.release_embargo_for(resource: resource) &&
11
+ Hyrax::AccessControlList(resource).save
12
+ end
13
+ end
14
+ end
15
+
16
+ namespace :lease do
17
+ desc 'Deactivate leases for which the expiration date has past'
18
+ task deactivate_expired: :environment do
19
+ ids = Hyrax::LeaseService.assets_with_expired_leases.map(&:id)
20
+
21
+ Hyrax.query_service.find_many_by_ids(ids: ids).each do |resource|
22
+ Hyrax::LeaseManager.release_lease_for(resource: resource) &&
23
+ Hyrax::AccessControlList(resource).save
24
+ end
25
+ end
26
+ end
27
+ end
@@ -106,6 +106,10 @@ module Wings
106
106
  class << self
107
107
  delegate :human_readable_type, to: :valkyrie_class
108
108
 
109
+ def _to_partial_path
110
+ "hyrax/#{valkyrie_class.model_name.collection}/#{valkyrie_class.model_name.element}"
111
+ end
112
+
109
113
  def model_name(*)
110
114
  Hyrax::Name.new(valkyrie_class)
111
115
  end
@@ -15,36 +15,46 @@ module Wings
15
15
  end
16
16
  end
17
17
 
18
- def self.run(obj, keys)
19
- # TODO: There is an open question about whether we want to treat all these relationships the same. See Issue #3904.
20
- attrs = keys.select { |k| k.to_s.end_with? '_ids' }.each_with_object({}) do |attr_name, mem|
21
- mem[attr_name.to_sym] =
22
- TransformerValueMapper.for(obj.try(attr_name)).result ||
23
- TransformerValueMapper.for(attribute_ids_for(name: attr_name.chomp('_ids'), obj: obj)).result ||
24
- TransformerValueMapper.for(attribute_ids_for(name: attr_name.chomp('_ids').pluralize, obj: obj)).result || []
18
+ def self.run(obj) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
19
+ attrs = obj.reflections.each_with_object({}) do |(key, reflection), mem|
20
+ case reflection
21
+ when ActiveFedora::Reflection::HasManyReflection,
22
+ ActiveFedora::Reflection::HasAndBelongsToManyReflection,
23
+ ActiveFedora::Reflection::IndirectlyContainsReflection
24
+ mem[:"#{key.to_s.singularize}_ids"] =
25
+ obj.association(key).ids_reader
26
+ when ActiveFedora::Reflection::DirectlyContainsReflection
27
+ mem[:"#{key.to_s.singularize}_ids"] =
28
+ Array(obj.public_send(reflection.name)).map(&:id)
29
+ when ActiveFedora::Reflection::FilterReflection,
30
+ ActiveFedora::Reflection::OrdersReflection,
31
+ ActiveFedora::Reflection::HasSubresourceReflection,
32
+ ActiveFedora::Reflection::BelongsToReflection,
33
+ ActiveFedora::Reflection::BasicContainsReflection
34
+ :noop
35
+ when ActiveFedora::Reflection::DirectlyContainsOneReflection
36
+ mem[:"#{key.to_s.singularize}_id"] =
37
+ obj.public_send(reflection.name)&.id
38
+ else
39
+ mem[reflection.foreign_key.to_sym] =
40
+ obj.public_send(reflection.foreign_key.to_sym)
41
+ end
25
42
  end
26
- keys.each_with_object(attrs) do |attr_name, mem|
43
+
44
+ obj.class.delegated_attributes.keys.each_with_object(attrs) do |attr_name, mem|
27
45
  next unless obj.respond_to?(attr_name) && !mem.key?(attr_name.to_sym)
28
46
  mem[attr_name.to_sym] = TransformerValueMapper.for(obj.public_send(attr_name)).result
29
47
  end
30
48
  end
31
-
32
- def self.attribute_ids_for(name:, obj:)
33
- attribute_value = obj.try(name)
34
- return if attribute_value.nil?
35
- Array(attribute_value).map(&:id)
36
- end
37
49
  end
38
50
 
39
51
  class FileAttributeTransformer
40
- KEYMAP = {}.freeze
52
+ def run(obj)
53
+ keys = obj.metadata_node.class.fields
41
54
 
42
- def run(obj, keys)
43
55
  attributes = keys.each_with_object({}) do |attr_name, mem|
44
56
  next unless obj.respond_to?(attr_name) && !mem.key?(attr_name.to_sym)
45
- valkyrie_attribute = KEYMAP.fetch(attr_name.to_sym) { attr_name.to_sym }
46
-
47
- mem[valkyrie_attribute] = TransformerValueMapper.for(obj.public_send(attr_name)).result
57
+ mem[attr_name.to_sym] = TransformerValueMapper.for(obj.public_send(attr_name)).result
48
58
  end
49
59
 
50
60
  attributes[:original_filename] = obj.original_name
@@ -116,16 +116,8 @@ module Wings
116
116
  end
117
117
 
118
118
  def attributes
119
- attribute_source = pcdm_object.try(:metadata_node) || pcdm_object
120
-
121
- all_keys =
122
- attribute_source.attributes.keys +
123
- OrmConverter.relationship_keys_for(reflections: pcdm_object.try(:reflections))
124
-
125
- result = AttributeTransformer.for(pcdm_object)
126
- .run(pcdm_object, all_keys)
127
- .merge(reflection_ids)
128
- .merge(additional_attributes)
119
+ transformer = AttributeTransformer.for(pcdm_object)
120
+ result = transformer.run(pcdm_object).merge(additional_attributes)
129
121
 
130
122
  append_embargo(result)
131
123
  append_lease(result)
@@ -133,16 +125,9 @@ module Wings
133
125
  result
134
126
  end
135
127
 
136
- def reflection_ids
137
- keys = pcdm_object.try(:reflections)&.keys || []
138
-
139
- keys.select { |k| k.to_s.end_with? '_id' }.each_with_object({}) do |k, mem|
140
- mem[k] = pcdm_object.try(k)
141
- end
142
- end
143
-
144
128
  def additional_attributes
145
- { :created_at => pcdm_object.try(:create_date),
129
+ { :id => pcdm_object.id,
130
+ :created_at => pcdm_object.try(:create_date),
146
131
  :updated_at => pcdm_object.try(:modified_date),
147
132
  :member_ids => member_ids,
148
133
  ::Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK => lock_token }
@@ -2,20 +2,10 @@
2
2
 
3
3
  module Wings
4
4
  ##
5
+ # @api private
6
+ #
5
7
  # Transform AF object class to Valkyrie::Resource class representation.
6
8
  class OrmConverter
7
- ##
8
- # @param reflections [Hash<Symbol, Object>]
9
- #
10
- # @return [Array<Symbol>]
11
- def self.relationship_keys_for(reflections:)
12
- Hash(reflections).keys.map do |k|
13
- key_string = k.to_s
14
- next if key_string.include?('id') || key_string.include?('proxies')
15
- key_string.singularize + '_ids'
16
- end.compact
17
- end
18
-
19
9
  ##
20
10
  # Selects an existing base class for the generated valkyrie class
21
11
  #
@@ -39,9 +29,6 @@ module Wings
39
29
  # rubocop:disable Metrics/MethodLength because metaprogramming a class
40
30
  # results in long methods
41
31
  def self.to_valkyrie_resource_class(klass:)
42
- relationship_keys = klass.respond_to?(:reflections) ? relationship_keys_for(reflections: klass.reflections) : []
43
- reflection_id_keys = klass.respond_to?(:reflections) ? klass.reflections.keys.select { |k| k.to_s.end_with? '_id' } : []
44
-
45
32
  Class.new(base_for(klass: klass)) do
46
33
  # store a string we can resolve to the internal resource
47
34
  @internal_resource = klass.try(:to_rdf_representation) || klass.name
@@ -74,14 +61,30 @@ module Wings
74
61
  end
75
62
  end
76
63
 
77
- relationship_keys.each do |linked_property_name|
78
- next if fields.include?(linked_property_name.to_sym)
79
- attribute linked_property_name.to_sym, ::Valkyrie::Types::Set.of(::Valkyrie::Types::ID)
64
+ # add reflection associations
65
+ ldp_reflections = (klass.try(:reflections) || []).select do |_key, reflection|
66
+ case reflection
67
+ when ActiveFedora::Reflection::FilterReflection,
68
+ ActiveFedora::Reflection::OrdersReflection,
69
+ ActiveFedora::Reflection::BasicContainsReflection,
70
+ ActiveFedora::Reflection::HasSubresourceReflection
71
+ false
72
+ else
73
+ true
74
+ end
80
75
  end
81
76
 
82
- reflection_id_keys.each do |property_name|
83
- next if fields.include?(property_name.to_sym)
84
- attribute property_name, ::Valkyrie::Types::ID
77
+ ldp_reflections.each do |reflection_key, reflection|
78
+ if reflection.collection?
79
+ type = ::Valkyrie::Types::Set.of(::Valkyrie::Types::ID)
80
+ attribute_name = (reflection_key.to_s.singularize + '_ids').to_sym
81
+ else
82
+ type = ::Valkyrie::Types::ID.optional
83
+ attribute_name = (reflection_key.to_s.singularize + '_id').to_sym
84
+ end
85
+
86
+ next if fields.include?(attribute_name)
87
+ attribute attribute_name, type
85
88
  end
86
89
 
87
90
  def internal_resource
@@ -53,6 +53,7 @@ module Wings
53
53
  af_object = ActiveFedora::Base.new
54
54
  af_object.id = resource.alternate_ids.first.to_s
55
55
  af_object.delete
56
+ resource
56
57
  end
57
58
 
58
59
  # Deletes all resources from Fedora and Solr
@@ -47,25 +47,30 @@ module Wings
47
47
  end
48
48
  end
49
49
 
50
- # Find an array of record using Valkyrie IDs, and map them to Valkyrie Resources maintaining order based on given ids
50
+ ##
51
+ # Find an array of record using Valkyrie IDs, and map them to Valkyrie
52
+ # Resources maintaining order based on given ids
53
+ #
54
+ # @note ignores non-existent ids.
55
+ #
51
56
  # @param [Array<Valkyrie::ID, String>] ids
57
+ #
52
58
  # @return [Array<Valkyrie::Resource>]
53
- # NOTE: Ignores non-existent ids.
59
+ # @raise [ArgumentError]
54
60
  def find_many_by_ids(ids:)
55
- ids.each do |id|
56
- id = ::Valkyrie::ID.new(id.to_s) if id.is_a?(String)
57
- validate_id(id)
58
- end
59
- resources = []
60
- ids.uniq.map(&:to_s).each do |id|
61
+ ids.all? { |i| i.respond_to?(:to_str) } ||
62
+ raise(ArgumentError, 'id must be a Valkyrie::ID')
63
+
64
+ return enum_for(:find_many_by_ids, ids: ids) unless block_given?
65
+
66
+ ids.map(&:to_s).uniq.each do |id|
61
67
  begin
62
68
  af_object = ActiveFedora::Base.find(id)
63
- resources << resource_factory.to_resource(object: af_object)
69
+ yield resource_factory.to_resource(object: af_object)
64
70
  rescue ::ActiveFedora::ObjectNotFoundError, Ldp::Gone
65
71
  next
66
72
  end
67
73
  end
68
- resources
69
74
  end
70
75
 
71
76
  # Find a record using an alternate ID, and map it to a Valkyrie Resource
@@ -74,12 +79,14 @@ module Wings
74
79
  # @return [Valkyrie::Resource]
75
80
  # @raise [Hyrax::ObjectNotFoundError]
76
81
  def find_by_alternate_identifier(alternate_identifier:, use_valkyrie: true)
77
- alternate_identifier = ::Valkyrie::ID.new(alternate_identifier.to_s) if alternate_identifier.is_a?(String)
78
- validate_id(alternate_identifier)
79
- object = ::ActiveFedora::Base.find(alternate_identifier.to_s)
80
- return object if use_valkyrie == false
81
- resource_factory.to_resource(object: object)
82
- rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone
82
+ raise(ArgumentError, 'id must be a Valkyrie::ID') unless
83
+ alternate_identifier.respond_to?(:to_str)
84
+
85
+ af_object = ActiveFedora::Base.find(alternate_identifier.to_s)
86
+
87
+ use_valkyrie ? resource_factory.to_resource(object: af_object) : af_object
88
+ rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone => err
89
+ raise err unless use_valkyrie
83
90
  raise Hyrax::ObjectNotFoundError
84
91
  end
85
92
 
@@ -88,11 +95,12 @@ module Wings
88
95
  # @param model [Class]
89
96
  # @return [Array<Valkyrie::Resource>]
90
97
  def find_members(resource:, model: nil)
91
- return [] unless resource.respond_to?(:member_ids) && resource.member_ids.present?
92
- all_members = find_many_by_ids(ids: resource.member_ids)
93
- return all_members unless model
98
+ return [] if resource.try(:member_ids).blank?
99
+ return find_many_by_ids(ids: resource.member_ids) unless model
100
+
94
101
  find_model = model_class_for(model)
95
- all_members.select { |member_resource| model_class_for(member_resource.class) == find_model }
102
+ find_many_by_ids(ids: resource.member_ids)
103
+ .select { |member_resource| model_class_for(member_resource.class) == find_model }
96
104
  end
97
105
 
98
106
  # Find the Valkyrie Resources referenced by another Valkyrie Resource
@@ -160,10 +168,14 @@ module Wings
160
168
  end
161
169
 
162
170
  def find_id_for(reference)
163
- return ::Hyrax::Base.uri_to_id(reference.id) if reference.class == ActiveTriples::Resource
164
- return reference if reference.class == String
165
- # not a supported type
166
- ''
171
+ case reference
172
+ when ActiveTriples::Resource
173
+ ::Hyrax::Base.uri_to_id(reference.id)
174
+ when String
175
+ reference
176
+ else # not a supported type
177
+ ''
178
+ end
167
179
  end
168
180
 
169
181
  def model_class_for(model)