class CMIS::Repository

Attributes

server[R]

Public Class Methods

new(raw, server) click to toggle source
# File lib/cmis/repository.rb, line 9
def initialize(raw, server)
  @hash = raw
  @hash.each_key do |key|
    self.class.class_eval "def #{key.as_ruby_property};@hash['#{key}'];end"
    self.class.class_eval "def #{key.gsub('repository', '').as_ruby_property};@hash['#{key}'];end" if key =~ /^repository/
  end

  @server = server
end

Public Instance Methods

bulk_update_objects(object_ids_and_change_tokens, properties) click to toggle source
# File lib/cmis/repository.rb, line 151
def bulk_update_objects(object_ids_and_change_tokens, properties)
  server.execute!(cmisaction: 'bulkUpdate',
                  repositoryId: id,
                  objectIdAndChangeToken: object_ids_and_change_tokens,
                  properties: properties)
end
content_changes(change_log_token, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 102
def content_changes(change_log_token, opts = {})
  server.execute!({ cmisselector: 'contentChanges',
                    repositoryId: id,
                    changeLogToken: change_log_token }, opts)
end
count_objects(type_id, properties = {}, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 118
def count_objects(type_id, properties = {}, opts = {})
  opts.merge!(page_size: 0)
  statement = Utils.build_query_statement(type_id, properties, 'cmis:objectId')
  query(statement, opts).total
end
create_relationship(object, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 92
def create_relationship(object, opts = {})
  raise 'Object is not a Relationship' unless object.is_a?(Relationship)

  result = server.execute!({ cmisaction: 'createRelationship',
                             repositoryId: id,
                             properties: object.properties }, opts)

  ObjectFactory.create(result, self)
end
create_type(type, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 88
def create_type(type, opts = {})
  type.create(opts)
end
find_object(type_id, properties = {}, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 112
def find_object(type_id, properties = {}, opts = {})
  opts.merge!(page_size: 1)
  statement = Utils.build_query_statement(type_id, properties)
  query(statement, opts).results.first
end
inspect() click to toggle source
# File lib/cmis/repository.rb, line 158
def inspect
  "#{self.class}[#{id}] @ #{server.inspect}"
end
new_document() click to toggle source
# File lib/cmis/repository.rb, line 19
def new_document
  Document.new({}, self)
end
new_folder() click to toggle source
# File lib/cmis/repository.rb, line 23
def new_folder
  Folder.new({}, self)
end
new_item() click to toggle source
# File lib/cmis/repository.rb, line 31
def new_item
  Item.new({}, self)
end
new_policy() click to toggle source
# File lib/cmis/repository.rb, line 35
def new_policy
  Policy.new({}, self)
end
new_relationship() click to toggle source
# File lib/cmis/repository.rb, line 27
def new_relationship
  Relationship.new({}, self)
end
new_type() click to toggle source
# File lib/cmis/repository.rb, line 39
def new_type
  Type.new({}, self)
end
object(cmis_object_id, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 51
def object(cmis_object_id, opts = {})
  result = server.execute!({ cmisselector: 'object',
                             repositoryId: id,
                             objectId: cmis_object_id }, opts)

  ObjectFactory.create(result, self)
end
query(statement, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 108
def query(statement, opts = {})
  Query.new(self, statement, opts)
end
root(opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 43
def root(opts = {})
  result = server.execute!({ cmisselector: 'object',
                             repositoryId: id,
                             objectId: root_folder_id }, opts)

  ObjectFactory.create(result, self)
end
type(type_id, opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 73
def type(type_id, opts = {})
  result = server.execute!({ cmisselector: 'typeDefinition',
                             repositoryId: id,
                             typeId: type_id }, opts)

  Type.new(result, self)
end
type?(type_id) click to toggle source
# File lib/cmis/repository.rb, line 81
def type?(type_id)
  type(type_id)
  true
rescue Exceptions::ObjectNotFound
  false
end
type_tree(opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 59
def type_tree(opts = {})
  server.execute!({ cmisselector: 'typeDescendants',
                    repositoryId: id,
                    includePropertyDefinitions: false }, opts)
end
types(opts = {}) click to toggle source
# File lib/cmis/repository.rb, line 65
def types(opts = {})
  result = server.execute!({ cmisselector: 'typeDescendants',
                             repositoryId: id,
                             includePropertyDefinitions: true }, opts)

  construct_types(result)
end
update_objects(type_id, conditions, properties) click to toggle source

Returns the changed objects

# File lib/cmis/repository.rb, line 125
def update_objects(type_id, conditions, properties)
  statement = Utils.build_query_statement(type_id, conditions, 'cmis:objectId', 'cmis:changeToken')
  object_ids_and_change_tokens = []
  query(statement).each_result(limit: :all) do |r|
    object_ids_and_change_tokens << [r.cmis_object_id, r.change_token]
  end
  if object_ids_and_change_tokens.empty?
    []
  else
    results = []
    object_ids_and_change_tokens.each_slice(10) do |part|
      r = server.execute!({ cmisaction: 'bulkUpdate',
                            repositoryId: id,
                            objectIdAndChangeToken: part,
                            properties: properties })
      r.map! do |h|
        object = CMIS::Object.new({}, self)
        object.cmis_object_id = h['id']
        object
      end
      results.concat(r)
    end
    results
  end
end

Private Instance Methods

construct_types(a) click to toggle source
# File lib/cmis/repository.rb, line 164
def construct_types(a)
  types = []
  a.each do |t|
    types << Type.new(t['type'], self)
    types << construct_types(t['children']) if t.key?('children')
  end
  types.flatten
end