class CMIS::Query

Public Class Methods

new(repository, statement, options = {}) click to toggle source

Options: from, page_size

# File lib/cmis/query.rb, line 7
def initialize(repository, statement, options = {})
  @repository = repository
  @statement = statement
  @options = options.symbolize_keys

  @total = -1

  init_options
end

Public Instance Methods

debug_info() click to toggle source
# File lib/cmis/query.rb, line 89
def debug_info
  @debug_info
end
do_token_query(max, token=nil) click to toggle source
# File lib/cmis/query.rb, line 72
def do_token_query(max, token=nil)
  params = { repositoryId: @repository.id, maxItems: max }
  params[:nextToken] = token if token

  if @method == 'post'
    params.merge!(cmisselector: 'query', q: @statement)
  else
    params.merge!(cmisaction: 'query', statement: @statement)
  end

  result = @repository.server.execute!(params, @opts)
  {
    nextToken: result['nextToken'] ,
    objects: result['results'].map { |r| ObjectFactory.create(r, @repository) }
  }
end
each_page(options = {}) { |r = results| ... } click to toggle source

Options: limit

# File lib/cmis/query.rb, line 36
def each_page(options = {}, &block)
  return enum_for(:each_page, options) unless block_given?

  init_options
  limit = parse_limit(options)
  counter = 0

  while has_next?
    break unless counter < limit
    yield r = results
    counter += r.size
  end
end
each_result(options = {}) { |object| ... } click to toggle source

Options: limit

# File lib/cmis/query.rb, line 18
def each_result(options = {}, &block)
  return enum_for(:each_result, options) unless block_given?

  init_options
  limit = parse_limit(options)
  return if limit == 0

  counter = 0
  while has_next?
    results.each do |object|
      yield object
      counter = counter.next
      return unless counter < limit
    end
  end
end
has_next?() click to toggle source
# File lib/cmis/query.rb, line 61
def has_next?
  @has_next
end
results() click to toggle source
# File lib/cmis/query.rb, line 50
def results
  result = do_query

  @skip_count += result.results.size
  @has_next = result.has_more_items
  @total = result.num_items
  @debug_info = result.debug_info

  result.results
end
total() click to toggle source
# File lib/cmis/query.rb, line 65
def total
  result = do_query

  @debug_info = result.debug_info
  @total = @total == -1 ? result.num_items : @total # CMIS AWS trickery
end

Private Instance Methods

do_query() click to toggle source
# File lib/cmis/query.rb, line 112
def do_query
  params = { repositoryId: @repository.id,
             maxItems: @max_items,
             skipCount: @skip_count }
  if @method == 'post'
    params.merge!(cmisselector: 'query', q: @statement)
  else
    params.merge!(cmisaction: 'query', statement: @statement)
  end

  result = @repository.server.execute!(params, @opts)

  results = result['results'].map do |r|
    ObjectFactory.create(r, @repository)
  end

  QueryResult.new(results, result['numItems'], result['hasMoreItems'], result['queryDebugInfo'])
end
init_options() click to toggle source
# File lib/cmis/query.rb, line 95
def init_options
  @method = (@options[:method] || 'get').to_s.downcase
  @max_items = @options[:page_size] || 10
  @skip_count = @options[:from] || 0
  @has_next = true

  @opts = @options.slice(:query, :headers)
end
parse_limit(options) click to toggle source
# File lib/cmis/query.rb, line 104
def parse_limit(options)
  options.symbolize_keys!
  limit = options[:limit] || 10
  limit = BigDecimal::INFINITY if limit == :all
  raise 'Not a valid limit' unless limit.is_a? Numeric
  limit
end