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, connection) ⇒ Repository

Returns a new instance of Repository.



5
6
7
8
9
10
11
12
13
# File 'lib/cmis/repository.rb', line 5

def initialize(raw, connection)
  @hash = raw
  @hash.each_key do |key|
    class_eval "def #{key.underscore};@hash['#{key}'];end"
    class_eval "def #{key.gsub('repository', '').underscore};@hash['#{key}'];end" if key =~ /^repository/
  end

  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/cmis/repository.rb', line 3

def connection
  @connection
end

Instance Method Details

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



96
97
98
99
100
# File 'lib/cmis/repository.rb', line 96

def content_changes(change_log_token, opts = {})
  connection.execute!({ cmisselector: 'contentChanges',
                        repositoryId: id,
                        changeLogToken: change_log_token }, opts)
end

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



86
87
88
89
90
91
92
93
94
# File 'lib/cmis/repository.rb', line 86

def create_relationship(object, opts = {})
  raise 'Object is not a Relationship' unless object.is_a?(Relationship)

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

  ObjectFactory.create(result, self)
end

#create_type(type, opts = {}) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/cmis/repository.rb', line 78

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

  Type.new(result, self)
end

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



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

def find_object(type_id, properties, opts = {})
  clause = properties.map { |k, v| "#{k}=#{normalize(v)}" }.join(' and ')
  statement = "select * from #{type_id} where #{clause}"
  opts.merge!(page_size: 1)
  query(statement, opts).results.first
end

#has_type?(type_id) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/cmis/repository.rb', line 71

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

#new_documentObject



15
16
17
# File 'lib/cmis/repository.rb', line 15

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

#new_folderObject



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

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

#new_itemObject



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

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

#new_policyObject



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

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

#new_relationshipObject



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

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

#new_typeObject



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

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

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



47
48
49
50
51
52
53
# File 'lib/cmis/repository.rb', line 47

def object(cmis_object_id, opts = {})
  result = connection.execute!({ cmisselector: 'object',
                                 repositoryId: id,
                                 objectId: cmis_object_id }, opts)

  ObjectFactory.create(result, self)
end

#query(statement, opts = {}) ⇒ Object



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

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

#root(opts = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/cmis/repository.rb', line 39

def root(opts = {})
  result = connection.execute!({ cmisselector: 'object',
                                 repositoryId: id,
                                 objectId: root_folder_id }, opts)

  ObjectFactory.create(result, self)
end

#type(type_id, opts = {}) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/cmis/repository.rb', line 63

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

  Type.new(result, self)
end

#types(opts = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/cmis/repository.rb', line 55

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

  construct_types(result)
end