Class: Reactor::Cm::Obj
- Inherits:
-
Object
- Object
- Reactor::Cm::Obj
- Defined in:
- lib/reactor/cm/obj.rb
Defined Under Namespace
Classes: ContentSetRequest, LinkAddRequest, LinkDeleteRequest, LinkSetRequest, ObjSetRequest, Request, ResolveRefsRequest, SimpleCommandRequest
Constant Summary collapse
- OBJ_ATTRS =
[:permalink, :objClass, :workflowName, :name, :suppressExport, :parent]
- ATTR_LENGTH_CONSTRAINT =
{:name => 250, :title => 250}
Instance Attribute Summary collapse
-
#obj_id ⇒ Object
readonly
Returns the value of attribute obj_id.
Class Method Summary collapse
- .create(name, parent, objClass) ⇒ Object
- .delete_where(conditions) ⇒ Object
- .exists?(path_or_id) ⇒ Boolean
- .get(path_or_id) ⇒ Object
- .load(id) ⇒ Object
Instance Method Summary collapse
- #blob_ticket_id(content = 'edited') ⇒ Object
- #commit!(msg = nil) ⇒ Object
- #composite_save(attrs, links_to_add, links_to_remove, links_to_set, links_modified = false) {|attrs, links_to_add, links_to_remove, links_to_set| ... } ⇒ Object
- #copy(new_parent, recursive = false, new_name = nil) ⇒ Object
- #delete! ⇒ Object
- #edit!(msg = nil) ⇒ Object
- #edited? ⇒ Boolean
- #edited_content ⇒ Object
- #editor ⇒ Object
- #forward!(msg = nil) ⇒ Object
- #get(key) ⇒ Object
- #get_links(attr) ⇒ Object
- #path ⇒ Object
- #permission_clear(permission) ⇒ Object
- #permission_grant(permission, groups) ⇒ Object
- #permission_granted_to(user, permission) ⇒ Object
- #permission_revoke(permission, groups) ⇒ Object
- #permission_set(permission, groups) ⇒ Object
- #reasons_for_incomplete_state ⇒ Object
- #reject!(msg = nil) ⇒ Object
- #release!(msg = nil) ⇒ Object
- #remove_active_contents! ⇒ Object
- #remove_archived_contents! ⇒ Object
- #resolve_refs! ⇒ Object
- #revert!(msg = nil) ⇒ Object
- #save! ⇒ Object
- #set(key, value, options = {}) ⇒ Object
- #set_link(attr, path) ⇒ Object
- #set_links(attr, new_links_as_hashes) ⇒ Object
- #set_multiple(attrs) ⇒ Object
- #sign!(msg = nil) ⇒ Object
- #take!(msg = nil) ⇒ Object
- #unrelease!(msg = nil) ⇒ Object
- #upload(data_or_io, extension) ⇒ Object
- #valid_actions ⇒ Object
- #workflow_comment ⇒ Object
Instance Attribute Details
#obj_id ⇒ Object (readonly)
Returns the value of attribute obj_id.
7 8 9 |
# File 'lib/reactor/cm/obj.rb', line 7 def obj_id @obj_id end |
Class Method Details
.create(name, parent, objClass) ⇒ Object
11 12 13 14 15 |
# File 'lib/reactor/cm/obj.rb', line 11 def self.create(name, parent, objClass) obj = Obj.new(name) obj.send(:create, parent, objClass) obj end |
.delete_where(conditions) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/reactor/cm/obj.rb', line 38 def self.delete_where(conditions) request = XmlRequest.prepare do |xml| xml.tag!('obj-where') do conditions.each do |key, value| xml.tag!(key, value) end end xml.tag!("obj-delete") end request.execute! end |
.exists?(path_or_id) ⇒ Boolean
17 18 19 20 21 22 23 24 |
# File 'lib/reactor/cm/obj.rb', line 17 def self.exists?(path_or_id) obj = Obj.new begin obj.send(:load, path_or_id).ok? rescue return false end end |
.get(path_or_id) ⇒ Object
32 33 34 35 36 |
# File 'lib/reactor/cm/obj.rb', line 32 def self.get(path_or_id) obj = Obj.new obj.send(:load, path_or_id) obj end |
.load(id) ⇒ Object
26 27 28 29 30 |
# File 'lib/reactor/cm/obj.rb', line 26 def self.load(id) obj = Obj.new obj.instance_variable_set('@obj_id', id) obj end |
Instance Method Details
#blob_ticket_id(content = 'edited') ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/reactor/cm/obj.rb', line 382 def blob_ticket_id(content='edited') request = XmlRequest.prepare do |xml| xml.tag!('content-where') do xml.tag!('objectId', @obj_id) xml.tag!('state', content) end xml.tag!('content-get') do xml.tag!('blob') end end response = request.execute! possible_ticket_id = response.xpath('//blob').text encoding = response.xpath('//blob/@encoding').to_s # blob is smaller than # [systemConfig getKeys tuning.minStreamingDataLength] # and thus it is returned in-line if encoding != 'stream' raise Reactor::Cm::BlobTooSmallError end possible_ticket_id end |
#commit!(msg = nil) ⇒ Object
268 269 270 |
# File 'lib/reactor/cm/obj.rb', line 268 def commit!(msg=nil) simple_command("commit",msg) end |
#composite_save(attrs, links_to_add, links_to_remove, links_to_set, links_modified = false) {|attrs, links_to_add, links_to_remove, links_to_set| ... } ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/reactor/cm/obj.rb', line 149 def composite_save(attrs, links_to_add, links_to_remove, links_to_set, links_modified=false) set_multiple(attrs) skip_version_creation = @attrs.empty? && links_to_remove.empty? && links_to_set.empty? && !links_modified # The save procedure consists of two multiplexed CM requests. # Each request combines multiple operations for better performance. # # It is necessary to split the procedure into two request because # of the linklist handling. For objects with only released content # the edit operation copies all links (and generates new ids). # Only the new links from the edited content can be manipulated. # Thus it is neccessary after perform a read of links after the # edit operation. # # The second request may seem strange and redundant, but has very # important reasons for being structured the way it is. # The CM in all versions (as of this moment <= 7.0.1) contains # multiple race conditions regarding slave workers and the CRUL # interface. # # It is possible that the two requests are processed by two different # slave workers which have an invalid cache. Without careful # programing it may lead to unexpected results and/or data loss. # The reason behind it is simple: the cache invalidate requests # are distributed asynchronously between workers. # # It is impossible to ensure that the two requests are processed # by the same worker: a worker may get killed at any time, without # warning (producing errors on keep-alive connections). Furthermore # the workers regularly kill themselves (after X processed requests) # to contain memory leaks. # # Following cases are especially important to handle correctly: # Let Slave 1 be the worker receiving the first request and Slave 2 # be the worker receiving the second request. Let Object be the # object on which the save operation is performed. # # 1. If the Object contains only released version, then Slave 2 # may be unaware of the newly created edited version by the time # the second request is being processed. Thefore all operations # involving indirect content references for example adding links # (obj where ... editedContent addLinkTo) would get rejected # by the Slave 2. # # 2. If the Object contains an edited version, then Slave 2 may # be unaware of the changes perfomed on it, change of editor for # example, and can reject valid requests. The more dramatic # scenario involves Slave 2 persisting its invalid cached content # which would result in a data loss. # # The requests have been thus crafted to deal with those problems. # The solution is based on the precise source-code level knowledge # of the CM internals. resp = MultiXmlRequest.execute do |reqs| reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'take') } unless skip_version_creation reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'edit') } unless skip_version_creation reqs.mandatory {|xml| ObjSetRequest.build(xml, @obj_id, @obj_attrs) } unless @obj_attrs.empty? #important! requires different permissions reqs.mandatory {|xml| ContentSetRequest.build(xml, @obj_id, @attrs, @attr_options) } unless skip_version_creation reqs.mandatory {|xml| ResolveRefsRequest.build(xml, @obj_id) } unless skip_version_creation end resp.assert_success yield(attrs, links_to_add, links_to_remove, links_to_set) if block_given? resp = MultiXmlRequest.execute do |reqs| reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'take') } reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'edit') } links_to_remove.each do |link_id| reqs.mandatory {|xml| LinkDeleteRequest.build(xml, link_id) } end links_to_set.each do |(link_id, link)| reqs.mandatory {|xml| LinkSetRequest.build(xml, link_id, link) } end links_to_add.each do |(attr, link)| reqs.mandatory {|xml| LinkAddRequest.build(xml, @obj_id, attr, link) } end end unless skip_version_creation || (links_to_remove.empty? && links_to_add.empty? && links_to_set.empty?) resp.assert_success end |
#copy(new_parent, recursive = false, new_name = nil) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/reactor/cm/obj.rb', line 289 def copy(new_parent, recursive = false, new_name = nil) request = XmlRequest.prepare do |xml| xml.tag!('obj-where') do xml.tag!("id", @obj_id) end xml.tag!("obj-copy") do xml.tag!("parent", new_parent) xml.tag!("name", new_name) if new_name xml.tag!("recursive", "1") if recursive end end response = request.execute! response.xpath("//obj/id").text end |
#delete! ⇒ Object
304 305 306 |
# File 'lib/reactor/cm/obj.rb', line 304 def delete! simple_command("delete") end |
#edit!(msg = nil) ⇒ Object
256 257 258 |
# File 'lib/reactor/cm/obj.rb', line 256 def edit!(msg=nil) simple_command("edit",msg) end |
#edited? ⇒ Boolean
336 337 338 339 340 341 342 343 |
# File 'lib/reactor/cm/obj.rb', line 336 def edited? request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'id', @obj_id) xml.get_key_tag!(base_name, 'isEdited') end response = request.execute! response.xpath("//isEdited").text == "1" end |
#edited_content ⇒ Object
404 405 406 407 408 409 410 411 |
# File 'lib/reactor/cm/obj.rb', line 404 def edited_content request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'id', @obj_id) xml.get_key_tag!(base_name, 'editedContent') end response = request.execute! response.xpath("//editedContent").text end |
#editor ⇒ Object
370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/reactor/cm/obj.rb', line 370 def editor request = XmlRequest.prepare do |xml| xml.tag!('content-where') do xml.tag!('objectId', @obj_id) xml.tag!('state', 'edited') end xml.get_key_tag!('content', 'editor') end response = request.execute! response.xpath('//editor').text end |
#forward!(msg = nil) ⇒ Object
264 265 266 |
# File 'lib/reactor/cm/obj.rb', line 264 def forward!(msg=nil) simple_command("forward",msg) end |
#get(key) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/reactor/cm/obj.rb', line 59 def get(key) request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'id', @obj_id) xml.get_key_tag!(base_name, key) end response = request.execute! result = response.xpath("//#{key}") if result.children.map {|i| i.respond_to?(:name) && (i.name == "listitem") }.reduce(:&) result.children.map {|i| i.text.to_s } else result = result.text unless result.is_a? Array result end end |
#get_links(attr) ⇒ Object
122 123 124 |
# File 'lib/reactor/cm/obj.rb', line 122 def get_links(attr) get_link_ids(attr).map {|id| Link.get(id)} end |
#path ⇒ Object
327 328 329 330 331 332 333 334 |
# File 'lib/reactor/cm/obj.rb', line 327 def path request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'id', @obj_id) xml.get_key_tag!(base_name, 'path') end response = request.execute! response.xpath("//obj/path").text end |
#permission_clear(permission) ⇒ Object
118 119 120 |
# File 'lib/reactor/cm/obj.rb', line 118 def () self.(, []) end |
#permission_grant(permission, groups) ⇒ Object
110 111 112 |
# File 'lib/reactor/cm/obj.rb', line 110 def (, groups) self.('GrantTo', , groups) end |
#permission_granted_to(user, permission) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/reactor/cm/obj.rb', line 84 def (user, ) request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, 'id', @obj_id) xml.get_tag!(base_name) do xml.tag!('permissionGrantedTo', :permission => , :user => user) end end response = request.execute! response.xpath("//permissionGrantedTo/text()") == "1" end |
#permission_revoke(permission, groups) ⇒ Object
114 115 116 |
# File 'lib/reactor/cm/obj.rb', line 114 def (, groups) self.('RevokeFrom', , groups) end |
#permission_set(permission, groups) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/reactor/cm/obj.rb', line 95 def (, groups) request = XmlRequest.prepare do |xml| xml.where_key_tag!(base_name, :id, @obj_id) = { :permission => , :type => :list, } xml.set_key_tag!(base_name, :permission, groups, ) end request.execute! end |
#reasons_for_incomplete_state ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/reactor/cm/obj.rb', line 345 def reasons_for_incomplete_state request = XmlRequest.prepare do |xml| xml.tag!('content-where') do xml.tag!('objectId', @obj_id) xml.tag!('state', 'edited') end xml.get_key_tag!('content', 'reasonsForIncompleteState') end response = request.execute! result = response.xpath('//reasonsForIncompleteState/*') result.kind_of?(Array) ? result.map(&:text).map(&:to_s) : [result.to_s] end |
#reject!(msg = nil) ⇒ Object
272 273 274 |
# File 'lib/reactor/cm/obj.rb', line 272 def reject!(msg=nil) simple_command("reject",msg) end |
#release!(msg = nil) ⇒ Object
248 249 250 |
# File 'lib/reactor/cm/obj.rb', line 248 def release!(msg=nil) simple_command("release",msg) end |
#remove_active_contents! ⇒ Object
308 309 310 |
# File 'lib/reactor/cm/obj.rb', line 308 def remove_active_contents! simple_command("removeActiveContents") end |
#remove_archived_contents! ⇒ Object
312 313 314 |
# File 'lib/reactor/cm/obj.rb', line 312 def remove_archived_contents! simple_command("removeArchivedContents") end |
#resolve_refs! ⇒ Object
316 317 318 319 320 321 322 323 324 325 |
# File 'lib/reactor/cm/obj.rb', line 316 def resolve_refs! request = XmlRequest.prepare do |xml| xml.tag!('content-where') do xml.tag!('objectId', @obj_id) xml.tag!('state', 'edited') end xml.tag!('content-resolveRefs') end request.execute! end |
#revert!(msg = nil) ⇒ Object
276 277 278 |
# File 'lib/reactor/cm/obj.rb', line 276 def revert!(msg=nil) simple_command("revert",msg) end |
#save! ⇒ Object
237 238 239 240 241 242 243 244 245 |
# File 'lib/reactor/cm/obj.rb', line 237 def save! links_to_remove = @removed_links.map {|l| l.link_id} links_to_add = @links.map do |attr, links| links.map do |link| [attr, {:destination_url => link.dest_url, :title => link.title, :target => link.target, :position => link.position}] end.flatten end composite_save([], links_to_add, links_to_remove, []) end |
#set(key, value, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/reactor/cm/obj.rb', line 74 def set(key, value, ={}) key = key.to_sym value = value[0, ATTR_LENGTH_CONSTRAINT[key]] if ATTR_LENGTH_CONSTRAINT[key] && value if OBJ_ATTRS.include?(key) then @obj_attrs[key] = value else @attrs[key] = value end @attr_options[key] = end |
#set_link(attr, path) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/reactor/cm/obj.rb', line 133 def set_link(attr, path) old_links = get_links(attr) if old_links.length == 1 old_link = old_links.first old_link.dest_url = path @links[attr] = [old_link] else @removed_links = old_links @links[attr] = [Link.create_inside(self, attr, path)] end end |
#set_links(attr, new_links_as_hashes) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/reactor/cm/obj.rb', line 126 def set_links(attr, new_links_as_hashes) get_links(attr).map(&:delete!) new_links_as_hashes.each do |link_hash| Link.create_inside(self, attr, link_hash[:destination_url], link_hash[:title], link_hash[:target]) end end |
#set_multiple(attrs) ⇒ Object
145 146 147 |
# File 'lib/reactor/cm/obj.rb', line 145 def set_multiple(attrs) attrs.each {|a,(v,o)| set(a,v,o||{}) } end |
#sign!(msg = nil) ⇒ Object
280 281 282 |
# File 'lib/reactor/cm/obj.rb', line 280 def sign!(msg=nil) simple_command("sign",msg) end |
#take!(msg = nil) ⇒ Object
260 261 262 |
# File 'lib/reactor/cm/obj.rb', line 260 def take!(msg=nil) simple_command("take",msg) end |
#unrelease!(msg = nil) ⇒ Object
252 253 254 |
# File 'lib/reactor/cm/obj.rb', line 252 def unrelease!(msg=nil) simple_command("unrelease",msg) end |
#upload(data_or_io, extension) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/reactor/cm/obj.rb', line 51 def upload(data_or_io, extension) data = (data_or_io.kind_of?IO) ? data_or_io.read : data_or_io base64_data = Base64.encode64(data) set(:contentType, extension) set(:blob, {base64_data=>{:encoding=>'base64'}}) end |
#valid_actions ⇒ Object
284 285 286 287 |
# File 'lib/reactor/cm/obj.rb', line 284 def valid_actions vcak = get('validControlActionKeys') (vcak || []).map(&:to_s) end |
#workflow_comment ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/reactor/cm/obj.rb', line 358 def workflow_comment request = XmlRequest.prepare do |xml| xml.tag!('content-where') do xml.tag!('objectId', @obj_id) xml.tag!('state', 'released') end xml.get_key_tag!('content', 'workflowComment') end response = request.execute! response.xpath('//workflowComment/*').map {|x| x.text.to_s}.first end |