From de01c3be29255c19fa4a7abf078fbdb7ec5a420e Mon Sep 17 00:00:00 2001 From: Dominic NEED Date: Fri, 15 Mar 2024 10:06:08 +0000 Subject: [PATCH] Add string sanitisation to strings being exported to word --- .../DocumentGenerator/DocumentGenerator.cs | 11 +- .../DocumentGeneratorStringSanitiser.cs | 51 ++++++ .../LegalRequirementsGenerator.cs | 15 +- .../OfstedInformationGenerator.cs | 50 ++---- .../DocumentGenerator/RationaleGenerator.cs | 39 ++-- .../RisksAndIssuesGenerator.cs | 8 +- ...rustInformationAndProjectDatesGenerator.cs | 166 +++++------------- .../SchoolOverviewGenerator.cs | 70 +++----- 8 files changed, 169 insertions(+), 241 deletions(-) create mode 100644 Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGeneratorStringSanitiser.cs diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGenerator.cs index eb53a16c4..fafb051a0 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGenerator.cs @@ -8,19 +8,18 @@ using System; using System.IO; using System.Reflection; - -// Document Section Generators -using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolAndTrustInformationAndProjectDatesGenerator; -using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolOverviewGenerator; -using static Dfe.PrepareConversions.Services.DocumentGenerator.OfstedInformationGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.EducationalAttendanceGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.KeyStage2Generator; using static Dfe.PrepareConversions.Services.DocumentGenerator.KeyStage4Generator; using static Dfe.PrepareConversions.Services.DocumentGenerator.KeyStage5Generator; +using static Dfe.PrepareConversions.Services.DocumentGenerator.LegalRequirementsGenerator; +using static Dfe.PrepareConversions.Services.DocumentGenerator.OfstedInformationGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.RationaleGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.RisksAndIssuesGenerator; -using static Dfe.PrepareConversions.Services.DocumentGenerator.LegalRequirementsGenerator; +// Document Section Generators +using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolAndTrustInformationAndProjectDatesGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolBudgetInformationGenerator; +using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolOverviewGenerator; using static Dfe.PrepareConversions.Services.DocumentGenerator.SchoolPupilForecastGenerator; namespace Dfe.PrepareConversions.Services.DocumentGenerator diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGeneratorStringSanitiser.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGeneratorStringSanitiser.cs new file mode 100644 index 000000000..29d9e1ec3 --- /dev/null +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/DocumentGeneratorStringSanitiser.cs @@ -0,0 +1,51 @@ +using Dfe.PrepareConversions.DocumentGeneration.Elements; +using System.Linq; +using System.Xml; + +namespace Dfe.PrepareConversions.Services.DocumentGenerator +{ + public static class DocumentGeneratorStringSanitiser + { + public static string SanitizeString(string input) + { + if (string.IsNullOrEmpty(input)) return input; + + string output = input.Replace("<", "<") + .Replace(">", ">") + .Replace("&", "&") + .Replace("\"", """) + .Replace("\'", "'") + .Replace("&amp;", "&"); + output = new string(output.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray()); + return output; + } + + // SanitizeTextElements method as provided + public static TextElement[] SanitizeTextElements(TextElement[] elements) + { + return elements.Select(element => new TextElement + { + Value = SanitizeString(element.Value), + Bold = element.Bold + }).ToArray(); + } + + // Utility method to create and sanitize TextElement arrays + public static TextElement[] CreateTextElements(string label, string value) + { + return SanitizeTextElements(new[] + { + new TextElement { Value = label, Bold = true }, + new TextElement { Value = value } + }); + } + public static TextElement[] CreateSingleTextElement(string value) + { + return new TextElement[] + { + new() { Value = SanitizeString(value) } + }; + } + + } +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/LegalRequirementsGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/LegalRequirementsGenerator.cs index 39cd88033..029c12276 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/LegalRequirementsGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/LegalRequirementsGenerator.cs @@ -16,12 +16,12 @@ public static void AddLegalRequirements(IDocumentBuilder builder, HtbTemplate do { build.AddHeading("Legal requirements", HeadingLevel.One); build.AddTable(new List - { - new[] { new TextElement { Value = "Management commitee resolution", Bold = true }, new TextElement { Value = document.GoverningBodyResolution } }, - new[] { new TextElement { Value = "Consultation", Bold = true }, new TextElement { Value = document.Consultation } }, - new[] { new TextElement { Value = "Diocesan consent", Bold = true }, new TextElement { Value = document.DiocesanConsent } }, - new[] { new TextElement { Value = "Foundation consent", Bold = true }, new TextElement { Value = document.FoundationConsent } }, - }); + { + DocumentGeneratorStringSanitiser.CreateTextElements("Management committee resolution", document.GoverningBodyResolution ?? "N/A"), + DocumentGeneratorStringSanitiser.CreateTextElements("Consultation", document.Consultation ?? "N/A"), + DocumentGeneratorStringSanitiser.CreateTextElements("Diocesan consent", document.DiocesanConsent ?? "N/A"), + DocumentGeneratorStringSanitiser.CreateTextElements("Foundation consent", document.FoundationConsent ?? "N/A"), + }); build.AddParagraph(""); }); } @@ -29,8 +29,9 @@ public static void AddLegalRequirements(IDocumentBuilder builder, HtbTemplate do { builder.ReplacePlaceholderWithContent("LegalRequirements", build => { + // If the academy route is sponsored, no legal requirements are displayed }); } } } -} \ No newline at end of file +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/OfstedInformationGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/OfstedInformationGenerator.cs index af9c675ac..7920f9ef2 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/OfstedInformationGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/OfstedInformationGenerator.cs @@ -14,32 +14,21 @@ public static void AddOfstedInformation(DocumentBuilder builder, HtbTemplate doc SchoolPerformance schoolPerformance = document.SchoolPerformance; List ofstedInformation = new() - { - new[] { new TextElement { Value = "School name", Bold = true }, new TextElement { Value = project.SchoolName } }, - new[] - { - new TextElement { Value = "Latest full inspection date", Bold = true }, - new TextElement { Value = schoolPerformance.InspectionEndDate?.ToString("d MMMM yyyy") ?? "No data" } - }, - new[] { new TextElement { Value = "Overall effectiveness", Bold = true }, new TextElement { Value = schoolPerformance.OverallEffectiveness.DisplayOfstedRating() } }, - new[] { new TextElement { Value = "Quality of education", Bold = true }, new TextElement { Value = schoolPerformance.QualityOfEducation.DisplayOfstedRating() } }, - new[] { new TextElement { Value = "Behaviour and attitudes", Bold = true }, new TextElement { Value = schoolPerformance.BehaviourAndAttitudes.DisplayOfstedRating() } }, - new[] { new TextElement { Value = "Personal development", Bold = true }, new TextElement { Value = schoolPerformance.PersonalDevelopment.DisplayOfstedRating() } }, - new[] - { - new TextElement { Value = "Effectiveness of leadership and management", Bold = true }, - new TextElement { Value = schoolPerformance.EffectivenessOfLeadershipAndManagement.DisplayOfstedRating() } - } - }; + { + DocumentGeneratorStringSanitiser.CreateTextElements("School name", project.SchoolName), + DocumentGeneratorStringSanitiser.CreateTextElements("Latest full inspection date", schoolPerformance.InspectionEndDate?.ToString("d MMMM yyyy") ?? "No data"), + DocumentGeneratorStringSanitiser.CreateTextElements("Overall effectiveness", schoolPerformance.OverallEffectiveness.DisplayOfstedRating()), + DocumentGeneratorStringSanitiser.CreateTextElements("Quality of education", schoolPerformance.QualityOfEducation.DisplayOfstedRating()), + DocumentGeneratorStringSanitiser.CreateTextElements("Behaviour and attitudes", schoolPerformance.BehaviourAndAttitudes.DisplayOfstedRating()), + DocumentGeneratorStringSanitiser.CreateTextElements("Personal development", schoolPerformance.PersonalDevelopment.DisplayOfstedRating()), + DocumentGeneratorStringSanitiser.CreateTextElements("Effectiveness of leadership and management", schoolPerformance.EffectivenessOfLeadershipAndManagement.DisplayOfstedRating()) + }; PopulateIfLatestInspectionIsSection8(schoolPerformance, ofstedInformation); PopulateIfEarlyYearsProvision(schoolPerformance, ofstedInformation); PopulateIfSixthFormProvision(schoolPerformance, ofstedInformation); - ofstedInformation.Add(new[] - { - new TextElement { Value = "Additional information", Bold = true }, new TextElement { Value = project.SchoolPerformanceAdditionalInformation } - }); + ofstedInformation.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Additional information", project.SchoolPerformanceAdditionalInformation)); builder.ReplacePlaceholderWithContent("SchoolPerformanceData", build => { @@ -53,11 +42,7 @@ private static void PopulateIfSixthFormProvision(SchoolPerformance schoolPerform { if (schoolPerformance.SixthFormProvision.DisplayOfstedRating().HasData()) { - ofstedInformation.Add(new[] - { - new TextElement { Value = "Sixth form provision", Bold = true }, - new TextElement { Value = schoolPerformance.SixthFormProvision.DisplayOfstedRating() } - }); + ofstedInformation.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Sixth form provision", schoolPerformance.SixthFormProvision.DisplayOfstedRating())); } } @@ -65,11 +50,7 @@ private static void PopulateIfEarlyYearsProvision(SchoolPerformance schoolPerfor { if (schoolPerformance.EarlyYearsProvision.DisplayOfstedRating().HasData()) { - ofstedInformation.Add(new[] - { - new TextElement { Value = "Early years provision", Bold = true }, - new TextElement { Value = schoolPerformance.EarlyYearsProvision.DisplayOfstedRating() } - }); + ofstedInformation.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Early years provision", schoolPerformance.EarlyYearsProvision.DisplayOfstedRating())); } } @@ -77,12 +58,7 @@ private static void PopulateIfLatestInspectionIsSection8(SchoolPerformance schoo { if (schoolPerformance.LatestInspectionIsSection8) { - ofstedInformation.Insert(1, - new[] - { - new TextElement { Value = "Latest short inspection date", Bold = true }, - new TextElement { Value = schoolPerformance.DateOfLatestSection8Inspection?.ToString("d MMMM yyyy") } - }); + ofstedInformation.Insert(1, DocumentGeneratorStringSanitiser.CreateTextElements("Latest short inspection date", schoolPerformance.DateOfLatestSection8Inspection?.ToString("d MMMM yyyy") ?? "No data")); } } } diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RationaleGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RationaleGenerator.cs index db10f2350..f155b26db 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RationaleGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RationaleGenerator.cs @@ -4,29 +4,30 @@ using Dfe.PrepareConversions.Models; using System.Collections.Generic; -namespace Dfe.PrepareConversions.Services.DocumentGenerator; - -public static class RationaleGenerator +namespace Dfe.PrepareConversions.Services.DocumentGenerator { - public static void AddRationale(IDocumentBuilder builder, HtbTemplate document, AcademyConversionProject project) + public static class RationaleGenerator { - builder.ReplacePlaceholderWithContent("Rationale", build => + public static void AddRationale(IDocumentBuilder builder, HtbTemplate document, AcademyConversionProject project) { - build.AddHeading("Rationale", HeadingLevel.One); - if (project.AcademyTypeAndRoute.Equals(AcademyTypeAndRoutes.Sponsored) is false) + builder.ReplacePlaceholderWithContent("Rationale", build => { - build.AddHeading("Rationale for the project", HeadingLevel.Two); - build.AddTable(new List + build.AddHeading("Rationale", HeadingLevel.One); + if (!project.AcademyTypeAndRoute.Equals(AcademyTypeAndRoutes.Sponsored)) { - new[] { new TextElement { Value = document.RationaleForProject ?? "N/A" } } - }); - } - - build.AddHeading("Rationale for the trust or sponsor", HeadingLevel.Two); - build.AddTable(new List - { - new[] { new TextElement { Value = document.RationaleForTrust ?? "N/A" } } + build.AddHeading("Rationale for the project", HeadingLevel.Two); + build.AddTable(new List + { + DocumentGeneratorStringSanitiser.CreateSingleTextElement(document.RationaleForProject ?? "N/A") + }); + } + + build.AddHeading("Rationale for the trust or sponsor", HeadingLevel.Two); + build.AddTable(new List + { + DocumentGeneratorStringSanitiser.CreateSingleTextElement(document.RationaleForTrust ?? "N/A") + }); }); - }); + } } -} \ No newline at end of file +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RisksAndIssuesGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RisksAndIssuesGenerator.cs index 1c0d710a9..7b4d7b102 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RisksAndIssuesGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/RisksAndIssuesGenerator.cs @@ -13,10 +13,10 @@ public static void AddRisksAndIssues(IDocumentBuilder builder, HtbTemplate docum { build.AddHeading("Risks and issues", HeadingLevel.One); build.AddTable(new List - { - new[] { new TextElement { Value = document.RisksAndIssues ?? "N/A" } } - }); + { + DocumentGeneratorStringSanitiser.CreateSingleTextElement(document.RisksAndIssues ?? "N/A") + }); }); } } -} \ No newline at end of file +} diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolAndTrustInformationAndProjectDatesGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolAndTrustInformationAndProjectDatesGenerator.cs index b6fda958c..3848cf215 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolAndTrustInformationAndProjectDatesGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolAndTrustInformationAndProjectDatesGenerator.cs @@ -9,177 +9,91 @@ namespace Dfe.PrepareConversions.Services.DocumentGenerator { public static class SchoolAndTrustInformationAndProjectDatesGenerator { - public static void AddSchoolAndTrustInfoAndProjectDates(DocumentBuilder documentBuilder, - AcademyConversionProject project) + public static void AddSchoolAndTrustInfoAndProjectDates(DocumentBuilder documentBuilder, AcademyConversionProject project) { AddAcademyRouteInfo(documentBuilder, project); AddAdvisoryBoardDetails(documentBuilder, project); AddLocalAuthorityAndSponsorDetails(documentBuilder, project); } + private static void AddLocalAuthorityAndSponsorDetails(IDocumentBuilder builder, AcademyConversionProject project) { List localAuthorityAndSponsorDetails = new() - { - new[] - { - new TextElement { Value = "Local authority", Bold = true }, - new TextElement { Value = project.LocalAuthority } - }, - new[] - { - new TextElement { Value = "Sponsor name", Bold = true }, - new TextElement { Value = project.SponsorName } - }, - new[] - { - new TextElement { Value = "Sponsor reference number", Bold = true }, - new TextElement { Value = project.SponsorReferenceNumber } - } - }; + { + DocumentGeneratorStringSanitiser.CreateTextElements("Local authority", project.LocalAuthority), + DocumentGeneratorStringSanitiser.CreateTextElements("Sponsor name", project.SponsorName), + DocumentGeneratorStringSanitiser.CreateTextElements("Sponsor reference number", project.SponsorReferenceNumber) + }; builder.ReplacePlaceholderWithContent("LocalAuthorityAndSponsorDetails", body => { body.AddTable(localAuthorityAndSponsorDetails); }); } + private static void AddAdvisoryBoardDetails(IDocumentBuilder builder, AcademyConversionProject project) { List advisoryBoardDetails = new() - { - new[] - { - new TextElement { Value = "Date of advisory board", Bold = true }, - new TextElement { Value = project.HeadTeacherBoardDate.ToDateString()} - }, - new[] - { - new TextElement { Value = "Proposed academy opening date", Bold = true }, - new TextElement { Value = project.ProposedAcademyOpeningDate.ToDateString() } - }, - new[] - { - new TextElement { Value = "Previous advisory board", Bold = true }, - new TextElement { Value = project.PreviousHeadTeacherBoardDate.ToDateString() } - } - }; + { + DocumentGeneratorStringSanitiser.CreateTextElements("Date of advisory board", project.HeadTeacherBoardDate.ToDateString()), + DocumentGeneratorStringSanitiser.CreateTextElements("Proposed academy opening date", project.ProposedAcademyOpeningDate.ToDateString()), + DocumentGeneratorStringSanitiser.CreateTextElements("Previous advisory board", project.PreviousHeadTeacherBoardDate.ToDateString()) + }; builder.ReplacePlaceholderWithContent("AdvisoryBoardDetails", body => body.AddTable(advisoryBoardDetails)); - } + private static void AddAcademyRouteInfo(IDocumentBuilder builder, AcademyConversionProject project) { - List academyRouteInfo = new(); - switch (project.AcademyTypeAndRoute) + List academyRouteInfo = project.AcademyTypeAndRoute switch { - case AcademyTypeAndRoutes.Voluntary: - academyRouteInfo = VoluntaryRouteInfo(project); - break; - case AcademyTypeAndRoutes.Sponsored: - academyRouteInfo = SponsoredRouteInfo(project); - break; - } + AcademyTypeAndRoutes.Voluntary => VoluntaryRouteInfo(project), + AcademyTypeAndRoutes.Sponsored => SponsoredRouteInfo(project), + _ => new List() + }; builder.ReplacePlaceholderWithContent("AcademyRouteInfo", body => { body.AddHeading("Conversion details", HeadingLevel.One); body.AddTable(academyRouteInfo); }); - } private static List VoluntaryRouteInfo(AcademyConversionProject project) { - List voluntaryRouteInfo = new() - { - new[] - { - new TextElement { Value = "Academy type and route", Bold = true }, - new TextElement { Value = project.AcademyTypeAndRoute } - }, - new[] - { - new TextElement { Value = "Grant funding amount", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantAmount.ToMoneyString(true) } - }, - new[] - { - new TextElement { Value = "Grant funding reason", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantChangeReason } - }, - new[] - { - new TextElement { Value = "Recommendation", Bold = true }, - new TextElement { Value = project.RecommendationForProject } - }, - }; + var voluntaryRouteInfo = new List + { + DocumentGeneratorStringSanitiser.CreateTextElements("Academy type and route", project.AcademyTypeAndRoute), + DocumentGeneratorStringSanitiser.CreateTextElements("Grant funding amount", project.ConversionSupportGrantAmount.ToMoneyString(true)), + DocumentGeneratorStringSanitiser.CreateTextElements("Grant funding reason", project.ConversionSupportGrantChangeReason), + DocumentGeneratorStringSanitiser.CreateTextElements("Recommendation", project.RecommendationForProject) + }; if (project.SchoolType.ToLower().Contains("pupil referral unit")) { - voluntaryRouteInfo.Add(new[] - { - new TextElement { Value = "Number of sites", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantNumberOfSites} - } - ); + voluntaryRouteInfo.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of sites", project.ConversionSupportGrantNumberOfSites.ToString())); } return voluntaryRouteInfo; - } + private static List SponsoredRouteInfo(AcademyConversionProject project) { - List sponsoredRouteInfo = new() - { - new[] - { - new TextElement { Value = "Academy type and route", Bold = true }, - new TextElement { Value = project.AcademyTypeAndRoute} - }, - new[] - { - new TextElement { Value = "Grant funding type", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantType } - }, - new[] - { - new TextElement { Value = "Grant funding amount", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantAmount.ToMoneyString(true) } - }, - new[] - { - new TextElement { Value = "Grant funding reason", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantChangeReason } - }, - new[] - { - new TextElement { Value = "Is the school applying for an EIG (Environmental Improvement Grant)?", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantEnvironmentalImprovementGrant } - }, - new[] - { - new TextElement { Value = "Has the Schools Notification Mailbox (SNM) received a Form 7?", Bold = true }, - new TextElement { Value = project.Form7Received } - }, - new[] - { - new TextElement { Value = "Date SNM received Form 7", Bold = true }, - new TextElement { Value = project.Form7ReceivedDate.ToDateString() } - }, - new[] - { - new TextElement { Value = "Date directive academy order (DAO) pack sent", Bold = true }, - new TextElement { Value = project.DaoPackSentDate.ToDateString() } - }, - }; + var sponsoredRouteInfo = new List + { + DocumentGeneratorStringSanitiser.CreateTextElements("Academy type and route", project.AcademyTypeAndRoute), + DocumentGeneratorStringSanitiser.CreateTextElements("Grant funding type", project.ConversionSupportGrantType), + DocumentGeneratorStringSanitiser.CreateTextElements("Grant funding amount", project.ConversionSupportGrantAmount.ToMoneyString(true)), + DocumentGeneratorStringSanitiser.CreateTextElements("Grant funding reason", project.ConversionSupportGrantChangeReason), + DocumentGeneratorStringSanitiser.CreateTextElements("Is the school applying for an EIG (Environmental Improvement Grant)?", project.ConversionSupportGrantEnvironmentalImprovementGrant), + DocumentGeneratorStringSanitiser.CreateTextElements("Has the Schools Notification Mailbox (SNM) received a Form 7?", project.Form7Received), + DocumentGeneratorStringSanitiser.CreateTextElements("Date SNM received Form 7", project.Form7ReceivedDate.ToDateString()), + DocumentGeneratorStringSanitiser.CreateTextElements("Date directive academy order (DAO) pack sent", project.DaoPackSentDate.ToDateString()) + }; if (project.SchoolType.ToLower().Contains("pupil referral unit")) { - sponsoredRouteInfo.Add(new[] - { - new TextElement { Value = "Number of sites", Bold = true }, - new TextElement { Value = project.ConversionSupportGrantNumberOfSites} - } - ); + sponsoredRouteInfo.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of sites", project.ConversionSupportGrantNumberOfSites.ToString())); } return sponsoredRouteInfo; diff --git a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolOverviewGenerator.cs b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolOverviewGenerator.cs index fe1eb3732..f80216671 100644 --- a/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolOverviewGenerator.cs +++ b/Dfe.PrepareConversions/Dfe.PrepareConversions/Services/DocumentGenerator/SchoolOverviewGenerator.cs @@ -1,68 +1,54 @@ using Dfe.PrepareConversions.DocumentGeneration.Elements; using Dfe.PrepareConversions.DocumentGeneration.Interfaces; using Dfe.PrepareConversions.Models; -using Dfe.PrepareConversions.Utils; using System.Collections.Generic; namespace Dfe.PrepareConversions.Services.DocumentGenerator { public static class SchoolOverviewGenerator { + public static void AddSchoolOverview(IDocumentBuilder builder, HtbTemplate document) { builder.ReplacePlaceholderWithContent("SchoolOverview", build => { build.AddHeading("School overview", HeadingLevel.One); - var schoolOverviewTable = new List(); - schoolOverviewTable.AddRange(new List { - new[] { new TextElement { Value = "School type", Bold = true }, new TextElement { Value = document.SchoolType } }, - new[] { new TextElement { Value = "School phase", Bold = true }, new TextElement { Value = document.SchoolPhase } }, - new[] { new TextElement { Value = "Age range", Bold = true }, new TextElement { Value = document.AgeRange } }, - new[] { new TextElement { Value = "Capacity", Bold = true }, new TextElement { Value = document.SchoolCapacity } }, - new[] { new TextElement { Value = "Published admission number (PAN)", Bold = true }, new TextElement { Value = document.PublishedAdmissionNumber } }, - new[] { new TextElement { Value = "Number on roll (NOR)", Bold = true }, new TextElement { Value = document.NumberOnRoll } }, - new[] { new TextElement { Value = "Percentage of the school is full", Bold = true }, new TextElement { Value = document.PercentageSchoolFull } }, - new[] - { - new TextElement { Value = "Percentage of free school meals at the school (%FSM)", Bold = true }, - new TextElement { Value = document.PercentageFreeSchoolMeals } - }, - new[] { new TextElement { Value = "Viability issues", Bold = true }, new TextElement { Value = document.ViabilityIssues } }}); + var schoolOverviewTable = new List + { + DocumentGeneratorStringSanitiser.CreateTextElements("School type", document.SchoolType), + DocumentGeneratorStringSanitiser.CreateTextElements("School phase", document.SchoolPhase), + DocumentGeneratorStringSanitiser.CreateTextElements("Age range", document.AgeRange), + DocumentGeneratorStringSanitiser.CreateTextElements("Capacity", document.SchoolCapacity), + DocumentGeneratorStringSanitiser.CreateTextElements("Published admission number (PAN)", document.PublishedAdmissionNumber), + DocumentGeneratorStringSanitiser.CreateTextElements("Number on roll (NOR)", document.NumberOnRoll), + DocumentGeneratorStringSanitiser.CreateTextElements("Percentage of the school is full", document.PercentageSchoolFull), + DocumentGeneratorStringSanitiser.CreateTextElements("Percentage of free school meals at the school (%FSM)", document.PercentageFreeSchoolMeals), + DocumentGeneratorStringSanitiser.CreateTextElements("Viability issues", document.ViabilityIssues) + }; if (document.SchoolType.ToLower().Contains("pupil referral unit")) { - schoolOverviewTable.AddRange(new List { - new[] { new TextElement { Value = "Which groups of pupils attend the school", Bold = true }, new TextElement { Value = document.PupilsAttendingGroup } }, - new[] { new TextElement { Value = "Number of places funded for", Bold = true }, new TextElement { Value = document.NumberOfPlacesFundedFor } }, - new[] { new TextElement { Value = "Alternative provision", Bold = true }, new TextElement { Value = document.NumberOfAlternativeProvisionPlaces } }, - new[] { new TextElement { Value = "SEN Unit", Bold = true }, new TextElement { Value = document.NumberOfSENUnitPlaces } }, - new[] { new TextElement { Value = "Medical", Bold = true }, new TextElement { Value = document.NumberOfMedicalPlaces } }, - new[] { new TextElement { Value = "Post-16", Bold = true }, new TextElement { Value = document.NumberOfPost16Places } }, - }); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Which groups of pupils attend the school", document.PupilsAttendingGroup)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of places funded for", document.NumberOfPlacesFundedFor)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Alternative provision", document.NumberOfAlternativeProvisionPlaces)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("SEN Unit", document.NumberOfSENUnitPlaces)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Medical", document.NumberOfMedicalPlaces)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Post-16", document.NumberOfPost16Places)); } - // Specific SEN fields if (document.SchoolType.ToLower().Contains("special")) { - schoolOverviewTable.AddRange(new List { - new[] { new TextElement { Value = "Number of places funded for", Bold = true }, new TextElement { Value = document.NumberOfPlacesFundedFor } }, - new[] { new TextElement { Value = "Number of residential places", Bold = true }, new TextElement { Value = document.NumberOfResidentialPlaces } }, - new[] { new TextElement { Value = "Number of funded residential places", Bold = true }, new TextElement { Value = document.NumberOfFundedResidentialPlaces } }, - }); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of places funded for", document.NumberOfPlacesFundedFor)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of residential places", document.NumberOfResidentialPlaces)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Number of funded residential places", document.NumberOfFundedResidentialPlaces)); } - schoolOverviewTable.AddRange(new List { - new[] { new TextElement { Value = "Financial deficit", Bold = true }, new TextElement { Value = document.FinancialDeficit } }, - new[] { new TextElement { Value = "Private finance initiative (PFI) scheme", Bold = true }, new TextElement { Value = document.PartOfPfiScheme } }, - new[] { new TextElement { Value = "Is the school linked to a diocese?", Bold = true }, new TextElement { Value = document.IsSchoolLinkedToADiocese } }, - new[] - { - new TextElement { Value = "Distance from the converting school to the trust or other schools in the trust", Bold = true }, - new TextElement { Value = $"{document.DistanceFromSchoolToTrustHeadquarters} {document.DistanceFromSchoolToTrustHeadquartersAdditionalInformation}" } - }, - new[] { new TextElement { Value = "Parliamentary constituency", Bold = true }, new TextElement { Value = document.ParliamentaryConstituency } }, - new[] { new TextElement { Value = "MP name and political party", Bold = true }, new TextElement { Value = document.MemberOfParliamentNameAndParty } } - }); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Financial deficit", document.FinancialDeficit)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Private finance initiative (PFI) scheme", document.PartOfPfiScheme)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Is the school linked to a diocese?", document.IsSchoolLinkedToADiocese)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Distance from the converting school to the trust or other schools in the trust", $"{document.DistanceFromSchoolToTrustHeadquarters} {document.DistanceFromSchoolToTrustHeadquartersAdditionalInformation}")); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("Parliamentary constituency", document.ParliamentaryConstituency)); + schoolOverviewTable.Add(DocumentGeneratorStringSanitiser.CreateTextElements("MP name and political party", document.MemberOfParliamentNameAndParty)); build.AddTable(schoolOverviewTable); });