Skip to content

Commit

Permalink
Merge pull request #411 from SkillsFundingAgency/DPP-1661_Ignore_Dloc…
Browse files Browse the repository at this point in the history
…k07_If_Also_Dlock09

Ignores dlock07 datalocks if also dlock09
  • Loading branch information
m-nagashree authored Oct 10, 2018
2 parents f0e73cb + 1e92193 commit d725eb4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,5 +413,34 @@ public async Task ThenDatalocksForStoppedAndBackdatedApprenticeshipsAreAutoResol

_dataLockRepository.Verify(x => x.UpdateDataLockStatus(It.Is<DataLockStatus>(d => d.IsResolved)), Times.Once);
}

[Test]
public async Task ThenPriceDatalocksInCombinationWithDlock09AreIgnored()
{
var page1 = new List<DataLockStatus>
{
new DataLockStatus
{
ApprenticeshipId = 1,
DataLockEventId = 2,
ErrorCode = DataLockErrorCode.Dlock07,
IlrEffectiveFromDate = DateTime.Today.AddMonths(-2)
}
};

_paymentEvents.Setup(x => x.GetDataLockEvents(1, null, null, 0L, 1)).ReturnsAsync(page1);

_apprenticeshipRepository.Setup(x => x.GetApprenticeship(It.IsAny<long>()))
.ReturnsAsync(new Apprenticeship
{
PaymentStatus = PaymentStatus.Withdrawn,
StartDate = DateTime.Today.AddMonths(-1),
StopDate = DateTime.Today.AddMonths(-1)
});

await _dataLockUpdater.RunUpdate();

_dataLockRepository.Verify(x => x.UpdateDataLockStatus(It.IsAny<DataLockStatus>()), Times.Never);
}
}
}
53 changes: 31 additions & 22 deletions src/SFA.DAS.CommitmentPayments.WebJob/Updater/DataLockUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,45 @@ public async Task RunUpdate()

if (datalockSuccess || dataLockStatus.ErrorCode != DataLockErrorCode.None)
{
_logger.Info($"Updating Apprenticeship {dataLockStatus.ApprenticeshipId} " +
$"Event Id {dataLockStatus.DataLockEventId} Status {dataLockStatus.ErrorCode}");
var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(dataLockStatus.ApprenticeshipId);

await AutoResolveDataLockIfApprenticeshipStoppedAndBackdated(dataLockStatus);

try
//temporarily ignore dlock7 & 9 combos until payments R14 fixes properly
if (dataLockStatus.ErrorCode.HasFlag(DataLockErrorCode.Dlock07) && dataLockStatus.IlrEffectiveFromDate < apprenticeship.StartDate)
{
await _dataLockRepository.UpdateDataLockStatus(dataLockStatus);

await _filterAcademicYearRolloverDataLocks.Filter(dataLockStatus.ApprenticeshipId);
_logger.Info($"Ignoring datalock for Apprenticeship #{dataLockStatus.ApprenticeshipId} Dlock07 with Effective Date before Start Date. Event Id {dataLockStatus.DataLockEventId}");
}
catch(RepositoryConstraintException ex) when (_config.IgnoreDataLockStatusConstraintErrors)
else
{
_logger.Warn(ex, $"Exception in DataLock updater");
}
_logger.Info($"Updating Apprenticeship {dataLockStatus.ApprenticeshipId} " +
$"Event Id {dataLockStatus.DataLockEventId} Status {dataLockStatus.ErrorCode}");

if (datalockSuccess)
{
await _apprenticeshipRepository.SetHasHadDataLockSuccess(dataLockStatus.ApprenticeshipId);
AutoResolveDataLockIfApprenticeshipStoppedAndBackdated(apprenticeship, dataLockStatus);

var pendingUpdate = await
_apprenticeshipUpdateRepository.GetPendingApprenticeshipUpdate(dataLockStatus.ApprenticeshipId);
try
{
await _dataLockRepository.UpdateDataLockStatus(dataLockStatus);

if (pendingUpdate != null && (pendingUpdate.Cost != null || pendingUpdate.TrainingCode != null))
await _filterAcademicYearRolloverDataLocks.Filter(dataLockStatus.ApprenticeshipId);
}
catch (RepositoryConstraintException ex) when (_config.IgnoreDataLockStatusConstraintErrors)
{
await _apprenticeshipUpdateRepository.ExpireApprenticeshipUpdate(pendingUpdate.Id);
_logger.Info($"Pending ApprenticeshipUpdate {pendingUpdate.Id} expired due to successful data lock event {dataLockStatus.DataLockEventId}");
_logger.Warn(ex, $"Exception in DataLock updater");
}

if (datalockSuccess)
{
await _apprenticeshipRepository.SetHasHadDataLockSuccess(dataLockStatus.ApprenticeshipId);

var pendingUpdate = await
_apprenticeshipUpdateRepository.GetPendingApprenticeshipUpdate(dataLockStatus.ApprenticeshipId);

if (pendingUpdate != null && (pendingUpdate.Cost != null || pendingUpdate.TrainingCode != null))
{
await _apprenticeshipUpdateRepository.ExpireApprenticeshipUpdate(pendingUpdate.Id);
_logger.Info($"Pending ApprenticeshipUpdate {pendingUpdate.Id} expired due to successful data lock event {dataLockStatus.DataLockEventId}");
}
}

}
}

Expand All @@ -123,10 +134,8 @@ public async Task RunUpdate()
}
}

private async Task AutoResolveDataLockIfApprenticeshipStoppedAndBackdated(DataLockStatus datalock)
private void AutoResolveDataLockIfApprenticeshipStoppedAndBackdated(Apprenticeship apprenticeship, DataLockStatus datalock)
{
var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(datalock.ApprenticeshipId);

if (apprenticeship.PaymentStatus == PaymentStatus.Withdrawn &&
apprenticeship.StopDate == apprenticeship.StartDate)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Script to remove data locks with price error code if the user has also had a start date data lock
We do not have dlock 09 stored in commitments, so have to establish the existence of one by
inferring it where the effective from date in the ILR is before the course start date
If the user attempts to triage a data lock in this state, they receive an exception.
*/


update dl
set dl.IsExpired = 1
from Apprenticeship a
join DataLockStatus dl on dl.ApprenticeshipId = a.Id
where
[Status]=2 and (ErrorCode & 64 = 64) and IsResolved=0 and IsExpired=0 and EventStatus<>3
and dl.IlrEffectiveFromDate < a.StartDate


Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Folder Include="PostDeployment" />
<Folder Include="AdhocScripts" />
<Folder Include="AdhocScripts\Support" />
<Folder Include="AdhocScripts\Support\DPP-1661" />
</ItemGroup>
<ItemGroup>
<Build Include="Tables\Commitment.sql" />
Expand Down Expand Up @@ -137,6 +138,7 @@
<Build Include="Tables\BulkUpload.sql" />
<None Include="AdhocScripts\Support\ApprenticeshipStopFixUpScript.sql" />
<None Include="AdhocScripts\Support\RelationshipCreationScript.sql" />
<None Include="AdhocScripts\Support\DPP-1661\DPP-1661_Remove_DataLock_7_if_also_Datalock_9.sql" />
</ItemGroup>
<ItemGroup>
<PostDeploy Include="PostDeployment\PostDeploymentScript.sql" />
Expand Down

0 comments on commit d725eb4

Please sign in to comment.