Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

CI-1056 Removing special list for apprenticeships #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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 @@ -23,8 +23,6 @@
<Setting name="ApprenticeshipIndexAlias" />
<Setting name="ProviderIndexAlias" />
<Setting name="AssessmentOrgsIndexAlias" />
<Setting name="FrameworksExpiredRequired" />
<Setting name="StandardsExpiredRequired" />
</ConfigurationSettings>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
<Setting name="ApprenticeshipIndexAlias" />
<Setting name="ProviderIndexAlias" />
<Setting name="AssessmentOrgsIndexAlias" />
<Setting name="FrameworksExpiredRequired" />
<Setting name="StandardsExpiredRequired" />
</ConfigurationSettings>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" loadBalancer="das-fatapi-ilb"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<Setting name="ApprenticeshipIndexAlias" value="__ApprenticeshipIndexAlias__" />
<Setting name="ProviderIndexAlias" value="__ProviderIndexAlias__" />
<Setting name="AssessmentOrgsIndexAlias" value="__AssessmentOrgsIndexAlias__" />
<Setting name="FrameworksExpiredRequired" value="__FrameworksExpiredRequired__"/>
<Setting name="StandardsExpiredRequired" value="__StandardsExpiredRequired__"/>
</ConfigurationSettings>
<Certificates>
<Certificate name="WebSslCert" thumbprint="7A1BC8263B7CBAA2B355934D0BB8031B469C1AE1" thumbprintAlgorithm="sha1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<Setting name="ApprenticeshipIndexAlias" value="localapprenticeshipindexalias" />
<Setting name="ProviderIndexAlias" value="localproviderindexalias" />
<Setting name="AssessmentOrgsIndexAlias" value="localassessmentorgsindexalias" />
<Setting name="FrameworksExpiredRequired" value=""/>
<Setting name="StandardsExpiredRequired" value="73"/>
</ConfigurationSettings>
<Certificates>
<Certificate name="WebSslCert" thumbprint="7A1BC8263B7CBAA2B355934D0BB8031B469C1AE1" thumbprintAlgorithm="sha1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<Setting name="ApprenticeshipIndexAlias" value="__ApprenticeshipIndexAlias__" />
<Setting name="ProviderIndexAlias" value="__ProviderIndexAlias__" />
<Setting name="AssessmentOrgsIndexAlias" value="__AssessmentOrgsIndexAlias__" />
<Setting name="FrameworksExpiredRequired" value="__FrameworksExpiredRequired__"/>
<Setting name="StandardsExpiredRequired" value="__StandardsExpiredRequired__"/>
</ConfigurationSettings>
<Certificates>
<Certificate name="WebSslCert" thumbprint="B64E63A87592DC4A8A46BFB68D3690C5B7E6AC04" thumbprintAlgorithm="sha1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<Setting name="ApprenticeshipIndexAlias" value="__ApprenticeshipIndexAlias__" />
<Setting name="ProviderIndexAlias" value="__ProviderIndexAlias__" />
<Setting name="AssessmentOrgsIndexAlias" value="__AssessmentOrgsIndexAlias__" />
<Setting name="FrameworksExpiredRequired" value="__FrameworksExpiredRequired__"/>
<Setting name="StandardsExpiredRequired" value="__StandardsExpiredRequired__"/>
</ConfigurationSettings>
<Certificates>
<Certificate name="WebSslCert" thumbprint="22C8DB7F51F0220677CCB62236F4AE3BD8E4A840" thumbprintAlgorithm="sha1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
<Setting name="ApprenticeshipIndexAlias" value="__ApprenticeshipIndexAlias__" />
<Setting name="ProviderIndexAlias" value="__ProviderIndexAlias__" />
<Setting name="AssessmentOrgsIndexAlias" value="__AssessmentOrgsIndexAlias__" />
<Setting name="FrameworksExpiredRequired" value="__FrameworksExpiredRequired__"/>
<Setting name="StandardsExpiredRequired" value="__StandardsExpiredRequired__"/>
</ConfigurationSettings>
<Certificates>
<Certificate name="WebSslCert" thumbprint="7A1BC8263B7CBAA2B355934D0BB8031B469C1AE1" thumbprintAlgorithm="sha1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
<Setting name="ApprenticeshipIndexAlias" />
<Setting name="ProviderIndexAlias" />
<Setting name="AssessmentOrgsIndexAlias" />
<Setting name="FrameworksExpiredRequired" />
<Setting name="StandardsExpiredRequired"/>
</ConfigurationSettings>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
Expand Down
2 changes: 0 additions & 2 deletions src/Sfa.Das.ApprenticeshipInfoService.Api/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
<add key="ElasticServerUrls" value="http://127.0.0.1:9200" />
<add key="ElasticsearchUsername" value="" />
<add key="ElasticsearchPassword" value="" />
<add key="FrameworksExpiredRequired" value="" />
<add key="StandardsExpiredRequired" value="" />
<add key="IFAStandardsApiUrl" value="https://www.instituteforapprenticeships.org/api/standards" />
<add key="ApplicationName" value="apprenticeship-programmes-api" />
<add key="ga.trackingid" value="" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ public interface IConfigurationSettings

string ElasticsearchPassword { get; }

List<string> FrameworksExpiredRequired { get; }

List<string> StandardsExpiredRequired { get; }

int PageSizeApprenticeshipSummary { get; }
int PageSizeApprenticeshipSummary { get; }

string IfaStandardApiUrl { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,14 @@ namespace Sfa.Das.ApprenticeshipInfoService.Core.Helpers
{
public class ActiveApprenticeshipChecker : IActiveApprenticeshipChecker
{
private readonly IConfigurationSettings _configurationSettings;

public ActiveApprenticeshipChecker(IConfigurationSettings configurationSettings)
{
_configurationSettings = configurationSettings;
}

public bool CheckActiveFramework(string frameworkId, DateTime? effectiveFrom, DateTime? effectiveTo)
{
return DateHelper.CheckEffectiveDates(effectiveFrom, effectiveTo) || IsSpecialLapsedFramework(frameworkId);
}

public bool CheckActiveStandard(string standardId, DateTime? effectiveFrom, DateTime? effectiveTo)
{
return DateHelper.CheckEffectiveDates(effectiveFrom, effectiveTo) || IsSpecialLapsedStandard(standardId);
}

private bool IsSpecialLapsedFramework(string frameworkId)
{
var lapsedFrameworks = _configurationSettings.FrameworksExpiredRequired;

return CheckValueIntoList(frameworkId, lapsedFrameworks);
}

private bool IsSpecialLapsedStandard(string standardId)
public bool IsActiveFramework(DateTime? effectiveFrom, DateTime? effectiveTo)
{
var lapsedStandards = _configurationSettings.StandardsExpiredRequired;

return CheckValueIntoList(standardId, lapsedStandards);
return DateHelper.CheckEffectiveDates(effectiveFrom, effectiveTo);
}

private static bool CheckValueIntoList(string apprenticeshipId, List<string> lapsedApprenticeships)
public bool IsActiveStandard(DateTime? effectiveFrom, DateTime? effectiveTo)
{
if (lapsedApprenticeships == null || lapsedApprenticeships.Count < 1)
{
return false;
}

return lapsedApprenticeships.Any(lapsedItem => lapsedItem == apprenticeshipId);
return DateHelper.CheckEffectiveDates(effectiveFrom, effectiveTo);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public FundingCapCalculator(IActiveApprenticeshipChecker activeApprenticeshipChe

public int CalculateCurrentFundingBand(StandardSearchResultsItem standard)
{
return _activeApprenticeshipChecker.CheckActiveStandard(standard.StandardId, standard.EffectiveFrom, standard.EffectiveTo) ? GetFundingCapFromPeriods(standard.FundingPeriods) : 0;
return _activeApprenticeshipChecker.IsActiveStandard(standard.EffectiveFrom, standard.EffectiveTo) ? GetFundingCapFromPeriods(standard.FundingPeriods) : 0;
}

public int CalculateCurrentFundingBand(FrameworkSearchResultsItem framework)
{
return _activeApprenticeshipChecker.CheckActiveFramework(framework.FrameworkId, framework.EffectiveFrom, framework.EffectiveTo) ? GetFundingCapFromPeriods(framework.FundingPeriods) : 0;
return _activeApprenticeshipChecker.IsActiveFramework(framework.EffectiveFrom, framework.EffectiveTo) ? GetFundingCapFromPeriods(framework.FundingPeriods) : 0;
}

private int GetFundingCapFromPeriods(List<FundingPeriod> fundingPeriods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Sfa.Das.ApprenticeshipInfoService.Core.Helpers
{
public interface IActiveApprenticeshipChecker
{
bool CheckActiveFramework(string frameworkId, DateTime? effectiveFrom, DateTime? effectiveTo);
bool CheckActiveStandard(string standardId, DateTime? effectiveFrom, DateTime? effectiveTo);
bool IsActiveFramework(DateTime? effectiveFrom, DateTime? effectiveTo);
bool IsActiveStandard(DateTime? effectiveFrom, DateTime? effectiveTo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ private IEnumerable<ApprenticeshipTraining> GetActiveFrameworksForUkprn(long ukp
var frameworks = GetFrameworksByProviderUkprn(ukprn);

return frameworks
.Where(x => _activeApprenticeshipChecker.CheckActiveFramework(x.FrameworkId, x.EffectiveFrom, x.EffectiveTo))
.Where(x => _activeApprenticeshipChecker.IsActiveFramework(x.EffectiveFrom, x.EffectiveTo))
.Select(framework => new ApprenticeshipTraining
{
Name = framework.PathwayName,
Expand All @@ -390,7 +390,7 @@ private IEnumerable<ApprenticeshipTraining> GetActiveStandardsForUkprn(long ukpr
var standards = GetStandardsByProviderUkprn(ukprn);

return standards
.Where(x => _activeApprenticeshipChecker.CheckActiveStandard(x.StandardId.ToString(), x.EffectiveFrom, x.EffectiveTo))
.Where(x => _activeApprenticeshipChecker.IsActiveStandard(x.EffectiveFrom, x.EffectiveTo))
.Select(standard => new ApprenticeshipTraining
{
Name = standard.Title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Framework MapToFramework(FrameworkSearchResultsItem document)
CombinedQualification = document.CombinedQualification?.OrderBy(x => x),
EffectiveFrom = document.EffectiveFrom,
EffectiveTo = document.EffectiveTo,
IsActiveFramework = _activeApprenticeshipChecker.CheckActiveFramework(document.FrameworkId, document.EffectiveFrom, document.EffectiveTo)
IsActiveFramework = _activeApprenticeshipChecker.IsActiveFramework(document.EffectiveFrom, document.EffectiveTo)
};

return framework;
Expand All @@ -74,7 +74,7 @@ public FrameworkSummary MapToFrameworkSummary(FrameworkSearchResultsItem documen
TypicalLength = new TypicalLength { From = document.Duration, To = document.Duration, Unit = "m" },
EffectiveFrom = document.EffectiveFrom,
EffectiveTo = document.EffectiveTo,
IsActiveFramework = _activeApprenticeshipChecker.CheckActiveFramework(document.FrameworkId, document.EffectiveFrom, document.EffectiveTo)
IsActiveFramework = _activeApprenticeshipChecker.IsActiveFramework(document.EffectiveFrom, document.EffectiveTo)
};

return framework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Standard MapToStandard(StandardSearchResultsItem document)
StandardSectorCode = document.StandardSectorCode,
EffectiveFrom = document.EffectiveFrom,
EffectiveTo = document.EffectiveTo,
IsActiveStandard = _activeApprenticeshipChecker.CheckActiveStandard(document.StandardId, document.EffectiveFrom, document.EffectiveTo),
IsActiveStandard = _activeApprenticeshipChecker.IsActiveStandard(document.EffectiveFrom, document.EffectiveTo),
LastDateForNewStarts = document.LastDateForNewStarts,
RegulatedStandard = document.RegulatedStandard
};
Expand All @@ -68,7 +68,7 @@ public StandardSummary MapToStandardSummary(StandardSearchResultsItem document)
Ssa2 = document.SectorSubjectAreaTier2,
EffectiveFrom = document.EffectiveFrom,
EffectiveTo = document.EffectiveTo,
IsActiveStandard = _activeApprenticeshipChecker.CheckActiveStandard(document.StandardId, document.EffectiveFrom, document.EffectiveTo),
IsActiveStandard = _activeApprenticeshipChecker.IsActiveStandard(document.EffectiveFrom, document.EffectiveTo),
LastDateForNewStarts = document.LastDateForNewStarts,
RegulatedStandard = document.RegulatedStandard
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,7 @@ public sealed class ApplicationSettings : IConfigurationSettings

public int PageSizeApprenticeshipSummary => int.Parse(
ConfigurationManager.AppSettings["PageSizeApprenticeshipSummary"]);

public List<string> FrameworksExpiredRequired
{
get
{
return
CloudConfigurationManager.GetSetting("FrameworksExpiredRequired")
?.Split(',')
.Where(s => s != string.Empty).Select(x => x.Trim()).ToList()
?? new List<string>();
}
}

public List<string> StandardsExpiredRequired
{
get
{
return
CloudConfigurationManager.GetSetting("StandardsExpiredRequired")
?.Split(',')
.Where(s => s != string.Empty).Select(x => x.Trim()).ToList()
?? new List<string>();
}
}


private IEnumerable<Uri> GetElasticSearchIps()
{
var urlStrings = CloudConfigurationManager.GetSetting("ElasticServerUrls").Split(',');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,30 @@ namespace Sfa.Das.ApprenticeshipInfoService.UnitTests.Helpers
[TestFixture]
public class ActiveApprenticeshipCheckerTests
{
[TestCase("123", null, null, "x", false, "No dates and no special case, so this should be false")]
[TestCase("123", null, null, "123", true, "No dates and special case, so this should be true")]
[TestCase("123", "2017-11-26", null, "x", true, "Effective from in past, so should be true")]
[TestCase("123", "2017-11-24", "2017-11-26", "x", false, "Effective from in past and effective to in past, so should be false")]
[TestCase("123", "2017-11-24", "2017-11-26", "123", true, "Effective from in past and effective to in past + special case, so should be true")]
[TestCase("123", "2040-01-01", null, null, false, "Effective from in future and no special case, so should be false")]
[TestCase("123", "2040-01-01", null, "123", true, "Effective from in future and special case, so should be true")]
[TestCase("123", null, "2040-01-01", null, false, "Effective from absent and effective to in future and no special case, so should be false")]
[TestCase(null, null, false, "No dates, so this should be false")]
[TestCase("2017-11-26", null, true, "Effective from in past, so should be true")]
[TestCase("2017-11-24", "2017-11-26", false, "Effective from in past and effective to in past, so should be false")]
[TestCase("2040-01-01", null, false, "Effective from in future, so should be false")]
[TestCase(null, "2040-01-01", false, "Effective from absent and effective to in future, so should be false")]

public void ShouldCheckActiveFrameworkScenarios(string frameworkId, DateTime? effectiveFrom, DateTime? effectiveTo, string frameworkExpiredRequired, bool expectedResult, string message)
public void ShouldCheckActiveFrameworkScenarios(DateTime? effectiveFrom, DateTime? effectiveTo, bool expectedResult, string message)
{
var mockConfigSettings = new Mock<IConfigurationSettings>();
mockConfigSettings.Setup(x => x.FrameworksExpiredRequired).Returns(new List<string> { frameworkExpiredRequired });

var activeFrameworkChecker = new ActiveApprenticeshipChecker(mockConfigSettings.Object);
var res = activeFrameworkChecker.CheckActiveFramework(frameworkId, effectiveFrom, effectiveTo);
var activeFrameworkChecker = new ActiveApprenticeshipChecker();
var res = activeFrameworkChecker.IsActiveFramework(effectiveFrom, effectiveTo);

Assert.AreEqual(expectedResult, res, message);
}

[TestCase("123", null, null, "x", false, "No dates and no special case, so this should be false")]
[TestCase("123", null, null, "123", true, "No dates and special case, so this should be true")]
[TestCase("123", "2017-11-26", null, "x", true, "Effective from in past, so should be true")]
[TestCase("123", "2017-11-24", "2017-11-26", "x", false, "Effective from in past and effective to in past, so should be false")]
[TestCase("123", "2017-11-24", "2017-11-26", "123", true, "Effective from in past and effective to in past + special case, so should be true")]
[TestCase("123", "2040-01-01", null, null, false, "Effective from in future and no special case, so should be false")]
[TestCase("123", "2040-01-01", null, "123", true, "Effective from in future and special case, so should be true")]
[TestCase("123", null, "2040-01-01", null, false, "Effective from absent and effective to in future and no special case, so should be false")]
[TestCase(null, null, false, "No dates, so this should be false")]
[TestCase("2017-11-26", null, true, "Effective from in past, so should be true")]
[TestCase("2017-11-24", "2017-11-26", false, "Effective from in past and effective to in past, so should be false")]
[TestCase("2040-01-01", null, false, "Effective from in future, so should be false")]
[TestCase(null, "2040-01-01", false, "Effective from absent and effective to in future, so should be false")]

public void ShouldCheckActiveStandardScenarios(string standardId, DateTime? effectiveFrom, DateTime? effectiveTo, string standardExpiredRequired, bool expectedResult, string message)
public void ShouldCheckActiveStandardScenarios(DateTime? effectiveFrom, DateTime? effectiveTo, bool expectedResult, string message)
{
var mockConfigSettings = new Mock<IConfigurationSettings>();
mockConfigSettings.Setup(x => x.StandardsExpiredRequired).Returns(new List<string> { standardExpiredRequired });

var activeFrameworkChecker = new ActiveApprenticeshipChecker(mockConfigSettings.Object);
var res = activeFrameworkChecker.CheckActiveStandard(standardId, effectiveFrom, effectiveTo);
var activeFrameworkChecker = new ActiveApprenticeshipChecker();
var res = activeFrameworkChecker.IsActiveStandard(effectiveFrom, effectiveTo);

Assert.AreEqual(expectedResult, res, message);
}
Expand Down
Loading