Class: CurationConcerns::Actors::FileSetActor

Inherits:
Object
  • Object
show all
Includes:
Lockable
Defined in:
app/actors/curation_concerns/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.

Since:

  • 0.14.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Lockable

#acquire_lock_for, #lock_manager

Constructor Details

#initialize(file_set, user) ⇒ FileSetActor

Returns a new instance of FileSetActor.

Since:

  • 0.14.0



9
10
11
12
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 9

def initialize(file_set, user)
  @file_set = file_set
  @user = user
end

Instance Attribute Details

#attributesObject (readonly)

Since:

  • 0.14.0



7
8
9
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 7

def attributes
  @attributes
end

#file_setObject (readonly)

Since:

  • 0.14.0



7
8
9
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 7

def file_set
  @file_set
end

#userObject (readonly)

Since:

  • 0.14.0



7
8
9
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 7

def user
  @user
end

Instance Method Details

#create_content(file, relation = 'original_file') ⇒ Object

Parameters:

  • file (File, ActionDigest::HTTP::UploadedFile, Tempfile)

    the file uploaded by the user.

  • relation (String) (defaults to: 'original_file')

    (‘original_file’)

Since:

  • 0.14.0



37
38
39
40
41
42
43
44
45
46
47
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 37

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

  file_actor_class.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.

Parameters:

  • work (ActiveFedora::Base)

    the parent work that will contain the file_set.

  • file_set (Hash)

    specifying the visibility, lease and/or embargo of the file set. If you don’t provide at least one of visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.

Yields:

Since:

  • 0.14.0



23
24
25
26
27
28
29
30
31
32
33
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 23

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]

  Actors::ActorStack.new(file_set, user, [InterpretVisibilityActor]).create(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

#destroyObject

Since:

  • 0.14.0



76
77
78
79
80
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 76

def destroy
  unlink_from_work
  file_set.destroy
  CurationConcerns.config.callback.run(:after_destroy, file_set.id, user)
end

#file_actor_classObject

Since:

  • 0.14.0



82
83
84
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 82

def file_actor_class
  CurationConcerns::Actors::FileActor
end

#revert_content(revision_id, relation = 'original_file') ⇒ Object

Parameters:

  • revision_id (String)

    the revision to revert to

  • relation (String) (defaults to: 'original_file')

    (‘original_file’)

Since:

  • 0.14.0



51
52
53
54
55
56
57
58
59
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 51

def revert_content(revision_id, relation = 'original_file')
  file_actor = file_actor_class.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

Parameters:

  • file (File, ActionDigest::HTTP::UploadedFile, Tempfile)

    the file uploaded by the user.

  • relation (String) (defaults to: 'original_file')

    (‘original_file’)

Since:

  • 0.14.0



63
64
65
66
67
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 63

def update_content(file, relation = 'original_file')
  file_actor_class.new(file_set, relation, user).ingest_file(file)
  CurationConcerns.config.callback.run(:after_update_content, file_set, user)
  true
end

#update_metadata(attributes) ⇒ Object

Since:

  • 0.14.0



69
70
71
72
73
74
# File 'app/actors/curation_concerns/actors/file_set_actor.rb', line 69

def (attributes)
  stack = Actors::ActorStack.new(file_set,
                                 user,
                                 [InterpretVisibilityActor, BaseActor])
  stack.update(attributes)
end