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.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -0
- data/.rubocop_todo.yml +363 -0
- data/Rakefile +10 -13
- data/app/models/rails_connector/abstract_obj.rb +2 -1
- data/config/routes.rb +0 -1
- data/infopark_reactor.gemspec +16 -15
- data/lib/generators/cm/migration/migration_generator.rb +4 -8
- data/lib/infopark_reactor.rb +43 -69
- data/lib/reactor/already_released.rb +1 -2
- data/lib/reactor/attributes.rb +92 -268
- data/lib/reactor/attributes/date_serializer.rb +20 -16
- data/lib/reactor/attributes/html_serializer.rb +6 -5
- data/lib/reactor/attributes/link_list_extender.rb +10 -8
- data/lib/reactor/attributes/link_list_from_accessor.rb +2 -1
- data/lib/reactor/attributes/link_list_from_attr_values.rb +2 -1
- data/lib/reactor/attributes/link_list_serializer.rb +8 -7
- data/lib/reactor/attributes_handlers.rb +164 -0
- data/lib/reactor/cache/permission.rb +6 -9
- data/lib/reactor/cache/user.rb +3 -6
- data/lib/reactor/cm/attribute.rb +16 -16
- data/lib/reactor/cm/attribute_group.rb +18 -21
- data/lib/reactor/cm/blob_too_small_error.rb +2 -2
- data/lib/reactor/cm/bridge.rb +6 -9
- data/lib/reactor/cm/channel.rb +3 -4
- data/lib/reactor/cm/editorial_group.rb +2 -9
- data/lib/reactor/cm/group.rb +30 -43
- data/lib/reactor/cm/job.rb +23 -25
- data/lib/reactor/cm/language.rb +21 -22
- data/lib/reactor/cm/link.rb +38 -40
- data/lib/reactor/cm/live_group.rb +2 -9
- data/lib/reactor/cm/log_entry.rb +22 -21
- data/lib/reactor/cm/missing_credentials.rb +3 -2
- data/lib/reactor/cm/multi_xml_request.rb +22 -25
- data/lib/reactor/cm/obj.rb +159 -154
- data/lib/reactor/cm/obj_class.rb +52 -51
- data/lib/reactor/cm/object_base.rb +26 -21
- data/lib/reactor/cm/permissions.rb +7 -7
- data/lib/reactor/cm/user.rb +43 -51
- data/lib/reactor/cm/workflow.rb +11 -12
- data/lib/reactor/cm/xml_attribute.rb +10 -19
- data/lib/reactor/cm/xml_markup.rb +7 -10
- data/lib/reactor/cm/xml_multi_request_error.rb +1 -3
- data/lib/reactor/cm/xml_request.rb +21 -29
- data/lib/reactor/cm/xml_request_error.rb +1 -3
- data/lib/reactor/cm/xml_response.rb +8 -16
- data/lib/reactor/cm/xml_single_request_error.rb +3 -5
- data/lib/reactor/configuration.rb +1 -3
- data/lib/reactor/engine.rb +5 -10
- data/lib/reactor/legacy.rb +6 -7
- data/lib/reactor/link/external.rb +8 -5
- data/lib/reactor/link/internal.rb +8 -5
- data/lib/reactor/link/temporary_link.rb +16 -17
- data/lib/reactor/main.rb +11 -15
- data/lib/reactor/migration.rb +52 -53
- data/lib/reactor/no_working_version.rb +1 -2
- data/lib/reactor/not_permitted.rb +1 -2
- data/lib/reactor/permission.rb +36 -38
- data/lib/reactor/persistence.rb +104 -178
- data/lib/reactor/plans/common_attribute.rb +7 -7
- data/lib/reactor/plans/common_attribute_group.rb +6 -6
- data/lib/reactor/plans/common_channel.rb +6 -6
- data/lib/reactor/plans/common_group.rb +7 -14
- data/lib/reactor/plans/common_job.rb +6 -6
- data/lib/reactor/plans/common_obj_class.rb +11 -11
- data/lib/reactor/plans/create_attribute.rb +1 -3
- data/lib/reactor/plans/create_attribute_group.rb +1 -3
- data/lib/reactor/plans/create_channel.rb +2 -3
- data/lib/reactor/plans/create_group.rb +3 -10
- data/lib/reactor/plans/create_job.rb +3 -4
- data/lib/reactor/plans/create_obj.rb +12 -14
- data/lib/reactor/plans/create_obj_class.rb +1 -2
- data/lib/reactor/plans/delete_attribute.rb +1 -3
- data/lib/reactor/plans/delete_attribute_group.rb +2 -4
- data/lib/reactor/plans/delete_channel.rb +3 -6
- data/lib/reactor/plans/delete_group.rb +2 -9
- data/lib/reactor/plans/delete_job.rb +3 -5
- data/lib/reactor/plans/delete_obj.rb +3 -4
- data/lib/reactor/plans/delete_obj_class.rb +1 -2
- data/lib/reactor/plans/prepared.rb +3 -4
- data/lib/reactor/plans/rename_group.rb +4 -11
- data/lib/reactor/plans/rename_obj_class.rb +1 -2
- data/lib/reactor/plans/update_attribute.rb +1 -3
- data/lib/reactor/plans/update_attribute_group.rb +2 -4
- data/lib/reactor/plans/update_group.rb +2 -9
- data/lib/reactor/plans/update_job.rb +4 -8
- data/lib/reactor/plans/update_obj.rb +6 -7
- data/lib/reactor/plans/update_obj_class.rb +0 -2
- data/lib/reactor/rc_independent.rb +0 -1
- data/lib/reactor/session.rb +27 -31
- data/lib/reactor/session/observers.rb +3 -5
- data/lib/reactor/session/user.rb +6 -7
- data/lib/reactor/session_helper/auth_filter.rb +9 -0
- data/lib/reactor/session_helper/auth_helper.rb +24 -0
- data/lib/reactor/session_helper/rsession_helper.rb +16 -0
- data/lib/reactor/session_helper/session_state.rb +31 -0
- data/lib/reactor/streaming_upload.rb +0 -1
- data/lib/reactor/sudo.rb +2 -3
- data/lib/reactor/support/link_matcher.rb +8 -7
- data/lib/reactor/tools/migrator.rb +30 -35
- data/lib/reactor/tools/response_handler/xml_attribute.rb +27 -33
- data/lib/reactor/tools/smart_xml_logger.rb +20 -22
- data/lib/reactor/tools/sower.rb +22 -23
- data/lib/reactor/tools/uploader.rb +12 -17
- data/lib/reactor/tools/versioner.rb +29 -30
- data/lib/reactor/tools/where_query.rb +11 -14
- data/lib/reactor/tools/workflow_generator.rb +26 -28
- data/lib/reactor/tools/xml_attributes.rb +7 -14
- data/lib/reactor/tools/xpath_extractor.rb +2 -1
- data/lib/reactor/validations.rb +20 -16
- data/lib/reactor/version.rb +1 -2
- data/lib/reactor/workflow.rb +10 -33
- data/lib/reactor/workflow/comment.rb +28 -0
- data/lib/reactor/workflow/empty.rb +0 -1
- data/lib/reactor/workflow/standard.rb +4 -3
- data/lib/tasks/cm_migrate.rake +3 -3
- data/lib/tasks/cm_seeds.rake +9 -16
- metadata +64 -28
- data/app/models/rails_connector/abstract_model.rb +0 -7
- data/app/models/rails_connector/attribute.rb +0 -94
- data/app/models/rails_connector/blob_mapping.rb +0 -16
- data/app/models/rails_connector/channel.rb +0 -41
- data/app/models/rails_connector/content.rb +0 -12
- data/app/models/rails_connector/job.rb +0 -14
- data/app/models/rails_connector/obj_class.rb +0 -158
- data/app/models/rails_connector/obj_class_attr.rb +0 -5
- data/app/models/rails_connector/object_with_meta_data.rb +0 -18
- data/lib/rails_connector/meta/eager_loader.rb +0 -91
- data/lib/reactor/rails_connector_meta.rb +0 -149
- data/lib/reactor/session_helper.rb +0 -72
@@ -1,8 +1,6 @@
|
|
1
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
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 =
|
44
|
+
out = " " * indent
|
46
45
|
|
47
|
-
attrs = node.attributes.values.map{|attr|
|
46
|
+
attrs = node.attributes.values.map { |attr| %(#{attr.name}="#{attr.value}") }.join(" ")
|
48
47
|
attrs = " #{attrs}" if attrs.present?
|
49
48
|
|
50
|
-
out << "<#{
|
49
|
+
out << "<#{node.name}#{attrs}#{"/" if empty}>"
|
51
50
|
|
52
|
-
if has_text
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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 <<
|
58
|
+
out << print_node(child, indent + 2)
|
60
59
|
end
|
61
60
|
|
62
|
-
out <<
|
63
|
-
out << "</#{
|
61
|
+
out << " " * indent unless has_text || empty
|
62
|
+
out << "</#{node.name}>\n" unless empty
|
64
63
|
out
|
65
64
|
end
|
66
|
-
|
67
65
|
end
|
data/lib/reactor/tools/sower.rb
CHANGED
@@ -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
|
26
|
-
|
27
|
-
#obj.
|
28
|
-
#obj.
|
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 =
|
45
|
-
obj = Obj.find_by_path(File.join(
|
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(:
|
45
|
+
obj = Obj.create(name: name, parent: path, obj_class: objClass)
|
48
46
|
else
|
49
|
-
obj = Obj.find_by_path(File.join(
|
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(
|
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 || !
|
60
|
+
obj.release unless obj.keep_edited || !obj.reload.edited?
|
63
61
|
obj
|
64
62
|
end
|
65
63
|
|
66
|
-
def self.with(path, objClass =
|
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
|
-
|
71
|
-
subpath = splitted_path[0,(i+1)].join(
|
72
|
-
subpath_parent = splitted_path[0,i].join(
|
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
|
-
|
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(
|
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
|
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=>{:
|
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 =
|
62
|
-
|
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(
|
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
|
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
|
95
|
+
if io.respond_to?(:stat)
|
101
96
|
# For files it is easy to read the filesize
|
102
|
-
|
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(
|
129
|
-
|
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
|
-
|
2
|
-
require
|
3
|
-
require
|
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,
|
33
|
-
xml.get_key_tag!(base_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
|
-
|
37
|
-
rescue
|
38
|
-
|
35
|
+
response.ok?
|
36
|
+
rescue StandardError
|
37
|
+
false
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
41
|
def load
|
43
|
-
create
|
42
|
+
create unless exists?
|
44
43
|
request = Reactor::Cm::XmlRequest.prepare do |xml|
|
45
|
-
xml.where_key_tag!(base_name,
|
46
|
-
xml.get_key_tag!(base_name,
|
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
|
51
|
-
data = YAML
|
52
|
-
return [] if data.nil?
|
53
|
-
|
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
|
57
|
+
create unless exists?
|
58
58
|
yaml = data.to_yaml
|
59
|
-
base64 = Base64
|
60
|
-
content =
|
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,
|
63
|
-
xml.set_key_tag!(base_name,
|
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!(
|
72
|
+
xml.tag!("name") do
|
73
73
|
xml.text!(name)
|
74
74
|
end
|
75
|
-
xml.tag!(
|
76
|
-
xml.text!(
|
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
|
-
|
108
|
+
!@versions.delete(version.to_s).nil?
|
109
109
|
end
|
110
110
|
|
111
|
-
|
112
|
-
@versions
|
113
|
-
end
|
111
|
+
attr_reader :versions
|
114
112
|
|
115
113
|
def current_version
|
116
|
-
current = @versions.
|
114
|
+
current = @versions.max
|
117
115
|
return 0 if current.nil?
|
118
|
-
|
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!(
|
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!(
|
14
|
-
|
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("//#{
|
22
|
-
result = [result] unless result.
|
19
|
+
result = response.xpath("//#{base_name}")
|
20
|
+
result = [result] unless result.is_a?(Array)
|
23
21
|
result.map do |elem|
|
24
|
-
values =
|
25
|
-
|
26
|
-
|
27
|
-
|
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}=",
|
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
|
14
|
-
@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(:
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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(
|
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,
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
:
|
102
|
-
:
|
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
|
114
|
-
|
115
|
-
|
116
|
-
|
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,
|
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 = (
|
191
|
-
|
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
|