Class: Hyrax::Actors::FileSetActor

Inherits:
Object
  • Object
show all
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.

Instance Attribute Summary collapse

Asynchronous Operations 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.



8
9
10
11
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 8

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6

def attributes
  @attributes
end

#file_setObject (readonly)

Returns the value of attribute file_set.



6
7
8
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6

def file_set
  @file_set
end

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 6

def user
  @user
end

Instance Method Details

#attach_to_work(work, file_set_params = {}) ⇒ Object Also known as: attach_file_to_work

Adds a FileSet to the work using ore:Aggregations. Locks to ensure that only one process is operating on the list at a time.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 71

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)
  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

Parameters:

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

    the file uploaded by the user

  • relation (Symbol, #to_s) (defaults to: :original_file)

Returns:

  • (IngestJob, FalseClass)

    false on failure, otherwise the queued job



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 20

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?
  return false unless file_set.save # Need to save to get an id
  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))
    # Copy visibility and permissions from parent (work) to
    # FileSets even if they come in from BrowseEverything
    VisibilityCopyJob.perform_later(file_set.parent)
    InheritPermissionsJob.perform_later(file_set.parent)
  else
    IngestJob.perform_later(wrapper!(file: file, relation: relation))
  end
end

#create_metadata(file_set_params = {}) {|file_set| ... } ⇒ Object

Note:

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

Parameters:

  • file_set_params (Hash) (defaults to: {})

    specifying the visibility, lease and/or embargo of the file set. Without visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.

Yields:



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

#destroyObject



102
103
104
105
106
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 102

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

#revert_content(revision_id, relation = :original_file) ⇒ Boolean

Returns true on success, false otherwise.

Parameters:

  • revision_id (String)

    the revision to revert to

  • relation (Symbol, #to_sym) (defaults to: :original_file)

Returns:

  • (Boolean)

    true on success, false otherwise



91
92
93
94
95
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 91

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)
  true
end

#update_content(file, relation = :original_file) ⇒ IngestJob

Spawns asynchronous IngestJob with user notification afterward

Parameters:

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

    the file uploaded by the user

  • relation (Symbol, #to_s) (defaults to: :original_file)

Returns:



44
45
46
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 44

def update_content(file, relation = :original_file)
  IngestJob.perform_later(wrapper!(file: file, relation: relation), notification: true)
end

#update_metadata(attributes) ⇒ Object



97
98
99
100
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 97

def (attributes)
  env = Actors::Environment.new(file_set, ability, attributes)
  CurationConcern.file_set_update_actor.update(env)
end