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.
Direct Known Subclasses
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.
Asynchronous Operations collapse
-
#create_content(file, relation = :original_file, from_url: false) ⇒ IngestJob, FalseClass
Spawns asynchronous IngestJob unless ingesting from URL Called from FileSetsController, AttachFilesToWorkJob, IngestLocalFileJob, ImportUrlJob.
-
#update_content(file, relation = :original_file) ⇒ IngestJob
Spawns asynchronous IngestJob with user notification afterward.
Instance Method Summary collapse
-
#attach_to_work(work, file_set_params = {}) ⇒ Object
Locks to ensure that only one process is operating on the list at a time.
-
#create_metadata(file_set_params = {}) {|file_set| ... } ⇒ Object
Adds the appropriate metadata, visibility and relationships to file_set.
- #destroy ⇒ Object
-
#initialize(file_set, user) ⇒ FileSetActor
constructor
A new instance of FileSetActor.
-
#revert_content(revision_id, relation = :original_file) ⇒ Boolean
True on success, false otherwise.
- #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.
9 10 11 12 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 9 def initialize(file_set, user) @file_set = file_set @user = user end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 7 def attributes @attributes end |
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
7 8 9 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 7 def file_set @file_set end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
7 8 9 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 7 def user @user end |
Instance Method Details
#attach_to_work(work, file_set_params = {}) ⇒ Object
Locks to ensure that only one process is operating on the list at a time.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 70 def attach_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? file_set.visibility = work.visibility unless assign_visibility?(file_set_params) work.ordered_members << file_set work.representative = file_set if work.representative_id.blank? work.thumbnail = file_set if work.thumbnail_id.blank? # 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 Hyrax.config.callback.run(:after_create_fileset, file_set, user, warn: false) end end |
#create_content(file, relation = :original_file, from_url: false) ⇒ IngestJob, FalseClass
Spawns asynchronous IngestJob unless ingesting from URL Called from FileSetsController, AttachFilesToWorkJob, IngestLocalFileJob, ImportUrlJob
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 21 def create_content(file, relation = :original_file, from_url: false) # If the file set doesn't have a title or label assigned, set a default. file_set.label ||= label_for(file) file_set.title = [file_set.label] if file_set.title.blank? @file_set = perform_save(file_set) return false unless file_set if from_url # If ingesting from URL, don't spawn an IngestJob; instead # reach into the FileActor and run the ingest with the file instance in # hand. Do this because we don't have the underlying UploadedFile instance file_actor = build_file_actor(relation) file_actor.ingest_file(wrapper!(file: file, relation: relation)) parent = parent_for(file_set: file_set) VisibilityCopyJob.perform_later(parent) InheritPermissionsJob.perform_later(parent) else IngestJob.perform_later(wrapper!(file: file, relation: relation)) end 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
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 56 def (file_set_params = {}) file_set.depositor = depositor_id(user) now = TimeService.time_in_utc file_set.date_uploaded = now file_set.date_modified = now file_set.creator = [user.user_key] if assign_visibility?(file_set_params) env = Actors::Environment.new(file_set, ability, file_set_params) CurationConcern.file_set_create_actor.create(env) end yield(file_set) if block_given? end |
#destroy ⇒ Object
99 100 101 102 103 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 99 def destroy unlink_from_work file_set.destroy Hyrax.config.callback.run(:after_destroy, file_set.id, user, warn: false) end |
#revert_content(revision_id, relation = :original_file) ⇒ Boolean
Returns true on success, false otherwise.
88 89 90 91 92 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 88 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, warn: false) true end |
#update_content(file, relation = :original_file) ⇒ IngestJob
Spawns asynchronous IngestJob with user notification afterward
45 46 47 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 45 def update_content(file, relation = :original_file) IngestJob.perform_later(wrapper!(file: file, relation: relation), notification: true) end |
#update_metadata(attributes) ⇒ Object
94 95 96 97 |
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 94 def (attributes) env = Actors::Environment.new(file_set, ability, attributes) CurationConcern.file_set_update_actor.update(env) end |