Class: Hyrax::Actors::CreateWithRemoteFilesActor::IngestRemoteFilesService

Inherits:
Object
  • Object
show all
Defined in:
app/actors/hyrax/actors/create_with_remote_files_actor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, curation_concern:, remote_files:, file_set_actor_class:, ordered_members: [], ordered: false) ⇒ IngestRemoteFilesService

rubocop:disable Metrics/ParameterLists

Parameters:

  • remote_files (HashWithIndifferentAccess)
  • file_set_actor_class
  • ordered_members (Array) (defaults to: [])
  • ordered (Boolean) (defaults to: false)


45
46
47
48
49
50
51
52
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 45

def initialize(user:, curation_concern:, remote_files:, file_set_actor_class:, ordered_members: [], ordered: false)
  @remote_files = remote_files
  @user = user
  @curation_concern = curation_concern
  @file_set_actor_class = file_set_actor_class
  @ordered_members = ordered_members
  @ordered = ordered
end

Instance Attribute Details

#curation_concernObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def curation_concern
  @curation_concern
end

#file_set_actor_classObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def file_set_actor_class
  @file_set_actor_class
end

#orderedObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def ordered
  @ordered
end

#ordered_membersObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def ordered_members
  @ordered_members
end

#remote_filesObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def remote_files
  @remote_files
end

#userObject (readonly)

rubocop:enable Metrics/ParameterLists



54
55
56
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 54

def user
  @user
end

Class Method Details

.registered_ingest_dirsObject



75
76
77
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 75

def self.registered_ingest_dirs
  Hyrax.config.registered_ingest_dirs
end

.validate_remote_url(uri) ⇒ Object

Parameters:

  • uri (URI)

    the uri fo the resource to import



80
81
82
83
84
85
86
87
88
89
90
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 80

def self.validate_remote_url(uri)
  if uri.scheme == 'file'
    path = File.absolute_path(CGI.unescape(uri.path))
    registered_ingest_dirs.any? do |dir|
      path.start_with?(dir) && path.length > dir.length
    end
  else
    Hyrax.logger.debug "Assuming #{uri.scheme} uri is valid without a serious attempt to validate: #{uri}"
    true
  end
end

Instance Method Details

#attach!Object

Returns true.

Returns:

  • true



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/actors/hyrax/actors/create_with_remote_files_actor.rb', line 58

def attach!
  return true unless remote_files
  remote_files.each do |file_info|
    next if file_info.blank? || file_info[:url].blank?
    # Escape any space characters, so that this is a legal URI
    uri = URI.parse(Addressable::URI.escape(file_info[:url]))
    unless self.class.validate_remote_url(uri)
      Hyrax.logger.error "User #{user.user_key} attempted to ingest file from url #{file_info[:url]}, which doesn't pass validation"
      return false
    end
    auth_header = file_info.fetch(:auth_header, {})
    create_file_from_url(uri, file_info[:file_name], auth_header)
  end
  add_ordered_members! if ordered
  true
end