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

TH-1099 Improve logging, null checks, and XML template update #686

Merged
merged 2 commits into from
Dec 12, 2024
Merged
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
33 changes: 29 additions & 4 deletions api/Hmcr.Chris/OasQueries.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
using System.IO;
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;

namespace Hmcr.Chris
{
public class OasQueries
{
private string _pointOnRfiSeqQuery;

public string PointOnRfiSegQuery
{
get {
var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates");
return _pointOnRfiSeqQuery ?? (_pointOnRfiSeqQuery = File.ReadAllText(Path.Combine(folder, "IsPointOnRfiSegment.xml")));
get
{
if (_pointOnRfiSeqQuery == null)
{
var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates");
var templatePath = Path.Combine(folder, "IsPointOnRfiSegment.xml");

try
{
var xmlTemplate = File.ReadAllText(templatePath, Encoding.UTF8);

xmlTemplate = xmlTemplate.Replace("\0", "");

_pointOnRfiSeqQuery = xmlTemplate;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Failed to process the XML template at '{templatePath}': {ex.Message}", ex);
}
}

return _pointOnRfiSeqQuery;
}
}

Expand Down
23 changes: 11 additions & 12 deletions api/Hmcr.Chris/XmlTemplates/IsPointOnRfiSegment.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<wfs:GetFeature service="WFS"
version="1.1.0"
outputFormat="json"
maxFeatures="10"
xmlns:topp="http://www.openplans.org/topp"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/WFS-basic.xsd">
<wfs:GetFeature service="WFS"
version="1.1.0"
outputFormat="json"
maxFeatures="10"
xmlns:topp="http://www.openplans.org/topp"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs https://schemas.opengis.net/wfs/1.1.0/wfs.xsd">

<wfs:Query typeName="cwr:V_NM_NLT_RFI_GRFI_SDO_DT">
<PropertyName>NE_UNIQUE</PropertyName>
<wfs:PropertyName>NE_UNIQUE</wfs:PropertyName>
<Filter>
<And>
<DWithin>
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Domain/Hangfire/Base/ReportJobServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task<bool> ProcessSubmissionMain(SubmissionDto submissionDto)
{
((HmcrRepositoryBase<HmrSubmissionObject>)_submissionRepo).RollBackEntities();

_submission.ErrorDetail = FileError.UnknownException;
_submission.ErrorDetail = $"{FileError.UnknownException}: {ex.Message}";
_submission.SubmissionStatusId = _statusService.FileUnexpectedError;
await CommitAndSendEmailAsync();
}
Expand Down
33 changes: 27 additions & 6 deletions api/Hmcr.Domain/Hangfire/RockfallReportJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public interface IRockfallReportJobService
}

public class RockfallReportJobService : ReportJobServiceBase, IRockfallReportJobService
{
{
private IRockfallReportRepository _rockfallReportRepo;
private readonly string _thresholdSpLevel = ThresholdSpLevels.Level1;

public RockfallReportJobService(IUnitOfWork unitOfWork, ILogger<IRockfallReportJobService> logger,
public RockfallReportJobService(IUnitOfWork unitOfWork, ILogger<IRockfallReportJobService> logger,
ISubmissionStatusService statusService, ISubmissionObjectRepository submissionRepo, IServiceAreaService serviceAreaService,
ISumbissionRowRepository submissionRowRepo, IRockfallReportRepository rockfallReportRepo, IFieldValidatorService validator,
ISumbissionRowRepository submissionRowRepo, IRockfallReportRepository rockfallReportRepo, IFieldValidatorService validator,
IEmailService emailService, IConfiguration config,
ISpatialService spatialService, ILookupCodeService lookupService)
: base(unitOfWork, statusService, submissionRepo, serviceAreaService, submissionRowRepo, emailService, logger, config, validator, spatialService, lookupService)
Expand Down Expand Up @@ -81,7 +81,7 @@ public override async Task<bool> ProcessSubmission(SubmissionDto submissionDto)

submissionRow.RowStatusId = _statusService.RowSuccess; //set the initial row status as success
untypedRow.HighwayUnique = untypedRow.HighwayUnique.ToTrimAndUppercase();

//rockfall requires Y/N fields to be set to Uppercase, see HMCR-643
untypedRow.HeavyPrecip = untypedRow.HeavyPrecip.ToTrimAndUppercase();
untypedRow.FreezeThaw = untypedRow.FreezeThaw.ToTrimAndUppercase();
Expand Down Expand Up @@ -496,11 +496,32 @@ private string GetValidationEntityName(RockfallReportCsvDto untypedRow)
CsvHelperUtils.Config(errors, csv, false);
csv.Configuration.RegisterClassMap<RockfallReportCsvDtoMap>();

var rows = GetRecords(csv);
var rows = GetRecords(csv).Select(row => SanitizeRow(row)).ToList();

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
var headers = string.Join(',', csv.Context.HeaderRecord)
.Replace("\"", "")
.Replace("\0", "");

return (rows, headers);
}

private RockfallReportCsvDto SanitizeRow(RockfallReportCsvDto row)
{
foreach (var property in typeof(RockfallReportCsvDto).GetProperties())
{
if (property.PropertyType == typeof(string))
{
var value = (string)property.GetValue(row);
if (value != null)
{
property.SetValue(row, value.Replace("\0", ""));
}
}
}
return row;
}


private List<RockfallReportCsvDto> GetRecords(CsvReader csv)
{
var rows = new List<RockfallReportCsvDto>();
Expand Down
26 changes: 23 additions & 3 deletions api/Hmcr.Domain/Hangfire/WildlifeReportJobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WildlifeReportJobService : ReportJobServiceBase, IWildlifeReportJob
public WildlifeReportJobService(IUnitOfWork unitOfWork, ILogger<IWildlifeReportJobService> logger,
ISubmissionStatusService statusService, ISubmissionObjectRepository submissionRepo, IServiceAreaService serviceAreaService,
ISumbissionRowRepository submissionRowRepo, IWildlifeReportRepository wildlifeReportRepo, IFieldValidatorService validator,
IEmailService emailService, IConfiguration config,
IEmailService emailService, IConfiguration config,
ISpatialService spatialService, ILookupCodeService lookupService)
: base(unitOfWork, statusService, submissionRepo, serviceAreaService, submissionRowRepo, emailService, logger, config, validator, spatialService, lookupService)
{
Expand Down Expand Up @@ -327,9 +327,29 @@ private string GetValidationEntityName(WildlifeReportCsvDto untypedRow)
CsvHelperUtils.Config(errors, csv, false);
csv.Configuration.RegisterClassMap<WildlifeReportCsvDtoMap>();

var rows = GetRecords(csv);
var rows = GetRecords(csv).Select(row => SanitizeRow(row)).ToList();

return (rows, string.Join(',', csv.Context.HeaderRecord).Replace("\"", ""));
var headers = string.Join(',', csv.Context.HeaderRecord)
.Replace("\"", "")
.Replace("\0", "");

return (rows, headers);
}

private WildlifeReportCsvDto SanitizeRow(WildlifeReportCsvDto row)
{
foreach (var property in typeof(WildlifeReportCsvDto).GetProperties())
{
if (property.PropertyType == typeof(string))
{
var value = (string)property.GetValue(row);
if (value != null)
{
property.SetValue(row, value.Replace("\0", ""));
}
}
}
return row;
}

private List<WildlifeReportCsvDto> GetRecords(CsvReader csv)
Expand Down
Loading
Loading