Class: ActiveCMIS::Document
- Defined in:
- lib/active_cmis/document.rb
Instance Attribute Summary
Attributes inherited from Object
#key, #repository, #updated_attributes
Instance Method Summary collapse
-
#cancel_checkout ⇒ void
This action may not be permitted (query allowable_actions to see whether it is permitted).
-
#checkin(major = true, comment = "", updated_attributes = {}) ⇒ Document
You can specify whether the new version should be major (defaults to true) You can optionally give a list of attributes that need to be set.
-
#checkout ⇒ Document
The checkout operation results in a Private Working Copy.
-
#content_stream ⇒ Rendition
Returns an ActiveCMIS::Rendition to the content stream or nil if there is none.
- #latest? ⇒ Boolean
- #latest_major? ⇒ Boolean
-
#latest_version ⇒ Document
Returns self if this is the latest version Note: There will allways be a latest version in a version series.
- #major? ⇒ Boolean
- #reload ⇒ void
-
#renditions ⇒ Array<Rendition>
Will reload if renditionFilter was not set or cmis:none, but not in other circumstances.
-
#set_content_stream(options) ⇒ void
Sets new content to be uploaded, does not alter values you will get from content_stream (for the moment).
-
#version_series_checked_out ⇒ Hash?
Returns information about the checked out status of this document.
-
#versions ⇒ Collection<Document>, Array(self)
Returns all documents in the version series of this document.
-
#working_copy ⇒ Document
Returns self if this is the working copy Returns nil if there is no working copy.
- #working_copy? ⇒ Boolean
Methods inherited from Object
#acl, #allowable_actions, #attribute, attributes, #attributes, #destroy, #file, from_atom_entry, from_parameters, #id, #initialize, #inspect, key, #method_missing, #name, #parent_folders, #save, #source_relations, #target_relations, #unfile, #update
Methods included from Internal::Caching
Constructor Details
This class inherits a constructor from ActiveCMIS::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ActiveCMIS::Object
Instance Method Details
#cancel_checkout ⇒ void
This method returns an undefined value.
This action may not be permitted (query allowable_actions to see whether it is permitted)
173 174 175 176 177 178 179 180 181 |
# File 'lib/active_cmis/document.rb', line 173 def cancel_checkout if !self.class.versionable raise Error::Constraint.new("Object is not versionable, can't cancel checkout") elsif working_copy? conn.delete(self_link) else raise Error::InvalidArgument.new("Not a working copy") end end |
#checkin(major = true, comment = "", updated_attributes = {}) ⇒ Document
You can specify whether the new version should be major (defaults to true) You can optionally give a list of attributes that need to be set.
This operation exists only for Private Working Copies
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/active_cmis/document.rb', line 188 def checkin(major = true, comment = "", updated_attributes = {}) if working_copy? update(updated_attributes) result = self updated_aspects([true, major, comment]).each do |hash| result = result.send(hash[:message], *hash[:parameters]) end result else raise "Not a working copy" end end |
#checkout ⇒ Document
The checkout operation results in a Private Working Copy
Most properties should be the same as for the document that was checked out, certain properties may differ such as cmis:objectId and cmis:creationDate.
The content stream of the PWC may be identical to that of the document that was checked out, or it may be unset.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/active_cmis/document.rb', line 153 def checkout body = render_atom_entry(self.class.attributes.reject {|k,v| k != "cmis:objectId"}) response = conn.post_response(repository.checkedout.url, body) if 200 <= response.code.to_i && response.code.to_i < 300 entry = Nokogiri::XML.parse(response.body, nil, nil, Nokogiri::XML::ParseOptions::STRICT).xpath("/at:entry", NS::COMBINED) result = self_or_new(entry) if result.working_copy? # Work around a bug in OpenCMIS where result returned is the version checked out not the PWC result else conn.logger.warn "Repository did not return working copy for checkout operation" result.working_copy end else raise response.body end end |
#content_stream ⇒ Rendition
Returns an ActiveCMIS::Rendition to the content stream or nil if there is none
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_cmis/document.rb', line 5 def content_stream if content = data.xpath("at:content", NS::COMBINED).first if content['src'] ActiveCMIS::Rendition.new(repository, self, "href" => content['src'], "type" => content["type"]) else if content['type'] =~ /\+xml$/ content_data = content.to_xml # FIXME: this may not preserve whitespace else content_data = data.unpack("m*").first end ActiveCMIS::Rendition.new(repository, self, "data" => content_data, "type" => content["type"]) end elsif content = data.xpath("cra:content", NS::COMBINED).first content.children.each do |node| next unless node.namespace and node.namespace.href == NS::CMIS_REST content_data = node.text if node.name == "base64" content_type = node.text if node.name == "mediaType" end data = content_data.unpack("m*").first ActiveCMIS::Rendition.new(repository, self, "data" => content_data, "type" => content_type) end end |
#latest? ⇒ Boolean
109 110 111 |
# File 'lib/active_cmis/document.rb', line 109 def latest? attributes["cmis:isLatestVersion"] end |
#latest_major? ⇒ Boolean
115 116 117 |
# File 'lib/active_cmis/document.rb', line 115 def latest_major? attributes["cmis:isLatestMajorVersion"] end |
#latest_version ⇒ Document
Returns self if this is the latest version Note: There will allways be a latest version in a version series
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/active_cmis/document.rb', line 85 def latest_version link = data.xpath("at:link[@rel = 'current-version']/@href", NS::COMBINED) if link.first entry = conn.get_atom_entry(link.first.text) self_or_new(entry) else # FIXME: should somehow return the current version even for opencmis self end end |
#major? ⇒ Boolean
112 113 114 |
# File 'lib/active_cmis/document.rb', line 112 def major? attributes["cmis:isMajorVersion"] end |
#reload ⇒ void
This method returns an undefined value.
202 203 204 205 |
# File 'lib/active_cmis/document.rb', line 202 def reload @updated_contents = nil super end |
#renditions ⇒ Array<Rendition>
Will reload if renditionFilter was not set or cmis:none, but not in other circumstances
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_cmis/document.rb', line 31 def renditions filter = used_parameters["renditionFilter"] if filter.nil? || filter == "cmis:none" reload end links = data.xpath("at:link[@rel = 'alternate']", NS::COMBINED) links.map do |link| ActiveCMIS::Rendition.new(repository, self, link) end end |
#set_content_stream(options) ⇒ void
This method returns an undefined value.
Sets new content to be uploaded, does not alter values you will get from content_stream (for the moment)
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_cmis/document.rb', line 52 def set_content_stream() if key.nil? if self.class.content_stream_allowed == "notallowed" raise Error::StreamNotSupported.new("Documents of this type can't have content") end else updatability = repository.capabilities["ContentStreamUpdatability"] if updatability == "none" raise Error::NotSupported.new("Content can't be updated in this repository") elsif updatability == "pwconly" && !working_copy? raise Error::Constraint.new("Content can only be updated for working copies in this repository") end end @updated_contents = end |
#version_series_checked_out ⇒ Hash?
Returns information about the checked out status of this document
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/active_cmis/document.rb', line 129 def version_series_checked_out attributes = self.attributes if attributes["cmis:isVersionSeriesCheckedOut"] result = {} if attributes.has_key? "cmis:versionSeriesCheckedOutBy" result[:by] = attributes["cmis:versionSeriesCheckedOutBy"] end if attributes.has_key? "cmis:versionSeriesCheckedOutId" result[:id] = attributes["cmis:versionSeriesCheckedOutId"] end result else nil end end |
#versions ⇒ Collection<Document>, Array(self)
Returns all documents in the version series of this document. Uses self to represent the version of this document
71 72 73 74 75 76 77 78 79 |
# File 'lib/active_cmis/document.rb', line 71 def versions link = data.xpath("at:link[@rel = 'version-history']/@href", NS::COMBINED) if link = link.first Collection.new(repository, link) # Problem: does not in fact use self else # The document is not versionable [self] end end |
#working_copy ⇒ Document
Returns self if this is the working copy Returns nil if there is no working copy
99 100 101 102 103 104 105 106 107 |
# File 'lib/active_cmis/document.rb', line 99 def working_copy link = data.xpath("at:link[@rel = 'working-copy']/@href", NS::COMBINED) if link.first entry = conn.get_atom_entry(link.first.text) self_or_new(entry) else nil end end |