Class: Rhoconnect::BulkData

Inherits:
StoreOrm show all
Defined in:
lib/rhoconnect/bulk_data/bulk_data.rb

Instance Attribute Summary

Attributes inherited from StoreOrm

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StoreOrm

_field_key, _prefix, class_prefix, #decrement!, field, #field_key, fields, #increment!, #initialize, is_exist?, list, load, marshal_class_name, #next_id, populate_attributes, set, #store, store, #to_array, validates_presence_of

Constructor Details

This class inherits a constructor from Rhoconnect::StoreOrm

Class Method Details

.create(fields = {}) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 61

def create(fields={})
  fields[:id] = fields[:name]
  fields[:state] ||= :inprogress
  fields[:sources] ||= []
  fields[:partition_sources] ||= []
  super(fields)
end

.enqueue(params = {}) ⇒ Object



69
70
71
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 69

def enqueue(params={})
  Resque.enqueue(BulkDataJob,params)
end

.get_name(partition, user_id) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 73

def get_name(partition,user_id)
  if partition == :user
    File.join(APP_NAME,user_id,user_id)
  else
    File.join(APP_NAME,APP_NAME)
  end
end

.index_fileObject



85
86
87
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 85

def index_file
  File.join(File.dirname(__FILE__),'syncdb.index.schema')
end

.schema_fileObject



81
82
83
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 81

def schema_file
  File.join(File.dirname(__FILE__),'syncdb.schema')
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 16

def completed?
  if state.to_sym == :completed
    return true
  end
  false
end

#dbfiles_exist?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 48

def dbfiles_exist?
  files = [dbfile,dbfile+'.rzip']
  files.each do |file|
    return false unless File.exist?(file)
  end
  true
end

#deleteObject



23
24
25
26
27
28
29
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 23

def delete
  sources[0, -1].each do |source|
    s = Source.load(source,{:app_id => app_id, :user_id => user_id})
    s.flush_data(:md_copy) if s
  end
  super
end

#delete_filesObject



56
57
58
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 56

def delete_files
  FileUtils.rm Dir.glob(File.join(Rhoconnect.base_directory, "#{self.url}*"))
end

#process_sourcesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 31

def process_sources
  sources[0, -1].each do |source|
    s = Source.load(source,{:app_id => app_id, :user_id => user_id})
    if s
      rh = lambda { @model.query(params[:query])}
      model = Rhoconnect::Model::Base.create(s)
      Rhoconnect::Handler::Query::Engine.new(model, rh, {}).run_query
      s.clone(:md, s.docname(:md_copy)) unless s.sync_type.to_sym == :bulk_sync_only
    end
  end
end

#urlObject



43
44
45
46
# File 'lib/rhoconnect/bulk_data/bulk_data.rb', line 43

def url
  zippath = dbfile.gsub(Regexp.compile(Regexp.escape(Rhoconnect.data_directory)), "")
  URI.escape(File.join('/data',zippath))
end