Skip to content

Commit 624a038

Browse files
authored
Move dummy classes out of Flex module (#32)
- Move classes in dummy application out of Flex module - Namespace "application submitted" event to name of ApplicationForm subclass. In other words, publish "<classname>ApplicationSubmitted" instead of the "application submitted" string
1 parent 415bfe2 commit 624a038

28 files changed

Lines changed: 313 additions & 338 deletions

template/{{app_name}}/engines/flex/app/helpers/flex/event_manager.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def self.unsubscribe(subscription)
1616
end
1717

1818
def self.publish(event_key, payload = {})
19+
puts "Event Manager: Publishing event '#{event_key}' with payload: #{payload.inspect}"
1920
ActiveSupport::Notifications.instrument(event_key, payload)
2021
end
2122

template/{{app_name}}/engines/flex/app/models/flex/application_form.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ApplicationForm < ApplicationRecord
99
before_update :prevent_changes_if_submitted, if: :was_submitted?
1010

1111
def submit_application
12+
puts "Submitting application with ID: #{id}"
1213
self[:status] = :submitted
1314
save!
1415
publish_event
@@ -32,7 +33,8 @@ def prevent_changes_if_submitted
3233
end
3334

3435
def publish_event
35-
EventManager.publish("application_submitted", self.event_payload)
36+
puts "Publishing event #{self.class.name}Submitted for application with ID: #{id}"
37+
EventManager.publish("#{self.class.name}Submitted", self.event_payload)
3638
end
3739
end
3840
end

template/{{app_name}}/engines/flex/spec/dummy/app/business_processes/flex/passport_application_business_process_manager.rb

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
class PassportApplicationBusinessProcessManager
2+
include Singleton
3+
4+
attr_reader :business_process
5+
6+
private
7+
8+
def initialize
9+
@business_process = create_passport_application_business_process
10+
end
11+
12+
def create_passport_application_business_process
13+
business_process = Flex::BusinessProcess.new(
14+
name: 'Passport Application Process',
15+
find_case_callback: ->(case_id) { PassportCase.find(case_id) },
16+
description: 'Process for applying for a passport'
17+
)
18+
business_process.define_steps(
19+
{
20+
"collect_application_info" => Flex::UserTask.new(
21+
"Collect App Info",
22+
UserTaskCreationService
23+
),
24+
"verify_identity" => Flex::SystemProcess.new("Verify Identity", ->(kase) {
25+
IdentityVerificationService.new(kase).verify_identity # IdentityVerificationService would publish an event when verify_identity completes
26+
}),
27+
"manual_adjudicator_review" => Flex::UserTask.new("Manual Adjudicator Review", AdjudicatorTaskCreationService), # create an adjudicator task for manual review
28+
"review_passport_photo" => Flex::SystemProcess.new("Review Passport Photo", ->(kase) {
29+
PhotoVerificationService.new(kase).verify_photo # PhotoVerificationService would publish an event when verify_photo completes
30+
}),
31+
"notify_user_passport_approved" => Flex::SystemProcess.new("Notify Passport Approval", ->(kase) {
32+
UserNotificationService.new(kase).send_notification("approval") # UserNotificationService would publish an event when send_notification completes
33+
}),
34+
"notify_user_passport_rejected" => Flex::SystemProcess.new("Notify Passport Rejection", ->(kase) {
35+
UserNotificationService.new(kase).send_notification("rejection") # UserNotificationService would publish an event when send_notification completes
36+
})
37+
}
38+
)
39+
business_process.define_transitions(
40+
{
41+
"collect_application_info" => {
42+
"PassportApplicationFormSubmitted" => 'verify_identity',
43+
"application_cancelled" => 'end'
44+
},
45+
"verify_identity" => {
46+
"identity_verified" => 'review_passport_photo',
47+
"identity_warning" => 'manual_adjudicator_review'
48+
},
49+
"manual_adjudicator_review" => {
50+
"identity_verified" => 'review_passport_photo',
51+
"identity_rejected" => 'application_rejected'
52+
},
53+
"review_passport_photo" => {
54+
"passport_photo_approved" => 'notify_user_passport_approved',
55+
"passport_photo_rejected" => 'review_passport_photo'
56+
},
57+
"notify_user_passport_approved" => {
58+
"notification_completed" => "end"
59+
},
60+
"notify_user_passport_rejected" => {
61+
"notification_completed" => 'end'
62+
}
63+
}
64+
)
65+
business_process.define_start('collect_application_info')
66+
67+
business_process
68+
end
69+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ApplicationRecord < ActiveRecord::Base
2+
primary_abstract_class
3+
end

template/{{app_name}}/engines/flex/spec/dummy/app/models/flex/application_record.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

template/{{app_name}}/engines/flex/spec/dummy/app/models/flex/passport_application_form.rb

Lines changed: 0 additions & 40 deletions
This file was deleted.

template/{{app_name}}/engines/flex/spec/dummy/app/models/flex/passport_case.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class PassportApplicationForm < Flex::ApplicationForm
2+
before_create :create_passport_case, unless: -> { has_case_id? }
3+
4+
attribute :first_name, :string
5+
attribute :last_name, :string
6+
attribute :date_of_birth, :date
7+
8+
attribute :case_id, :integer
9+
private def case_id=(value)
10+
self[:case_id] = value
11+
end
12+
13+
def has_all_necessary_fields?
14+
!first_name.nil? && !last_name.nil? && !date_of_birth.nil?
15+
end
16+
17+
def submit_application
18+
has_all_necessary_fields? ? super : false
19+
end
20+
21+
protected
22+
23+
def event_payload
24+
parent_payload = super
25+
parent_payload.merge({ case_id: case_id })
26+
end
27+
28+
private
29+
30+
def has_case_id?
31+
!case_id.nil?
32+
end
33+
34+
def create_passport_case
35+
kase = PassportCase.create
36+
self.case_id = kase.id
37+
end
38+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class PassportCase < Flex::Case
2+
readonly attribute :passport_id, :string, default: SecureRandom.uuid # always defaults to a new UUID
3+
4+
attribute :business_process_current_step, :string, default: "collect_application_info"
5+
6+
after_create :initialize_business_process
7+
8+
private
9+
10+
def initialize_business_process
11+
business_process = PassportApplicationBusinessProcessManager.instance.business_process
12+
business_process.execute({ case_id: id })
13+
end
14+
end

0 commit comments

Comments
 (0)