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, relation = 'original_file') ⇒ Object
-
#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, relation = 'original_file') ⇒ Object
- #update_content(file, relation = 'original_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, relation = 'original_file') ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 40 def create_content(file, relation = 'original_file') # 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? # Need to save the file_set in order to get an id return false unless file_set.save FileActor.new(file_set, relation, user).ingest_file(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
82 83 84 85 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 82 def destroy file_set.destroy CurationConcerns.config.callback.run(:after_destroy, file_set.id, user) end |
#revert_content(revision_id, relation = 'original_file') ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 54 def revert_content(revision_id, relation = 'original_file') file_actor = FileActor.new(file_set, relation, user) if file_actor.revert_to(revision_id) CurationConcerns.config.callback.run(:after_revert_content, file_set, user, revision_id) true else false end end |
#update_content(file, relation = 'original_file') ⇒ Object
66 67 68 69 70 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 66 def update_content(file, relation = 'original_file') FileActor.new(file_set, relation, user).ingest_file(file) CurationConcerns.config.callback.run(:after_update_content, file_set, user) true end |
#update_metadata(attributes) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/actors/curation_concerns/file_set_actor.rb', line 72 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 |