bizflow 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +105 -0
  7. data/Rakefile +2 -0
  8. data/bin/bizflow +28 -0
  9. data/bizflow.gemspec +29 -0
  10. data/lib/bizflow/business_model/handler.rb +13 -0
  11. data/lib/bizflow/business_model/head.rb +34 -0
  12. data/lib/bizflow/business_model/input_action.rb +47 -0
  13. data/lib/bizflow/business_model/process.rb +46 -0
  14. data/lib/bizflow/business_model/simple_wrapper.rb +22 -0
  15. data/lib/bizflow/business_model/task.rb +41 -0
  16. data/lib/bizflow/business_model/task_action.rb +36 -0
  17. data/lib/bizflow/command/build_command.rb +33 -0
  18. data/lib/bizflow/command/clean_command.rb +9 -0
  19. data/lib/bizflow/command/command_helper.rb +19 -0
  20. data/lib/bizflow/command/help_command.rb +11 -0
  21. data/lib/bizflow/command/install_command.rb +16 -0
  22. data/lib/bizflow/command/setup_command.rb +29 -0
  23. data/lib/bizflow/config_generator.rb +16 -0
  24. data/lib/bizflow/data_model/action.rb +22 -0
  25. data/lib/bizflow/data_model/action_blueprint.rb +22 -0
  26. data/lib/bizflow/data_model/handler.rb +16 -0
  27. data/lib/bizflow/data_model/handler_blueprint.rb +17 -0
  28. data/lib/bizflow/data_model/head.rb +16 -0
  29. data/lib/bizflow/data_model/next_action.rb +17 -0
  30. data/lib/bizflow/data_model/next_action_blueprint.rb +17 -0
  31. data/lib/bizflow/data_model/process.rb +31 -0
  32. data/lib/bizflow/data_model/process_blueprint.rb +17 -0
  33. data/lib/bizflow/data_model/task.rb +17 -0
  34. data/lib/bizflow/data_model/task_blueprint.rb +17 -0
  35. data/lib/bizflow/fakes/action.rb +23 -0
  36. data/lib/bizflow/fakes/action_blueprint.rb +24 -0
  37. data/lib/bizflow/fakes/handler.rb +15 -0
  38. data/lib/bizflow/fakes/handler_blueprint.rb +18 -0
  39. data/lib/bizflow/fakes/head.rb +14 -0
  40. data/lib/bizflow/fakes/process.rb +20 -0
  41. data/lib/bizflow/fakes/process_blueprint.rb +14 -0
  42. data/lib/bizflow/fakes/task.rb +16 -0
  43. data/lib/bizflow/fakes/task_blueprint.rb +19 -0
  44. data/lib/bizflow/interpreters/domain_interpreter.rb +19 -0
  45. data/lib/bizflow/interpreters/input_action_interpreter.rb +35 -0
  46. data/lib/bizflow/interpreters/process_interpreter.rb +37 -0
  47. data/lib/bizflow/interpreters/task_action_interpreter.rb +29 -0
  48. data/lib/bizflow/lib/blueprint_builder.rb +90 -0
  49. data/lib/bizflow/lib/callback_handler.rb +27 -0
  50. data/lib/bizflow/lib/callbackable.rb +25 -0
  51. data/lib/bizflow/lib/process_builder.rb +61 -0
  52. data/lib/bizflow/lib/semantic_builder.rb +36 -0
  53. data/lib/bizflow/migrations/001_create_processes.rb +21 -0
  54. data/lib/bizflow/migrations/002_create_actions.rb +17 -0
  55. data/lib/bizflow/migrations/003_create_process_heads.rb +15 -0
  56. data/lib/bizflow/migrations/004_create_tasks.rb +16 -0
  57. data/lib/bizflow/migrations/005_create_process_blueprints.rb +14 -0
  58. data/lib/bizflow/migrations/006_action_blueprints.rb +16 -0
  59. data/lib/bizflow/migrations/007_next_action_blueprints.rb +14 -0
  60. data/lib/bizflow/migrations/008_handler_blueprints.rb +15 -0
  61. data/lib/bizflow/migrations/009_task_blueprints.rb +16 -0
  62. data/lib/bizflow/migrations/010_create_handlers.rb +16 -0
  63. data/lib/bizflow/migrations/011_next_actions.rb +14 -0
  64. data/lib/bizflow/monkey_patch.rb +12 -0
  65. data/lib/bizflow/repos/repo.rb +21 -0
  66. data/lib/bizflow/semantic_model/action.rb +29 -0
  67. data/lib/bizflow/semantic_model/domain_repo.rb +19 -0
  68. data/lib/bizflow/semantic_model/handler.rb +21 -0
  69. data/lib/bizflow/semantic_model/input_action.rb +19 -0
  70. data/lib/bizflow/semantic_model/process.rb +29 -0
  71. data/lib/bizflow/semantic_model/task.rb +18 -0
  72. data/lib/bizflow/semantic_model/task_action.rb +26 -0
  73. data/lib/bizflow/source_generator.rb +62 -0
  74. data/lib/bizflow/source_presenters/process_template_presenter.rb +26 -0
  75. data/lib/bizflow/templates/js/descriptor.tt +9 -0
  76. data/lib/bizflow/templates/js/process.tt +41 -0
  77. data/lib/bizflow/templates/rb/config.tt +11 -0
  78. data/lib/bizflow/templates/rb/handler.tt +4 -0
  79. data/lib/bizflow/templates/rb/process.tt +53 -0
  80. data/lib/bizflow/version.rb +3 -0
  81. data/lib/bizflow.rb +15 -0
  82. data/spec/factories/factories.rb +38 -0
  83. data/spec/spec_config.rb +42 -0
  84. data/spec/spec_helper.rb +89 -0
  85. data/spec/unit/business/business_process_spec.rb +203 -0
  86. data/spec/unit/business/process_alternative_spec.rb +77 -0
  87. data/spec/unit/command/build_order_spec.rb +44 -0
  88. data/spec/unit/command/build_spec.rb +44 -0
  89. data/spec/unit/creating_processes_spec.rb +59 -0
  90. data/spec/unit/dsl_scripts/breakfast/process_file.rb +50 -0
  91. data/spec/unit/dsl_scripts/order/order.rb +41 -0
  92. data/spec/unit/interpreters/interpreters_spec.rb +105 -0
  93. data/text/Master.odt +0 -0
  94. data/text/prezentacija.odp +0 -0
  95. data/text/zbornik.doc +0 -0
  96. metadata +248 -0
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class HandlerBlueprint < Sequel::Model
8
+
9
+ many_to_one :action_blueprint
10
+ one_to_many :handlers
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,16 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class Head < Sequel::Model
8
+
9
+ many_to_one :action
10
+ many_to_one :process
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class NextAction < Sequel::Model
8
+
9
+ many_to_one :action
10
+ many_to_one :next, :class => :'Bizflow::DataModel::Action'
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class NextActionBlueprint < Sequel::Model
8
+
9
+ many_to_one :action_blueprint
10
+ many_to_one :next_blueprint, :class => :'Bizflow::DataModel::ActionBlueprint'
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,31 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class Process < Sequel::Model
8
+
9
+ many_to_one :process_blueprint
10
+ one_to_many :actions
11
+ one_to_many :heads
12
+ one_to_one :start, :class => :'Bizflow::DataModel::Action'
13
+
14
+ def human_name
15
+ name.humanize
16
+ end
17
+
18
+ def head
19
+ heads.first
20
+ end
21
+
22
+ def current
23
+ head.action
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class ProcessBlueprint < Sequel::Model
8
+
9
+ one_to_many :processes
10
+ one_to_many :action_blueprints
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class Task < Sequel::Model
8
+
9
+ many_to_one :action
10
+ many_to_one :task_blueprint
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ require 'sequel'
2
+
3
+ module Bizflow
4
+
5
+ module DataModel
6
+
7
+ class TaskBlueprint < Sequel::Model
8
+
9
+ one_to_many :tasks
10
+ many_to_one :action_blueprint
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+
@@ -0,0 +1,23 @@
1
+ require_relative 'task'
2
+
3
+ module Bizflow
4
+ module Fakes
5
+ class Action
6
+
7
+ attr_accessor :name, :type, :process, :next_actions, :tasks, :handlers, :action_blueprint
8
+
9
+ def initialize(process, action_blueprint, name, type)
10
+ @process = process
11
+ @action_blueprint = action_blueprint
12
+ @name = name
13
+ @type = type
14
+ @tasks = []
15
+ end
16
+
17
+ def add_task(hash)
18
+ tasks << Bizflow::Fakes::Task.new(self, hash[:name], hash[:description])
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'task_blueprint'
2
+
3
+ module Bizflow
4
+ module Fakes
5
+ class ActionBlueprint
6
+
7
+ attr_accessor :name, :type, :description, :process_blueprint, :task_blueprints, :handler_blueprints
8
+
9
+ def initialize(process_blueprint, name, type, description = nil, task_blueprints = [], handler_blueprints)
10
+ @process_blueprint = process_blueprint
11
+ @name = name
12
+ @type = type
13
+ @description = description
14
+ @task_blueprints = task_blueprints
15
+ @handler_blueprints = handler_blueprints
16
+ end
17
+
18
+ def add_task(hash)
19
+ task_blueprints << Bizflow::Fakes::TaskBlueprint.new(self, hash[:name], hash[:description])
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Bizflow
2
+ module Fakes
3
+ class Handler
4
+
5
+ attr_accessor :name, :namespace, :action, :finished
6
+
7
+ def initialize(action, name, namespace)
8
+ @action = action
9
+ @name = name
10
+ @namespace = namespace
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'task_blueprint'
2
+
3
+ module Bizflow
4
+ module Fakes
5
+ class HandlerBlueprint
6
+
7
+ attr_accessor :name, :namespace, :description, :action_blueprint
8
+
9
+ def initialize(action_blueprint, name, namespace, description = nil)
10
+ @action_blueprint = action_blueprint
11
+ @name = name
12
+ @namespace = namespace
13
+ @description = description
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Bizflow
2
+ module Fakes
3
+ class Head
4
+
5
+ attr_accessor :process, :action
6
+
7
+ def initialize(process, action = nil)
8
+ @process = process
9
+ @actions = [action]
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module Bizflow
2
+ module Fakes
3
+ class Process
4
+
5
+ attr_accessor :name, :description, :actions, :heads, :start
6
+
7
+ def initialize(name, description = nil)
8
+ @name = name
9
+ @description = description
10
+ @heads = []
11
+ @actions = []
12
+ end
13
+
14
+ def update(*args)
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ module Bizflow
2
+ module Fakes
3
+ class Process
4
+
5
+ attr_accessor :name, :description
6
+
7
+ def initialize(name, description = nil)
8
+ @name = name
9
+ @description = description
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ module Bizflow
2
+ module Fakes
3
+ class Task
4
+
5
+ attr_accessor :name, :description, :action, :assignee_id, :auto_assign
6
+
7
+ def initialize(action, name, auto_assign = false, description = nil)
8
+ @action = action
9
+ @name = name
10
+ @description = description
11
+ @auto_assign = auto_assign
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'task_blueprint'
2
+
3
+ module Bizflow
4
+ module Fakes
5
+ class TaskBlueprint
6
+
7
+ attr_accessor :name, :roles, :description, :auto_assign, :action_blueprint
8
+
9
+ def initialize(action_blueprint, name, roles, description = nil, auto_assign = nil)
10
+ @action_blueprint = action_blueprint
11
+ @name = name
12
+ @roles = roles
13
+ @description = description
14
+ @auto_assign = auto_assign || false
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "bizflow/interpreters/process_interpreter"
2
+
3
+
4
+ class Bizflow::DomainInterpreter
5
+
6
+ attr_accessor :repo, :process_interpreter
7
+
8
+ def initialize(repo)
9
+ @repo = repo
10
+ end
11
+
12
+ def process(name, &action)
13
+ process_interpreter = Bizflow::ProcessInterpreter.new(name)
14
+ process_interpreter.instance_eval(&action)
15
+ repo.add_process(process_interpreter.process)
16
+ end
17
+
18
+
19
+ end
@@ -0,0 +1,35 @@
1
+
2
+ require "bizflow/semantic_model/input_action"
3
+ require "bizflow/semantic_model/handler"
4
+
5
+ class Bizflow::InputActionInterpreter
6
+
7
+ attr_accessor :action
8
+
9
+ def initialize(name)
10
+ @action = Bizflow::SemanticModel::InputAction.new(name)
11
+ end
12
+
13
+ def description(description)
14
+ action.description = description
15
+ end
16
+
17
+ def handler(name, options = {})
18
+ raise "handler for action already defined" if action.handler
19
+ action.handler = Bizflow::SemanticModel::Handler.new(name, options)
20
+ end
21
+
22
+ def next_actions(actions_hash)
23
+ raise "next actions already defined" if !action.next_actions.empty?
24
+ action.next_actions = actions_hash
25
+ end
26
+
27
+ def question(question)
28
+ action.question = question
29
+ end
30
+
31
+ def roles(roles_array)
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,37 @@
1
+ require "bizflow/interpreters/task_action_interpreter"
2
+ require "bizflow/interpreters/input_action_interpreter"
3
+ require "bizflow/semantic_model/process"
4
+
5
+ class Bizflow::ProcessInterpreter
6
+
7
+ attr_accessor :process, :task_action_interpreter, :input_action_interpreter
8
+
9
+ def initialize(process_name)
10
+ @process = Bizflow::SemanticModel::Process.new(process_name)
11
+ end
12
+
13
+ def input_action(name, &action)
14
+ input_action_interpreter = Bizflow::InputActionInterpreter.new(name)
15
+ input_action_interpreter.instance_eval(&action)
16
+ process.add_action(input_action_interpreter.action)
17
+ end
18
+
19
+ def task_action(name, &action)
20
+ task_action_interpreter = Bizflow::TaskActionInterpreter.new(name)
21
+ task_action_interpreter.instance_eval(&action)
22
+ process.add_action(task_action_interpreter.action)
23
+ end
24
+
25
+ def handler_action(name, &action)
26
+
27
+ end
28
+
29
+ def description(description)
30
+ process.description = description
31
+ end
32
+
33
+ def start(action_name)
34
+ process.start = action_name
35
+ end
36
+
37
+ end
@@ -0,0 +1,29 @@
1
+
2
+ require "bizflow/semantic_model/task_action"
3
+ require "bizflow/semantic_model/task"
4
+
5
+ class Bizflow::TaskActionInterpreter
6
+
7
+ attr_accessor :action
8
+
9
+ def initialize(name)
10
+ @action = Bizflow::SemanticModel::TaskAction.new(name)
11
+ end
12
+
13
+ def next_action(name)
14
+ action.next_action = name
15
+ end
16
+
17
+ def description(description)
18
+ action.description = description
19
+ end
20
+
21
+ def task(name, options)
22
+ action.add_task(Bizflow::SemanticModel::Task.new(name, options))
23
+ end
24
+
25
+ def input_task(name, options)
26
+ task(name, options)
27
+ end
28
+
29
+ end
@@ -0,0 +1,90 @@
1
+ require 'bizflow/data_model/process_blueprint'
2
+ require 'bizflow/data_model/action_blueprint'
3
+ require 'bizflow/data_model/task_blueprint'
4
+ require 'bizflow/data_model/next_action_blueprint'
5
+
6
+ module Bizflow
7
+ module Lib
8
+ class BlueprintBuilder
9
+
10
+ def build(semantic_repo)
11
+
12
+ semantic_repo.processes.each do |p|
13
+
14
+ # processes
15
+
16
+ process = Bizflow::DataModel::ProcessBlueprint.create(
17
+ name: p.name,
18
+ description: p.description,
19
+ start: p.start
20
+ )
21
+
22
+ p.actions.each do |a|
23
+
24
+ # actions
25
+
26
+ action = process.add_action_blueprint(
27
+ name: a.name,
28
+ type: a.type,
29
+ description: a.description,
30
+ question: a.question
31
+ )
32
+
33
+ # tasks
34
+
35
+ a.tasks.each do |t|
36
+ action.add_task_blueprint(
37
+ name: t.name,
38
+ roles: t.roles.join(" "),
39
+ description: t.description
40
+ )
41
+ end
42
+
43
+ end
44
+
45
+ data_actions = process.action_blueprints
46
+
47
+ # next_actions
48
+
49
+ p.actions.each do |a|
50
+
51
+ a.next_actions.each do |k, v|
52
+
53
+ ending = nil
54
+ ending = k.to_s if k != :only_one
55
+
56
+ current_action = data_actions.select { |acc| acc.name == a.name }.first
57
+ next_action = data_actions.select { |acc| acc.name == v }.first
58
+
59
+ Bizflow::DataModel::NextActionBlueprint.create(
60
+ action_blueprint: current_action,
61
+ next_blueprint: next_action,
62
+ ending: ending
63
+ )
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ private
74
+
75
+ def handle_next_blueprints(action)
76
+ res = []
77
+ if action.type == "task"
78
+ res = Bizflow::DataModel::NextActionBlueprint.new()
79
+ elsif action.type == "input"
80
+
81
+ else
82
+
83
+ end
84
+
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,27 @@
1
+ module Bizflow
2
+ module Lib
3
+ class CallbackHandler
4
+
5
+ attr_accessor :callbacks
6
+
7
+ def initialize
8
+ @callbacks = {}
9
+ end
10
+
11
+ def method_missing(name, *args, &block)
12
+ raise "Callback #{name} registered more times" if @callbacks[name.to_sym]
13
+ @callbacks[name.to_sym] = block
14
+ end
15
+
16
+ def callback(name, *args)
17
+ raise "Callback '#{name}' not registered" unless @callbacks[name.to_sym]
18
+ @callbacks[name.to_sym].call(args[0])
19
+ end
20
+
21
+ def clear
22
+ @callbacks.clear()
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'bizflow/lib/callback_handler'
2
+
3
+ module Bizflow
4
+ module Lib
5
+ module Callbackable
6
+
7
+ private
8
+
9
+ def setup_callbacks
10
+ raise "business method needs a block" unless block_given?
11
+ callback_handler.clear()
12
+ yield(callback_handler)
13
+ end
14
+
15
+ def callback(name, *args)
16
+ @callback_handler.callback(name, args[0])
17
+ end
18
+
19
+ def callback_handler
20
+ @callback_handler ||= Bizflow::Lib::CallbackHandler.new
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,61 @@
1
+ require 'bizflow/business_model/process'
2
+ require 'securerandom'
3
+
4
+
5
+ module Bizflow
6
+ module Lib
7
+ class ProcessBuilder
8
+
9
+ PID_LENGTH = 9
10
+
11
+ def build(blueprint_id, creator_id)
12
+
13
+ pbp = Bizflow::DataModel::ProcessBlueprint[blueprint_id]
14
+ raise "no process with id '#{blueprint_id}'" unless pbp
15
+
16
+ actions_map = {}
17
+
18
+ bp = Bizflow::DataModel::ProcessBlueprint.where(id: blueprint_id).eager(:action_blueprints => [:next_action_blueprints]).all.first
19
+ process = bp.add_process(
20
+ name: bp.name,
21
+ creator_id: creator_id,
22
+ description: bp.description,
23
+ pid: (SecureRandom.random_number * 10**PID_LENGTH).to_i)
24
+
25
+ bp.action_blueprints.each do |a|
26
+
27
+ action = Bizflow::DataModel::Action.create(
28
+ name: a.name,
29
+ type: a.type,
30
+ process: process,
31
+ description: a.description,
32
+ question: a.question,
33
+ action_blueprint_id: a.id)
34
+
35
+ actions_map[a.name] = action.id
36
+
37
+ process.update(start_action_id: action.id) if bp.start == a.name
38
+
39
+ end
40
+
41
+ bp.action_blueprints.each do |abp|
42
+
43
+ abp.next_action_blueprints.each do |nbp|
44
+ acc = Bizflow::DataModel::NextAction.create(
45
+ action_id: actions_map[nbp.action_blueprint.name],
46
+ next_id: nbp.next_blueprint ? actions_map[nbp.next_blueprint.name] : nil,
47
+ ending: nbp.ending
48
+ )
49
+
50
+ end
51
+
52
+ end
53
+
54
+ process.add_head({})
55
+
56
+ Bizflow::BusinessModel::Process.wrap(process)
57
+ end
58
+
59
+ end
60
+ end
61
+ end