infopark_reactor_migrations 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +165 -0
  4. data/README +64 -0
  5. data/Rakefile +19 -0
  6. data/infopark_reactor_migrations.gemspec +27 -0
  7. data/lib/generators/cm/migration/USAGE +8 -0
  8. data/lib/generators/cm/migration/migration_generator.rb +15 -0
  9. data/lib/generators/cm/migration/templates/template.rb +7 -0
  10. data/lib/infopark_reactor_migrations.rb +29 -0
  11. data/lib/reactor/cm/attribute.rb +84 -0
  12. data/lib/reactor/cm/bridge.rb +49 -0
  13. data/lib/reactor/cm/editorial_group.rb +22 -0
  14. data/lib/reactor/cm/group.rb +270 -0
  15. data/lib/reactor/cm/language.rb +56 -0
  16. data/lib/reactor/cm/link.rb +132 -0
  17. data/lib/reactor/cm/live_group.rb +22 -0
  18. data/lib/reactor/cm/missing_credentials.rb +7 -0
  19. data/lib/reactor/cm/obj.rb +402 -0
  20. data/lib/reactor/cm/obj_class.rb +186 -0
  21. data/lib/reactor/cm/object_base.rb +164 -0
  22. data/lib/reactor/cm/user.rb +100 -0
  23. data/lib/reactor/cm/workflow.rb +40 -0
  24. data/lib/reactor/cm/xml_attribute.rb +35 -0
  25. data/lib/reactor/cm/xml_markup.rb +85 -0
  26. data/lib/reactor/cm/xml_request.rb +82 -0
  27. data/lib/reactor/cm/xml_request_error.rb +16 -0
  28. data/lib/reactor/cm/xml_response.rb +41 -0
  29. data/lib/reactor/configuration.rb +7 -0
  30. data/lib/reactor/migration.rb +82 -0
  31. data/lib/reactor/migrations/railtie.rb +10 -0
  32. data/lib/reactor/migrations/version.rb +5 -0
  33. data/lib/reactor/plans/common_attribute.rb +32 -0
  34. data/lib/reactor/plans/common_group.rb +44 -0
  35. data/lib/reactor/plans/common_obj_class.rb +69 -0
  36. data/lib/reactor/plans/create_attribute.rb +32 -0
  37. data/lib/reactor/plans/create_group.rb +34 -0
  38. data/lib/reactor/plans/create_obj.rb +48 -0
  39. data/lib/reactor/plans/create_obj_class.rb +28 -0
  40. data/lib/reactor/plans/delete_attribute.rb +23 -0
  41. data/lib/reactor/plans/delete_group.rb +28 -0
  42. data/lib/reactor/plans/delete_obj.rb +22 -0
  43. data/lib/reactor/plans/delete_obj_class.rb +22 -0
  44. data/lib/reactor/plans/prepared.rb +15 -0
  45. data/lib/reactor/plans/rename_group.rb +32 -0
  46. data/lib/reactor/plans/rename_obj_class.rb +24 -0
  47. data/lib/reactor/plans/update_attribute.rb +23 -0
  48. data/lib/reactor/plans/update_group.rb +30 -0
  49. data/lib/reactor/plans/update_obj.rb +30 -0
  50. data/lib/reactor/plans/update_obj_class.rb +26 -0
  51. data/lib/reactor/tools/migrator.rb +135 -0
  52. data/lib/reactor/tools/response_handler/base.rb +22 -0
  53. data/lib/reactor/tools/response_handler/string.rb +19 -0
  54. data/lib/reactor/tools/response_handler/xml_attribute.rb +52 -0
  55. data/lib/reactor/tools/smart_xml_logger.rb +69 -0
  56. data/lib/reactor/tools/sower.rb +89 -0
  57. data/lib/reactor/tools/uploader.rb +131 -0
  58. data/lib/reactor/tools/versioner.rb +120 -0
  59. data/lib/reactor/tools/xml_attributes.rb +70 -0
  60. data/lib/tasks/cm_migrate.rake +8 -0
  61. data/lib/tasks/cm_seeds.rake +41 -0
  62. metadata +193 -0
@@ -0,0 +1,32 @@
1
+ module Reactor
2
+ module Plans
3
+ class CommonAttribute
4
+ include Prepared
5
+
6
+ ALLOWED_PARAMS = [:callback, :helpText, :maxSize, :minSize,
7
+ :title, :values]
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!(attribute=nil)
23
+ @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
24
+ end
25
+
26
+ def migrate_params!(attribute)
27
+ @params.each{|k,v|attribute.set(k,v)}
28
+ attribute.save!
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ module Reactor
2
+
3
+ module Plans
4
+
5
+ class CommonGroup
6
+
7
+ include Prepared
8
+
9
+ ALLOWED_PARAMS = [
10
+ :users,
11
+ :global_permissions,
12
+ :real_name,
13
+ :owner,
14
+ ]
15
+
16
+ def initialize
17
+ @params = {}
18
+ end
19
+
20
+ def set(key, value)
21
+ @params[key.to_sym] = value
22
+ end
23
+
24
+ def migrate!
25
+ raise "#{self.class.name} did not implement migrate!"
26
+ end
27
+
28
+ protected
29
+
30
+ def prepare_params!(group = nil)
31
+ @params.keys.each { |key| error("unknown parameter: #{key}") unless ALLOWED_PARAMS.include?(key) }
32
+ end
33
+
34
+ def migrate_params!(group)
35
+ @params.each { |key, value| group.send("#{key}=", value) }
36
+
37
+ group.save!
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,69 @@
1
+ module Reactor
2
+ module Plans
3
+ class CommonObjClass
4
+ include Prepared
5
+
6
+ ALLOWED_PARAMS = [:completionCheck, :isEnabled, :recordSetCallback, :title,
7
+ :validContentTypes, :workflowModification]
8
+
9
+ def initialize
10
+ @take_attrs = []
11
+ @drop_attrs = []
12
+ @mandatory_attrs = []
13
+ @mandatory_drop_attrs = []
14
+ @preset_attrs = {}
15
+ @params = {}
16
+ @params_options = {}
17
+ end
18
+
19
+ def set(key, value, options={})
20
+ @params_options[key.to_sym] = options
21
+ @params[key.to_sym] = value
22
+ end
23
+
24
+ def take(attr_name, opts={})
25
+ attr_name = attr_name.to_s
26
+ @take_attrs << attr_name
27
+ @drop_attrs.delete(attr_name)
28
+ @mandatory_attrs << attr_name if opts[:mandatory] == true
29
+ @mandatory_drop_attrs << attr_name if opts[:mandatory] == false
30
+ @preset_attrs[attr_name] = opts[:preset] if opts.key? :preset
31
+ end
32
+
33
+ def drop(attr_name, opts={})
34
+ attr_name = attr_name.to_s
35
+ @drop_attrs << attr_name
36
+ @take_attrs.delete(attr_name)
37
+ @mandatory_attrs.delete(attr_name)
38
+ @preset_attrs.delete(attr_name)
39
+ end
40
+
41
+ def migrate!
42
+ raise "#{self.class.name} did not implement migrate!"
43
+ end
44
+
45
+ protected
46
+ def prepare_attrs!(klass=nil)
47
+ @take_attrs.each do |attr|
48
+ error("attribute doesn't exist #{attr}") unless Reactor::Cm::Attribute.exists?(attr)
49
+ end
50
+ end
51
+
52
+ def prepare_params!(klass=nil)
53
+ @params.keys.each{|k| error("unknown parameter: #{k}") unless ALLOWED_PARAMS.include? k}
54
+ end
55
+
56
+ def migrate_attrs!(klass)
57
+ attrs = (klass.attributes + @take_attrs).uniq - @drop_attrs
58
+ klass.attributes = attrs
59
+ klass.mandatory_attributes = ((klass.mandatory_attributes + @mandatory_attrs).uniq - @drop_attrs - @mandatory_drop_attrs)
60
+ end
61
+
62
+ def migrate_params!(klass)
63
+ @params.each{|k,v|klass.set(k,v,@params_options[k])}
64
+ klass.preset_attributes.merge(@preset_attrs).each{|k,v|klass.preset(k,v)}
65
+ klass.save!
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,32 @@
1
+ require 'reactor/plans/common_attribute'
2
+
3
+ module Reactor
4
+ module Plans
5
+ class CreateAttribute < CommonAttribute
6
+ def initialize(*args)
7
+ super()
8
+ (name, type), options = separate_arguments(*args)
9
+ @name = name || options[:name]
10
+ @type = type || options[:type]
11
+ # Default values for attributes:
12
+ # isSearchableInCM: false
13
+ # isSearchableInTE: false
14
+ set(:isSearchableInCM, 0)
15
+ set(:isSearchableInTE, 0)
16
+ end
17
+
18
+ def prepare!
19
+ error("name ist nil") if @name.nil?
20
+ error("type is nil") if @type.nil?
21
+ # TODO: Type check
22
+ prepare_params!(nil)
23
+ end
24
+
25
+ def migrate!
26
+ attrib = Reactor::Cm::Attribute.create(@name, @type)
27
+ migrate_params!(attrib)
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ require 'reactor/plans/common_group'
2
+
3
+ module Reactor
4
+
5
+ module Plans
6
+
7
+ class CreateGroup < CommonGroup
8
+
9
+ def initialize(*args)
10
+ super()
11
+
12
+ (name, _), options = separate_arguments(*args)
13
+
14
+ @name = name || options[:name]
15
+
16
+ set(:name, @name)
17
+ end
18
+
19
+ def prepare!
20
+ error('name is nil') if @name.nil?
21
+ error("group #{@name} already exists") if Reactor::Cm::Group.exists?(@name)
22
+
23
+ prepare_params!(nil)
24
+ end
25
+
26
+ def migrate!
27
+ Reactor::Cm::Group.create(@params)
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,48 @@
1
+ module Reactor
2
+ module Plans
3
+ class CreateObj
4
+
5
+ def set(key, value)
6
+ @attrs[key.to_sym] = value
7
+ end
8
+
9
+ def initialize(opts={})
10
+ @name = opts[:name]
11
+ @parent = opts[:parent]
12
+ @objClass = opts[:objClass]
13
+ @attrs = {}
14
+ @ignoreExisting = opts[:ignoreExisting]
15
+ end
16
+
17
+ def prepare!
18
+ raise "#{self.class.name}: name is nil" if @name.nil?
19
+ raise "#{self.class.name}: parent is nil" if @parent.nil?
20
+ raise "#{self.class.name}: objClass is nil" if @objClass.nil?
21
+ raise "#{self.class.name}: parent does not exist" if not Reactor::Cm::Obj.exists?(@parent)
22
+ raise "#{self.class.name}: obj with name #{@name} already exists" if (!@ignoreExisting) && Reactor::Cm::Obj.exists?(path)
23
+ =begin
24
+ raise "#{self.class.name}: objClass #{@objClass} not found" if not Reactor::Cm::ObjClass.exists?(@objClass)
25
+ @attrs.keys.each do |attr|
26
+ raise "#{self.class.name}: attr #{attr} not found for objClass #{@objClass}" if not Reactor::Cm::ObjClass.has_attribute?(attr)
27
+ end
28
+ =end
29
+ # ...?
30
+ end
31
+
32
+ def migrate!
33
+ return true if (@ignoreExisting) && Reactor::Cm::Obj.exists?(path)
34
+ @obj = Cm::Obj.create(@name, @parent, @objClass)
35
+ @attrs.each do |key,value|
36
+ @obj.set(key,value)
37
+ end
38
+ @obj.save!
39
+ @obj.release!
40
+ end
41
+
42
+ def path
43
+ File.join(@parent, @name)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,28 @@
1
+ require 'reactor/plans/common_obj_class'
2
+
3
+ module Reactor
4
+ module Plans
5
+ class CreateObjClass < CommonObjClass
6
+ def initialize(*args)
7
+ super()
8
+ (name, type), options = separate_arguments(*args)
9
+ @name = name || options[:name]
10
+ @type = type || options[:objType] || options[:type]
11
+ end
12
+
13
+ def prepare!
14
+ error("name is nil") if @name.nil?
15
+ error("type is nil") if @type.nil?
16
+ error("objClass #{@name} already exists") if Reactor::Cm::ObjClass.exists?(@name)
17
+ prepare_attrs!(nil)
18
+ prepare_params!(nil)
19
+ end
20
+
21
+ def migrate!
22
+ klass = Reactor::Cm::ObjClass.create(@name, @type)
23
+ migrate_attrs!(klass)
24
+ migrate_params!(klass)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module Reactor
2
+ module Plans
3
+ class DeleteAttribute < CommonAttribute
4
+ def initialize(*args)
5
+ super()
6
+ (name, x), options = separate_arguments(*args)
7
+ @name = name || options[:name]
8
+ end
9
+
10
+ def prepare!
11
+ error("name is nil") if @name.nil?
12
+ error("attribute #{@name} does not exist") if not Reactor::Cm::Attribute.exists?(@name)
13
+ # TODO: check used..
14
+ end
15
+
16
+ def migrate!
17
+ attrib = Reactor::Cm::Attribute.get(@name)
18
+ attrib.delete!
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ module Reactor
2
+
3
+ module Plans
4
+
5
+ class DeleteGroup < CommonGroup
6
+
7
+ def initialize(*args)
8
+ super()
9
+
10
+ (name, _), options = separate_arguments(*args)
11
+ @name = name || options[:name]
12
+ end
13
+
14
+ def prepare!
15
+ error('name is nil') if @name.nil?
16
+ error("group #{@name} does not exist") unless Reactor::Cm::Group.exists?(@name)
17
+ end
18
+
19
+ def migrate!
20
+ group = Reactor::Cm::Group.get(@name)
21
+ group.delete!
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,22 @@
1
+ require 'reactor/plans/prepared'
2
+
3
+ module Reactor
4
+ module Plans
5
+ class DeleteObj
6
+ include Prepared
7
+
8
+ def initialize(opts={})
9
+ @key = opts[:obj_id] || opts[:path]
10
+ end
11
+
12
+ def prepare!
13
+ error("object (key=#{@key}) not found") if not Reactor::Cm::Obj.exists?(@key)
14
+ end
15
+
16
+ def migrate!
17
+ obj = Reactor::Cm::Obj.get(@key)
18
+ obj.delete!
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module Reactor
2
+ module Plans
3
+ class DeleteObjClass < CommonObjClass
4
+ include Prepared
5
+
6
+ def initialize(*args)
7
+ super()
8
+ (name, x), options = separate_arguments(*args)
9
+ @name = name || options[:name]
10
+ end
11
+
12
+ def prepare!
13
+ error("objClass #{@name} not found") if not Reactor::Cm::ObjClass.exists?(@name)
14
+ end
15
+
16
+ def migrate!
17
+ klass = Reactor::Cm::ObjClass.get(@name)
18
+ klass.delete!
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Reactor
2
+ module Plans
3
+ module Prepared
4
+ def error(message)
5
+ "#{self.class.name}: #{message}"
6
+ end
7
+
8
+ def separate_arguments(*args)
9
+ array_args = args.select {|a| !a.is_a?(Hash) }
10
+ hash_args = args.select {|a| a.is_a?(Hash) }.reduce({}, &:merge)
11
+ return array_args, hash_args
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Reactor
2
+
3
+ module Plans
4
+
5
+ class RenameGroup
6
+
7
+ include Prepared
8
+
9
+ def initialize(*args)
10
+ (from, to), options = separate_arguments(*args)
11
+
12
+ @from = from || options[:from]
13
+ @to = to || options[:to]
14
+ end
15
+
16
+ def prepare!
17
+ error('from is nil') if @from.nil?
18
+ error('to is nil') if @to.nil?
19
+ error('from does not exist') unless Reactor::Cm::Group.exists?(@from)
20
+ error('to does exist') if Reactor::Cm::Group.exists?(@to)
21
+ end
22
+
23
+ def migrate!
24
+ group = Reactor::Cm::Group.get(@from)
25
+ group.rename!(@to)
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,24 @@
1
+ module Reactor
2
+ module Plans
3
+ class RenameObjClass
4
+ include Prepared
5
+
6
+ def initialize(*args)
7
+ (from, to), options = separate_arguments(*args)
8
+ @from = from || options[:from]
9
+ @to = to || options[:to]
10
+ end
11
+
12
+ def prepare!
13
+ error("from is nil") if @from.nil?
14
+ error("to is nil") if @to.nil?
15
+ error("from does not exist") if not Reactor::Cm::ObjClass.exists?(@from)
16
+ error("to does exist") if Reactor::Cm::ObjClass.exists?(@to)
17
+ end
18
+
19
+ def migrate!
20
+ Reactor::Cm::ObjClass.rename(@from, @to)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Reactor
2
+ module Plans
3
+ class UpdateAttribute < CommonAttribute
4
+ def initialize(*args)
5
+ super()
6
+ (name, x), options = separate_arguments(*args)
7
+ @name = name || options[:name]
8
+ end
9
+
10
+ def prepapre!
11
+ error("name is nil") if @name.nil?
12
+ error("attribute #{@name} not found") if not Reactor::Cm::Attribute.exists?(@name)
13
+ prepare_params!(nil)
14
+ end
15
+
16
+ def migrate!
17
+ attrib = Reactor::Cm::Attribute.get(@name)
18
+ migrate_params!(attrib)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ module Reactor
2
+
3
+ module Plans
4
+
5
+ class UpdateGroup < CommonGroup
6
+
7
+ def initialize(*args)
8
+ super()
9
+
10
+ (name, _), options = separate_arguments(*args)
11
+ @name = name || options[:name]
12
+ end
13
+
14
+ def prepapre!
15
+ error('name is nil') if @name.nil?
16
+ error("group #{@name} not found") unless Reactor::Cm::Group.exists?(@name)
17
+
18
+ prepare_params!(nil)
19
+ end
20
+
21
+ def migrate!
22
+ group = Reactor::Cm::Group.get(@name)
23
+ migrate_params!(group)
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ module Reactor
2
+ module Plans
3
+ class UpdateObj
4
+ include Prepared
5
+
6
+ def initialize(opts={})
7
+ @key = opts[:obj_id] || opts[:path]
8
+ @attrs = {}
9
+ end
10
+
11
+ def set(key, value)
12
+ @attrs[key.to_sym] = value
13
+ end
14
+
15
+ def prepare!
16
+ error("object (key=#{@key}) not found") if not Reactor::Cm::Obj.exists?(@key)
17
+ #TODO: attribute check
18
+ end
19
+
20
+ def migrate!
21
+ obj = Reactor::Cm::Obj.get(@key)
22
+ @attrs.each do |key,value|
23
+ @obj.set(key,value)
24
+ end
25
+ @obj.save!
26
+ @obj.release!
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ module Reactor
2
+ module Plans
3
+ class UpdateObjClass < CommonObjClass
4
+ include Prepared
5
+
6
+ def initialize(*args)
7
+ super()
8
+ (name, x), options = separate_arguments(*args)
9
+ @name = name || options[:name]
10
+ end
11
+
12
+ def prepare!
13
+ error("objClass #{@name} not found") if Reactor::Cm::ObjClass.exists?(@name)
14
+ @klass = Reactor::Cm::ObjClass.get(@name)
15
+ prepare_attrs!(@klass)
16
+ prepare_params!(@klass)
17
+ end
18
+
19
+ def migrate!
20
+ migrate_attrs!(@klass)
21
+ migrate_params!(@klass)
22
+ end
23
+
24
+ end
25
+ end
26
+ end