Skip to content

JASPER-887: Court Location Panel: Set up job to extract the data from the spreadsheet and update the table entries - #1350

Open
ronaldo-macapobre wants to merge 14 commits into
masterfrom
feature/JASPER-887
Open

ronaldo-macapobre wants to merge 14 commits into
masterfrom
feature/JASPER-887

Conversation

@ronaldo-macapobre

Copy link
Copy Markdown
Contributor

Pull Request for JIRA Ticket: JASPER-887

Issue ticket number and link

https://jira.justice.gov.bc.ca/browse/JASPER-887

Description

Implements the job that checks and parses an email containing the Court Locations. If the parsing is successful, it would replace the existing court locations in the database and persist the new ones.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Local
  • Deploy to DEV env

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screen Grab

image

}

[Fact]
public void GetSheet_Ignores_Unknown_Columns()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this doesn't match the requirement:
the format of the spreadsheet is as expected (correct tabs and columns)

But to be fair, I don't understand the context behind that requirement. Is this really a case where we need to be strict and ignore excel documents that don't exactly conform? Or is this more of a "best effort" workflow?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the ExcelParser and ExcelWorkBook to handle generic operations to excel files in case a new data extraction feature is required in the future. The behavior right now parses the spreadsheet on "best effort" and ignore the data it doesn't recognize.

In this unit test, "Region" is not a valid column that CourtLocation model recognize so rather than throw an error, it is just ignored.

public static void Register(TypeAdapterConfig config)
{
config.NewConfig<ParserModel.CourtLocation, CourtLocationDto>()
.Map(dest => dest.IsStaffed, src => src.Staffed == "Staffed")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be "Staffed" or "Yes"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spreadsheet data has either "Staffed" or "Unstaffed". To easily handle this in the frontend, I added a boolean IsStaffed property to interpret it easier.

Comment thread api/Jobs/SyncCourtLocationsJob.cs Outdated
}

this.Logger.LogInformation("Court Location Attachment found.");
return attachments.First().Value;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably get the attachment with the matching key and not just the first attachment, right? I feel like if we have multiple attachments where one has the right key this may not work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah make sense. I will update the code.

}
}

public async Task<OperationResult> ReplaceCourtLocationsAsync(CourtLocationDto[] dtos)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is potentially risky with the logic that doesn't validate missing columns/format, if we get an invalid/empty file will that clear out the court locations?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the existing court locations will definitely be overwritten. However, since this feature is only used internally by the client, the chances of uploading an incorrect spreadsheet is very low and any mistakes are easily corrected by sending the another file and rerunning the job.

@devinleighsmith

devinleighsmith commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Question, should we validate the sender as well? it seems like our only "security" checks are filename + subject. Since this is an open source project, could someone take down the application by crafting a malicious email attachment + expected subject?

Comment thread api/Jobs/SyncCourtLocationsJob.cs Outdated
return attachments.First().Value;
}

private async Task<CourtLocationDto[]> GetCourtLocations(MemoryStream stream)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't see any await in here, does this need to be async?

.Setup(s => s.GetFilteredEmailsAsync(Mailbox, Subject, null, true))
.ReturnsAsync([]);

var result = _job.Execute();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you awaited this elsewhere, in this test file, should here as well.

@devinleighsmith

Copy link
Copy Markdown
Contributor

Will approve pending responses to questions about security and column validation.

@ronaldo-macapobre

Copy link
Copy Markdown
Contributor Author

Question, should we validate the sender as well? it seems like our only "security" checks are filename + subject. Since this is an open source project, could someone take down the application by crafting a malicious email attachment + expected subject?

Interesting thought. I will clarify if we could determine the sender of this email. I'll also add a file scanning step for added safety.

@devinleighsmith

Copy link
Copy Markdown
Contributor

Question, should we validate the sender as well? it seems like our only "security" checks are filename + subject. Since this is an open source project, could someone take down the application by crafting a malicious email attachment + expected subject?

Interesting thought. I will clarify if we could determine the sender of this email. I'll also add a file scanning step for added safety.

Yes, only started thinking about that with this PR, but it's not like the JASPER inbox is VPN protected or anything like that, so as far as I know anyone could send a file to it.

@ronaldo-macapobre

Copy link
Copy Markdown
Contributor Author

Question, should we validate the sender as well? it seems like our only "security" checks are filename + subject. Since this is an open source project, could someone take down the application by crafting a malicious email attachment + expected subject?

Interesting thought. I will clarify if we could determine the sender of this email. I'll also add a file scanning step for added safety.

Yes, only started thinking about that with this PR, but it's not like the JASPER inbox is VPN protected or anything like that, so as far as I know anyone could send a file to it.

I'll probably use a pattern for the sender (e.g. *@provincialcourt.bc.ca) if client doesn't want it to be "hard-coded" to a specific email. I think its better than nothing.

Comment thread api/Services/EmailService.cs Fixed
@sonarqubecloud

Copy link
Copy Markdown

This branch was successfully deployed

1 active deployment
lz-dev — 7f592d34 Deployed Sep 24, 2026 by ronaldo-macapobre via build #448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants