Class: Hyrax::Actors::FileSetActor
- Inherits:
-
Object
- Object
- Hyrax::Actors::FileSetActor
- Includes:
- Lockable
- Defined in:
- app/actors/hyrax/actors/file_set_actor.rb
Overview
Actions are decoupled from controller logic so that they may be called from a controller or a background job.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#attach_file_to_work(work, file_set_params = {}) ⇒ Object
Adds a FileSet to the work using ore:Aggregations.
-
#create_content(file, relation = 'original_file', asynchronous = true) ⇒ Object
Called from AttachFilesActor, FileSetsController, AttachFilesToWorkJob, ImportURLJob, IngestLocalFileJob.
-
#create_metadata(file_set_params = {}) {|file_set| ... } ⇒ Object
Adds the appropriate metadata, visibility and relationships to file_set.
- #destroy ⇒ Object
- #file_actor_class ⇒ Object
-
#import_url(url) ⇒ Object
Spawns async job to attach file to fileset.
-
#initialize(file_set, user) ⇒ FileSetActor
constructor
A new instance of FileSetActor.
- #revert_content(revision_id, relation = 'original_file') ⇒ Object
- #update_content(file, relation = 'original_file') ⇒ Object
- #update_metadata(attributes) ⇒ Object
Methods included from Lockable
#acquire_lock_for, #lock_manager
Constructor Details
#initialize(file_set, user) ⇒ FileSetActor
Returns a new instance of FileSetActor.
8 9 10 11 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 8 def initialize(file_set, user) @file_set = file_set @user = user end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6 def attributes @attributes end |
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
6 7 8 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6 def file_set @file_set end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
6 7 8 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6 def user @user end |
Instance Method Details
#attach_file_to_work(work, file_set_params = {}) ⇒ Object
Adds a FileSet to the work using ore:Aggregations. Locks to ensure that only one process is operating on the list at a time.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 44 def attach_file_to_work(work, file_set_params = {}) acquire_lock_for(work.id) do # Ensure we have an up-to-date copy of the members association, so that we append to the end of the list. work.reload unless work.new_record? copy_visibility(work, file_set) unless assign_visibility?(file_set_params) work.ordered_members << file_set set_representative(work, file_set) set_thumbnail(work, file_set) # Save the work so the association between the work and the file_set is persisted (head_id) # NOTE: the work may not be valid, in which case this save doesn't do anything. work.save end end |
#create_content(file, relation = 'original_file', asynchronous = true) ⇒ Object
Called from AttachFilesActor, FileSetsController, AttachFilesToWorkJob, ImportURLJob, IngestLocalFileJob
33 34 35 36 37 38 39 40 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 33 def create_content(file, relation = 'original_file', asynchronous = true) # If the file set doesn't have a title or label assigned, set a default. file_set.label ||= file.respond_to?(:original_filename) ? file.original_filename : ::File.basename(file) file_set.title = [file_set.label] if file_set.title.blank? return false unless file_set.save # Need to save the file_set in order to get an id build_file_actor(relation).ingest_file(file, asynchronous) true end |
#create_metadata(file_set_params = {}) {|file_set| ... } ⇒ Object
In past versions of Hyrax this method did not perform a save because it is mainly used in conjunction with create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects, we have to save both the parent work and the file_set in order to record the “metadata” relationship between them.
Adds the appropriate metadata, visibility and relationships to file_set
19 20 21 22 23 24 25 26 27 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 19 def (file_set_params = {}) file_set.(user) now = TimeService.time_in_utc file_set.date_uploaded = now file_set.date_modified = now file_set.creator = [user.user_key] Actors::ActorStack.new(file_set, ability, [InterpretVisibilityActor]).create(file_set_params) if assign_visibility?(file_set_params) yield(file_set) if block_given? end |
#destroy ⇒ Object
81 82 83 84 85 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 81 def destroy unlink_from_work file_set.destroy Hyrax.config.callback.run(:after_destroy, file_set.id, user) end |
#file_actor_class ⇒ Object
87 88 89 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 87 def file_actor_class Hyrax::Actors::FileActor end |
#import_url(url) ⇒ Object
Spawns async job to attach file to fileset
93 94 95 96 97 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 93 def import_url(url) file_set.update(import_url: url.to_s) operation = Hyrax::Operation.create!(user: user, operation_type: "Attach File") ImportUrlJob.perform_later(file_set, operation) end |
#revert_content(revision_id, relation = 'original_file') ⇒ Object
60 61 62 63 64 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 60 def revert_content(revision_id, relation = 'original_file') return false unless build_file_actor(relation).revert_to(revision_id) Hyrax.config.callback.run(:after_revert_content, file_set, user, revision_id) true end |
#update_content(file, relation = 'original_file') ⇒ Object
68 69 70 71 72 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 68 def update_content(file, relation = 'original_file') build_file_actor(relation).ingest_file(file, true) Hyrax.config.callback.run(:after_update_content, file_set, user) true end |
#update_metadata(attributes) ⇒ Object
74 75 76 77 78 79 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 74 def (attributes) stack = Actors::ActorStack.new(file_set, ability, [InterpretVisibilityActor, BaseActor]) stack.update(attributes) end |