infopark_reactor 1.26.1 → 1.27.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +25 -0
  3. data/.rubocop_todo.yml +363 -0
  4. data/Rakefile +10 -13
  5. data/app/models/rails_connector/abstract_obj.rb +2 -1
  6. data/config/routes.rb +0 -1
  7. data/infopark_reactor.gemspec +16 -15
  8. data/lib/generators/cm/migration/migration_generator.rb +4 -8
  9. data/lib/infopark_reactor.rb +43 -69
  10. data/lib/reactor/already_released.rb +1 -2
  11. data/lib/reactor/attributes.rb +92 -268
  12. data/lib/reactor/attributes/date_serializer.rb +20 -16
  13. data/lib/reactor/attributes/html_serializer.rb +6 -5
  14. data/lib/reactor/attributes/link_list_extender.rb +10 -8
  15. data/lib/reactor/attributes/link_list_from_accessor.rb +2 -1
  16. data/lib/reactor/attributes/link_list_from_attr_values.rb +2 -1
  17. data/lib/reactor/attributes/link_list_serializer.rb +8 -7
  18. data/lib/reactor/attributes_handlers.rb +164 -0
  19. data/lib/reactor/cache/permission.rb +6 -9
  20. data/lib/reactor/cache/user.rb +3 -6
  21. data/lib/reactor/cm/attribute.rb +16 -16
  22. data/lib/reactor/cm/attribute_group.rb +18 -21
  23. data/lib/reactor/cm/blob_too_small_error.rb +2 -2
  24. data/lib/reactor/cm/bridge.rb +6 -9
  25. data/lib/reactor/cm/channel.rb +3 -4
  26. data/lib/reactor/cm/editorial_group.rb +2 -9
  27. data/lib/reactor/cm/group.rb +30 -43
  28. data/lib/reactor/cm/job.rb +23 -25
  29. data/lib/reactor/cm/language.rb +21 -22
  30. data/lib/reactor/cm/link.rb +38 -40
  31. data/lib/reactor/cm/live_group.rb +2 -9
  32. data/lib/reactor/cm/log_entry.rb +22 -21
  33. data/lib/reactor/cm/missing_credentials.rb +3 -2
  34. data/lib/reactor/cm/multi_xml_request.rb +22 -25
  35. data/lib/reactor/cm/obj.rb +159 -154
  36. data/lib/reactor/cm/obj_class.rb +52 -51
  37. data/lib/reactor/cm/object_base.rb +26 -21
  38. data/lib/reactor/cm/permissions.rb +7 -7
  39. data/lib/reactor/cm/user.rb +43 -51
  40. data/lib/reactor/cm/workflow.rb +11 -12
  41. data/lib/reactor/cm/xml_attribute.rb +10 -19
  42. data/lib/reactor/cm/xml_markup.rb +7 -10
  43. data/lib/reactor/cm/xml_multi_request_error.rb +1 -3
  44. data/lib/reactor/cm/xml_request.rb +21 -29
  45. data/lib/reactor/cm/xml_request_error.rb +1 -3
  46. data/lib/reactor/cm/xml_response.rb +8 -16
  47. data/lib/reactor/cm/xml_single_request_error.rb +3 -5
  48. data/lib/reactor/configuration.rb +1 -3
  49. data/lib/reactor/engine.rb +5 -10
  50. data/lib/reactor/legacy.rb +6 -7
  51. data/lib/reactor/link/external.rb +8 -5
  52. data/lib/reactor/link/internal.rb +8 -5
  53. data/lib/reactor/link/temporary_link.rb +16 -17
  54. data/lib/reactor/main.rb +11 -15
  55. data/lib/reactor/migration.rb +52 -53
  56. data/lib/reactor/no_working_version.rb +1 -2
  57. data/lib/reactor/not_permitted.rb +1 -2
  58. data/lib/reactor/permission.rb +36 -38
  59. data/lib/reactor/persistence.rb +104 -178
  60. data/lib/reactor/plans/common_attribute.rb +7 -7
  61. data/lib/reactor/plans/common_attribute_group.rb +6 -6
  62. data/lib/reactor/plans/common_channel.rb +6 -6
  63. data/lib/reactor/plans/common_group.rb +7 -14
  64. data/lib/reactor/plans/common_job.rb +6 -6
  65. data/lib/reactor/plans/common_obj_class.rb +11 -11
  66. data/lib/reactor/plans/create_attribute.rb +1 -3
  67. data/lib/reactor/plans/create_attribute_group.rb +1 -3
  68. data/lib/reactor/plans/create_channel.rb +2 -3
  69. data/lib/reactor/plans/create_group.rb +3 -10
  70. data/lib/reactor/plans/create_job.rb +3 -4
  71. data/lib/reactor/plans/create_obj.rb +12 -14
  72. data/lib/reactor/plans/create_obj_class.rb +1 -2
  73. data/lib/reactor/plans/delete_attribute.rb +1 -3
  74. data/lib/reactor/plans/delete_attribute_group.rb +2 -4
  75. data/lib/reactor/plans/delete_channel.rb +3 -6
  76. data/lib/reactor/plans/delete_group.rb +2 -9
  77. data/lib/reactor/plans/delete_job.rb +3 -5
  78. data/lib/reactor/plans/delete_obj.rb +3 -4
  79. data/lib/reactor/plans/delete_obj_class.rb +1 -2
  80. data/lib/reactor/plans/prepared.rb +3 -4
  81. data/lib/reactor/plans/rename_group.rb +4 -11
  82. data/lib/reactor/plans/rename_obj_class.rb +1 -2
  83. data/lib/reactor/plans/update_attribute.rb +1 -3
  84. data/lib/reactor/plans/update_attribute_group.rb +2 -4
  85. data/lib/reactor/plans/update_group.rb +2 -9
  86. data/lib/reactor/plans/update_job.rb +4 -8
  87. data/lib/reactor/plans/update_obj.rb +6 -7
  88. data/lib/reactor/plans/update_obj_class.rb +0 -2
  89. data/lib/reactor/rc_independent.rb +0 -1
  90. data/lib/reactor/session.rb +27 -31
  91. data/lib/reactor/session/observers.rb +3 -5
  92. data/lib/reactor/session/user.rb +6 -7
  93. data/lib/reactor/session_helper/auth_filter.rb +9 -0
  94. data/lib/reactor/session_helper/auth_helper.rb +24 -0
  95. data/lib/reactor/session_helper/rsession_helper.rb +16 -0
  96. data/lib/reactor/session_helper/session_state.rb +31 -0
  97. data/lib/reactor/streaming_upload.rb +0 -1
  98. data/lib/reactor/sudo.rb +2 -3
  99. data/lib/reactor/support/link_matcher.rb +8 -7
  100. data/lib/reactor/tools/migrator.rb +30 -35
  101. data/lib/reactor/tools/response_handler/xml_attribute.rb +27 -33
  102. data/lib/reactor/tools/smart_xml_logger.rb +20 -22
  103. data/lib/reactor/tools/sower.rb +22 -23
  104. data/lib/reactor/tools/uploader.rb +12 -17
  105. data/lib/reactor/tools/versioner.rb +29 -30
  106. data/lib/reactor/tools/where_query.rb +11 -14
  107. data/lib/reactor/tools/workflow_generator.rb +26 -28
  108. data/lib/reactor/tools/xml_attributes.rb +7 -14
  109. data/lib/reactor/tools/xpath_extractor.rb +2 -1
  110. data/lib/reactor/validations.rb +20 -16
  111. data/lib/reactor/version.rb +1 -2
  112. data/lib/reactor/workflow.rb +10 -33
  113. data/lib/reactor/workflow/comment.rb +28 -0
  114. data/lib/reactor/workflow/empty.rb +0 -1
  115. data/lib/reactor/workflow/standard.rb +4 -3
  116. data/lib/tasks/cm_migrate.rake +3 -3
  117. data/lib/tasks/cm_seeds.rake +9 -16
  118. metadata +64 -28
  119. data/app/models/rails_connector/abstract_model.rb +0 -7
  120. data/app/models/rails_connector/attribute.rb +0 -94
  121. data/app/models/rails_connector/blob_mapping.rb +0 -16
  122. data/app/models/rails_connector/channel.rb +0 -41
  123. data/app/models/rails_connector/content.rb +0 -12
  124. data/app/models/rails_connector/job.rb +0 -14
  125. data/app/models/rails_connector/obj_class.rb +0 -158
  126. data/app/models/rails_connector/obj_class_attr.rb +0 -5
  127. data/app/models/rails_connector/object_with_meta_data.rb +0 -18
  128. data/lib/rails_connector/meta/eager_loader.rb +0 -91
  129. data/lib/reactor/rails_connector_meta.rb +0 -149
  130. data/lib/reactor/session_helper.rb +0 -72
@@ -1,8 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'nokogiri'
1
+ require "nokogiri"
3
2
 
4
3
  class SmartXmlLogger
5
-
6
4
  def initialize(forward_to, method = nil)
7
5
  @logger = forward_to
8
6
  @method = method
@@ -15,6 +13,7 @@ class SmartXmlLogger
15
13
 
16
14
  def log(text)
17
15
  return unless @logger
16
+
18
17
  @logger.send(@method, text)
19
18
  end
20
19
 
@@ -27,41 +26,40 @@ class SmartXmlLogger
27
26
 
28
27
  node_set = options[:xpath] ? dom.xpath(options[:xpath]) : dom
29
28
 
30
- self.log(if node_set.respond_to?(:each)
31
- node_set.map{|node| self.print_node(node, options[:start_indent] || 0)}.join
32
- else
33
- self.print_node(node_set, options[:start_indent] || 0)
29
+ log(if node_set.respond_to?(:each)
30
+ node_set.map { |node| print_node(node, options[:start_indent] || 0) }.join
31
+ else
32
+ print_node(node_set, options[:start_indent] || 0)
34
33
  end)
35
34
  end
36
35
 
37
- #private
36
+ # private
38
37
 
39
38
  def print_node(node, indent = 0)
40
- return '' if node.text?
39
+ return "" if node.text?
41
40
 
42
41
  empty = node.children.empty?
43
- has_text = node.children.detect{|child| child.text?}
42
+ has_text = node.children.detect { |child| child.text? }
44
43
 
45
- out = ' ' * indent
44
+ out = " " * indent
46
45
 
47
- attrs = node.attributes.values.map{|attr| %|#{attr.name}="#{(attr.value)}"|}.join(' ')
46
+ attrs = node.attributes.values.map { |attr| %(#{attr.name}="#{attr.value}") }.join(" ")
48
47
  attrs = " #{attrs}" if attrs.present?
49
48
 
50
- out << "<#{(node.name)}#{attrs}#{'/' if empty}>"
49
+ out << "<#{node.name}#{attrs}#{"/" if empty}>"
51
50
 
52
- if has_text
53
- out << "#{(node.text)}"
54
- else
55
- out << "\n"
56
- end
51
+ out << if has_text
52
+ node.text.to_s
53
+ else
54
+ "\n"
55
+ end
57
56
 
58
57
  node.children.each do |child|
59
- out << self.print_node(child, indent + 2)
58
+ out << print_node(child, indent + 2)
60
59
  end
61
60
 
62
- out << ' ' * indent unless has_text || empty
63
- out << "</#{(node.name)}>\n" unless empty
61
+ out << " " * indent unless has_text || empty
62
+ out << "</#{node.name}>\n" unless empty
64
63
  out
65
64
  end
66
-
67
65
  end
@@ -1,15 +1,13 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Reactor
3
-
4
2
  class Sower
5
3
  def initialize(filename)
6
4
  @filename = filename
7
5
  end
6
+
8
7
  def sow
9
8
  require @filename
10
9
  end
11
10
  end
12
-
13
11
  end
14
12
 
15
13
  class SeedObject < RailsConnector::AbstractObj
@@ -17,15 +15,15 @@ end
17
15
 
18
16
  module RailsConnector
19
17
  class AbstractObj
20
-
21
18
  attr_accessor :keep_edited
22
19
 
23
20
  def self.plant(path, &block)
24
21
  obj = Obj.find_by_path(path)
25
- raise ActiveRecord::RecordNotFound.new('plant: Ground not found:' +path) if obj.nil?
26
- #obj.objClass = 'Container' # TODO: enable it!
27
- #obj.save!
28
- #obj.release!
22
+ raise ActiveRecord::RecordNotFound, "plant: Ground not found:" + path if obj.nil?
23
+
24
+ # obj.objClass = 'Container' # TODO: enable it!
25
+ # obj.save!
26
+ # obj.release!
29
27
  obj.send(:reload_attributes)
30
28
  obj.instance_eval(&block) if block_given?
31
29
  # ActiveRecord is incompatible with changing the obj class, therefore you get RecordNotFound
@@ -41,39 +39,41 @@ module RailsConnector
41
39
  # executes a block on it (instance_eval)
42
40
  # saves and releases (unless keep_edited = true was called)
43
41
  # the object afterwards
44
- def obj(name, objClass = 'Container', &block)
45
- obj = Obj.find_by_path(File.join(self.path.to_s, name.to_s))
42
+ def obj(name, objClass = "Container", &block)
43
+ obj = Obj.find_by_path(File.join(path.to_s, name.to_s))
46
44
  if obj.nil?
47
- obj = Obj.create(:name => name, :parent => self.path, :obj_class => objClass)
45
+ obj = Obj.create(name: name, parent: path, obj_class: objClass)
48
46
  else
49
- obj = Obj.find_by_path(File.join(self.path.to_s, name.to_s))
47
+ obj = Obj.find_by_path(File.join(path.to_s, name.to_s))
50
48
  if obj.obj_class != objClass
51
49
  obj.obj_class = objClass
52
50
  begin
53
51
  obj.save!
54
52
  rescue ActiveRecord::RecordNotFound
55
53
  end
56
- obj = Obj.find_by_path(File.join(self.path.to_s, name.to_s))
54
+ obj = Obj.find_by_path(File.join(path.to_s, name.to_s))
57
55
  end
58
56
  end
59
57
  obj.send(:reload_attributes, objClass)
60
58
  obj.instance_eval(&block) if block_given?
61
59
  obj.save!
62
- obj.release unless obj.keep_edited || !Obj.last.edited?
60
+ obj.release unless obj.keep_edited || !obj.reload.edited?
63
61
  obj
64
62
  end
65
63
 
66
- def self.with(path, objClass = 'Container', &block)
67
- splitted_path = path.split('/')
64
+ def self.with(path, objClass = "Container", &block)
65
+ splitted_path = path.split("/")
68
66
  name = splitted_path.pop
69
67
  # ensure path exists
70
- (splitted_path.length).times do |i|
71
- subpath = splitted_path[0,(i+1)].join('/').presence || '/'
72
- subpath_parent = splitted_path[0,i].join('/').presence || '/'
68
+ splitted_path.length.times do |i|
69
+ subpath = splitted_path[0, (i + 1)].join("/").presence || "/"
70
+ subpath_parent = splitted_path[0, i].join("/").presence || "/"
73
71
  subpath_name = splitted_path[i]
74
- create(:name => subpath_name, :parent => subpath_parent, :obj_class => 'Container') unless Obj.find_by_path(subpath) unless subpath_name.blank?
72
+ unless subpath_name.blank? || Obj.find_by_path(subpath)
73
+ create(name: subpath_name, parent: subpath_parent, obj_class: "Container")
74
+ end
75
75
  end
76
- parent_path = splitted_path.join('/').presence || '/'
76
+ parent_path = splitted_path.join("/").presence || "/"
77
77
  parent = Obj.find_by_path(parent_path)
78
78
  parent.obj(name, objClass, &block)
79
79
  end
@@ -82,9 +82,8 @@ module RailsConnector
82
82
  @keep_edited = true
83
83
  end
84
84
 
85
- def t(key, opts={})
85
+ def t(key, opts = {})
86
86
  I18n.t(key, opts)
87
87
  end
88
-
89
88
  end
90
89
  end
@@ -1,8 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Reactor
3
2
  module Tools
4
3
  class Uploader
5
-
6
4
  attr_reader :cm_obj
7
5
 
8
6
  def initialize(cm_obj)
@@ -24,7 +22,7 @@ module Reactor
24
22
  # the upload may fail randomly. For this platform
25
23
  # and this case fallback to memory streaming is used.
26
24
  def upload(data_or_io, extension)
27
- if (data_or_io.kind_of?IO)
25
+ if data_or_io.is_a? IO
28
26
  io = data_or_io
29
27
  begin
30
28
  ticket_id = stream_io(io, extension)
@@ -46,7 +44,7 @@ module Reactor
46
44
  end
47
45
 
48
46
  cm_obj.set(:contentType, extension)
49
- cm_obj.set(:blob, {ticket_id=>{:encoding=>'stream'}})
47
+ cm_obj.set(:blob, { ticket_id => { encoding: "stream" } })
50
48
 
51
49
  ticket_id
52
50
  end
@@ -58,8 +56,8 @@ module Reactor
58
56
  # Stream into CM from memory. Used in cases when the file
59
57
  # has already been read into memory
60
58
  def stream_data(data, extension)
61
- response = (Net::HTTP.new(self.class.streaming_host, self.class.streaming_port).post('/stream', data,
62
- {'Content-Type' => self.class.content_type_for_ext(extension)}))
59
+ response = Net::HTTP.new(self.class.streaming_host, self.class.streaming_port).post("/stream", data,
60
+ { "Content-Type" => self.class.content_type_for_ext(extension) })
63
61
  ticket_id = response.body
64
62
 
65
63
  handle_response(response, ticket_id)
@@ -68,12 +66,13 @@ module Reactor
68
66
  # Stream directly an IO object into CM. Uses minimal memory,
69
67
  # as the IO is read in 1024B-Blocks
70
68
  def stream_io(io, extension)
71
- request = Net::HTTP::Post.new('/stream')
69
+ request = Net::HTTP::Post.new("/stream")
72
70
  request.body_stream = io
73
71
  request.content_length = read_io_content_length(io)
74
72
  request.content_type = self.class.content_type_for_ext(extension)
75
73
 
76
- response, ticket_id = nil, nil
74
+ response = nil
75
+ ticket_id = nil
77
76
  Net::HTTP.start(self.class.streaming_host, self.class.streaming_port) do |http|
78
77
  http.read_timeout = Reactor::Cm::XmlRequest.timeout
79
78
  response = http.request(request)
@@ -85,11 +84,7 @@ module Reactor
85
84
 
86
85
  # Returns ticket_id if response if one of success (success or redirect)
87
86
  def handle_response(response, ticket_id)
88
- if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
89
- ticket_id
90
- else
91
- nil
92
- end
87
+ ticket_id if response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection)
93
88
  end
94
89
 
95
90
  # Returns the size of the IO stream.
@@ -97,9 +92,9 @@ module Reactor
97
92
  # the :stat method or be able to seek to
98
93
  # random position
99
94
  def read_io_content_length(io)
100
- if (io.respond_to?(:stat))
95
+ if io.respond_to?(:stat)
101
96
  # For files it is easy to read the filesize
102
- return io.stat.size
97
+ io.stat.size
103
98
  else
104
99
  # For streams it is not. We seek to end of
105
100
  # the stream, read the position, and rewind
@@ -125,8 +120,8 @@ module Reactor
125
120
  # mime type for given extension. But since the CM
126
121
  # accepts 'application/octet-stream', no extra logic
127
122
  # or external dependency is required.
128
- def self.content_type_for_ext(extension)
129
- 'application/octet-stream'
123
+ def self.content_type_for_ext(_extension)
124
+ "application/octet-stream"
130
125
  end
131
126
  end
132
127
  end
@@ -1,7 +1,6 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'base64'
3
- require 'yaml'
4
- require 'singleton'
1
+ require "base64"
2
+ require "yaml"
3
+ require "singleton"
5
4
 
6
5
  module Reactor
7
6
  # Class responsible for interfacing with version-storing mechanism
@@ -29,38 +28,39 @@ module Reactor
29
28
  def exists?
30
29
  begin
31
30
  request = Reactor::Cm::XmlRequest.prepare do |xml|
32
- xml.where_key_tag!(base_name, 'name', name)
33
- xml.get_key_tag!(base_name, 'name')
31
+ xml.where_key_tag!(base_name, "name", name)
32
+ xml.get_key_tag!(base_name, "name")
34
33
  end
35
34
  response = request.execute!
36
- return response.ok?
37
- rescue
38
- return false
35
+ response.ok?
36
+ rescue StandardError
37
+ false
39
38
  end
40
39
  end
41
40
 
42
41
  def load
43
- create if not exists?
42
+ create unless exists?
44
43
  request = Reactor::Cm::XmlRequest.prepare do |xml|
45
- xml.where_key_tag!(base_name, 'name', name)
46
- xml.get_key_tag!(base_name, 'recordSetCallback')
44
+ xml.where_key_tag!(base_name, "name", name)
45
+ xml.get_key_tag!(base_name, "recordSetCallback")
47
46
  end
48
47
  response = request.execute!
49
48
  base64 = response.xpath("//recordSetCallback").text.to_s
50
- yaml = Base64::decode64(base64)
51
- data = YAML::load(yaml)
52
- return [] if data.nil? or data == false
53
- return data.to_a
49
+ yaml = Base64.decode64(base64)
50
+ data = YAML.load(yaml)
51
+ return [] if data.nil? || (data == false)
52
+
53
+ data.to_a
54
54
  end
55
55
 
56
56
  def store(data)
57
- create if not exists?
57
+ create unless exists?
58
58
  yaml = data.to_yaml
59
- base64 = Base64::encode64(yaml).gsub("\n", '').gsub("\r", '')
60
- content = '#' + base64
59
+ base64 = Base64.encode64(yaml).delete("\n").delete("\r")
60
+ content = "#" + base64
61
61
  request = Reactor::Cm::XmlRequest.prepare do |xml|
62
- xml.where_key_tag!(base_name, 'name', name)
63
- xml.set_key_tag!(base_name, 'recordSetCallback', content)
62
+ xml.where_key_tag!(base_name, "name", name)
63
+ xml.set_key_tag!(base_name, "recordSetCallback", content)
64
64
  end
65
65
  response = request.execute!
66
66
  response.ok?
@@ -69,11 +69,11 @@ module Reactor
69
69
  def create
70
70
  request = Reactor::Cm::XmlRequest.prepare do |xml|
71
71
  xml.create_tag!(base_name) do
72
- xml.tag!('name') do
72
+ xml.tag!("name") do
73
73
  xml.text!(name)
74
74
  end
75
- xml.tag!('objType') do
76
- xml.text!('document')
75
+ xml.tag!("objType") do
76
+ xml.text!("document")
77
77
  end
78
78
  end
79
79
  end
@@ -105,17 +105,16 @@ module Reactor
105
105
  end
106
106
 
107
107
  def remove(version)
108
- not @versions.delete(version.to_s).nil?
108
+ !@versions.delete(version.to_s).nil?
109
109
  end
110
110
 
111
- def versions
112
- @versions
113
- end
111
+ attr_reader :versions
114
112
 
115
113
  def current_version
116
- current = @versions.sort.reverse.first
114
+ current = @versions.max
117
115
  return 0 if current.nil?
118
- return current
116
+
117
+ current
119
118
  end
120
119
  end
121
120
  end
@@ -2,32 +2,29 @@ module Reactor
2
2
  module WhereQuery
3
3
  def where(key, value)
4
4
  request = Cm::XmlRequest.prepare do |xml|
5
- xml.where_tag!(self.base_name) do
5
+ xml.where_tag!(base_name) do
6
6
  xml.tag!(key) do
7
- if value
8
- xml.text!(value)
9
- end
7
+ xml.text!(value) if value
10
8
  end
11
9
  end
12
10
 
13
- xml.get_tag!(self.base_name) do
14
- self.attributes.each do |_, xml_attribute|
11
+ xml.get_tag!(base_name) do
12
+ attributes.each do |_, xml_attribute|
15
13
  xml.tag!(xml_attribute.name)
16
14
  end
17
15
  end
18
16
  end
19
17
 
20
18
  response = request.execute!
21
- result = response.xpath("//#{self.base_name}")
22
- result = [result] unless result.kind_of?(Array)
19
+ result = response.xpath("//#{base_name}")
20
+ result = [result] unless result.is_a?(Array)
23
21
  result.map do |elem|
24
- values = {}
25
- values = self.response_handler.multiple(elem, self.attributes.values)
26
- instance = self.new
27
- values.each do |name, value|
28
- pair = self.attributes.find {|n, a| a.name.to_sym == name.to_sym }
22
+ values = response_handler.multiple(elem, attributes.values)
23
+ instance = new
24
+ values.each do |name, response_value|
25
+ pair = attributes.find { |_n, a| a.name.to_sym == name.to_sym }
29
26
  attribute = pair[0]
30
- instance.send(:"#{attribute}=", value)
27
+ instance.send(:"#{attribute}=", response_value)
31
28
  end
32
29
  instance
33
30
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding : utf-8 -*-
2
1
  module Reactor
3
2
  module Tools
4
3
  class WorkflowGenerator
@@ -10,8 +9,8 @@ module Reactor
10
9
  @users = @editors + @correctors
11
10
  @groups = personal_groups(@users)
12
11
  @class_name = options[:obj_class] || generate_obj_class_name
13
- @workflow_name = options[:workflow_name] || generate_workflow_name
14
- @obj_name = options[:obj_name] || generate_obj_name
12
+ @workflow_name = options[:workflow_name] || generate_workflow_name
13
+ @obj_name = options[:obj_name] || generate_obj_name
15
14
  end
16
15
 
17
16
  def generate!
@@ -45,7 +44,7 @@ module Reactor
45
44
  end
46
45
 
47
46
  def personal_groups(users)
48
- users.map {|user| personal_group(user) }
47
+ users.map { |user| personal_group(user) }
49
48
  end
50
49
 
51
50
  def create_groups
@@ -53,20 +52,20 @@ module Reactor
53
52
  if Reactor::Cm::Group.exists?(group)
54
53
  Reactor::Cm::Group.get(group)
55
54
  else
56
- Reactor::Cm::Group.create(:name => group)
55
+ Reactor::Cm::Group.create(name: group)
57
56
  end
58
57
  end
59
58
  end
60
59
 
61
60
  def create_users
62
61
  @users.each do |user|
63
- if Reactor::Cm::User::Internal.exists?(user)
64
- internal_user = Reactor::Cm::User::Internal.get(user)
65
- else
66
- internal_user = Reactor::Cm::User::Internal.create(user, personal_group(user))
67
- end
62
+ internal_user = if Reactor::Cm::User::Internal.exists?(user)
63
+ Reactor::Cm::User::Internal.get(user)
64
+ else
65
+ Reactor::Cm::User::Internal.create(user, personal_group(user))
66
+ end
68
67
 
69
- internal_user.change_password('thepasswordispassword')
68
+ internal_user.change_password("thepasswordispassword")
70
69
  end
71
70
  end
72
71
 
@@ -76,21 +75,21 @@ module Reactor
76
75
  @users.each do |user|
77
76
  signature = personal_signature(user)
78
77
  if Reactor::Cm::Attribute.exists?(signature)
79
- #Reactor::Cm::Attribute.get(signature)
78
+ # Reactor::Cm::Attribute.get(signature)
80
79
  @signatures[user] = signature
81
80
  else
82
- Reactor::Cm::Attribute.create(signature, 'signature')
81
+ Reactor::Cm::Attribute.create(signature, "signature")
83
82
  @signatures[user] = signature
84
83
  end
85
84
  end
86
85
  end
87
86
 
88
87
  def create_workflow
89
- if Reactor::Cm::Workflow.exists?(@workflow_name)
90
- @workflow = Reactor::Cm::Workflow.get(@workflow_name)
91
- else
92
- @workflow = Reactor::Cm::Workflow.create(@workflow_name)
93
- end
88
+ @workflow = if Reactor::Cm::Workflow.exists?(@workflow_name)
89
+ Reactor::Cm::Workflow.get(@workflow_name)
90
+ else
91
+ Reactor::Cm::Workflow.create(@workflow_name)
92
+ end
94
93
 
95
94
  # set up workflow steps
96
95
  @workflow.edit_groups = personal_groups(@editors)
@@ -98,8 +97,8 @@ module Reactor
98
97
  serialized_signatures = []
99
98
  @correctors.each do |corrector|
100
99
  signature = {
101
- :group => personal_group(corrector),
102
- :attribute => @signatures[corrector]
100
+ group: personal_group(corrector),
101
+ attribute: @signatures[corrector]
103
102
  }
104
103
  serialized_signatures << signature
105
104
  end
@@ -110,15 +109,15 @@ module Reactor
110
109
  end
111
110
 
112
111
  def create_obj_class
113
- @obj_class = if Reactor::Cm::ObjClass.exists?(@class_name)
114
- Reactor::Cm::ObjClass.get(@class_name)
115
- else
116
- Reactor::Cm::ObjClass.create(@class_name, 'publication')
112
+ @obj_class = if Reactor::Cm::ObjClass.exists?(@class_name)
113
+ Reactor::Cm::ObjClass.get(@class_name)
114
+ else
115
+ Reactor::Cm::ObjClass.create(@class_name, "publication")
117
116
  end
118
117
  end
119
118
 
120
119
  def create_obj
121
- @obj = Reactor::Cm::Obj.create(@obj_name, '/', @class_name)
120
+ @obj = Reactor::Cm::Obj.create(@obj_name, "/", @class_name)
122
121
  @obj.set(:workflowName, @workflow_name)
123
122
  @obj.save!
124
123
  end
@@ -187,10 +186,9 @@ module Reactor
187
186
  end
188
187
 
189
188
  def generate_token
190
- characters = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
191
- token = 8.times.map { characters[rand(characters.length)] }.join
189
+ characters = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a
190
+ Array.new(8) { characters[rand(characters.length)] }.join
192
191
  end
193
-
194
192
  end
195
193
  end
196
194
  end