infopark_reactor_migrations 1.9.0.beta2 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3683df998cfb7366c3484a518fb90b6e92d5eba8
4
- data.tar.gz: 8901065a07371fca7d400b9bbb3f89679b0eb26a
3
+ metadata.gz: a79422bdeff7f67cd50cfa57de204d9c0a88ce52
4
+ data.tar.gz: 920130097cd74911b52b2d52d48b6b080c3a73d8
5
5
  SHA512:
6
- metadata.gz: 2a65898a08d1afa3db0610e2604ff659b014e2a77806900992bf4c05144d1caab01712509c9be68aa1ae476e08a406edf1216625b40ae92e16ad84302ddab151
7
- data.tar.gz: c87be39c05b3998995ad47abaf535a1ab03af5db69cd71db680717df4671485a371c98eb3e3998ea08c66c2db895d82c339bf0ff214aee15328204a755931d49
6
+ metadata.gz: 7ce8837352a635b9621460169c71d1be0c3c1d1f536d383f89cfdb4b7f669b78e2f5c5f22281b272fe4601fb6e5b5b68ed9422a99b59d4bc6106344a0fcf4d8c
7
+ data.tar.gz: c8b0dc9d2627c00afe41ce0f289e730789a5f318113dc0d6e362b096efb284ffec7d212ab6db7b99bb608e5b32b13d1f979424d3405fea4f49e256282ba146d5
@@ -17,7 +17,9 @@ module Reactor
17
17
  response = request.execute!
18
18
 
19
19
  result = []
20
- response.xpath('//logEntry').each do |log_entry_node|
20
+ log_entries = response.xpath('//logEntry')
21
+ log_entries = [log_entries] unless log_entries.kind_of?(Array)
22
+ log_entries.each do |log_entry_node|
21
23
  dict = {}
22
24
  log_entry_node.each_element do |value_node|
23
25
  if value_node.name == 'logTime'
@@ -0,0 +1,102 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'net/http'
3
+ require 'reactor/cm/xml_response'
4
+ require 'reactor/cm/xml_multi_request_error'
5
+ require 'reactor/cm/xml_markup'
6
+ require 'nokogiri'
7
+
8
+ module Reactor
9
+ module Cm
10
+
11
+ class MultiXmlRequest
12
+
13
+ def self.token(login, instance_secret)
14
+ Digest::MD5.hexdigest(login + instance_secret)
15
+ end
16
+
17
+ def self.execute
18
+ access = Configuration::xml_access
19
+ sanity_check(access)
20
+ xml = XmlMarkup.new
21
+ xml2 = nil
22
+ ret = nil
23
+ xml.instruct!
24
+ req = nil
25
+ ret = xml.tag!('cm-payload', 'payload-id' =>'abcabc', 'timestamp' => Time.now.getutc.strftime('%Y%m%d%H%M%S'), 'version' => '6.7.3') do
26
+ xml.tag!('cm-header') do
27
+ xml.tag!('cm-sender', 'sender-id' => access[:id], 'name' => "ruby-simple-client")
28
+ xml.tag!('cm-authentication', 'login' => access[:username], 'token' => token(access[:username],access[:secret]))
29
+ end
30
+ req = self.new(xml).tap do |instance|
31
+ yield instance
32
+ end
33
+ end
34
+ req.execute!(ret)
35
+ end
36
+
37
+ def mandatory(&block)
38
+ req_id = self.class.generate_id
39
+ @mandatory << req_id
40
+ @builder.tag!('cm-request', 'request-id' => req_id, 'preclusive' => 'true') do |xml2|
41
+ yield xml2
42
+ end
43
+ end
44
+
45
+ def optional(&block)
46
+ req_id = self.class.generate_id
47
+ @optional << req_id
48
+ @builder.tag!('cm-request', 'request-id' => req_id, 'preclusive' => 'false') do |xml2|
49
+ yield xml2
50
+ end
51
+ end
52
+
53
+ def execute!(xml)
54
+ access = Configuration::xml_access
55
+ payload = xml
56
+
57
+ res = Net::HTTP.new(access[:host], access[:port]).start do |http|
58
+ req = Net::HTTP::Post.new('/xml')
59
+ req.body = payload
60
+ http.request(req)
61
+ end
62
+
63
+ result = MultiXmlResponse.new(res.body, @mandatory, @optional)
64
+ end
65
+
66
+ class << self
67
+
68
+ def generate_id
69
+ rand(10000)
70
+ end
71
+
72
+ protected
73
+
74
+ def sanity_check(access)
75
+ raise Reactor::Cm::MissingCredentials if access[:username].nil? || access[:username].empty?
76
+ end
77
+ end
78
+
79
+ protected
80
+
81
+ def initialize(builder)
82
+ @builder = builder
83
+ @mandatory = []
84
+ @optional = []
85
+ end
86
+
87
+ class MultiXmlResponse
88
+ def initialize(xml, mandatory, optional)
89
+ @xml, @mandatory, @optional = xml, mandatory, optional
90
+ @n = Nokogiri::XML.parse(@xml)
91
+ end
92
+
93
+ def assert_success
94
+ first_failed = nil
95
+ @mandatory.any? do |mandatory_id|
96
+ @n.xpath("//cm-response[@request-id='#{mandatory_id}']//cm-code[@numeric='200']").empty? && (first_failed = mandatory_id)
97
+ end && raise(XmlMultiRequestError, @n.xpath("//cm-response[@request-id='#{first_failed}']//cm-code//error/phrase/text()").map(&:to_s).join("\n"))
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,4 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
+ require 'reactor/cm/multi_xml_request'
3
+
2
4
  module Reactor
3
5
  module Cm
4
6
  class Obj
@@ -140,49 +142,55 @@ module Reactor
140
142
  end
141
143
  end
142
144
 
143
- def save!
144
- edit! if not edited?
145
- content = edited_content
146
- @request = XmlRequest.prepare do |xml|
147
- xml.where_key_tag!('content', 'id', content)
148
- xml.tag!("content-set") do
149
- @attrs.each do |key, value|
150
- if (@attr_options[key] || {})[:cdata]
151
- xml.tag!(key.to_s) do
152
- xml.cdata!(value)
153
- end
154
- else
155
- xml.value_tag!(key.to_s, value)
156
- end
157
- end
158
- end
159
- end
160
- response = @request.execute!
161
- return response if !response.ok?
162
-
163
- unless @obj_attrs.empty?
164
- request = XmlRequest.prepare do |xml|
165
- xml.where_key_tag!(base_name, 'id', @obj_id)
166
- xml.set_tag!(base_name) do
167
- @obj_attrs.each do |key, value|
168
- xml.value_tag!(key, value)
169
- end
170
- end
171
- end
172
- response = request.execute!
173
- end
145
+ def set_mutiple(attrs)
146
+ attrs.each {|a,(v,o)| set(a,v,o||{}) }
147
+ end
148
+
149
+ def composite_save(attrs, links_to_add, links_to_remove, links_to_set, links_modified=false)
150
+ set_mutiple(attrs)
151
+
152
+ skip_version_creation = @attrs.empty? && links_to_remove.empty? && links_to_set.empty? && !links_modified
174
153
 
175
- return response if !response.ok?
154
+ resp = MultiXmlRequest.execute do |reqs|
155
+ reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'take') } unless skip_version_creation
156
+ reqs.optional {|xml| SimpleCommandRequest.build(xml, @obj_id, 'edit') } unless skip_version_creation
176
157
 
177
- @removed_links.each do |link|
178
- link.delete!
158
+
159
+ reqs.mandatory {|xml| ObjSetRequest.build(xml, @obj_id, @obj_attrs) } unless @obj_attrs.empty? #important! requires different permissions
160
+ reqs.mandatory {|xml| ContentSetRequest.build(xml, @obj_id, @attrs, @attr_options) } unless skip_version_creation
179
161
  end
180
162
 
181
- @links.each do |attr, links|
182
- links.each do |link|
183
- link.save!
163
+ resp.assert_success
164
+
165
+ yield(attrs, links_to_add, links_to_remove, links_to_set) if block_given?
166
+
167
+ resp = MultiXmlRequest.execute do |reqs|
168
+ links_to_remove.each do |link_id|
169
+ reqs.mandatory {|xml| LinkDeleteRequest.build(xml, link_id) }
170
+ end
171
+ links_to_add.each do |(attr, link)|
172
+
173
+ reqs.mandatory {|xml| LinkAddRequest.build(xml, @obj_id, attr, link) }
174
+ end
175
+
176
+ links_to_set.each do |(link_id, link)|
177
+ reqs.mandatory {|xml| LinkSetRequest.build(xml, link_id, link) }
184
178
  end
179
+
180
+ reqs.optional {|xml| ResolveRefsRequest.build(xml, @obj_id) }
181
+ end unless skip_version_creation
182
+
183
+ resp.assert_success
184
+ end
185
+
186
+ def save!
187
+ links_to_remove = @removed_links.map {|l| l.link_id}
188
+ links_to_add = @links.map do |attr, links|
189
+ links.map do |link|
190
+ [attr, {:destination_url => link.dest_url, :title => link.title, :target => link.target, :position => link.position}]
191
+ end.flatten
185
192
  end
193
+ composite_save([], links_to_add, links_to_remove, [])
186
194
  end
187
195
 
188
196
 
@@ -426,6 +434,107 @@ module Reactor
426
434
 
427
435
  request.execute!
428
436
  end
437
+
438
+ class Request
439
+ attr_reader :xml
440
+
441
+ def initialize(xml)
442
+ @xml = xml
443
+ end
444
+
445
+ def self.build(xml, *args)
446
+ self.new(xml).build(*args)
447
+ end
448
+ end
449
+
450
+ class SimpleCommandRequest < Request
451
+ def build(obj_id, cmd_name, comment = nil)
452
+ xml.where_key_tag!('obj', 'id', obj_id)
453
+ if comment
454
+ xml.tag!("obj-#{cmd_name}") do
455
+ xml.tag!('comment', comment)
456
+ end
457
+ else
458
+ xml.tag!("obj-#{cmd_name}")
459
+ end
460
+ end
461
+ end
462
+
463
+ class ObjSetRequest < Request
464
+ def build(obj_id, obj_attrs)
465
+ xml.where_key_tag!('obj', 'id', obj_id)
466
+ xml.set_tag!('obj') do
467
+ obj_attrs.each do |key, value|
468
+ xml.value_tag!(key, value)
469
+ end
470
+ end
471
+ end
472
+ end
473
+
474
+ class ContentSetRequest < Request
475
+ def build(id, attrs, attr_options)
476
+ xml.tag!('content-where') do
477
+ xml.tag!('objectId', id.to_s)
478
+ xml.tag!('state', 'edited')
479
+ end
480
+ xml.tag!("content-set") do
481
+ attrs.each do |key, value|
482
+ if (attr_options[key] || {})[:cdata]
483
+ xml.tag!(key.to_s) do
484
+ xml.cdata!(value)
485
+ end
486
+ else
487
+ xml.value_tag!(key.to_s, value)
488
+ end
489
+ end
490
+ end
491
+ end
492
+ end
493
+
494
+ class LinkDeleteRequest < Request
495
+ def build(link_id)
496
+ xml.where_key_tag!('link', 'id', link_id)
497
+ xml.tag!("link-delete")
498
+ end
499
+ end
500
+
501
+ class LinkAddRequest < Request
502
+ def build(obj_id, attr, link_data)
503
+ title = link_data[:title]
504
+ xml.tag!('content-where') do
505
+ xml.tag!('objectId', obj_id.to_s)
506
+ xml.tag!('state', 'edited')
507
+ end
508
+ xml.tag!('content-addLinkTo') do
509
+ xml.tag!('attribute', attr.to_s)
510
+ xml.tag!('destinationUrl', link_data[:destination_url].to_s)
511
+ xml.tag!('title', title.to_s) if title
512
+ end
513
+ end
514
+ end
515
+
516
+ class LinkSetRequest < Request
517
+ def build(link_id, link_data)
518
+ title = link_data[:title]
519
+ xml.tag!('link-where') do
520
+ xml.tag!('id', link_id)
521
+ end
522
+ xml.tag!('link-set') do
523
+ xml.tag!('destinationUrl', link_data[:destination_url].to_s)
524
+ xml.tag!('title', title.to_s) if title
525
+ end
526
+ end
527
+ end
528
+
529
+ class ResolveRefsRequest < Request
530
+ def build(obj_id)
531
+ xml.tag!('content-where') do
532
+ xml.tag!('objectId', obj_id.to_s)
533
+ xml.tag!('state', 'edited')
534
+ end
535
+ xml.tag!('content-resolveRefs')
536
+ end
537
+ end
429
538
  end
430
539
  end
431
540
  end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/cm/xml_request_error'
3
+
4
+ module Reactor
5
+ module Cm
6
+ class XmlMultiRequestError < XmlRequestError
7
+
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  require 'net/http'
3
3
  require 'reactor/cm/xml_response'
4
- require 'reactor/cm/xml_request_error'
4
+ require 'reactor/cm/xml_single_request_error'
5
5
  require 'reactor/cm/xml_markup'
6
6
  require 'reactor/tools/smart_xml_logger'
7
7
 
@@ -56,7 +56,7 @@ module Reactor
56
56
  Reactor::Cm::LOGGER.log('RESPONSE:')
57
57
  Reactor::Cm::LOGGER.log_xml(:response, res.body)
58
58
  response = XmlResponse.new(res.body)
59
- raise XmlRequestError, response unless response.ok?
59
+ raise XmlSingleRequestError, response unless response.ok?
60
60
  response
61
61
  end
62
62
 
@@ -2,14 +2,8 @@
2
2
  module Reactor
3
3
  module Cm
4
4
  class XmlRequestError < StandardError
5
- def initialize(response)
6
- @response = response
7
- @xml = response.xml
8
- super(phrase)
9
- end
10
-
11
5
  def phrase
12
- @response.xpath('//phrase').to_s
6
+ self.message
13
7
  end
14
8
 
15
9
  end
@@ -0,0 +1,21 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/cm/xml_request_error'
3
+
4
+ module Reactor
5
+ module Cm
6
+ class XmlSingleRequestError < XmlRequestError
7
+ def initialize(response)
8
+ @response = response
9
+ super(phrase)
10
+ end
11
+
12
+ def phrase
13
+ result = @response.xpath('//phrase')
14
+ result = [result] unless result.kind_of?(Array)
15
+
16
+ result.map(&:to_s).join("\n")
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Reactor
3
3
  module Migrations
4
- VERSION = "1.9.0.beta2"
4
+ VERSION = "1.9.1"
5
5
  end
6
6
  end
@@ -33,7 +33,7 @@ module RailsConnector
33
33
  obj.save!
34
34
  rescue ActiveRecord::RecordNotFound
35
35
  end
36
- obj.release unless obj.keep_edited || !Obj.last.edited?
36
+ obj.release unless obj.keep_edited
37
37
  obj
38
38
  end
39
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_reactor_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0.beta2
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Przedmojski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-14 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,6 +100,7 @@ files:
100
100
  - lib/reactor/cm/live_group.rb
101
101
  - lib/reactor/cm/log_entry.rb
102
102
  - lib/reactor/cm/missing_credentials.rb
103
+ - lib/reactor/cm/multi_xml_request.rb
103
104
  - lib/reactor/cm/obj.rb
104
105
  - lib/reactor/cm/obj_class.rb
105
106
  - lib/reactor/cm/object_base.rb
@@ -107,9 +108,11 @@ files:
107
108
  - lib/reactor/cm/workflow.rb
108
109
  - lib/reactor/cm/xml_attribute.rb
109
110
  - lib/reactor/cm/xml_markup.rb
111
+ - lib/reactor/cm/xml_multi_request_error.rb
110
112
  - lib/reactor/cm/xml_request.rb
111
113
  - lib/reactor/cm/xml_request_error.rb
112
114
  - lib/reactor/cm/xml_response.rb
115
+ - lib/reactor/cm/xml_single_request_error.rb
113
116
  - lib/reactor/configuration.rb
114
117
  - lib/reactor/migration.rb
115
118
  - lib/reactor/migrations/railtie.rb
@@ -161,9 +164,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
164
  version: '0'
162
165
  required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  requirements:
164
- - - '>'
167
+ - - '>='
165
168
  - !ruby/object:Gem::Version
166
- version: 1.3.1
169
+ version: '0'
167
170
  requirements: []
168
171
  rubyforge_project:
169
172
  rubygems_version: 2.0.14