Skip to content

Commit

Permalink
tenant, event connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWeinstein92 committed Mar 13, 2024
1 parent a83c90f commit 8cb8b58
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 45 deletions.
36 changes: 18 additions & 18 deletions src/main/riddl/Events/eventContext.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ context EventContext is {

handler EventHandler is {
on command CreateEvent {
send event EventCreated to outlet EventEvents.Events
send event EventCreated to outlet EventEventsSource.Events
morph entity Event to state DraftEvent with record DraftEventState
}
on other {
Expand All @@ -60,20 +60,20 @@ context EventContext is {
on command ScheduleEvent{
if "all required info fields are present" then {
"set a scheduled Akka call for emitting StartEvent at DraftEventState.info.expectedStart"
send event EventScheduled to outlet EventEvents.Events
send event EventScheduled to outlet EventEventsSource.Events
morph entity Event to state ScheduledEvent with record ScheduledEventState
}
}
on command EditEventInfo{
set field DraftEventState.info to "EventContext.newEditableInfoFromFieldsPresentInEditable"
set field DraftEventState.meta to "EventMetaInfo"
send event EventRescheduled
to outlet EventEvents.Events
to outlet EventEventsSource.Events
}
on command CancelEvent{
if "all required info fields are present" then {
"cancel associated scheduled call to emit StartEvent"
send event EventCancelled to outlet EventEvents.Events
send event EventCancelled to outlet EventEventsSource.Events
morph entity Event to state ScheduledEvent with record ScheduledEventState
}
}
Expand All @@ -82,13 +82,13 @@ context EventContext is {
"adjust associated scheduled call to emit StartEvent"
set field DraftEventState.info to "EditableEventInfo"
set field DraftEventState.meta to "EventMetaInfo"
send event EventRescheduled to outlet EventEvents.Events
send event EventRescheduled to outlet EventEventsSource.Events
}
}
on command DelayEvent{
if "all required info fields are present" then {
"adjust associated scheduled call to emit StartEvent"
send event EventDelayed to outlet EventEvents.Events
send event EventDelayed to outlet EventEventsSource.Events
morph entity Event to state ScheduledEvent with record ScheduledEventState
}
}
Expand Down Expand Up @@ -127,29 +127,29 @@ context EventContext is {
on command EditEventInfo {
set field ScheduledEventState.info to "EventContext.newInfoFromFieldsPresentInEditable"
set field ScheduledEventState.meta to "EventMetaInfo"
send event EventInfoEdited to outlet EventEvents.Events
send event EventInfoEdited to outlet EventEventsSource.Events
}
on command CancelEvent {
"cancel associated scheduled call to emit StartEvent"
send event EventCancelled to outlet EventEvents.Events
send event EventCancelled to outlet EventEventsSource.Events
become entity Event to handler CancelledEventHandler
}
on command DelayEvent {
"adjust associated scheduled Akka call to emit StartEvent"
send event EventDelayed to outlet EventEvents.Events
send event EventDelayed to outlet EventEventsSource.Events
become entity Event to handler DelayedEventHandler
}
on command StartEvent{
"create scheduled Akka call using ScheduledEventState.info.expectedEnd to emit EndEvent"
send event EventStarted to outlet EventEvents.Events
send event EventStarted to outlet EventEventsSource.Events
become entity Event to handler InProgressEventHandler
} briefly "to be invoked by Akka scheduler upon ScheduleEvent reception"
on command RescheduleEvent {
if "start is validated to be before end in command" then {
"adjust associated scheduled call to emit StartEvent"
set field ScheduledEventState.info to "EventInfo"
set field ScheduledEventState.meta to "EventMetaInfo"
send event EventRescheduled to outlet EventEvents.Events
send event EventRescheduled to outlet EventEventsSource.Events
}
}
on command EndEvent{
Expand Down Expand Up @@ -178,14 +178,14 @@ context EventContext is {
}
on command DelayEvent{
"adjust associated scheduled Akka call to emit StartEvent"
send event EventDelayed to outlet EventEvents.Events
send event EventDelayed to outlet EventEventsSource.Events
become entity Event to handler DelayedEventHandler
}
on command StartEvent {
error "Event is already started. Cannot start an event that is already in progress"
}
on command EndEvent {
send event EventEnded to outlet EventEvents.Events
send event EventEnded to outlet EventEventsSource.Events
become entity Event to handler PastEventHandler
}
// TODO: specify AddLiveUpdate on clause
Expand All @@ -203,27 +203,27 @@ context EventContext is {
on command EditEventInfo{
set field ScheduledEventState.info to "EventContext.newInfoFromFieldsPresentInEditable"
set field ScheduledEventState.meta to "EventMetaInfo"
send event EventInfoEdited to outlet EventEvents.Events
send event EventInfoEdited to outlet EventEventsSource.Events
}
on command CancelEvent{
"cancel associated scheduled call to emit StartEvent"
send event EventCancelled to outlet EventEvents.Events
send event EventCancelled to outlet EventEventsSource.Events
become entity Event to handler CancelledEventHandler
}
on command RescheduleEvent{
if "start is validated to be before end in command" then {
"adjust associated scheduled call to emit StartEvent"
set field ScheduledEventState.info to "EventInfo"
set field ScheduledEventState.meta to "EventMetaInfo"
send event EventRescheduled to outlet EventEvents.Events
send event EventRescheduled to outlet EventEventsSource.Events
}
}
on command DelayEvent{
error "Cannot delay a delayed event again, must be rescheduled"
}
on command StartEvent{
"create scheduled Akka call using ScheduledEventState.info.expectedEnd to emit EndEvent"
send event EventStarted to outlet EventEvents.Events
send event EventStarted to outlet EventEventsSource.Events
become entity Event to handler InProgressEventHandler
} briefly "to be invoked by Akka scheduler upon ScheduleEvent reception"
on command EndEvent{
Expand All @@ -240,7 +240,7 @@ context EventContext is {
"adjust associated scheduled call to emit StartEvent"
set field ScheduledEventState.info to "EventInfo"
set field ScheduledEventState.meta to "EventMetaInfo"
send event EventRescheduled to outlet EventEvents.Events
send event EventRescheduled to outlet EventEventsSource.Events
}
}
on other {
Expand Down
62 changes: 50 additions & 12 deletions src/main/riddl/Events/eventSources.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,54 @@
// } explained as "This is a source for things that happen as an event progresses"

//ReservationAddedToEvent,
type PublicEventEvent is one of {
Events.EventContext.EventInfoEdited,
Events.EventContext.EventCreated,
Events.EventContext.EventScheduled,
Events.EventContext.EventCancelled,
Events.EventContext.EventRescheduled,
Events.EventContext.EventDelayed,
Events.EventContext.EventStarted,
Events.EventContext.EventEnded

connector EventCommandsChannel is {
from outlet EventCommandsSource.Commands to
inlet EventCommandsSink.Commands
}

connector EventEventsChannel is {
from outlet EventEventsSource.Events to
inlet EventEventsSink.Events
}

source EventCommandsSource is {
outlet Commands is type EventCommand
}

sink EventCommandsSink is {
inlet Commands is type EventCommand
}
source EventEvents is {
outlet Events is type PublicEventEvent
} explained as "This is a source for event from Events entities"

source EventEventsSource is {
outlet Events is type EventEvent
}

sink EventEventsSink is {
inlet Events is type EventEvent
}

type EventCommand is one of {
EditEventInfo,
CreateEvent,
ScheduleEvent,
CancelEvent,
RescheduleEvent,
DelayEvent,
StartEvent,
EndEvent,
TerminateEvent,
AddLiveUpdate
}

type EventEvent is one of {
EventInfoEdited,
EventCreated,
EventScheduled,
EventCancelled,
EventRescheduled,
EventDelayed,
EventStarted,
EventEnded,
EventTerminated
}
14 changes: 7 additions & 7 deletions src/main/riddl/Tenant/tenant.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ context TenantContext is {
if "primaryContact info is not complete" then {
error "primaryContact must be complete in order to establish a Tenant"
} else {
send event TenantEstablished to outlet TenantEvents.Events
send event TenantEstablished to outlet TenantEventsSource.Events
morph entity Tenant to state EstablishedTenant with
record EstablishedTenantState
}
Expand Down Expand Up @@ -155,14 +155,14 @@ context TenantContext is {
"Copy fields which are present from TenantContext.EditInfo.newInfo into info fields"
set field EstablishedTenantState.meta to "record TenantContext.TenantMetaInfo"
send event TenantContext.InfoEdited
to outlet TenantEvents.Events
to outlet TenantEventsSource.Events
}
on command SuspendTenant {
if "updating user is not authorized to suspend tenant" then {
error "User is not authorized to suspend Tenant"
} else {
set field EstablishedTenantState.meta to "record TenantContext.TenantMetaInfo"
send event TenantContext.TenantSuspended to outlet TenantEvents.Events
send event TenantContext.TenantSuspended to outlet TenantEventsSource.Events
become entity Tenant to handler SuspendedTenantHandler
}
}
Expand All @@ -171,7 +171,7 @@ context TenantContext is {
error "User is not authorized to modify Tenant"
} else {
set field EstablishedTenantState.meta to "TenantContext.TenantMetaInfo"
send event TenantContext.TenantTerminated to outlet TenantEvents.Events
send event TenantContext.TenantTerminated to outlet TenantEventsSource.Events
morph entity Tenant to state TerminatedTenant with record TerminatedTenantState
}
}
Expand Down Expand Up @@ -215,14 +215,14 @@ context TenantContext is {
"Copy fields which are present from TenantContext.EditInfo.newInfo into info fields"
set field EstablishedTenantState.meta to "TenantContext.TenantMetaInfo"
send event TenantContext.InfoEdited
to outlet TenantEvents.Events
to outlet TenantEventsSource.Events
}
on command ActivateTenant {
if "updating user is not authorized to activate the tenant" then{
error "User is not authorized to Activate Tenant"
} else {
set field EstablishedTenantState.meta to "TenantContext.TenantMetaInfo"
send event TenantContext.TenantSuspended to outlet TenantEvents.Events
send event TenantContext.TenantSuspended to outlet TenantEventsSource.Events
become entity Tenant to handler ActiveTenantHandler
}
}
Expand All @@ -232,7 +232,7 @@ context TenantContext is {
} else {
// set field EstablishedTenantState.meta to "TenantContext.TenantMetaInfo"
send event TenantContext.TenantTerminated
to outlet TenantEvents.Events
to outlet TenantEventsSource.Events
morph entity Tenant to state TerminatedTenant with record TerminatedTenantState
}
}
Expand Down
47 changes: 39 additions & 8 deletions src/main/riddl/Tenant/tenantSources.riddl
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
type PublicTenantEvent is one of {
TenantContext.InfoEdited,
TenantContext.TenantActivated,
TenantContext.TenantSuspended,
TenantContext.TenantTerminated
connector TenantCommandsChannel is {
from outlet TenantCommandsSource.Commands to
inlet TenantCommandsSink.Commands
}

source TenantEvents is {
outlet Events is type PublicTenantEvent
} explained as "This is a source for Tenant Events"
connector TenantEventsChannel is {
from outlet TenantEventsSource.Events to
inlet TenantEventsSink.Events
}

source TenantCommandsSource is {
outlet Commands is type TenantCommand
}

sink TenantCommandsSink is {
inlet Commands is type TenantCommand
}

source TenantEventsSource is {
outlet Events is type TenantEvent
}

sink TenantEventsSink is {
inlet Events is type TenantEvent
}

type TenantCommand is one of {
EstablishTenant,
ActivateTenant,
SuspendTenant,
TerminateTenant,
EditInfo
}

type TenantEvent is one of {
TenantEstablished,
TenantActivated,
TenantSuspended,
TenantTerminated,
InfoEdited
}

0 comments on commit 8cb8b58

Please sign in to comment.