forked from IFRCGo/cbs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IFRCGo#13 from cbs-reporting-senegal/Convertion
Convertion training to case report
- Loading branch information
Showing
21 changed files
with
396 additions
and
10 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
28 changes: 28 additions & 0 deletions
28
Source/Reporting/Domain/Reporting/CaseReports/CaseReportsHandler.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,28 @@ | ||
using Dolittle.Commands.Handling; | ||
using Dolittle.Domain; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class CaseReportsHandler : ICanHandleCommands | ||
{ | ||
readonly IAggregateRootRepositoryFor<CaseReporting> _aggregateRootRepoForCaseReporting; | ||
|
||
public CaseReportsHandler( | ||
IAggregateRootRepositoryFor<CaseReporting> aggregateRootRepoForCaseReporting | ||
) | ||
{ | ||
_aggregateRootRepoForCaseReporting = aggregateRootRepoForCaseReporting; | ||
} | ||
|
||
public void Handle(ConvertToLiveReport cmd) | ||
{ | ||
_aggregateRootRepoForCaseReporting.Get(cmd.CaseReportId.Value).ConvertToLiveReport(); | ||
} | ||
|
||
public void Handle(ConvertToTrainingReport cmd) | ||
{ | ||
_aggregateRootRepoForCaseReporting.Get(cmd.CaseReportId.Value).ConvertToTrainingReport(); | ||
} | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Reporting/Domain/Reporting/CaseReports/ConvertToLiveReport.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 Concepts.CaseReports; | ||
using Dolittle.Commands; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToLiveReport : ICommand | ||
{ | ||
public CaseReportId CaseReportId {get; set;} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Source/Reporting/Domain/Reporting/CaseReports/ConvertToLiveReportBusinessValidator.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,9 @@ | ||
using Dolittle.Commands.Validation; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToLiveReportBusinessValidator : CommandBusinessValidatorFor<ConvertToLiveReport> | ||
{ | ||
// Case report must exist | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Source/Reporting/Domain/Reporting/CaseReports/ConvertToLiveReportInputValidator.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,18 @@ | ||
using Concepts.CaseReports; | ||
using Dolittle.Commands.Validation; | ||
using FluentValidation; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToLiveReportInputValidator : CommandInputValidatorFor<ConvertToLiveReport> | ||
{ | ||
public ConvertToLiveReportInputValidator() | ||
{ | ||
RuleFor(_ => _.CaseReportId) | ||
.Cascade(CascadeMode.StopOnFirstFailure) | ||
.NotNull().WithMessage("Case Report Id is required") | ||
.SetValidator(new CaseReportIdValidator()); | ||
|
||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Source/Reporting/Domain/Reporting/CaseReports/ConvertToTrainingReport.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 Concepts.CaseReports; | ||
using Dolittle.Commands; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToTrainingReport : ICommand | ||
{ | ||
public CaseReportId CaseReportId {get; set;} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Source/Reporting/Domain/Reporting/CaseReports/ConvertToTrainingReportBusinessValidator.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,9 @@ | ||
using Dolittle.Commands.Validation; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToTrainingReportBusinessValidator : CommandBusinessValidatorFor<ConvertToTrainingReport> | ||
{ | ||
// Case report must exist | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Source/Reporting/Domain/Reporting/CaseReports/ConvertToTrainingReportInputValidator.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,19 @@ | ||
using Concepts.CaseReports; | ||
using Dolittle.Commands.Validation; | ||
using FluentValidation; | ||
|
||
namespace Domain.Reporting.CaseReports | ||
{ | ||
public class ConvertToTrainingReportInputValidator : CommandInputValidatorFor<ConvertToTrainingReport> | ||
{ | ||
|
||
public ConvertToTrainingReportInputValidator() | ||
{ | ||
RuleFor(_ => _.CaseReportId) | ||
.Cascade(CascadeMode.StopOnFirstFailure) | ||
.NotNull().WithMessage("Case Report Id is required") | ||
.SetValidator(new CaseReportIdValidator()); | ||
|
||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Source/Reporting/Events/Reporting/CaseReports/LiveReportConvertedToTraining.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,18 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) The International Federation of Red Cross and Red Crescent Societies. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
using System; | ||
using Dolittle.Events; | ||
|
||
namespace Events.Reporting.CaseReports | ||
{ | ||
public class LiveReportConvertedToTraining : IEvent | ||
{ | ||
|
||
public LiveReportConvertedToTraining() | ||
{ | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Source/Reporting/Events/Reporting/CaseReports/TrainingReportConvertedToLive.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,18 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) The International Federation of Red Cross and Red Crescent Societies. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
using System; | ||
using Dolittle.Events; | ||
|
||
namespace Events.Reporting.CaseReports | ||
{ | ||
public class TrainingReportConvertedToLive : IEvent | ||
{ | ||
|
||
public TrainingReportConvertedToLive() | ||
{ | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
Source/Reporting/Policies/Reporting/CaseReports/CaseReportsProcessor.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,78 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) The International Federation of Red Cross and Red Crescent Societies. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
using Dolittle.Domain; | ||
using Dolittle.Events.Processing; | ||
using Dolittle.ReadModels; | ||
using Domain.Reporting.CaseReports; | ||
using Dolittle.Runtime.Commands.Coordination; | ||
using Events.Reporting.CaseReports; | ||
using Dolittle.Runtime.Events; | ||
using Read.Reporting.TrainingCaseReportsForListing; | ||
using Concepts.CaseReports; | ||
using Concepts.HealthRisks; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Policies.Reporting.CaseReports | ||
{ | ||
public class CaseReportsProcessor : ICanProcessEvents | ||
{ | ||
readonly IReadModelRepositoryFor<TrainingCaseReportForListing> _trainingReports; | ||
readonly ICommandContextManager _commandContextManager; | ||
readonly IAggregateRootRepositoryFor<CaseReporting> _caseReportingRepository; | ||
|
||
public CaseReportsProcessor( | ||
ICommandContextManager commandContextManager, | ||
IAggregateRootRepositoryFor<CaseReporting> caseReportingRepository) | ||
{ | ||
_commandContextManager = commandContextManager; | ||
_caseReportingRepository = caseReportingRepository; | ||
} | ||
|
||
[EventProcessor("04623be4-2508-4f27-b845-8cc349ea8f17")] | ||
public void Process(TrainingReportConvertedToLive notification, EventSourceId caseReportId) | ||
{ | ||
var transaction = _commandContextManager.EstablishForCommand(new Dolittle.Runtime.Commands.CommandRequest(Guid.NewGuid(), Guid.Empty, 0, new Dictionary<string, object>())); | ||
|
||
var report = _trainingReports.GetById((CaseReportId)caseReportId.Value); | ||
var aggregateRoot = _caseReportingRepository.Get(caseReportId); | ||
|
||
var reportFromKnownDataCollector = report.DataCollectorId != null && report.DataCollectorId != CaseReportId.NotSet; | ||
var validReport = report.HealthRiskId != null && report.HealthRiskId != HealthRiskId.NotSet; | ||
|
||
if (reportFromKnownDataCollector && validReport) | ||
{ | ||
aggregateRoot.Report( | ||
report.DataCollectorId.Value, report.HealthRiskId.Value, report.Origin, report.NumberOfMalesUnder5, | ||
report.NumberOfMalesAged5AndOlder, report.NumberOfFemalesUnder5, report.NumberOfFemalesAged5AndOlder, | ||
report.Location.Longitude, report.Location.Latitude, report.Timestamp, report.Message | ||
); | ||
} | ||
else if (reportFromKnownDataCollector && !validReport) | ||
{ | ||
aggregateRoot.ReportInvalidReport( | ||
report.DataCollectorId.Value, report.Origin, report.Message, report.Location.Longitude, | ||
report.Location.Latitude, report.ParsingErrorMessage, report.Timestamp | ||
); | ||
} | ||
else if (!reportFromKnownDataCollector && validReport) | ||
{ | ||
aggregateRoot.ReportFromUnknownDataCollector( | ||
report.Origin, report.HealthRiskId.Value, report.NumberOfMalesUnder5, report.NumberOfMalesAged5AndOlder, | ||
report.NumberOfFemalesUnder5, report.NumberOfFemalesAged5AndOlder, report.Timestamp, report.Message | ||
); | ||
} | ||
else if (!reportFromKnownDataCollector && !validReport) | ||
{ | ||
aggregateRoot.ReportInvalidReportFromUnknownDataCollector( | ||
report.Origin, report.Message, report.ParsingErrorMessage, report.Timestamp | ||
); | ||
} | ||
transaction.Commit(); | ||
|
||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
Source/Reporting/Web/src/app/Reporting/CaseReports/ConvertToLiveReport.js
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,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* This file is an automatically generated Command Proxy | ||
* | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { Command } from '@dolittle/commands'; | ||
|
||
export class ConvertToLiveReport extends Command | ||
{ | ||
constructor() { | ||
super(); | ||
this.type = '5cb02e26-a5fb-4c71-ab0a-97ffa68d653d'; | ||
|
||
this.caseReportId = '00000000-0000-0000-0000-000000000000'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Source/Reporting/Web/src/app/Reporting/CaseReports/ConvertToTrainingReport.js
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,15 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* This file is an automatically generated Command Proxy | ||
* | ||
*--------------------------------------------------------------------------------------------*/ | ||
import { Command } from '@dolittle/commands'; | ||
|
||
export class ConvertToTrainingReport extends Command | ||
{ | ||
constructor() { | ||
super(); | ||
this.type = 'd1322c24-1d73-4d21-ac08-62b36e5e0307'; | ||
|
||
this.caseReportId = '00000000-0000-0000-0000-000000000000'; | ||
} | ||
} |
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
Oops, something went wrong.