Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
using Microsoft.Extensions.Logging;
using NServiceBus;
using SFA.DAS.CommitmentsV2.Configuration;
using SFA.DAS.CommitmentsV2.Data;
using SFA.DAS.CommitmentsV2.Data.Extensions;
using SFA.DAS.CommitmentsV2.Domain;
using SFA.DAS.CommitmentsV2.Domain.Exceptions;
using SFA.DAS.CommitmentsV2.Domain.Extensions;
using SFA.DAS.CommitmentsV2.Domain.Interfaces;
Expand All @@ -32,7 +30,7 @@
IWithDrawalNotificationToEmployerService service)
: IHandleMessages<LearningWithdrawnEvent>
{
public async Task Handle(LearningWithdrawnEvent message, IMessageHandlerContext context)
public async Task Handle(LearningWithdrawnEvent message, IMessageHandlerContext context)
{
try
{
Expand All @@ -41,11 +39,10 @@
logger.LogInformation("LearnerWithdrawals feature is not active. Ignoring LearningWithdrawnEvent for ApprenticeshipId {ApprenticeshipId}", message.ApprenticeshipId);
return;
}
logger.LogInformation("LearningWithdrawnEvent for ApprenticeshipId {ApprenticeshipId} with WithdrawalDate {WithdrawalDate} and WithdrawalReasonCode {WithdrawalReasonCode}",
message.ApprenticeshipId, message.WithdrawalDate, message.WithdrawalReasonCode);
logger.LogInformation("LearningWithdrawnEvent for ApprenticeshipId {ApprenticeshipId} with WithdrawalDate {WithdrawalDate}", message.ApprenticeshipId, message.WithdrawalDate);
var db = dbContext.Value;
var apprentice = await db.GetApprenticeshipAggregate(message.ApprenticeshipId, default);

var withdrawalDate = new DateTime(message.WithdrawalDate.Year, message.WithdrawalDate.Month, 1);
if (message.WithdrawalReasonCode < 0)
{
Expand All @@ -66,7 +63,7 @@
ChangeType = LearningChangeType.AutoApproved,
LearningKey = message.LearningKey,
AppliedDate = message.Created,
Description = BuildWithdrawalReasonDesciption(message.WithdrawalReasonCode)
Description = BuildWithdrawalReasonDescription()
};
await context.Send(historyCommand);
}
Expand All @@ -77,13 +74,9 @@
}
}

private static string BuildWithdrawalReasonDesciption(short withdrawalReasonCode)
private string BuildWithdrawalReasonDescription()

Check warning on line 77 in src/CommitmentsV2/SFA.DAS.CommitmentsV2.ExternalHandlers/EventHandlers/LearningWithdrawnEventHandler.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this method and declare a constant for this value.

See more on https://sonarcloud.io/project/issues?id=SkillsFundingAgency_das-commitments&issues=AZ_ILIfwkEUtho0DAXre&open=AZ_ILIfwkEUtho0DAXre&pullRequest=1567

Check warning on line 77 in src/CommitmentsV2/SFA.DAS.CommitmentsV2.ExternalHandlers/EventHandlers/LearningWithdrawnEventHandler.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make 'BuildWithdrawalReasonDescription' a static method.

See more on https://sonarcloud.io/project/issues?id=SkillsFundingAgency_das-commitments&issues=AZ_ILIfwkEUtho0DAXrd&open=AZ_ILIfwkEUtho0DAXrd&pullRequest=1567

Check warning on line 77 in src/CommitmentsV2/SFA.DAS.CommitmentsV2.ExternalHandlers/EventHandlers/LearningWithdrawnEventHandler.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Member 'BuildWithdrawalReasonDescription' does not access instance data and can be marked as static

See more on https://sonarcloud.io/project/issues?id=SkillsFundingAgency_das-commitments&issues=AZ_ILIfwkEUtho0DAXrf&open=AZ_ILIfwkEUtho0DAXrf&pullRequest=1567
{
if (Constants.IlrWithdrawalReasons.TryGetValue(withdrawalReasonCode, out var description))
{
return $"ILR Learner status changed from Live to Withdrawn due to {withdrawalReasonCode} - '{description}'";
}
return $"ILR Learner status changed from Live to Withdrawn due to {withdrawalReasonCode} - 'Unknown Reason Code'";
return "ILR Learner status changed from Live to Stopped";
}

private void ValidateStopDateForWithdrawal(DateTime stopDate, Apprenticeship apprenticeship)
Expand Down Expand Up @@ -114,7 +107,7 @@
}
}

if(stopDate.Day != 1)
if (stopDate.Day != 1)
{
throw new DomainException(nameof(stopDate), "Invalid Stop Date. Stop date must be the 1st of the month.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ public async Task When_LearnerWithDrawnEvent_AppliedToExistingApprenticeshipWith
apprentice.MadeRedundant.Should().BeFalse();
}

[TestCase(29, "Learner has been made redundant")]
[TestCase(2, "Learner has transferred to another provider")]
[TestCase(46, "Exclusion")]
[TestCase(97, "Other")]
[TestCase(98, "Reason not known")]
[TestCase(99, "Unknown Reason Code")]
[TestCase(100, "Unknown Reason Code")]
[TestCase(0, "Unknown Reason Code")]
public async Task When_LearnerWithDrawnEvent_AppliedToExistingApprenticeship_StoreLearnerHistoryCommand_IsPublished(short code, string description)
[TestCase(29)]
[TestCase(2)]
[TestCase(46)]
[TestCase(97)]
[TestCase(98)]
[TestCase(99)]
[TestCase(100)]
[TestCase(0)]
public async Task When_LearnerWithDrawnEvent_AppliedToExistingApprenticeship_StoreLearnerHistoryCommand_IsPublished(short code)
{
var apprentice = await _fixture.SetupApprenticeship(PaymentStatus.Active);
var stopDate = DateTime.Today.AddMonths(-1);
_fixture.SetEventValues(apprentice.Id, new DateTime(stopDate.Year, stopDate.Month, 1), code);

await _fixture.Handle();
_fixture.VerifyStoreLearnerHistoryCommandIsSent($"ILR Learner status changed from Live to Withdrawn due to {code} - '{description}'");
_fixture.VerifyStoreLearnerHistoryCommandIsSent("ILR Learner status changed from Live to Stopped");
}

[Test]
Expand Down
19 changes: 0 additions & 19 deletions src/CommitmentsV2/SFA.DAS.CommitmentsV2/Domain/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,4 @@ public static class FieldLengths
public const int ProviderReference = 50;
public const int Uln = 50;
}

public static readonly Dictionary<short, string> IlrWithdrawalReasons = new Dictionary<short, string>
{
{ 2, "Learner has transferred to another provider" },
{ 3, "Learner injury / illness" },
{ 7, "Learner has transferred between providers due to intervention by or with the written agreement of the ESFA" },
{ 29, "Learner has been made redundant" },
{ 40, "Learner has transferred to a new learning aim with the same provider" },
{ 41, "Learner has transferred to another provider to undertake learning that meets a specific government strategy" },
{ 42, "Academic failure / left in bad standing / not permitted to progress – HE learning aims only" },
{ 43, "Financial reasons" },
{ 44, "Other personal reasons" },
{ 45, "Written off after lapse of time – HE learning aims only" },
{ 46, "Exclusion" },
{ 47, "Learner has transferred to another provider due to merger" },
{ 48, "Industry placement learner has withdrawn due to circumstances outside the providers' control" },
{ 97, "Other" },
{ 98, "Reason not known" }
};
}
Loading