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

#bulk_update_objects(object_ids_and_change_tokens, properties) ⇒ Object


151
152
153
154
155
156
# 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 = {}) ⇒ Object


102
103
104
105
106
# 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 = {}) ⇒ Object


118
119
120
121
122
# 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 = {}) ⇒ Object


92
93
94
95
96
97
98
99
100
# 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 = {}) ⇒ Object


88
89
90
# File 'lib/cmis/repository.rb', line 88

def create_type(type, opts = {})
  type.create(opts)
end

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


112
113
114
115
116
# 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

#inspectObject


158
159
160
# File 'lib/cmis/repository.rb', line 158

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


108
109
110
# File 'lib/cmis/repository.rb', line 108

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


73
74
75
76
77
78
79
# 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) ⇒ Boolean


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

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

#type_tree(opts = {}) ⇒ Object


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

def type_tree(opts = {})
  server.execute!({ cmisselector: 'typeDescendants',
                    repositoryId: id,
                    includePropertyDefinitions: false }, opts)
end

#types(opts = {}) ⇒ Object


65
66
67
68
69
70
71
# 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) ⇒ Object

Returns the changed objects


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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