class Dgrid::API::Workspace::Backup_0_1

Public Class Methods

backed_up_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 311
def self.backed_up_classes
  self.entity_classes + [ Incident]
end
entity_classes() click to toggle source
# File lib/dgrid/api/workspace.rb, line 300
def self.entity_classes 
  @@entity_classes ||= Set.new(
    [Item,
     Person,
     Place,
     Organization,
     Link,
     Lens,
    ])
end

Protected Class Methods

predecessor() click to toggle source
# File lib/dgrid/api/workspace.rb, line 316
def self.predecessor
  nil
end

Protected Instance Methods

do_restore(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 320
def do_restore(workspace)
  @new_entities = {}
  restore_entities_into(workspace)
  restore_weird_special_cases_into(workspace)
  restore_lenses_into(workspace)
  restore_links_into(workspace)
end
incidents_are_entities?() click to toggle source
# File lib/dgrid/api/workspace.rb, line 328
def incidents_are_entities?
  if @incidents_are_entities.nil?
    @incidents_are_entities = entity_classes.include?(Incident)
  end
  return @incidents_are_entities
end

Private Instance Methods

hashify_all_members(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 349
def hashify_all_members(workspace)
  @members = {'lensings'=>{}}
  @members[Incident.pluralized] = {} unless incidents_are_entities?
  hashify_entities(workspace)
  if !workspace.nil?
    hashify_incidents(workspace) unless incidents_are_entities?
    hashify_lensings(workspace)
  end
end
hashify_entities(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 359
def hashify_entities(workspace)
  backed_up_classes.each do |klass|
    if !get_entities_hash(klass)
      set_entities(klass, workspace.nil? ? nil : workspace.send(klass.pluralized))
    end
  end
end
hashify_incidents(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 367
def hashify_incidents(workspace)
  workspace.items.each do |item|
    set_incidents(item.id,item.incidents)
  end
end
hashify_lensings(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 373
def hashify_lensings(workspace)
  workspace.lenses.each do |lens|
    set_lensings(lens.id,lens.item_ids)
  end
end
incidents(item_id) click to toggle source
# File lib/dgrid/api/workspace.rb, line 337
def incidents(item_id)
  raise "The method incidents(item_id) is invalid in class #{self.class.name}" if incidents_are_entities?
  @members[Incident.pluralized][item_id]
end
restore_entities_into(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 379
def restore_entities_into(workspace)
  entity_classes.each do |entity_class|
    next if entity_class.type == 'Link'
    entity_hash = get_entities_hash(entity_class)
    entity_hash.each do |old_id, entity_params|
      new_entity = workspace.add_entity(entity_class.new(change_string_keys_to_symbol_keys(entity_params)))
      entity_key =[entity_class.type,old_id]
      @new_entities[entity_key] = new_entity
    end
  end
end
restore_lenses_into(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 391
def restore_lenses_into(workspace)
  get_entities_hash(Lens).each_pair do |old_lens_id, old_lens_params|
    lens_key = [Lens.type, old_lens_id]
    new_lens = @new_entities[lens_key]
    raise "lens #{lens_key.inspect} not found in #{@new_entities.inspect}" unless new_lens

    lensings(old_lens_id).each do |old_item_id|
      item_key = [Item.type, old_item_id]
      new_item = @new_entities[item_key]
      raise "item #{item_key.inspect} not found in #{@new_entities.inspect}" unless new_item
      new_lens.add_item(new_item)
    end
  end
end
restore_weird_special_cases_into(workspace) click to toggle source
# File lib/dgrid/api/workspace.rb, line 439
def restore_weird_special_cases_into(workspace)
  get_entities_hash(Item).each_pair do |old_item_id, old_item_params|
    item_key = [Item.type, old_item_id]
    new_item = @new_entities[item_key]
    raise "item #{item_key.inspect} not found in #{@new_entities.inspect}" unless new_item
    incidents(old_item_id).each_pair do |old_incident_id, old_incident_params|
      new_incident = workspace.add_incident(Incident.new(change_string_keys_to_symbol_keys(old_incident_params)), new_item)
      incident_key =[Incident.type,old_incident_id]
      @new_entities[incident_key]  = new_incident
    end
  end
end
set_incidents(item_id,incidents) click to toggle source
# File lib/dgrid/api/workspace.rb, line 342
def set_incidents(item_id,incidents)
  raise "The method set_incidents(item_id,incidents) is invalid in class #{self.class.name}" if incidents_are_entities?
  raise "argument_error: expected String id" unless item_id.is_a?(String)
  raise "argumet_error: expected array of Incident" unless incidents.is_a?(Array) && (incidents.empty? || incidents.first.is_a?(Dgrid::API::Incident))
  @members[Incident.pluralized][item_id] = hashify_obj_list(incidents)
end