-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket #4 : Can launch case instance
- Loading branch information
Showing
94 changed files
with
1,668 additions
and
839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,24 @@ | ||
namespace Microsoft.AspNetCore.Builder | ||
using CaseManagement.CMMN.CaseInstance.EventHandlers; | ||
using CaseManagement.Workflow.Domains.Events; | ||
using CaseManagement.Workflow.Infrastructure.EvtBus; | ||
|
||
namespace Microsoft.AspNetCore.Builder | ||
{ | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseCMMN(this IApplicationBuilder appBuilder) | ||
{ | ||
appBuilder.ConfigureEventBus(); | ||
appBuilder.UseMvc(); | ||
return appBuilder; | ||
} | ||
|
||
private static void ConfigureEventBus(this IApplicationBuilder app) | ||
{ | ||
var evtBus = (IEventBus)app.ApplicationServices.GetService(typeof(IEventBus)); | ||
evtBus.Subscribe<ProcessFlowInstanceCreatedEvent, ProcessFlowInstanceCreatedEventHandler>(); | ||
evtBus.Subscribe<ProcessFlowInstanceLaunchedEvent, ProcessFlowInstanceLaunchedEventHandler>(); | ||
evtBus.Subscribe<ProcessFlowInstanceFormConfirmedEvent, ProcessFlowInstanceFormConfirmedEventHandler>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/CaseManagement.CMMN/CaseInstance/CommandHandlers/ConfirmFormCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using CaseManagement.CMMN.CaseInstance.Commands; | ||
using CaseManagement.CMMN.Domains; | ||
using CaseManagement.Workflow.Domains; | ||
using CaseManagement.Workflow.Infrastructure.EvtBus; | ||
using CaseManagement.Workflow.Infrastructure.EvtStore; | ||
using Microsoft.Extensions.Options; | ||
using NEventStore; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace CaseManagement.CMMN.CaseInstance.CommandHandlers | ||
{ | ||
public class ConfirmFormCommandHandler : BaseCommandHandler<ProcessFlowInstance>, IConfirmFormCommandHandler | ||
{ | ||
private readonly IEventStoreRepository<ProcessFlowInstance> _eventStoreRepository; | ||
|
||
public ConfirmFormCommandHandler(IStoreEvents storeEvents, IEventBus eventBus, IEventStoreRepository<ProcessFlowInstance> eventStoreRepository, IAggregateSnapshotStore<ProcessFlowInstance> aggregateSnapshotStore, IOptions<SnapshotConfiguration> snapshotConfiguration) : base(storeEvents, eventBus, aggregateSnapshotStore, snapshotConfiguration) | ||
{ | ||
_eventStoreRepository = eventStoreRepository; | ||
} | ||
|
||
public async Task<bool> Handle(ConfirmFormCommand confirmFormCommand) | ||
{ | ||
var caseInstance = await _eventStoreRepository.GetLastAggregate(confirmFormCommand.CaseInstanceId, ProcessFlowInstance.GetStreamName(confirmFormCommand.CaseInstanceId)); | ||
if (caseInstance == null || string.IsNullOrWhiteSpace(caseInstance.Id)) | ||
{ | ||
// TODO : THROW EXCEPTION. | ||
} | ||
|
||
var flowInstanceElt = caseInstance.Elements.FirstOrDefault(e => e.Id == confirmFormCommand.CaseElementInstanceId) as CMMNPlanItem; | ||
if (flowInstanceElt == null) | ||
{ | ||
// TODO : THROW EXCEPTION. | ||
} | ||
|
||
caseInstance.ConfirmForm(confirmFormCommand.CaseElementInstanceId); | ||
await Commit(caseInstance, caseInstance.GetStreamName()); | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/CaseManagement.CMMN/CaseInstance/CommandHandlers/IConfirmFormCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using CaseManagement.CMMN.CaseInstance.Commands; | ||
using System.Threading.Tasks; | ||
|
||
namespace CaseManagement.CMMN.CaseInstance.CommandHandlers | ||
{ | ||
public interface IConfirmFormCommandHandler | ||
{ | ||
Task<bool> Handle(ConfirmFormCommand confirmFormCommand); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...lers/ICreateCaseInstanceCommandHandler.cs → ...lers/ICreateCaseInstanceCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...lers/ILaunchCaseInstanceCommandHandler.cs → ...lers/ILaunchCaseInstanceCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/CaseManagement.CMMN/CaseInstance/CommandHandlers/LaunchCaseInstanceCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using CaseManagement.CMMN.CaseInstance.Commands; | ||
using CaseManagement.Workflow.Domains; | ||
using CaseManagement.Workflow.Infrastructure.EvtBus; | ||
using CaseManagement.Workflow.Infrastructure.EvtStore; | ||
using Microsoft.Extensions.Options; | ||
using NEventStore; | ||
using System.Threading.Tasks; | ||
|
||
namespace CaseManagement.CMMN.CaseInstance.CommandHandlers | ||
{ | ||
public class LaunchCaseInstanceCommandHandler : BaseCommandHandler<ProcessFlowInstance>, ILaunchCaseInstanceCommandHandler | ||
{ | ||
private readonly IEventStoreRepository<ProcessFlowInstance> _eventStoreRepository; | ||
|
||
public LaunchCaseInstanceCommandHandler(IStoreEvents storeEvents, IEventBus eventBus, IEventStoreRepository<ProcessFlowInstance> eventStoreRepository, IAggregateSnapshotStore<ProcessFlowInstance> aggregateSnapshotStore, IOptions<SnapshotConfiguration> snapshotConfiguration) : base(storeEvents, eventBus, aggregateSnapshotStore, snapshotConfiguration) | ||
{ | ||
_eventStoreRepository = eventStoreRepository; | ||
} | ||
|
||
public async Task Handle(LaunchCaseInstanceCommand launchCaseInstanceCommand) | ||
{ | ||
var caseInstance = await _eventStoreRepository.GetLastAggregate(launchCaseInstanceCommand.CaseInstanceId, ProcessFlowInstance.GetStreamName(launchCaseInstanceCommand.CaseInstanceId)); | ||
if (caseInstance == null || string.IsNullOrWhiteSpace(caseInstance.Id)) | ||
{ | ||
// TODO : THROW EXCEPTION. | ||
} | ||
|
||
|
||
caseInstance.Launch(); | ||
await Commit(caseInstance, caseInstance.GetStreamName()); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/CaseManagement.CMMN/CaseInstance/Commands/ConfirmFormCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Runtime.Serialization; | ||
|
||
namespace CaseManagement.CMMN.CaseInstance.Commands | ||
{ | ||
[DataContract] | ||
public class ConfirmFormCommand | ||
{ | ||
public string CaseInstanceId { get; set; } | ||
public string CaseElementInstanceId { get; set; } | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/CaseManagement.CMMN/CaseInstance/EventHandlers/ProcessFlowInstanceCreatedEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CaseManagement.Workflow.Domains; | ||
using CaseManagement.Workflow.Domains.Events; | ||
using CaseManagement.Workflow.Infrastructure; | ||
using CaseManagement.Workflow.Infrastructure.EvtBus; | ||
using CaseManagement.Workflow.Persistence; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace CaseManagement.CMMN.CaseInstance.EventHandlers | ||
{ | ||
public class ProcessFlowInstanceCreatedEventHandler : IDomainEventHandler<ProcessFlowInstanceCreatedEvent> | ||
{ | ||
private readonly IProcessFlowInstanceCommandRepository _processFlowInstanceCommandRepository; | ||
|
||
public ProcessFlowInstanceCreatedEventHandler(IProcessFlowInstanceCommandRepository processFlowInstanceCommandRepository) | ||
{ | ||
_processFlowInstanceCommandRepository = processFlowInstanceCommandRepository; | ||
} | ||
|
||
public async Task Handle(ProcessFlowInstanceCreatedEvent @event) | ||
{ | ||
var processFlowInstance = ProcessFlowInstance.New(new List<DomainEvent> { @event }); | ||
_processFlowInstanceCommandRepository.Add(processFlowInstance); | ||
await _processFlowInstanceCommandRepository.SaveChanges(); | ||
} | ||
} | ||
} |
Oops, something went wrong.