Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apr 1152 store not required rules #532

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1c81450
APR-1152 add not required overrides JSON field to Apply table
David-B-Read Apr 28, 2020
183e5a4
APR-1152 internal API to read/write not required override config
David-B-Read Apr 28, 2020
4b8faf9
APR-1152 update not required overrides service to persist data via API
David-B-Read Apr 28, 2020
9594b49
APR-1152 add unit tests for not required override handlers
David-B-Read Apr 28, 2020
b0225b3
Merge branch 'APR-1356_task_list_view_model_tech_debt' into APR-1152_…
David-B-Read Jun 2, 2020
c59fa36
APR-1152 fix field duplicated in merge
David-B-Read Jun 2, 2020
e193f03
APR-1152b merged in master and trying to sort out issues
MarkFCain Aug 18, 2020
46a3553
APR-1152b updated broken tests
MarkFCain Aug 19, 2020
a0b5575
APR-1152b merged in master
MarkFCain Aug 19, 2020
6541243
APR-1152b cleaned up commented out stuff
MarkFCain Aug 19, 2020
28b10fe
APR-1152b added in retrieval from appData
MarkFCain Aug 19, 2020
19fbb1e
Merge pull request #577 from SkillsFundingAgency/APR-1152b_merge_issues
MarkFCain Aug 19, 2020
195f1d5
APR-1152 updated interaction code and coverage for appData
MarkFCain Aug 20, 2020
ce7108d
APR-1152 - Make test Async
martin-lush Aug 21, 2020
fa26b49
Tidy up from merge
martin-lush Aug 21, 2020
bef548a
Merge branch 'master' into APR-1152_store_not_required_rules
MarkFCain Aug 26, 2020
b488c17
APR-1152 added in async
MarkFCain Aug 27, 2020
032a8db
APR-1152 reworking some async calls
MarkFCain Aug 27, 2020
72807d7
APR-1152 added logging to notRequiredOverrides service
MarkFCain Sep 1, 2020
c91802a
APR-1152 added logging to api side
MarkFCain Sep 1, 2020
96329ed
APR-1152 removed unneeded filter variable
MarkFCain Sep 1, 2020
49a2961
APR-1152 cleaned up getnotrequiredoverrides handler
MarkFCain Sep 1, 2020
4e2a92d
APR-1152 minor addition to override handler
MarkFCain Sep 1, 2020
17e9ec8
APR-1152 added logging to SaveAnswersGiven where it updates not requi…
MarkFCain Sep 1, 2020
afd7c00
APR-1152 minor typo correction
MarkFCain Sep 1, 2020
9e42904
APR-1152 - Code tidy up
martin-lush Sep 10, 2020
8134987
APR-1152 - Refactored code to ensure appropriate retrieval of NotRequ…
martin-lush Sep 10, 2020
a2b2260
APR-1152 - Use async calls to RefreshNotRequiredOverrides
martin-lush Sep 10, 2020
d43e343
Merge branch 'master' into APR-1152_store_not_required_rules
martin-lush Sep 11, 2020
4b3a377
APR-1152 refreshed from master
MarkFCain Oct 8, 2020
9e3ebd7
Merge branch 'master' of https://github.com/SkillsFundingAgency/das-a…
Oct 15, 2020
0bc8230
APR-1152 - Added a couple of tweaks
martin-lush Oct 16, 2020
a91f50f
APR-1152 - Optimise GetApplicationSequences in RoatpTaskListWorkflowS…
martin-lush Oct 16, 2020
f041efd
Pass app sequences into tasklist ctor
chrisfoster76 Oct 19, 2020
4f849c5
Merge pull request #600 from SkillsFundingAgency/pass-app-sequences-i…
chrisfoster76 Oct 19, 2020
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
@@ -0,0 +1,74 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.ApplyService.Application.Apply;
using SFA.DAS.ApplyService.Application.Apply.Roatp;
using SFA.DAS.ApplyService.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.ApplyService.Application.UnitTests.Handlers.NotRequiredOverrideHandlerTests
{
[TestFixture]
public class GetNotRequiredOverridesHandlerTests
{
private readonly Guid _applicationId = Guid.NewGuid();

private Mock<IApplyRepository> _repository;

private GetNotRequiredOverridesHandler _handler;

[SetUp]
public void Before_each_test()
{
_repository = new Mock<IApplyRepository>();

_handler = new GetNotRequiredOverridesHandler(_repository.Object);
}

[Test]
public async Task Handler_returns_null_if_NotRequiredOverrides_not_persisted()
{
List<NotRequiredOverride> notRequiredOverrides = null;

_repository.Setup(x => x.GetNotRequiredOverrides(_applicationId)).ReturnsAsync(notRequiredOverrides);

var result = await _handler.Handle(new GetNotRequiredOverridesRequest(_applicationId), new CancellationToken());

_repository.Verify(x => x.GetNotRequiredOverrides(_applicationId), Times.Once);
result.Should().BeNull();
}

[Test]
public async Task Handler_returns_NotRequiredOverrides_if_persisted()
{
var notRequiredOverrides = new List<NotRequiredOverride>
{
new NotRequiredOverride
{
Conditions = new List<NotRequiredCondition>
{
new NotRequiredCondition
{
ConditionalCheckField = "FIELD1",
MustEqual = "Y",
Value = ""
}
},
SectionId = 1,
SequenceId = 4
}
};

_repository.Setup(x => x.GetNotRequiredOverrides(_applicationId)).ReturnsAsync(notRequiredOverrides);

var result = await _handler.Handle(new GetNotRequiredOverridesRequest(_applicationId), new CancellationToken());

_repository.Verify(x => x.GetNotRequiredOverrides(_applicationId), Times.Once);
result.Should().NotBeNull();
result.Count.Should().Be(1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.ApplyService.Application.Apply;
using SFA.DAS.ApplyService.Application.Apply.Roatp;
using SFA.DAS.ApplyService.Domain.Entities;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.ApplyService.Application.UnitTests.Handlers.NotRequiredOverrideHandlerTests
{
[TestFixture]
public class UpdateNotRequiredOverridesHandlerTests
{
private readonly Guid _applicationId = Guid.NewGuid();

private Mock<IApplyRepository> _repository;

private UpdateNotRequiredOverridesHandler _handler;

[SetUp]
public void Before_each_test()
{
_repository = new Mock<IApplyRepository>();

_handler = new UpdateNotRequiredOverridesHandler(_repository.Object);
}

[Test]
public async Task Handler_returns_true_when_NotRequiredOverrides_are_persisted()
{
var notRequiredOverrides = new List<NotRequiredOverride>
{
new NotRequiredOverride
{
Conditions = new List<NotRequiredCondition>
{
new NotRequiredCondition
{
ConditionalCheckField = "FIELD1",
MustEqual = "Y",
Value = ""
}
},
SectionId = 1,
SequenceId = 4
}
};

_repository.Setup(x => x.UpdateNotRequiredOverrides(_applicationId, notRequiredOverrides)).ReturnsAsync(true);

var result = await _handler.Handle(new UpdateNotRequiredOverridesRequest(_applicationId, notRequiredOverrides), new CancellationToken());

_repository.Verify(x => x.UpdateNotRequiredOverrides(_applicationId, notRequiredOverrides), Times.Once);
result.Should().BeTrue();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using SFA.DAS.ApplyService.Application.Apply.Roatp;
using SFA.DAS.ApplyService.Domain.Apply;
using SFA.DAS.ApplyService.Domain.Entities;
using SFA.DAS.ApplyService.Domain.Roatp;
Expand Down Expand Up @@ -67,6 +68,9 @@ public interface IApplyRepository
Task<Contact> GetContactForApplication(Guid applicationId);
Task<Organisation> GetOrganisationForApplication(Guid applicationId);

Task<List<NotRequiredOverride>> GetNotRequiredOverrides(Guid applicationId);
Task<bool> UpdateNotRequiredOverrides(Guid applicationId, IEnumerable<NotRequiredOverride> notRequiredOverrides);

Task<List<ApplicationOversightDetails>> GetOversightsPending();
Task<List<ApplicationOversightDetails>> GetOversightsCompleted();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using MediatR;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using SFA.DAS.ApplyService.Domain.Entities;

namespace SFA.DAS.ApplyService.Application.Apply.Roatp
{
public class GetNotRequiredOverridesHandler : IRequestHandler<GetNotRequiredOverridesRequest, List<NotRequiredOverride>>
{
private readonly IApplyRepository _applyRepository;

public GetNotRequiredOverridesHandler(IApplyRepository applyRepository)
{
_applyRepository = applyRepository;
}

public async Task<List<NotRequiredOverride>> Handle(GetNotRequiredOverridesRequest request, CancellationToken cancellationToken)
{
return await _applyRepository.GetNotRequiredOverrides(request.ApplicationId);
}
}
}
MarkFCain marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MediatR;
using System;
using System.Collections.Generic;
using SFA.DAS.ApplyService.Domain.Entities;

namespace SFA.DAS.ApplyService.Application.Apply.Roatp
{
public class GetNotRequiredOverridesRequest : IRequest<List<NotRequiredOverride>>
{
public Guid ApplicationId { get; }

public GetNotRequiredOverridesRequest(Guid applicationId)
{
ApplicationId = applicationId;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace SFA.DAS.ApplyService.Application.Apply.Roatp
{
public class UpdateNotRequiredOverridesHandler : IRequestHandler<UpdateNotRequiredOverridesRequest, bool>
{
private readonly IApplyRepository _applyRepository;

public UpdateNotRequiredOverridesHandler(IApplyRepository applyRepository)
{
_applyRepository = applyRepository;
}

public async Task<bool> Handle(UpdateNotRequiredOverridesRequest request, CancellationToken cancellationToken)
{
return await _applyRepository.UpdateNotRequiredOverrides(request.ApplicationId, request.NotRequiredOverrides);
}
}
}
MarkFCain marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using MediatR;
using System;
using System.Collections.Generic;
using SFA.DAS.ApplyService.Domain.Entities;

namespace SFA.DAS.ApplyService.Application.Apply.Roatp
{
public class UpdateNotRequiredOverridesRequest : IRequest<bool>
{
public Guid ApplicationId { get; }
public IEnumerable<NotRequiredOverride> NotRequiredOverrides { get; }

public UpdateNotRequiredOverridesRequest(Guid applicationId, IEnumerable<NotRequiredOverride> notRequiredOverrides)
{
ApplicationId = applicationId;
NotRequiredOverrides = notRequiredOverrides;
}
}
}
33 changes: 33 additions & 0 deletions src/SFA.DAS.ApplyService.Data/ApplyRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ApplyRepository(IConfigurationService configurationService, ILogger<Apply
SqlMapper.AddTypeHandler(typeof(QnAData), new QnADataHandler());
SqlMapper.AddTypeHandler(typeof(ApplicationData), new ApplicationDataHandler());
SqlMapper.AddTypeHandler(typeof(FinancialReviewDetails), new FinancialReviewDetailsDataHandler());
SqlMapper.AddTypeHandler(typeof(NotRequiredOverrideConfiguration), new NotRequiredOverrideDataHandler());
}

public async Task<Guid> StartApplication(Guid applicationId, ApplyData applyData, Guid organisationId, Guid createdBy)
Expand Down Expand Up @@ -935,6 +936,38 @@ await connection.ExecuteAsync(@"UPDATE Apply SET ApplyData = @applyData,
return await Task.FromResult(true);
}

public async Task<List<NotRequiredOverride>> GetNotRequiredOverrides(Guid applicationId)
{
using (var connection = new SqlConnection(_config.SqlConnectionString))
{
var notRequiredOverrideConfiguration = await connection.QuerySingleAsync<NotRequiredOverrideConfiguration>(@"SELECT NotRequiredOverrides FROM Apply WHERE ApplicationId = @applicationId",
new { applicationId });

return notRequiredOverrideConfiguration?.NotRequiredOverrides.ToList();
}
}

public async Task<bool> UpdateNotRequiredOverrides(Guid applicationId, IEnumerable<NotRequiredOverride> notRequiredOverrides)
{
var notRequiredOverrideConfiguration = new NotRequiredOverrideConfiguration
{
NotRequiredOverrides = notRequiredOverrides
};

using (var connection = new SqlConnection(_config.SqlConnectionString))
{
await connection.ExecuteAsync(@"UPDATE Apply SET NotRequiredOverrides = @notRequiredOverrideConfiguration
WHERE ApplicationId = @applicationId",
new
{
applicationId,
notRequiredOverrideConfiguration
});
}

return true;
}

public async Task<bool> UpdateOversightReviewStatus(Guid applicationId, string oversightStatus, DateTime applicationDeterminedDate, string updatedBy)
{
using (var connection = new SqlConnection(_config.SqlConnectionString))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Dapper;
using Newtonsoft.Json;
using System.Data;
using SFA.DAS.ApplyService.Domain.Entities;

namespace SFA.DAS.ApplyService.Data.DapperTypeHandlers
{
public class NotRequiredOverrideDataHandler : SqlMapper.TypeHandler<NotRequiredOverrideConfiguration>
{
public override NotRequiredOverrideConfiguration Parse(object value)
{
return JsonConvert.DeserializeObject<NotRequiredOverrideConfiguration>(value.ToString());
}

public override void SetValue(IDbDataParameter parameter, NotRequiredOverrideConfiguration value)
{
parameter.Value = JsonConvert.SerializeObject(value);
}
}
}
45 changes: 45 additions & 0 deletions src/SFA.DAS.ApplyService.Domain/Entities/NotRequiredOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Collections.Generic;

namespace SFA.DAS.ApplyService.Domain.Entities
{
public class NotRequiredOverride
{
public int SequenceId { get; set; }
public int SectionId { get; set; }
public List<NotRequiredCondition> Conditions { get; set; }

public bool AllConditionsMet
{
get
{
var allConditionsMet = true;

if (Conditions != null)
{
foreach (var condition in Conditions)
{
if (condition.Value != condition.MustEqual)
{
allConditionsMet = false;
break;
}
}
}

return allConditionsMet;
}
}
}

public class NotRequiredCondition
{
public string ConditionalCheckField { get; set; }
public string MustEqual { get; set; }
public string Value { get; set; }
}

public class NotRequiredOverrideConfiguration
{
public IEnumerable<NotRequiredOverride> NotRequiredOverrides { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SFA.DAS.ApplyService.Application.Apply.Roatp;
using SFA.DAS.ApplyService.Domain.Entities;

namespace SFA.DAS.ApplyService.InternalApi.Controllers
{
[Authorize]
public class NotRequiredOverridesController : Controller
{
private readonly IMediator _mediator;

public NotRequiredOverridesController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet("NotRequiredOverrides/{applicationId}")]
public async Task<IActionResult> GetNotRequiredOverrides(Guid applicationId)
{
var notRequiredOverrides = await _mediator.Send(new GetNotRequiredOverridesRequest(applicationId));
return Ok(notRequiredOverrides);
}

[HttpPost("NotRequiredOverrides/{applicationId}")]
public async Task<IActionResult> SaveNotRequiredOverrides(Guid applicationId, [FromBody] IEnumerable<NotRequiredOverride> notRequiredOverrides)
{
var updateResult = await _mediator.Send(new UpdateNotRequiredOverridesRequest(applicationId, notRequiredOverrides));
return Ok(updateResult);
}
}
}
Loading