infopark_reactor 1.10.0.beta → 1.11.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/rails_connector/abstract_model.rb +7 -0
  3. data/app/models/rails_connector/abstract_obj.rb +31 -0
  4. data/app/models/rails_connector/attribute.rb +94 -0
  5. data/app/models/rails_connector/blob_mapping.rb +12 -0
  6. data/app/models/rails_connector/channel.rb +41 -0
  7. data/app/models/rails_connector/content.rb +12 -0
  8. data/app/models/rails_connector/meta/eager_loader.rb +41 -0
  9. data/app/models/rails_connector/obj_class.rb +143 -0
  10. data/app/models/rails_connector/object_with_meta_data.rb +18 -0
  11. data/infopark_reactor.gemspec +4 -4
  12. data/lib/generators/cm/migration/USAGE +8 -0
  13. data/lib/generators/cm/migration/migration_generator.rb +16 -0
  14. data/lib/generators/cm/migration/templates/template.rb +8 -0
  15. data/lib/infopark_reactor.rb +35 -1
  16. data/lib/reactor/attributes.rb +2 -4
  17. data/lib/reactor/cm/attribute.rb +91 -0
  18. data/lib/reactor/cm/bridge.rb +50 -0
  19. data/lib/reactor/cm/channel.rb +18 -0
  20. data/lib/reactor/cm/editorial_group.rb +23 -0
  21. data/lib/reactor/cm/group.rb +241 -0
  22. data/lib/reactor/cm/language.rb +57 -0
  23. data/lib/reactor/cm/link.rb +136 -0
  24. data/lib/reactor/cm/live_group.rb +23 -0
  25. data/lib/reactor/cm/log_entry.rb +64 -0
  26. data/lib/reactor/cm/missing_credentials.rb +8 -0
  27. data/lib/reactor/cm/multi_xml_request.rb +102 -0
  28. data/lib/reactor/cm/obj.rb +544 -0
  29. data/lib/reactor/cm/obj_class.rb +187 -0
  30. data/lib/reactor/cm/object_base.rb +165 -0
  31. data/lib/reactor/cm/permissions.rb +44 -0
  32. data/lib/reactor/cm/user.rb +139 -0
  33. data/lib/reactor/cm/workflow.rb +41 -0
  34. data/lib/reactor/cm/xml_attribute.rb +36 -0
  35. data/lib/reactor/cm/xml_markup.rb +86 -0
  36. data/lib/reactor/cm/xml_multi_request_error.rb +10 -0
  37. data/lib/reactor/cm/xml_request.rb +83 -0
  38. data/lib/reactor/cm/xml_request_error.rb +11 -0
  39. data/lib/reactor/cm/xml_response.rb +43 -0
  40. data/lib/reactor/cm/xml_single_request_error.rb +21 -0
  41. data/lib/reactor/configuration.rb +8 -0
  42. data/lib/{engine.rb → reactor/engine.rb} +16 -1
  43. data/lib/reactor/legacy.rb +3 -3
  44. data/lib/reactor/link/temporary_link.rb +8 -4
  45. data/lib/reactor/migration.rb +87 -0
  46. data/lib/reactor/permission.rb +2 -2
  47. data/lib/reactor/persistence.rb +14 -12
  48. data/lib/reactor/plans/common_attribute.rb +33 -0
  49. data/lib/reactor/plans/common_channel.rb +32 -0
  50. data/lib/reactor/plans/common_group.rb +45 -0
  51. data/lib/reactor/plans/common_obj_class.rb +70 -0
  52. data/lib/reactor/plans/create_attribute.rb +33 -0
  53. data/lib/reactor/plans/create_channel.rb +24 -0
  54. data/lib/reactor/plans/create_group.rb +35 -0
  55. data/lib/reactor/plans/create_obj.rb +49 -0
  56. data/lib/reactor/plans/create_obj_class.rb +29 -0
  57. data/lib/reactor/plans/delete_attribute.rb +24 -0
  58. data/lib/reactor/plans/delete_channel.rb +22 -0
  59. data/lib/reactor/plans/delete_group.rb +29 -0
  60. data/lib/reactor/plans/delete_obj.rb +23 -0
  61. data/lib/reactor/plans/delete_obj_class.rb +23 -0
  62. data/lib/reactor/plans/prepared.rb +16 -0
  63. data/lib/reactor/plans/rename_group.rb +33 -0
  64. data/lib/reactor/plans/rename_obj_class.rb +25 -0
  65. data/lib/reactor/plans/update_attribute.rb +24 -0
  66. data/lib/reactor/plans/update_group.rb +31 -0
  67. data/lib/reactor/plans/update_obj.rb +31 -0
  68. data/lib/reactor/plans/update_obj_class.rb +27 -0
  69. data/lib/reactor/rails_connector_meta.rb +144 -0
  70. data/lib/reactor/tools/migrator.rb +136 -0
  71. data/lib/reactor/tools/response_handler/base.rb +23 -0
  72. data/lib/reactor/tools/response_handler/string.rb +20 -0
  73. data/lib/reactor/tools/response_handler/xml_attribute.rb +53 -0
  74. data/lib/reactor/tools/smart_xml_logger.rb +70 -0
  75. data/lib/reactor/tools/sower.rb +90 -0
  76. data/lib/reactor/tools/uploader.rb +134 -0
  77. data/lib/reactor/tools/versioner.rb +121 -0
  78. data/lib/reactor/tools/workflow_generator.rb +1 -1
  79. data/lib/reactor/tools/xml_attributes.rb +71 -0
  80. data/lib/reactor/version.rb +1 -1
  81. data/lib/tasks/cm_migrate.rake +8 -0
  82. data/lib/tasks/cm_seeds.rake +41 -0
  83. metadata +82 -13
  84. data/README.md +0 -186
@@ -0,0 +1,83 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'net/http'
3
+ require 'reactor/cm/xml_response'
4
+ require 'reactor/cm/xml_single_request_error'
5
+ require 'reactor/cm/xml_markup'
6
+ require 'reactor/tools/smart_xml_logger'
7
+
8
+ module Reactor
9
+ module Cm
10
+
11
+ if Rails.env.development? && false
12
+ #LOGGER = SmartXmlLogger.new(Rails.logger, :debug)
13
+ LOGGER = SmartXmlLogger.new(Kernel, :puts)
14
+ else
15
+ LOGGER = SmartXmlLogger.new(nil) # turn off logging
16
+ end
17
+ LOGGER.configure(:request, :xpath => 'cm-payload/cm-request/*', :start_indent => 2)
18
+ LOGGER.configure(:response, :xpath => 'cm-payload/cm-response/*', :start_indent => 2)
19
+
20
+ class XmlRequest
21
+
22
+ def self.token(login, instance_secret)
23
+ Digest::MD5.hexdigest(login + instance_secret)
24
+ end
25
+
26
+ def self.prepare
27
+ access = Configuration::xml_access
28
+ sanity_check(access)
29
+ xml = XmlMarkup.new
30
+ ret = nil
31
+ xml.instruct!
32
+ ret = xml.tag!('cm-payload', 'payload-id' =>'abcabc', 'timestamp' => Time.now.getutc.strftime('%Y%m%d%H%M%S'), 'version' => '6.7.3') do
33
+ xml.tag!('cm-header') do
34
+ xml.tag!('cm-sender', 'sender-id' => access[:id], 'name' => "ruby-simple-client")
35
+ xml.tag!('cm-authentication', 'login' => access[:username], 'token' => token(access[:username],access[:secret]))
36
+ end
37
+ id = self.generate_id
38
+ xml.tag!('cm-request', 'request-id' => id) do |xml2|
39
+ yield xml2 if block_given?
40
+ end
41
+ end
42
+ XmlRequest.new(ret)
43
+ end
44
+
45
+ def execute!
46
+ access = Configuration::xml_access
47
+ payload = @xml
48
+
49
+ res = Net::HTTP.new(access[:host], access[:port]).start do |http|
50
+ req = Net::HTTP::Post.new('/xml')
51
+ Reactor::Cm::LOGGER.log('REQUEST:')
52
+ Reactor::Cm::LOGGER.log_xml(:request, payload)
53
+ req.body = payload
54
+ http.request(req)
55
+ end
56
+ Reactor::Cm::LOGGER.log('RESPONSE:')
57
+ Reactor::Cm::LOGGER.log_xml(:response, res.body)
58
+ response = XmlResponse.new(res.body)
59
+ raise XmlSingleRequestError, response unless response.ok?
60
+ response
61
+ end
62
+
63
+ class << self
64
+ protected
65
+
66
+ def generate_id
67
+ rand(10000)
68
+ end
69
+
70
+ def sanity_check(access)
71
+ raise Reactor::Cm::MissingCredentials if access[:username].nil? || access[:username].empty?
72
+ end
73
+ end
74
+
75
+ protected
76
+
77
+ def initialize(xml)
78
+ @xml = xml
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+ module Cm
4
+ class XmlRequestError < StandardError
5
+ def phrase
6
+ self.message
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,43 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/tools/response_handler/xml_attribute'
3
+ require 'rexml/document'
4
+
5
+ module Reactor
6
+
7
+ module Cm
8
+
9
+ class XmlResponse
10
+
11
+ attr_reader :xml
12
+ attr_reader :xml_str
13
+
14
+ def initialize(xml)
15
+ @xml_str = xml
16
+ @xml = REXML::Document.new(xml)
17
+ @handler = Reactor::ResponseHandler::XmlAttribute.new
18
+ end
19
+
20
+ def xpath(expr)
21
+ arr = REXML::XPath.match(@xml, expr)
22
+
23
+ return arr.first if arr.length == 1
24
+ return arr
25
+ end
26
+
27
+ def ok?
28
+ xp = xpath('//cm-code')
29
+
30
+ if xp.is_a?(Array)
31
+ codes = xp.map { |result| result.attribute('numeric').value }.uniq
32
+
33
+ return codes.size == 1 && codes.first == '200'
34
+ end
35
+
36
+ xp.attribute('numeric').value == '200'
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ 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
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+ class Configuration
4
+ class << self
5
+ attr_accessor :xml_access
6
+ end
7
+ end
8
+ end
@@ -2,8 +2,23 @@
2
2
  module Reactor
3
3
 
4
4
  class Engine < Rails::Engine
5
+ rake_tasks do
6
+ load "tasks/cm_migrate.rake"
7
+ load "tasks/cm_seeds.rake"
8
+ end
9
+
10
+ initializer "reactor.upgrade" do
11
+ if Gem::Specification.find_all_by_name('infopark_reactor_migrations').any? || Gem::Specification.find_all_by_name('infopark_rails_connector_meta').any?
12
+ raise "Please remove 'infopark_reactor_migrations' and 'infopark_rails_connector_meta' from your Gemfile. They are deprecated and no longer needed."
13
+ end
14
+ end
15
+
16
+ initializer "reactor.rsession" do |app|
17
+ if app.config.action_dispatch.cookies_serializer && app.config.action_dispatch.cookies_serializer != :marshal
18
+ Rails.logger.info "Cookie session serializer #{app.config.action_dispatch.cookies_serializer} unsupported. Enforcing :marshal instead."
19
+ app.config.action_dispatch.cookies_serializer = :marshal
20
+ end
5
21
 
6
- initializer "reactor.rsession" do
7
22
  # FIXME: extract !
8
23
  AbstractController::Base.__send__(:define_method, :rsession) do
9
24
  self.session[:rsession] ||= Reactor::Session.instance
@@ -46,9 +46,9 @@ module Reactor
46
46
 
47
47
  def obj_from_anything(anything)
48
48
  case anything
49
- when Fixnum then Obj.find(anything)
50
- when String then Obj.find_by_path(anything)
51
- when Obj then anything
49
+ when Fixnum then RailsConnector::AbstractObj.find(anything)
50
+ when String then RailsConnector::AbstractObj.find_by_path(anything)
51
+ when RailsConnector::AbstractObj then anything
52
52
  else raise ArgumentError, "Link target must Fixnum, String or Obj, but was #{anything.class}."
53
53
  end
54
54
  end
@@ -4,6 +4,7 @@ module Reactor
4
4
  class TemporaryLink
5
5
  attr_reader :url
6
6
  attr_accessor :title
7
+ attr_accessor :target
7
8
 
8
9
  def external? ; raise TypeError, "This link needs to be persisted to gain any meaningful information" ; end
9
10
  def internal? ; false ; end
@@ -14,17 +15,20 @@ module Reactor
14
15
  case anything
15
16
  when Hash
16
17
  link_data = anything
18
+ when Fixnum
19
+ link_data[:url] = RailsConnector::AbstractObj.find(anything).path
17
20
  else
18
- link_data[:target] = anything
21
+ link_data[:url] = anything
19
22
  end
20
23
 
21
- self.url = link_data[:target] || link_data[:url] || link_data[:destination_object]
24
+ self.url = link_data[:url] || link_data[:destination_object]
25
+ self.target = link_data[:target] if link_data.key?(:target)
22
26
  self.title = link_data[:title] if link_data.key?(:title)
23
27
  end
24
28
 
25
29
  def url=(some_target)
26
30
  @url = case some_target
27
- when Obj
31
+ when RailsConnector::AbstractObj
28
32
  @destination_object = some_target
29
33
  some_target.path
30
34
  else
@@ -33,7 +37,7 @@ module Reactor
33
37
  end
34
38
 
35
39
  def destination_object
36
- @destination_object ||= Obj.find_by_path(url)
40
+ @destination_object ||= RailsConnector::AbstractObj.find_by_path(url)
37
41
  end
38
42
 
39
43
  def id
@@ -0,0 +1,87 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/plans/create_obj'
3
+ require 'reactor/plans/delete_obj'
4
+ require 'reactor/plans/update_obj'
5
+ require 'reactor/plans/create_obj_class'
6
+ require 'reactor/plans/delete_obj_class'
7
+ require 'reactor/plans/update_obj_class'
8
+ require 'reactor/plans/rename_obj_class'
9
+ require 'reactor/plans/create_attribute'
10
+ require 'reactor/plans/delete_attribute'
11
+ require 'reactor/plans/update_attribute'
12
+ require 'reactor/plans/create_group'
13
+ require 'reactor/plans/update_group'
14
+ require 'reactor/plans/delete_group'
15
+ require 'reactor/plans/rename_group'
16
+ require 'reactor/plans/create_channel'
17
+ require 'reactor/plans/delete_channel'
18
+
19
+ module Reactor
20
+ class Migration
21
+ METHODS = {
22
+ :create_obj => Plans::CreateObj,
23
+ :delete_obj => Plans::DeleteObj,
24
+ :update_obj => Plans::UpdateObj,
25
+ :create_class => Plans::CreateObjClass,
26
+ :delete_class => Plans::DeleteObjClass,
27
+ :update_class => Plans::UpdateObjClass,
28
+ :rename_class => Plans::RenameObjClass,
29
+ :create_attribute => Plans::CreateAttribute,
30
+ :delete_attribute => Plans::DeleteAttribute,
31
+ :update_attribute => Plans::UpdateAttribute,
32
+ :create_group => Plans::CreateGroup,
33
+ :delete_group => Plans::DeleteGroup,
34
+ :update_group => Plans::UpdateGroup,
35
+ :rename_group => Plans::RenameGroup,
36
+ :create_channel => Plans::CreateChannel,
37
+ :delete_channel => Plans::DeleteChannel
38
+ }
39
+
40
+ def self.method_missing(name, *args, &block)
41
+ if METHODS.key? name.to_sym then
42
+ instance = init(name,*args)
43
+ plan(instance,&block)
44
+ prepare(instance)
45
+ migrate(instance)
46
+ else
47
+ super(name, *args, &block)
48
+ end
49
+ end
50
+
51
+ def self.respond_to?(name)
52
+ METHODS.key?(name.to_sym) || super(name)
53
+ end
54
+
55
+ def self.contains(*args)
56
+ @contained ||= []
57
+ args.flatten.each do |arg|
58
+ migration_num = arg.to_i.to_s
59
+ @contained << migration_num
60
+ end
61
+ end
62
+
63
+ def self.contained
64
+ @contained || []
65
+ end
66
+
67
+ protected
68
+ def self.init(name,*args)
69
+ METHODS[name.to_sym].new(*args)
70
+ end
71
+
72
+ def self.plan(instance,&block)
73
+ instance.instance_eval(&block) if block_given?
74
+ end
75
+
76
+ def self.prepare(instance)
77
+ instance.prepare! if instance.respond_to? :prepare!
78
+ end
79
+
80
+ def self.migrate(instance)
81
+ instance.migrate!
82
+ end
83
+
84
+ private
85
+ def initialize ; end
86
+ end
87
+ end
@@ -98,8 +98,8 @@ module Reactor
98
98
  end
99
99
 
100
100
  def ensure_create_permission_granted(obj_id)
101
- raise RuntimeError, "Permission check for object with id=#{obj_id.inspect} which does not exist" unless Obj.exists?(obj_id)
102
- raise Reactor::NotPermitted, 'Obj lacks neccessary permissions for creation' unless Obj.find(obj_id).permission.create_children?
101
+ raise RuntimeError, "Permission check for object with id=#{obj_id.inspect} which does not exist" unless RailsConnector::AbstractObj.exists?(obj_id)
102
+ raise Reactor::NotPermitted, 'Obj lacks neccessary permissions for creation' unless RailsConnector::AbstractObj.find(obj_id).permission.create_children?
103
103
  return true
104
104
  end
105
105
 
@@ -177,12 +177,12 @@ module Reactor
177
177
  # any other reload methods (neither from RailsConnector nor from ActiveRecord)
178
178
  # but tries to mimmic their behaviour.
179
179
  def reload(options = nil)
180
- Obj.uncached do
180
+ RailsConnector::AbstractObj.uncached do
181
181
  #super # Throws RecordNotFound when changing obj_class
182
182
  # AR reload
183
183
  clear_aggregation_cache
184
184
  clear_association_cache
185
- fresh_object = Obj.find(self.id, options)
185
+ fresh_object = RailsConnector::AbstractObj.find(self.id, options)
186
186
  @attributes = fresh_object.instance_variable_get('@attributes')
187
187
  @attributes_cache = {}
188
188
  # RC reload
@@ -231,7 +231,7 @@ module Reactor
231
231
  super(attributes)
232
232
  end
233
233
  end
234
- elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_0?
234
+ elsif Reactor.rails3_1? || Reactor.rails3_2? || Reactor.rails4_0? || Reactor.rails4_1?
235
235
  # It should excactly match ActiveRecord::Base.new in it's behavior
236
236
  # @see ActiveRecord::Base.new
237
237
  def initialize(attributes = nil, options={}, &block)
@@ -326,7 +326,7 @@ module Reactor
326
326
  new_links = {}.tap do |result|
327
327
  linklists.map do |field|
328
328
  result[field] = self.__read_link(field).map do |l|
329
- {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url)}
329
+ {:link_id => l.id, :title => l.title, :destination_url => (l.internal? ? l.destination_object.path : l.url), :target => l.target}
330
330
  end
331
331
  end
332
332
  end
@@ -339,7 +339,7 @@ module Reactor
339
339
  links_to_remove.clear
340
340
  links_to_set.clear
341
341
 
342
- copy = Obj.find(self.id)
342
+ copy = RailsConnector::AbstractObj.uncached { RailsConnector::AbstractObj.find(self.id) }
343
343
 
344
344
  linklists.each do |linklist|
345
345
  original_link_ids = copy.__read_link(linklist).original_link_ids
@@ -371,6 +371,8 @@ module Reactor
371
371
  end
372
372
  end
373
373
  end
374
+
375
+ self.class.connection.clear_query_cache
374
376
  end
375
377
 
376
378
  def __read_link(name)
@@ -385,7 +387,7 @@ module Reactor
385
387
  # @param [true, false] recursive set to true to also copy the underlying subtree
386
388
  # @param [String] new_name gives the object new name
387
389
  def copy(new_parent, recursive = false, new_name = nil)
388
- self.id = crul_obj.copy(Obj.path_from_anything(new_parent), recursive, new_name)
390
+ self.id = crul_obj.copy(RailsConnector::AbstractObj.path_from_anything(new_parent), recursive, new_name)
389
391
  #self.reload
390
392
  resolve_refs #?
391
393
  self.id
@@ -412,8 +414,8 @@ module Reactor
412
414
  end
413
415
  end
414
416
 
415
- if Reactor.rails4_0?
416
- if Reactor.rails4_0_ge6?
417
+ if Reactor.rails4_0? || Reactor.rails4_1?
418
+ if Reactor.rails4_0_ge6? || Reactor.rails4_1?
417
419
  alias_method :_create_record, :create
418
420
  else
419
421
  alias_method :create_record, :create
@@ -428,8 +430,8 @@ module Reactor
428
430
  end
429
431
  end
430
432
 
431
- if Reactor.rails4_0?
432
- if Reactor.rails4_0_ge6?
433
+ if Reactor.rails4_0? || Reactor.rails4_1?
434
+ if Reactor.rails4_0_ge6? || Reactor.rails4_1?
433
435
  alias_method :_update_record, :update
434
436
  else
435
437
  alias_method :update_record, :update
@@ -482,7 +484,7 @@ module Reactor
482
484
  new_name
483
485
  end
484
486
 
485
- if Reactor.rails4_0?
487
+ if Reactor.rails4_0? || Reactor.rails4_1?
486
488
  # Detect the subclass from the inheritance column of attrs. If the inheritance column value
487
489
  # is not self or a valid subclass, raises ActiveRecord::SubclassNotFound
488
490
  # If this is a StrongParameters hash, and access to inheritance_column is not permitted,
@@ -503,7 +505,7 @@ module Reactor
503
505
  end
504
506
  end
505
507
 
506
- if Reactor.rails4_0_ge6?
508
+ if Reactor.rails4_0_ge6? || Reactor.rails4_1?
507
509
  alias_method :subclass_from_attributes, :subclass_from_attrs
508
510
  remove_method :subclass_from_attrs
509
511
  end
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+ module Plans
4
+ class CommonAttribute
5
+ include Prepared
6
+
7
+ ALLOWED_PARAMS = [:callback, :helpText, :maxSize, :minSize,
8
+ :title, :values]
9
+
10
+ def initialize
11
+ @params = {}
12
+ end
13
+
14
+ def set(key,value)
15
+ @params[key.to_sym] = value
16
+ end
17
+
18
+ def migrate!
19
+ raise "#{self.class.name} did not implement migrate!"
20
+ end
21
+
22
+ protected
23
+ def prepare_params!(attribute=nil)
24
+ @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
25
+ end
26
+
27
+ def migrate_params!(attribute)
28
+ @params.each{|k,v|attribute.set(k,v)}
29
+ attribute.save!
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+ module Plans
4
+ class CommonChannel
5
+ include Prepared
6
+
7
+ ALLOWED_PARAMS = [:title]
8
+
9
+ def initialize
10
+ @params = {}
11
+ end
12
+
13
+ def set(key,value)
14
+ @params[key.to_sym] = value
15
+ end
16
+
17
+ def migrate!
18
+ raise "#{self.class.name} did not implement migrate!"
19
+ end
20
+
21
+ protected
22
+ def prepare_params!(channel=nil)
23
+ @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
24
+ end
25
+
26
+ def migrate_params!(channel)
27
+ @params.each{|k,v|channel.send(:"#{k}=",v)}
28
+ channel.save!
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+
4
+ module Plans
5
+
6
+ class CommonGroup
7
+
8
+ include Prepared
9
+
10
+ ALLOWED_PARAMS = [
11
+ :users,
12
+ :global_permissions,
13
+ :real_name,
14
+ :owner,
15
+ ]
16
+
17
+ def initialize
18
+ @params = {}
19
+ end
20
+
21
+ def set(key, value)
22
+ @params[key.to_sym] = value
23
+ end
24
+
25
+ def migrate!
26
+ raise "#{self.class.name} did not implement migrate!"
27
+ end
28
+
29
+ protected
30
+
31
+ def prepare_params!(group = nil)
32
+ @params.keys.each { |key| error("unknown parameter: #{key}") unless ALLOWED_PARAMS.include?(key) }
33
+ end
34
+
35
+ def migrate_params!(group)
36
+ @params.each { |key, value| group.send("#{key}=", value) }
37
+
38
+ group.save!
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,70 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Reactor
3
+ module Plans
4
+ class CommonObjClass
5
+ include Prepared
6
+
7
+ ALLOWED_PARAMS = [:completionCheck, :isEnabled, :recordSetCallback, :title,
8
+ :validContentTypes, :workflowModification]
9
+
10
+ def initialize
11
+ @take_attrs = []
12
+ @drop_attrs = []
13
+ @mandatory_attrs = []
14
+ @mandatory_drop_attrs = []
15
+ @preset_attrs = {}
16
+ @params = {}
17
+ @params_options = {}
18
+ end
19
+
20
+ def set(key, value, options={})
21
+ @params_options[key.to_sym] = options
22
+ @params[key.to_sym] = value
23
+ end
24
+
25
+ def take(attr_name, opts={})
26
+ attr_name = attr_name.to_s
27
+ @take_attrs << attr_name
28
+ @drop_attrs.delete(attr_name)
29
+ @mandatory_attrs << attr_name if opts[:mandatory] == true
30
+ @mandatory_drop_attrs << attr_name if opts[:mandatory] == false
31
+ @preset_attrs[attr_name] = opts[:preset] if opts.key? :preset
32
+ end
33
+
34
+ def drop(attr_name, opts={})
35
+ attr_name = attr_name.to_s
36
+ @drop_attrs << attr_name
37
+ @take_attrs.delete(attr_name)
38
+ @mandatory_attrs.delete(attr_name)
39
+ @preset_attrs.delete(attr_name)
40
+ end
41
+
42
+ def migrate!
43
+ raise "#{self.class.name} did not implement migrate!"
44
+ end
45
+
46
+ protected
47
+ def prepare_attrs!(klass=nil)
48
+ @take_attrs.each do |attr|
49
+ error("attribute doesn't exist #{attr}") unless Reactor::Cm::Attribute.exists?(attr)
50
+ end
51
+ end
52
+
53
+ def prepare_params!(klass=nil)
54
+ @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
55
+ end
56
+
57
+ def migrate_attrs!(klass)
58
+ attrs = (klass.attributes + @take_attrs).uniq - @drop_attrs
59
+ klass.attributes = attrs
60
+ klass.mandatory_attributes = ((klass.mandatory_attributes + @mandatory_attrs).uniq - @drop_attrs - @mandatory_drop_attrs)
61
+ end
62
+
63
+ def migrate_params!(klass)
64
+ @params.each{|k,v|klass.set(k,v,@params_options[k])}
65
+ klass.preset_attributes.merge(@preset_attrs).each{|k,v|klass.preset(k,v)}
66
+ klass.save!
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,33 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/plans/common_attribute'
3
+
4
+ module Reactor
5
+ module Plans
6
+ class CreateAttribute < CommonAttribute
7
+ def initialize(*args)
8
+ super()
9
+ (name, type), options = separate_arguments(*args)
10
+ @name = name || options[:name]
11
+ @type = type || options[:type]
12
+ # Default values for attributes:
13
+ # isSearchableInCM: false
14
+ # isSearchableInTE: false
15
+ set(:isSearchableInCM, 0)
16
+ set(:isSearchableInTE, 0)
17
+ end
18
+
19
+ def prepare!
20
+ error("name ist nil") if @name.nil?
21
+ error("type is nil") if @type.nil?
22
+ # TODO: Type check
23
+ prepare_params!(nil)
24
+ end
25
+
26
+ def migrate!
27
+ attrib = Reactor::Cm::Attribute.create(@name, @type)
28
+ migrate_params!(attrib)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'reactor/cm/channel'
3
+ require 'reactor/plans/common_channel'
4
+
5
+ module Reactor
6
+ module Plans
7
+ class CreateChannel < CommonChannel
8
+ def initialize(*args)
9
+ super()
10
+ (name, x), options = separate_arguments(*args)
11
+ @name = name || options[:name]
12
+ end
13
+
14
+ def prepare!
15
+ error("name is nil") if @name.nil?
16
+ end
17
+
18
+ def migrate!
19
+ channel = Reactor::Cm::Channel.create(@name)
20
+ migrate_params!(channel)
21
+ end
22
+ end
23
+ end
24
+ end