Class: Aqueduct::Repositories::Elastic

Inherits:
Object
  • Object
show all
Includes:
Aqueduct::Repository
Defined in:
lib/aqueduct/repositories/elastic.rb

Instance Method Summary collapse

Instance Method Details

#count_files(file_locators, file_type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aqueduct/repositories/elastic.rb', line 11

def count_files(file_locators, file_type)
  error = ''
  file_paths = []
  url_paths = []

  file_locators.each do |file_locator|
    file_locator = file_locator.to_s.gsub(/[\/*]/, '') # Don't allow wild cards or subfolders
    file_type = file_type.to_s.gsub(/[\/*]/, '')       # Don't allow wild cards or subfolders
    file_name = file_locator + file_type
    file_paths << file_name unless file_locator.blank?
  end

  # These should be set by the server itself.
  name = "#{@source.name.gsub(/[^\w]/, '')}_#{file_type.split(/[_\.]/).select{|i| not i.blank?}.join('_').downcase}"
  target_file_name = ''
  comments = ''

  result_hash = send_message("downloaders.json", { 'downloader[name]' => name, 'downloader[files]' => file_paths.join("\n"), 'downloader[folder]' => "source_#{@source.id}", 'downloader[comments]' => comments, 'target_file_name' => target_file_name, 'downloader[external_user_id]' => @current_user.id }, "post")
  downloader_hash = result_hash[:result].blank? ? {} : ActiveSupport::JSON.decode(result_hash[:result])
  url_paths = [downloader_hash['simple_executable_file_url']].compact
  file_count = downloader_hash['file_count'].to_i

  error = "Processing...retry in a few minutes." if url_paths.blank?
  { result: file_count, error: error, file_paths: file_paths, urls: url_paths }
end

#file_server_available?Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/aqueduct/repositories/elastic.rb', line 41

def file_server_available?
  result_hash = send_message("about")
  { result: result_hash[:error].blank?, error: result_hash[:error] }
end

#has_repository?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/aqueduct/repositories/elastic.rb', line 37

def has_repository?
  { result: true, error: '' }
end