Class: CurationConcerns::FileSetActor
- Inherits:
-
Object
- Object
- CurationConcerns::FileSetActor
- Includes:
- Lockable, ManagesEmbargoesActor
- Defined in:
- app/actors/curation_concerns/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.
-
#curation_concern ⇒ Object
readonly
Returns the value of attribute curation_concern.
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#create_content(file) ⇒ Object
Puts the uploaded content into a staging directory.
-
#create_metadata(work, 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) ⇒ Object
- #update_content(file) ⇒ Object
- #update_metadata(attributes) ⇒ Object
Methods included from Lockable
#acquire_lock_for, #lock_manager
Methods included from ManagesEmbargoesActor
#interpret_embargo_visibility, #interpret_lease_visibility, #interpret_visibility
Constructor Details
#initialize(file_set, user) ⇒ FileSetActor
Returns a new instance of FileSetActor.
9 10 11 12 13 14 15 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 9 def initialize(file_set, user) # we're setting attributes and curation_concern to bridge the difference # between CurationConcerns::FileSetActor and ManagesEmbargoesActor @curation_concern = file_set @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/curation_concerns/file_set_actor.rb', line 7 def attributes @attributes end |
#curation_concern ⇒ Object (readonly)
Returns the value of attribute curation_concern.
7 8 9 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 7 def curation_concern @curation_concern end |
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
7 8 9 |
# File 'app/actors/curation_concerns/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/curation_concerns/file_set_actor.rb', line 7 def user @user end |
Instance Method Details
#create_content(file) ⇒ Object
Puts the uploaded content into a staging directory. Then kicks off a job to characterize and create derivatives with this on disk variant. Simultaneously moving a preservation copy to the repostiory. TODO: create a job to monitor this directory and prune old files that have made it to the repo
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 44 def create_content(file) # Assign label and title of File Set is necessary. 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? # Need to save the file_set in order to get an id return false unless file_set.save working_file = copy_file_to_working_directory(file, file_set.id) mime_type = file.respond_to?(:content_type) ? file.content_type : nil IngestFileJob.perform_later(file_set.id, working_file, mime_type, user.user_key) make_derivative(file_set.id, working_file) true end |
#create_metadata(work, file_set_params = {}) {|file_set| ... } ⇒ Object
Adds the appropriate metadata, visibility and relationships to file_set
Note: In past versions of Sufia 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.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 26 def (work, file_set_params = {}) file_set.(user) now = CurationConcerns::TimeService.time_in_utc file_set.date_uploaded = now file_set.date_modified = now file_set.creator = [user.user_key] interpret_visibility file_set_params if assign_visibility?(file_set_params) attach_file_to_work(work, file_set, file_set_params) if work yield(file_set) if block_given? end |
#destroy ⇒ Object
92 93 94 95 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 92 def destroy file_set.destroy CurationConcerns.config.callback.run(:after_destroy, file_set.id, user) end |
#revert_content(revision_id) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 59 def revert_content(revision_id) file_set.original_file.restore_version(revision_id) return false unless file_set.save CurationConcerns::VersioningService.create(file_set.original_file, user) # Retrieve a copy of the orginal file from the repository working_file = copy_repository_resource_to_working_directory(file_set) make_derivative(file_set.id, working_file) CurationConcerns.config.callback.run(:after_revert_content, file_set, user, revision_id) true end |
#update_content(file) ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 74 def update_content(file) working_file = copy_file_to_working_directory(file, file_set.id) IngestFileJob.perform_later(file_set.id, working_file, file.content_type, user.user_key) make_derivative(file_set.id, working_file) CurationConcerns.config.callback.run(:after_update_content, file_set, user) true end |
#update_metadata(attributes) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 82 def (attributes) update_visibility(attributes) # attributes.delete(:visibility) # Applying this attribute is handled by update_visibility file_set.attributes = attributes file_set.date_modified = CurationConcerns::TimeService.time_in_utc save do CurationConcerns.config.callback.run(:after_update_metadata, file_set, user) end end |