Skip to content

Commit 897a1e5

Browse files
committed
Implements models for handling upload
1 parent fd7550c commit 897a1e5

File tree

5 files changed

+102
-13
lines changed

5 files changed

+102
-13
lines changed

DigitalLearningSolutions.Data/Models/Frameworks/Import/CompetencyTableRow.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
namespace DigitalLearningSolutions.Data.Models.Frameworks.Import
22
{
33
using ClosedXML.Excel;
4-
using System;
5-
using System.Collections.Generic;
6-
using System.Text;
74
public enum RowStatus
85
{
96
NotYetProcessed,
107
Skipped,
11-
CompetencyGroupInserted,
128
CompetencyGroupAndCompetencyInserted,
13-
CompetencyInserted
9+
CompetencyInserted,
10+
CompetencyUpdated,
11+
CompetencyGroupInserted,
12+
CompetencyGroupUpdated,
13+
CompetencyGroupAndCompetencyUpdated
1414
}
1515
public class CompetencyTableRow : BulkCompetency
1616
{
@@ -23,9 +23,12 @@ public CompetencyTableRow(IXLTable table, IXLRangeRow row)
2323
}
2424

2525
RowNumber = row.RowNumber();
26-
CompetencyGroup = FindFieldValue("competency group");
27-
Competency = FindFieldValue("competency name");
28-
CompetencyDescription = FindFieldValue("competency description");
26+
id = int.Parse(FindFieldValue("ID"));
27+
CompetencyGroup = FindFieldValue("CompetencyGroup");
28+
Competency = FindFieldValue("Competency");
29+
CompetencyDescription = FindFieldValue("CompetencyDescription");
30+
GroupDescription = FindFieldValue("CompetencyGroupDescription");
31+
FlagsCsv = FindFieldValue("FlagsCSV");
2932
RowStatus = RowStatus.NotYetProcessed;
3033
}
3134
public int RowNumber { get; set; }

DigitalLearningSolutions.Web.Tests/Controllers/Frameworks/FrameworkControllerTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.Extensions.Logging;
1313
using NUnit.Framework;
1414
using GDS.MultiPageFormData;
15+
using DigitalLearningSolutions.Data.Utilities;
16+
using Microsoft.AspNetCore.Hosting;
1517

1618
public partial class FrameworkControllerTests
1719
{
@@ -28,6 +30,8 @@ public partial class FrameworkControllerTests
2830
private ILearningHubApiClient learningHubApiClient = null!;
2931
private ISearchSortFilterPaginateService searchSortFilterPaginateService = null!;
3032
private IMultiPageFormService multiPageFormService = null!;
33+
private IClockUtility clockUtility = null!;
34+
private IWebHostEnvironment webHostEnvironment = null!;
3135

3236
[SetUp]
3337
public void SetUp()
@@ -42,7 +46,8 @@ public void SetUp()
4246
learningHubApiClient = A.Fake<ILearningHubApiClient>();
4347
searchSortFilterPaginateService = A.Fake<ISearchSortFilterPaginateService>();
4448
multiPageFormService = A.Fake<IMultiPageFormService>();
45-
49+
clockUtility = A.Fake<ClockUtility>();
50+
webHostEnvironment = A.Fake<IWebHostEnvironment>();
4651
A.CallTo(() => config["CurrentSystemBaseUrl"]).Returns(BaseUrl);
4752

4853
var user = new ClaimsPrincipal(
@@ -65,7 +70,9 @@ public void SetUp()
6570
competencyLearningResourcesService,
6671
learningHubApiClient,
6772
searchSortFilterPaginateService,
68-
multiPageFormService
73+
multiPageFormService,
74+
clockUtility,
75+
webHostEnvironment
6976
)
7077
{
7178
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } },

DigitalLearningSolutions.Web.Tests/ServiceFilter/RedirectToErrorEmptySessionDataTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
using NUnit.Framework;
2323
using GDS.MultiPageFormData;
2424
using GDS.MultiPageFormData.Enums;
25+
using DigitalLearningSolutions.Data.Utilities;
26+
using Microsoft.AspNetCore.Hosting;
2527

2628
public class RedirectToErrorEmptySessionDataTests
2729
{
@@ -41,7 +43,9 @@ public void Setup()
4143
A.Fake<ICompetencyLearningResourcesService>(),
4244
A.Fake<ILearningHubApiClient>(),
4345
A.Fake<ISearchSortFilterPaginateService>(),
44-
A.Fake<IMultiPageFormService>()
46+
A.Fake<IMultiPageFormService>(),
47+
A.Fake<IClockUtility>(),
48+
A.Fake<IWebHostEnvironment>()
4549
)
4650
.WithDefaultContext().WithMockTempData();
4751

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
1-
namespace DigitalLearningSolutions.Web.Models
1+
using DigitalLearningSolutions.Data.Models.Frameworks.Import;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace DigitalLearningSolutions.Web.Models
26
{
37
public class BulkCompetenciesResult
48
{
9+
public enum ErrorReason
10+
{
11+
InvalidId,
12+
MissingCompetencyName,
13+
TooLongCompetencyName,
14+
TooLongCompetencyGroupName,
15+
InvalidAlwaysShowDescription
16+
}
17+
18+
public BulkCompetenciesResult() { }
19+
20+
public BulkCompetenciesResult(
21+
IReadOnlyCollection<CompetencyTableRow> competencyRows
22+
)
23+
{
24+
ProcessedCount = competencyRows.Count;
25+
CompetencyAddedCount = competencyRows.Count(cr => cr.RowStatus == RowStatus.CompetencyInserted || cr.RowStatus == RowStatus.CompetencyGroupAndCompetencyInserted);
26+
GroupAddedCount = competencyRows.Count(cr => cr.RowStatus == RowStatus.CompetencyGroupAndCompetencyInserted);
27+
GroupUpdatedCount = competencyRows.Count(cr => cr.RowStatus == RowStatus.CompetencyGroupUpdated || cr.RowStatus == RowStatus.CompetencyGroupAndCompetencyUpdated);
28+
SkippedCount = competencyRows.Count(cr => cr.RowStatus == RowStatus.Skipped);
29+
Errors = (IEnumerable<(int RowNumber, ErrorReason Reason)>)competencyRows.Where(cr => cr.Error.HasValue).Select(cr => (cr.RowNumber, cr.Error!.Value));
30+
}
31+
32+
public IEnumerable<(int RowNumber, ErrorReason Reason)>? Errors { get; set; }
33+
public int ProcessedCount { get; set; }
34+
public int CompetencyAddedCount { get; set; }
35+
public int CompetencyUpdatedCount { get; set; }
36+
public int GroupAddedCount { get; set; }
37+
public int GroupUpdatedCount { get; set; }
38+
public int SkippedCount { get; set; }
539
}
640
}
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
1-
namespace DigitalLearningSolutions.Web.ViewModels.Frameworks
1+
using System.Collections.Generic;
2+
using System;
3+
using DigitalLearningSolutions.Web.Models;
4+
using System.Linq;
5+
6+
namespace DigitalLearningSolutions.Web.ViewModels.Frameworks
27
{
38
public class ImportCompetenciesPreProcessViewModel
49
{
10+
public ImportCompetenciesPreProcessViewModel(BulkCompetenciesResult bulkCompetenciesResult)
11+
{
12+
ToProcessCount = bulkCompetenciesResult.ProcessedCount;
13+
CompetenciesToAddCount = bulkCompetenciesResult.CompetencyAddedCount;
14+
CompetenciesToUpdateCount = bulkCompetenciesResult.CompetencyUpdatedCount;
15+
CompetencyGroupsToAddCount = bulkCompetenciesResult.GroupAddedCount;
16+
CompetencyGroupsToUpdateCount = bulkCompetenciesResult.GroupUpdatedCount;
17+
Errors = bulkCompetenciesResult.Errors.Select(x => (x.RowNumber, MapReasonToErrorMessage(x.Reason)));
18+
}
19+
20+
public IEnumerable<(int RowNumber, string ErrorMessage)> Errors { get; set; }
21+
public int ErrorCount => Errors.Count();
22+
public int ToProcessCount { get; set; }
23+
public int CompetenciesToAddCount { get; set; }
24+
public int CompetenciesToUpdateCount { get; set; }
25+
public int CompetencyGroupsToAddCount { get; set; }
26+
public int CompetencyGroupsToUpdateCount { get; set; }
27+
public int ToUpdateOrSkipCount { get; set; }
28+
29+
private static string MapReasonToErrorMessage(BulkCompetenciesResult.ErrorReason reason)
30+
{
31+
return reason switch
32+
{
33+
BulkCompetenciesResult.ErrorReason.TooLongCompetencyGroupName =>
34+
"Group name must be 255 characters or less.",
35+
BulkCompetenciesResult.ErrorReason.MissingCompetencyName =>
36+
"Competency is blank. Competency is a required field and cannot be left blank",
37+
BulkCompetenciesResult.ErrorReason.InvalidId =>
38+
"The ID provided does not match a Competency ID in this Framework",
39+
BulkCompetenciesResult.ErrorReason.TooLongCompetencyName =>
40+
"Competency must be 255 characters or less.",
41+
BulkCompetenciesResult.ErrorReason.InvalidAlwaysShowDescription =>
42+
"Always show description is invalid. The Always show description field must contain 'TRUE' or 'FALSE'",
43+
_ => "Unspecified error.",
44+
};
45+
}
546
}
647
}

0 commit comments

Comments
 (0)