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, use_valkyrie: Hyrax.config.query_index_from_valkyrie) ⇒ FileSetActor

Returns a new instance of FileSetActor.



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

def initialize(file_set, user, use_valkyrie: Hyrax.config.query_index_from_valkyrie)
  @use_valkyrie = use_valkyrie
  @file_set = file_set
  @user = user
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#file_setObject (readonly)

Returns the value of attribute file_set.



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

def file_set
  @file_set
end

#use_valkyrieObject (readonly)

Returns the value of attribute use_valkyrie.



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

def use_valkyrie
  @use_valkyrie
end

#userObject (readonly)

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#attach_to_af_work(work, file_set_params) ⇒ Object

Adds a FileSet to the work using ore:Aggregations.



100
101
102
103
104
105
106
107
108
109
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 100

def attach_to_af_work(work, file_set_params)
  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
end

#attach_to_valkyrie_work(work, file_set_params) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 85

def attach_to_valkyrie_work(work, file_set_params)
  work = Hyrax.query_service.find_by(id: work.id) unless work.new_record
  file_set.visibility = work.visibility unless assign_visibility?(file_set_params)
  fs = Hyrax.persister.save(resource: file_set)
  Hyrax.publisher.publish('object.metadata.updated', object: fs, user: user)
  work.member_ids << fs.id
  work.representative_id = fs.id if work.representative_id.blank?
  work.thumbnail_id = fs.id 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.
  Hyrax.persister.save(resource: work)
  Hyrax.publisher.publish('object.metadata.updated', object: work, user: user)
end

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

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
# 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.
    if valkyrie_object?(work)
      attach_to_valkyrie_work(work, file_set_params)
    else
      attach_to_af_work(work, file_set_params)
    end
    Hyrax.config.callback.run(:after_create_fileset, file_set, user, warn: false)
  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)

    the file uploaded by the user

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

Returns:

  • (IngestJob, FalseClass)

    false on failure, otherwise the queued job



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

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?
  @file_set = perform_save(file_set)
  return false unless file_set
  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))
    parent = parent_for(file_set: file_set)
    VisibilityCopyJob.perform_later(parent)
    InheritPermissionsJob.perform_later(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:



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 57

def (file_set_params = {})
  file_set.depositor = depositor_id(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



125
126
127
128
129
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 125

def destroy
  unlink_from_work
  file_set.destroy
  Hyrax.config.callback.run(:after_destroy, file_set.id, user, warn: false)
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



114
115
116
117
118
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 114

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, warn: false)
  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:



46
47
48
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 46

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

#update_metadata(attributes) ⇒ Object



120
121
122
123
# File 'app/actors/hyrax/actors/file_set_actor.rb', line 120

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