class SakaiInfo::ContentCollection

Attributes

dbrow[R]

Public Class Methods

clear_cache() click to toggle source
# File lib/sakai-info/content.rb, line 324
def self.clear_cache
  @@cache = {}
end
count_by_parent(parent_id) click to toggle source
# File lib/sakai-info/content.rb, line 467
def self.count_by_parent(parent_id)
  ContentCollection.query_by_parent(parent_id).count
end
find(id) click to toggle source
# File lib/sakai-info/content.rb, line 339
def self.find(id)
  if id !~ /\/$/
    id += "/"
  end

  if @@cache[id].nil?
    row = DB.connect[:content_collection].where(:collection_id => id).first
    if row.nil?
      raise ObjectNotFoundException.new(ContentCollection, id)
    end
    @@cache[id] = ContentCollection.new(row)
  end
  @@cache[id]
end
find!(id) click to toggle source

return a content collection, even if it’s a missing one

# File lib/sakai-info/content.rb, line 355
def self.find!(id)
  begin
    ContentCollection.find(id)
  rescue ObjectNotFoundException
    MissingContentCollection.find(id)
  end
end
find_by_parent(parent_id) click to toggle source
# File lib/sakai-info/content.rb, line 471
def self.find_by_parent(parent_id)
  collections = []
  ContentCollection.query_by_parent(parent_id).all.each do |row|
    @@cache[row[:collection_id]] = ContentCollection.new(row)
    collections << @@cache[row[:collection_id]]
  end
  collections
end
find_portfolio_interaction_collections() click to toggle source
# File lib/sakai-info/content.rb, line 363
def self.find_portfolio_interaction_collections
  collections = []
  DB.connect[:content_collection].
    where(Sequel.like(:collection_id, '%/portfolio-interaction/')) do |row|
    @@cache[row[:collection_id]] = ContentCollection.new(row)
    collections << @@cache[row[:collection_id]]
  end
  collections
end
new(dbrow) click to toggle source
# File lib/sakai-info/content.rb, line 329
def initialize(dbrow)
  @dbrow = dbrow

  @id = @dbrow[:collection_id]
  @parent_id = @dbrow[:in_collection]

  @table_name = "content_collection"
  @id_column = "collection_id"
end
query_by_parent(parent_id) click to toggle source
# File lib/sakai-info/content.rb, line 463
def self.query_by_parent(parent_id)
  DB.connect[:content_collection].where(:in_collection => parent_id)
end

Public Instance Methods

child_counts() click to toggle source
# File lib/sakai-info/content.rb, line 388
def child_counts
  @child_collection_count ||= if @child_collections.nil?
                                ContentCollection.count_by_parent(@id)
                              else
                                @child_collections.length
                              end
  @child_resource_count ||= if @child_resources.nil?
                              ContentResource.count_by_parent(@id)
                            else
                              @child_resources.length
                            end
  {
    "collections" => @child_collection_count,
    "resources" => @child_resource_count,
    "total" => @child_collection_count + @child_resource_count
  }
end
children() click to toggle source
# File lib/sakai-info/content.rb, line 379
def children
  @child_collections ||= ContentCollection.find_by_parent(@id)
  @child_resources ||= ContentResource.find_by_parent(@id)
  {
    "collections" => @child_collections,
    "resources" => @child_resources
  }
end
children_serialization() click to toggle source
# File lib/sakai-info/content.rb, line 427
def children_serialization
  result = {
    "collections" => self.children["collections"].collect { |cc|
      cc.serialize(:child_summary, :children)
    },
    "resources" => self.children["resources"].collect { |cr|
      cr.serialize(:child_summary)
    }
  }
  if result["collections"] == []
    result.delete("collections")
  end
  if result["resources"] == []
    result.delete("resources")
  end
  result
end
default_serialization() click to toggle source
# File lib/sakai-info/content.rb, line 406
def default_serialization
  {
    "id" => self.id,
    "size_on_disk" => self.size_on_disk,
    "children" => self.child_counts,
  }
end
detailed_summary_serialization() click to toggle source
# File lib/sakai-info/content.rb, line 420
def detailed_summary_serialization
  {
    "id" => self.id,
    "size_on_disk" => self.size_on_disk,
  }
end
full_children_serialization() click to toggle source
# File lib/sakai-info/content.rb, line 445
def full_children_serialization
  result = {
    "collections" => self.children["collections"].collect { |cc|
      cc.serialize(:detailed_summary, :full_children)
    },
    "resources" => self.children["resources"].collect { |cr|
      cr.serialize(:detailed_summary)
    }
  }
  if result["collections"] == []
    result.delete("collections")
  end
  if result["resources"] == []
    result.delete("resources")
  end
  result
end
size_on_disk() click to toggle source
# File lib/sakai-info/content.rb, line 373
def size_on_disk
  @size_on_disk ||=
    DB.connect[:content_resource].select(Sequel.function(:sum, :file_size).as(:total_size)).
    where(Sequel.like(:resource_id, "#{@id}%")).first[:total_size].to_i
end
summary_serialization() click to toggle source
# File lib/sakai-info/content.rb, line 414
def summary_serialization
  {
    "id" => self.id,
  }
end