Class: CurationConcerns::FileSetActor
- Inherits:
-
Object
- Object
- CurationConcerns::FileSetActor
- Includes:
- 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(upload_set_id, 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 ManagesEmbargoesActor
#interpret_embargo_visibility, #interpret_lease_visibility, #interpret_visibility
Constructor Details
#initialize(file_set, user) ⇒ FileSetActor
Returns a new instance of FileSetActor.
8 9 10 11 12 13 14 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 8 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.
6 7 8 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 6 def attributes @attributes end |
#curation_concern ⇒ Object (readonly)
Returns the value of attribute curation_concern.
6 7 8 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 6 def curation_concern @curation_concern end |
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
6 7 8 |
# File 'app/actors/curation_concerns/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/curation_concerns/file_set_actor.rb', line 6 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
54 55 56 57 58 59 60 61 62 63 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 54 def create_content(file) file_set.label ||= file.original_filename file_set.title = [file_set.label] if file_set.title.blank? return false unless file_set.save 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) true end |
#create_metadata(upload_set_id, 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 37 38 39 40 41 42 43 44 45 46 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 26 def (upload_set_id, 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] if upload_set_id && file_set.respond_to?(:upload_set_id=) UploadSet.create(id: upload_set_id) unless UploadSet.exists?(upload_set_id) file_set.upload_set_id = upload_set_id else ActiveFedora::Base.logger.warn 'unable to find UploadSet to attach to' end if assign_visibility?(file_set_params) interpret_visibility file_set_params end # TODO: Why do we need to check if work is nil? Shoudn't that raise an error? attach_file_to_work(work, file_set, file_set_params) if work yield(file_set) if block_given? end |
#destroy ⇒ Object
98 99 100 101 102 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 98 def destroy file_set.destroy # TODO: need to mend the linked list of proxies (possibly wrap with a lock) CurationConcerns.config.callback.run(:after_destroy, file_set.id, user) end |
#revert_content(revision_id) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 65 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
80 81 82 83 84 85 86 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 80 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
88 89 90 91 92 93 94 95 96 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 88 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 |