rules_engine 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rules_engine/process/runner.rb +81 -75
- data/lib/rules_engine/process/runner/db_runner.rb +2 -2
- data/lib/rules_engine/rule/definition.rb +1 -1
- data/lib/rules_engine_view/alerts.rb +3 -4
- data/lib/rules_engine_view/navigate.rb +2 -2
- data/rails_generators/manifests/complex.rb +6 -6
- data/rails_generators/manifests/complex.yml +6 -6
- data/rails_generators/manifests/simple.rb +5 -5
- data/rails_generators/manifests/simple.yml +5 -5
- data/rails_generators/templates/app/controllers/re_plans_controller.rb +2 -2
- data/rails_generators/templates/app/models/re_plan.rb +7 -2
- data/rails_generators/templates/app/models/re_workflow.rb +8 -1
- data/rails_generators/templates/app/rules/complex.rb +21 -21
- data/rails_generators/templates/app/rules/simple.rb +4 -4
- data/rails_generators/templates/app/views/re_plan_workflows/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plan_workflows/new.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plans/_menu.html.erb +6 -8
- data/rails_generators/templates/app/views/re_plans/change.html.erb +1 -0
- data/rails_generators/templates/app/views/re_plans/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_plans/new.js.erb +2 -0
- data/rails_generators/templates/app/views/re_rules/complex/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form.html.erb +10 -10
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_form_word.html.erb +1 -1
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/complex/_help.html.erb +0 -0
- data/rails_generators/templates/app/views/re_rules/complex/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_rules/simple/_edit.html.erb +1 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_form.html.erb +0 -0
- data/rails_generators/templates/app/views/{re_rule_definitions → re_rules}/simple/_help.html.erb +0 -0
- data/rails_generators/templates/app/views/re_rules/simple/_new.html.erb +1 -0
- data/rails_generators/templates/app/views/re_workflows/edit.js.erb +2 -0
- data/rails_generators/templates/app/views/re_workflows/new.js.erb +3 -1
- data/rails_generators/templates/lib/tasks/rules_engine.rake +4 -4
- data/rails_generators/templates/public/javascripts/rules_engine/re_plan_change.js +13 -1
- data/rails_generators/templates/public/stylesheets/rules_engine/screen.css +2 -2
- data/rails_generators/templates/spec/controllers/re_plans_controller_spec.rb +0 -8
- data/rails_generators/templates/spec/lib/rules/complex_spec.rb +70 -69
- data/rails_generators/templates/spec/lib/rules/simple_spec.rb +8 -8
- data/rails_generators/templates/spec/models/re_plan_spec.rb +3 -3
- data/rails_generators/templates/spec/models/re_rule_spec.rb +14 -19
- data/rails_generators/templates/spec/models/re_workflow_spec.rb +9 -0
- data/spec/railsenv/log/debug.log +4050 -0
- data/spec/railsenv/log/test.log +592 -0
- data/spec/rules_engine/process/runner/db_runner_spec.rb +15 -16
- data/spec/rules_engine/process/runner_spec.rb +166 -113
- data/spec/rules_engine/rule/definition_spec.rb +2 -2
- metadata +13 -13
- data/rails_generators/templates/app/views/re_rule_definitions/complex/_edit.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/complex/_new.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/simple/_edit.html.erb +0 -1
- data/rails_generators/templates/app/views/re_rule_definitions/simple/_new.html.erb +0 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
@@ -40,8 +40,32 @@ module RulesEngine
|
|
40
40
|
# 0
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
43
|
+
def run_plan(process_id, plan, data = {})
|
44
|
+
RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : started", RulesEngine::Process::AUDIT_INFO)
|
45
|
+
|
46
|
+
success = _run_plan_workflow(process_id, plan, plan["workflow"], data)
|
47
|
+
|
48
|
+
if success
|
49
|
+
RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : success", RulesEngine::Process::AUDIT_SUCCESS)
|
50
|
+
else
|
51
|
+
RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : failure", RulesEngine::Process::AUDIT_FAILURE)
|
52
|
+
end
|
53
|
+
|
54
|
+
success
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_workflow(process_id, plan, workflow_name, data = {})
|
58
|
+
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : started", RulesEngine::Process::AUDIT_INFO)
|
59
|
+
|
60
|
+
success = _run_plan_workflow(process_id, plan, workflow_name, data)
|
61
|
+
|
62
|
+
if success
|
63
|
+
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : success", RulesEngine::Process::AUDIT_SUCCESS)
|
64
|
+
else
|
65
|
+
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : failure", RulesEngine::Process::AUDIT_FAILURE)
|
66
|
+
end
|
67
|
+
|
68
|
+
success
|
45
69
|
end
|
46
70
|
|
47
71
|
def status(process_id)
|
@@ -56,91 +80,73 @@ module RulesEngine
|
|
56
80
|
end
|
57
81
|
|
58
82
|
protected
|
59
|
-
def
|
83
|
+
def _run_plan_workflow(process_id, plan, workflow_name, data = {})
|
60
84
|
|
61
|
-
RulesEngine::Process.auditor.audit(process_id, "Plan : #{plan["code"]} : started", RulesEngine::Process::AUDIT_INFO)
|
62
|
-
|
63
85
|
workflow_count = 0
|
64
|
-
|
65
|
-
error = false
|
66
|
-
|
67
|
-
first_workflow = plan['first_workflow']
|
68
|
-
if (first_workflow.blank? || plan["workflow_#{first_workflow}"].nil?)
|
69
|
-
RulesEngine::Process.auditor.audit(process_id, "First Workflow : #{first_workflow} : missing", RulesEngine::Process::AUDIT_FAILURE)
|
70
|
-
error = done = true
|
71
|
-
end
|
72
|
-
|
73
|
-
current_workflow = first_workflow
|
74
|
-
next_workflow = ""
|
75
|
-
while (!done && workflow_count < @@max_workflows)
|
86
|
+
while (workflow_count < @@max_workflows)
|
76
87
|
workflow_count += 1
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
workflow = plan["workflow_#{current_workflow}"]
|
88
|
+
|
89
|
+
workflow = plan["workflow_#{workflow_name}"]
|
81
90
|
if workflow.nil?
|
82
|
-
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{
|
83
|
-
|
84
|
-
break
|
91
|
+
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{workflow_name} : not found", RulesEngine::Process::AUDIT_FAILURE)
|
92
|
+
return false;
|
85
93
|
end
|
86
|
-
|
87
|
-
workflow["rules"].each do | workflow_rule |
|
88
|
-
rule_class = RulesEngine::Discovery.rule_class(workflow_rule["rule_class_name"])
|
89
|
-
unless rule_class
|
90
|
-
RulesEngine::Process.auditor.audit(process_id, "Rule : #{workflow_rule["rule_class_name"]} : not found", RulesEngine::Process::AUDIT_FAILURE)
|
91
|
-
error = done = true
|
92
|
-
break
|
93
|
-
end
|
94
|
-
rule = rule_class.new
|
95
|
-
rule.data = workflow_rule["data"]
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
|
95
|
+
rule_outcome = _run_workflow_rules(process_id, plan, workflow, data)
|
96
|
+
|
97
|
+
if rule_outcome.nil?
|
98
|
+
return true
|
99
|
+
elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
100
|
+
return true
|
101
|
+
elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
|
102
|
+
return false
|
103
|
+
elsif rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
|
104
|
+
workflow_name = rule_outcome.workflow_code
|
105
|
+
else # rule_outcome.outcome == RulesEngine::Rule::Outcome::NEXT
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
end
|
100
109
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
break
|
105
|
-
end
|
106
|
-
|
107
|
-
if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
|
108
|
-
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : stop failure", RulesEngine::Process::AUDIT_FAILURE)
|
109
|
-
error = done = true
|
110
|
-
break
|
111
|
-
end
|
110
|
+
RulesEngine::Process.auditor.audit(process_id, "Maximum workflow depth #{@@max_workflows} exceeded", RulesEngine::Process::PROCESS_STATUS_FAILURE)
|
111
|
+
return false
|
112
|
+
end
|
112
113
|
|
113
|
-
|
114
|
-
RulesEngine::Process.auditor.audit(process_id, "Workflow : #{current_workflow} : start next workflow - #{rule_outcome.workflow_code}", RulesEngine::Process::AUDIT_INFO)
|
115
|
-
next_workflow = rule_outcome.workflow_code
|
116
|
-
break
|
117
|
-
end
|
118
|
-
end
|
114
|
+
def _run_workflow_rules(process_id, plan, workflow, data = {})
|
119
115
|
|
120
|
-
|
121
|
-
current_workflow = workflow["next_workflow"]
|
122
|
-
else
|
123
|
-
current_workflow = next_workflow
|
124
|
-
end
|
116
|
+
RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : started", RulesEngine::Process::AUDIT_INFO)
|
125
117
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
118
|
+
workflow["rules"].each do | workflow_rule |
|
119
|
+
rule_class = RulesEngine::Discovery.rule_class(workflow_rule["rule_class_name"])
|
120
|
+
unless rule_class
|
121
|
+
RulesEngine::Process.auditor.audit(process_id, "Rule : #{workflow_rule["rule_class_name"]} : not found", RulesEngine::Process::AUDIT_FAILURE)
|
122
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
|
123
|
+
end
|
124
|
+
|
125
|
+
rule = rule_class.new
|
126
|
+
rule.data = workflow_rule["data"]
|
127
|
+
|
128
|
+
RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : starting")
|
129
|
+
rule_outcome = rule.process(process_id, plan, data)
|
130
|
+
RulesEngine::Process.auditor.audit(process_id, "Rule : #{rule.title} : finished")
|
136
131
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
end
|
132
|
+
if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_SUCCESS
|
133
|
+
RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
|
134
|
+
return rule_outcome
|
135
|
+
end
|
142
136
|
|
143
|
-
|
137
|
+
if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::STOP_FAILURE
|
138
|
+
RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop failure", RulesEngine::Process::AUDIT_FAILURE)
|
139
|
+
return rule_outcome
|
140
|
+
end
|
141
|
+
|
142
|
+
if !rule_outcome.nil? && rule_outcome.outcome == RulesEngine::Rule::Outcome::START_WORKFLOW
|
143
|
+
RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : start next workflow - #{rule_outcome.workflow_code}", RulesEngine::Process::AUDIT_INFO)
|
144
|
+
return rule_outcome
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
RulesEngine::Process.auditor.audit(process_id, "Rules For : #{workflow["code"]} : stop success", RulesEngine::Process::AUDIT_SUCCESS)
|
149
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
|
144
150
|
end
|
145
151
|
end
|
146
152
|
end
|
@@ -31,7 +31,7 @@ module RulesEngine
|
|
31
31
|
ReProcessRun.create(:process_status => RulesEngine::Process::PROCESS_STATUS_NONE).id
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
34
|
+
def run_plan(process_id, plan, data = {})
|
35
35
|
re_process = ReProcessRun.find_by_id(process_id)
|
36
36
|
|
37
37
|
if re_process.nil?
|
@@ -41,7 +41,7 @@ module RulesEngine
|
|
41
41
|
|
42
42
|
re_process.update_attributes(:plan_code => plan["code"], :plan_version => plan["version"], :started_at => Time.now.utc, :process_status => RulesEngine::Process::PROCESS_STATUS_RUNNING)
|
43
43
|
|
44
|
-
success =
|
44
|
+
success = super(process_id, plan, data)
|
45
45
|
|
46
46
|
re_process.update_attributes(:finished_at => Time.now.utc, :process_status => success ? RulesEngine::Process::PROCESS_STATUS_SUCCESS : RulesEngine::Process::PROCESS_STATUS_FAILURE)
|
47
47
|
|
@@ -76,7 +76,7 @@ module RulesEngine
|
|
76
76
|
# execute the rule
|
77
77
|
# return an RulesEngine::Rule::Outcome object to define what to do next
|
78
78
|
# if nil to continue to the next rule
|
79
|
-
def process(process_id, data)
|
79
|
+
def process(process_id, plan, data)
|
80
80
|
# process.audit("process #{title}", RulesEngine::Process::AUDIT_INFO)
|
81
81
|
# RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_SUCCESS)
|
82
82
|
# RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
|
@@ -7,7 +7,7 @@ module RulesEngineView
|
|
7
7
|
unless flash[:error].blank?
|
8
8
|
result << '<div class="error"><strong>Error : </strong><span>'
|
9
9
|
result << flash.delete(:error)
|
10
|
-
result << '</span></div>'
|
10
|
+
result << '</span><a class="re-alert-close" href="#">Close</a></div>'
|
11
11
|
|
12
12
|
flash.delete(:success)
|
13
13
|
flash.delete(:notice)
|
@@ -16,7 +16,7 @@ module RulesEngineView
|
|
16
16
|
unless flash[:success].blank?
|
17
17
|
result << '<div class="success"><strong>Success : </strong><span>'
|
18
18
|
result << flash.delete(:success)
|
19
|
-
result << '</span></div>'
|
19
|
+
result << '</span><a class="re-alert-close" href="#">Close</a></div>'
|
20
20
|
|
21
21
|
flash.delete(:notice)
|
22
22
|
end
|
@@ -24,9 +24,8 @@ module RulesEngineView
|
|
24
24
|
unless flash[:notice].blank?
|
25
25
|
result << '<div class="notice"><strong>Warning : </strong><span>'
|
26
26
|
result << flash.delete(:notice)
|
27
|
-
result << '</span></div>'
|
27
|
+
result << '</span><a class="re-alert-close" href="#">Close</a></div>'
|
28
28
|
end
|
29
|
-
|
30
29
|
result << '</div>'
|
31
30
|
|
32
31
|
return result
|
@@ -12,7 +12,7 @@ module RulesEngineView
|
|
12
12
|
result << "<em>"
|
13
13
|
result << "#{links[-1]}"
|
14
14
|
result << "</em>"
|
15
|
-
result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-1] == links[0]
|
15
|
+
# result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-1] == links[0]
|
16
16
|
result << '</div>'
|
17
17
|
result
|
18
18
|
end
|
@@ -28,7 +28,7 @@ module RulesEngineView
|
|
28
28
|
result << "<em>"
|
29
29
|
result << "#{links[-2]}"
|
30
30
|
result << "</em>"
|
31
|
-
result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-2] == links[0]
|
31
|
+
# result << "<span class='re-breadcrumbs-seperator'>></span>" if links[-2] == links[0]
|
32
32
|
|
33
33
|
result << "<div class='re-breadcrumb-right'>#{links[-1]}</div>"
|
34
34
|
result << '</div>'
|
@@ -3,7 +3,7 @@ class ComplexManifest
|
|
3
3
|
|
4
4
|
%W(
|
5
5
|
app/rules
|
6
|
-
app/views/
|
6
|
+
app/views/re_rules/#{rule_name}
|
7
7
|
spec/lib/rules
|
8
8
|
).each do |dirname|
|
9
9
|
m.directory dirname
|
@@ -15,11 +15,11 @@ class ComplexManifest
|
|
15
15
|
end
|
16
16
|
|
17
17
|
m.template "app/rules/complex.rb", "app/rules/#{rule_name}.rb"
|
18
|
-
m.template "app/views/
|
19
|
-
m.template "app/views/
|
20
|
-
m.template "app/views/
|
21
|
-
m.template "app/views/
|
22
|
-
m.template "app/views/
|
18
|
+
m.template "app/views/re_rules/complex/_edit.html.erb", "app/views/re_rules/#{rule_name}/_edit.html.erb"
|
19
|
+
m.template "app/views/re_rules/complex/_form.html.erb", "app/views/re_rules/#{rule_name}/_form.html.erb"
|
20
|
+
m.template "app/views/re_rules/complex/_form_word.html.erb", "app/views/re_rules/#{rule_name}/_form_word.html.erb"
|
21
|
+
m.template "app/views/re_rules/complex/_help.html.erb", "app/views/re_rules/#{rule_name}/_help.html.erb"
|
22
|
+
m.template "app/views/re_rules/complex/_new.html.erb", "app/views/re_rules/#{rule_name}/_new.html.erb"
|
23
23
|
m.template "spec/lib/rules/complex_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
|
24
24
|
|
25
25
|
end
|
@@ -8,13 +8,13 @@ templates :
|
|
8
8
|
- Complex : rule_class
|
9
9
|
|
10
10
|
directories :
|
11
|
-
- app/views/
|
11
|
+
- app/views/re_rules/complex
|
12
12
|
|
13
13
|
files :
|
14
14
|
- app/rules/complex.rb
|
15
|
-
- app/views/
|
16
|
-
- app/views/
|
17
|
-
- app/views/
|
18
|
-
- app/views/
|
19
|
-
- app/views/
|
15
|
+
- app/views/re_rules/complex/_edit.html.erb
|
16
|
+
- app/views/re_rules/complex/_form_word.html.erb
|
17
|
+
- app/views/re_rules/complex/_form.html.erb
|
18
|
+
- app/views/re_rules/complex/_help.html.erb
|
19
|
+
- app/views/re_rules/complex/_new.html.erb
|
20
20
|
- spec/lib/rules/complex_spec.rb
|
@@ -3,7 +3,7 @@ class SimpleManifest
|
|
3
3
|
|
4
4
|
%W(
|
5
5
|
app/rules
|
6
|
-
app/views/
|
6
|
+
app/views/re_rules/#{rule_name}
|
7
7
|
spec/lib/rules
|
8
8
|
).each do |dirname|
|
9
9
|
m.directory dirname
|
@@ -15,10 +15,10 @@ class SimpleManifest
|
|
15
15
|
end
|
16
16
|
|
17
17
|
m.template "app/rules/simple.rb", "app/rules/#{rule_name}.rb"
|
18
|
-
m.template "app/views/
|
19
|
-
m.template "app/views/
|
20
|
-
m.template "app/views/
|
21
|
-
m.template "app/views/
|
18
|
+
m.template "app/views/re_rules/simple/_edit.html.erb", "app/views/re_rules/#{rule_name}/_edit.html.erb"
|
19
|
+
m.template "app/views/re_rules/simple/_form.html.erb", "app/views/re_rules/#{rule_name}/_form.html.erb"
|
20
|
+
m.template "app/views/re_rules/simple/_help.html.erb", "app/views/re_rules/#{rule_name}/_help.html.erb"
|
21
|
+
m.template "app/views/re_rules/simple/_new.html.erb", "app/views/re_rules/#{rule_name}/_new.html.erb"
|
22
22
|
m.template "spec/lib/rules/simple_spec.rb", "spec/lib/rules/#{rule_name}_spec.rb"
|
23
23
|
|
24
24
|
end
|
@@ -8,13 +8,13 @@ templates :
|
|
8
8
|
- RuleSimple : rule_class
|
9
9
|
|
10
10
|
directories :
|
11
|
-
- app/views/
|
11
|
+
- app/views/re_rules/simple
|
12
12
|
|
13
13
|
files :
|
14
14
|
- app/rules/simple.rb
|
15
|
-
- app/views/
|
16
|
-
- app/views/
|
17
|
-
- app/views/
|
18
|
-
- app/views/
|
15
|
+
- app/views/re_rules/simple/_edit.html.erb
|
16
|
+
- app/views/re_rules/simple/_form.html.erb
|
17
|
+
- app/views/re_rules/simple/_help.html.erb
|
18
|
+
- app/views/re_rules/simple/_new.html.erb
|
19
19
|
- spec/lib/rules/simple_spec.rb
|
20
20
|
|
@@ -86,8 +86,8 @@ class RePlansController < ApplicationController
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def publish
|
89
|
-
if
|
90
|
-
flash[:error] = '
|
89
|
+
if params['tag'].blank?
|
90
|
+
flash[:error] = 'Tag Required.'
|
91
91
|
else
|
92
92
|
@re_plan.plan_version = RulesEngine::Publish.publisher.publish(@re_plan.code, params['tag'], @re_plan.publish)
|
93
93
|
@re_plan.plan_status = RePlan::PLAN_STATUS_PUBLISHED
|
@@ -38,7 +38,7 @@ class RePlan < ActiveRecord::Base
|
|
38
38
|
"code" => code,
|
39
39
|
"title" => title,
|
40
40
|
"description" => description,
|
41
|
-
"
|
41
|
+
"workflow" => re_workflows.empty? ? '' : re_workflows[0].code,
|
42
42
|
}
|
43
43
|
re_workflows.each_with_index do | re_workflow, index |
|
44
44
|
data["workflow_#{re_workflow.code}"] = re_workflow.publish
|
@@ -59,7 +59,7 @@ class RePlan < ActiveRecord::Base
|
|
59
59
|
self.description = rule_data["description"]
|
60
60
|
|
61
61
|
orig_re_workflows = []
|
62
|
-
workflow_data = rule_data["workflow_#{rule_data["
|
62
|
+
workflow_data = rule_data["workflow_#{rule_data["workflow"]}"]
|
63
63
|
while (workflow_data && orig_re_workflows.length < 500)
|
64
64
|
workflow_code = workflow_data["code"]
|
65
65
|
re_workflow = ReWorkflow.find_by_code(workflow_code) || ReWorkflow.new
|
@@ -93,7 +93,12 @@ class RePlan < ActiveRecord::Base
|
|
93
93
|
return if self.re_workflows.empty? || self.re_workflows[0] == re_workflow
|
94
94
|
re_plan_workflow = re_plan_workflows.detect { | re_plan_workflow | re_plan_workflow.re_workflow_id == re_workflow.id}
|
95
95
|
return unless re_plan_workflow
|
96
|
+
|
96
97
|
re_plan_workflow.move_to_top
|
98
|
+
|
99
|
+
self.re_plan_workflows(true)
|
100
|
+
self.re_workflows(true)
|
101
|
+
|
97
102
|
changed!
|
98
103
|
end
|
99
104
|
|
@@ -10,11 +10,18 @@ class ReWorkflow < ActiveRecord::Base
|
|
10
10
|
named_scope :order_code, :order => 're_workflows.code ASC'
|
11
11
|
named_scope :order_title, :order => 're_workflows.title ASC'
|
12
12
|
|
13
|
-
before_save
|
13
|
+
before_save :before_save_workflow
|
14
|
+
before_destroy :before_destroy_workflow
|
14
15
|
|
15
16
|
def before_save_workflow
|
16
17
|
self.changed! if changes.detect { |change| !ignore_attributes.include?(change[0])}
|
17
18
|
end
|
19
|
+
|
20
|
+
def before_destroy_workflow
|
21
|
+
re_plans.each do |re_plan|
|
22
|
+
re_plan.changed!
|
23
|
+
end
|
24
|
+
end
|
18
25
|
|
19
26
|
def code=(new_code)
|
20
27
|
self[:code] = new_code.strip.downcase.gsub(/[^a-zA-Z0-9]+/i, '_') if new_code && new_record?
|
@@ -2,9 +2,9 @@ module RulesEngine
|
|
2
2
|
module Rule
|
3
3
|
class <%=rule_class%> < RulesEngine::Rule::Definition
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :match_words
|
6
6
|
attr_reader :workflow_action
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :workflow_code
|
8
8
|
|
9
9
|
##################################################################
|
10
10
|
# class options
|
@@ -12,9 +12,9 @@ module RulesEngine
|
|
12
12
|
{
|
13
13
|
:group => 'General',
|
14
14
|
:display_name => '<%=rule_class%>',
|
15
|
-
:help_partial => '/
|
16
|
-
:new_partial => '/
|
17
|
-
:edit_partial => '/
|
15
|
+
:help_partial => '/re_rules/<%=rule_name%>/help',
|
16
|
+
:new_partial => '/re_rules/<%=rule_name%>/new',
|
17
|
+
:edit_partial => '/re_rules/<%=rule_name%>/edit'
|
18
18
|
}
|
19
19
|
|
20
20
|
##################################################################
|
@@ -22,11 +22,11 @@ module RulesEngine
|
|
22
22
|
def data= data
|
23
23
|
if data.nil?
|
24
24
|
@title = nil
|
25
|
-
@
|
25
|
+
@match_words = nil
|
26
26
|
@workflow_action = 'continue'
|
27
|
-
@
|
27
|
+
@workflow_code = nil
|
28
28
|
else
|
29
|
-
@title, @
|
29
|
+
@title, @match_words, @workflow_action, @workflow_code = ActiveSupport::JSON.decode(data)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -37,11 +37,11 @@ module RulesEngine
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def summary
|
40
|
-
"Match the #{
|
40
|
+
"Match the #{match_words.size == 1 ? 'word' : 'words'} #{match_words.join(', ')}"
|
41
41
|
end
|
42
42
|
|
43
43
|
def data
|
44
|
-
[title,
|
44
|
+
[title, match_words, workflow_action, workflow_code].to_json
|
45
45
|
end
|
46
46
|
|
47
47
|
def expected_outcomes
|
@@ -53,7 +53,7 @@ module RulesEngine
|
|
53
53
|
when 'stop_failure'
|
54
54
|
[:outcome => RulesEngine::Rule::Outcome::STOP_FAILURE]
|
55
55
|
when 'start_workflow'
|
56
|
-
[:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :title => "Start Workflow : #{
|
56
|
+
[:outcome => RulesEngine::Rule::Outcome::START_WORKFLOW, :title => "Start Workflow : #{workflow_code}"]
|
57
57
|
else
|
58
58
|
[:outcome => RulesEngine::Rule::Outcome::NEXT]
|
59
59
|
end
|
@@ -66,26 +66,26 @@ module RulesEngine
|
|
66
66
|
|
67
67
|
@title = param_hash[:<%=rule_name%>_title]
|
68
68
|
|
69
|
-
@
|
70
|
-
return if param_hash[:<%=rule_name%>
|
71
|
-
param_hash[:<%=rule_name%>
|
69
|
+
@match_words = []
|
70
|
+
return if param_hash[:<%=rule_name%>_match_words].nil?
|
71
|
+
param_hash[:<%=rule_name%>_match_words].each do |key, values|
|
72
72
|
if values.is_a?(Hash)
|
73
73
|
word_hash = values.symbolize_keys
|
74
|
-
@
|
74
|
+
@match_words << word_hash[:word].downcase unless word_hash[:word].blank? || word_hash[:_delete] == '1'
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
@workflow_action = param_hash[:<%=rule_name%>_workflow_action] || 'continue'
|
79
|
-
@
|
79
|
+
@workflow_code = param_hash[:<%=rule_name%>_workflow_code]
|
80
80
|
end
|
81
81
|
|
82
82
|
##################################################################
|
83
83
|
# validation and errors
|
84
84
|
def valid?
|
85
85
|
@errors = {}
|
86
|
-
@errors[:<%=rule_name%>_words] = "At least one word must be defined" if words.nil? || words.empty?
|
87
86
|
@errors[:<%=rule_name%>_title] = "Title required" if title.blank?
|
88
|
-
@errors[:<%=rule_name%>
|
87
|
+
@errors[:<%=rule_name%>_match_words] = "At least one word must be defined" if match_words.nil? || match_words.empty?
|
88
|
+
@errors[:<%=rule_name%>_workflow_code] = "Workflow code required" if workflow_action == 'start_workflow' && workflow_code.blank?
|
89
89
|
return @errors.empty?
|
90
90
|
end
|
91
91
|
|
@@ -105,13 +105,13 @@ module RulesEngine
|
|
105
105
|
# if a match is found procees to the expected outcome
|
106
106
|
# it gets the data parameter :tweet
|
107
107
|
# it sets the data parameter :match
|
108
|
-
def process(process_id, data)
|
108
|
+
def process(process_id, plan, data)
|
109
109
|
tweet = data[:tweet] || data["tweet"]
|
110
110
|
if tweet.blank?
|
111
111
|
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
|
112
112
|
end
|
113
113
|
|
114
|
-
|
114
|
+
match_words.each do |word|
|
115
115
|
if /\b#{word}\b/i =~ tweet
|
116
116
|
RulesEngine::Process.auditor.audit(process_id, "Found #{word}", RulesEngine::Process::AUDIT_INFO)
|
117
117
|
data[:tweet_match] = word
|
@@ -122,7 +122,7 @@ module RulesEngine
|
|
122
122
|
when 'stop_failure'
|
123
123
|
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::STOP_FAILURE)
|
124
124
|
when 'start_workflow'
|
125
|
-
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW,
|
125
|
+
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::START_WORKFLOW, workflow_code)
|
126
126
|
else #'next'
|
127
127
|
return RulesEngine::Rule::Outcome.new(RulesEngine::Rule::Outcome::NEXT)
|
128
128
|
end
|