Class: CMIS::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw, server) ⇒ Repository



9
10
11
12
13
14
15
16
17
# 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

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



7
8
9
# File 'lib/cmis/repository.rb', line 7

def server
  @server
end

Instance Method Details

#content_changes(change_log_token, opts = {}) ⇒ Object



100
101
102
103
104
# File 'lib/cmis/repository.rb', line 100

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 = {}) ⇒ Object



116
117
118
119
120
# File 'lib/cmis/repository.rb', line 116

def count_objects(type_id, properties = {}, opts = {})
  opts.merge!(page_size: 0)
  statement = Utils.build_query_statement(type_id, properties)
  query(statement, opts).total
end

#create_relationship(object, opts = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/cmis/repository.rb', line 90

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 = {}) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/cmis/repository.rb', line 82

def create_type(type, opts = {})
  result = server.execute!({ cmisaction: 'createType',
                             repositoryId: id,
                             type: JSON.generate(type.to_hash) }, opts)

  Type.new(result, self)
end

#find_object(type_id, properties = {}, opts = {}) ⇒ Object



110
111
112
113
114
# File 'lib/cmis/repository.rb', line 110

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

#inspectObject



122
123
124
# File 'lib/cmis/repository.rb', line 122

def inspect
  "#{self.class}[#{id}] @ #{server.inspect}"
end

#new_documentObject



19
20
21
# File 'lib/cmis/repository.rb', line 19

def new_document
  Document.new({}, self)
end

#new_folderObject



23
24
25
# File 'lib/cmis/repository.rb', line 23

def new_folder
  Folder.new({}, self)
end

#new_itemObject



31
32
33
# File 'lib/cmis/repository.rb', line 31

def new_item
  Item.new({}, self)
end

#new_policyObject



35
36
37
# File 'lib/cmis/repository.rb', line 35

def new_policy
  Policy.new({}, self)
end

#new_relationshipObject



27
28
29
# File 'lib/cmis/repository.rb', line 27

def new_relationship
  Relationship.new({}, self)
end

#new_typeObject



39
40
41
# File 'lib/cmis/repository.rb', line 39

def new_type
  Type.new({}, self)
end

#object(cmis_object_id, opts = {}) ⇒ Object



51
52
53
54
55
56
57
# 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 = {}) ⇒ Object



106
107
108
# File 'lib/cmis/repository.rb', line 106

def query(statement, opts = {})
  Query.new(self, statement, opts)
end

#root(opts = {}) ⇒ Object



43
44
45
46
47
48
49
# 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 = {}) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/cmis/repository.rb', line 67

def type(type_id, opts = {})
  result = server.execute!({ cmisselector: 'typeDefinition',
                             repositoryId: id,
                             typeId: type_id }, opts)

  Type.new(result, self)
end

#type?(type_id) ⇒ Boolean



75
76
77
78
79
80
# File 'lib/cmis/repository.rb', line 75

def type?(type_id)
  type(type_id)
  true
rescue Exceptions::ObjectNotFound
  false
end

#types(opts = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/cmis/repository.rb', line 59

def types(opts = {})
  result = server.execute!({ cmisselector: 'typeDescendants',
                             repositoryId: id,
                             includePropertyDefinitions: true }, opts)

  construct_types(result)
end