Skip to content

Commit

Permalink
Merge pull request IFRCGo#13 from cbs-reporting-senegal/Convertion
Browse files Browse the repository at this point in the history
Convertion training to case report
  • Loading branch information
woksin committed Apr 22, 2019
2 parents 124008b + d09ceb2 commit bd971d5
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 10 deletions.
19 changes: 18 additions & 1 deletion Source/Reporting/Core/.dolittle/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@
"queries": {}
},
"2b37f877-532e-4e35-ba76-1977d56739ac": {
"commands": {},
"commands": {
"5cb02e26-a5fb-4c71-ab0a-97ffa68d653d": {
"generation": 1,
"type": "Domain.Reporting.CaseReports.ConvertToLiveReport, Domain"
},
"d1322c24-1d73-4d21-ac08-62b36e5e0307": {
"generation": 1,
"type": "Domain.Reporting.CaseReports.ConvertToTrainingReport, Domain"
}
},
"events": {
"525ec773-014e-44dd-a215-20af627bfde6": {
"generation": 1,
Expand All @@ -215,6 +224,14 @@
"02feb265-8444-4d97-9b18-a066172c6d47": {
"generation": 1,
"type": "Events.Reporting.CaseReports.InvalidReportReceived, Events"
},
"18d13c55-fc67-4439-ad86-58231453a9e1": {
"generation": 1,
"type": "Events.Reporting.CaseReports.LiveReportConvertedToTraining, Events"
},
"7302a848-e262-4424-96b1-60d1077fae58": {
"generation": 1,
"type": "Events.Reporting.CaseReports.TrainingReportConvertedToLive, Events"
}
},
"eventSources": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,13 @@ Guid dataCollectorId
{
Apply(new CaseReportIdentified(dataCollectorId));
}
public void ConvertToTrainingReport()
{
Apply(new LiveReportConvertedToTraining());
}
public void ConvertToLiveReport()
{
Apply(new TrainingReportConvertedToLive());
}
}
}
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();
}

}
}
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;}
}
}
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
}
}
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());

}
}
}
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;}
}
}
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
}
}
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());

}
}
}
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()
{
}
}
}
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()
{
}
}
}
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();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Edit implements OnInit {
private route: ActivatedRoute,
private commandCoordinator: CommandCoordinator,
private toastr: ToastrService,
private queryCoordinator: QueryCoordinator<DataCollector>,
private queryCoordinator: QueryCoordinator,
private appInsightsService: AppInsightsService
) {
toastr.toastrConfig.positionClass = 'toast-top-center';
Expand Down
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';
}
}
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';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h3>
{{ 'REGISTER.REPORT.page_next' | translate }} >
</button>
</div>

</div>

<div class="row">
Expand All @@ -77,6 +77,7 @@ <h3>
(click)="toggleSortColum(column)"
[ngClass]="{'sortable': column.isSortable}"
></th>
<th>Actions</th>
</tr>
</thead>
<tbody *ngIf="!page.isLoading">
Expand Down Expand Up @@ -120,9 +121,19 @@ <h3>
{{caseReport.message}} {{ 'REGISTER.REPORT.parse_error' | translate }}: {{caseReport.parsingErrorMessage}}
</td>
</ng-container>
<td><button (click)="convertToTrainingCase(caseReport)" type="button" name="button" class="btn btn-warning">{{ 'REGISTER.REPORT.convert_to_training' | translate }}</button> </td>
</tr>
</tbody>
</table>
<div *ngIf="page.isLoading">
<p class="text-center">{{ 'REGISTER.REPORT.loader' | translate }}</p>
</div>

<ngx-smart-modal #modalExportDataCollectors identifier="modalExportDataCollectors" [backdrop]="false">
<h4>{{ 'REGISTER.REPORT.convert_to_training_message' | translate }}</h4>
<br><br>
<div class="actions">
<button class="btn btn-default" (click)="modalExportDataCollectors.close()">Cancel</button>
<button (click)="convert()" class="btn btn-primary" type="submit">Convert</button>
</div>
</ngx-smart-modal>

0 comments on commit bd971d5

Please sign in to comment.