Class: CMIS::Document

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

Instance Attribute Summary

Attributes inherited from Object

#properties, #repository

Instance Method Summary collapse

Methods inherited from Object

#acls, #add_aces, #allowable_actions, #delete, #detached?, #move, #object_type, #parents, #policies, #relationships, #remove_aces, #unfile, #update_properties

Methods included from Helpers

#cmis_properties, #initialize_properties, #method_missing, respond_to?, #with_change_token

Constructor Details

#initialize(raw, repository) ⇒ Document

Returns a new instance of Document.



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

def initialize(raw, repository)
  super
  cmis_properties %w( cmis:isImmutable cmis:isLatestVersion
                      cmis:isMajorVersion cmis:isLatestMajorVersion
                      cmis:isPrivateWorkingCopy cmis:versionLabel
                      cmis:versionSeriesId cmis:isVersionSeriesCheckedOut
                      cmis:versionSeriesCheckedOutBy
                      cmis:versionSeriesCheckedOutId cmis:checkinComment
                      cmis:contentStreamLength cmis:contentStreamMimeType
                      cmis:contentStreamFileName cmis:contentStreamId )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CMIS::Helpers

Instance Method Details

#content(opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cmis/document.rb', line 35

def content(opts = {})
  server.execute!({ cmisselector: 'content',
                    repositoryId: repository.id,
                    objectId: cmis_object_id }, opts)

rescue Exceptions::Constraint => e
  if e.message =~ /no content stream/
    nil
  else
    raise e
  end
end

#content=(opts = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cmis/document.rb', line 48

def content=(opts = {})
  opts.symbolize_keys!
  content = { stream: opts.delete(:stream),
              mime_type: opts.delete(:mime_type),
              filename: opts.delete(:filename) }

  if content[:stream].is_a? String
    content[:stream] = StringIO.new(content[:stream])
  end

  if detached?
    @local_content = content
  else
    with_change_token do
      server.execute!({ cmisaction: 'setContent',
                        repositoryId: repository.id,
                        objectId: cmis_object_id,
                        content: content,
                        changeToken: change_token }, opts)
    end
  end
end

#copy_in_folder(folder, opts = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/cmis/document.rb', line 26

def copy_in_folder(folder, opts = {})
  id = server.execute!({ cmisaction: 'createDocument',
                         repositoryId: repository.id,
                         sourceId: cmis_object_id,
                         objectId: folder.cmis_object_id }, opts)

  repository.object(id)
end

#create_in_folder(folder, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/cmis/document.rb', line 15

def create_in_folder(folder, opts = {})
  r = server.execute!({ cmisaction: 'createDocument',
                        repositoryId: repository.id,
                        properties: properties,
                        objectId: folder.cmis_object_id,
                        folderId: folder.cmis_object_id,
                        content: @local_content }, opts)

  ObjectFactory.create(r, repository)
end