Add validation for missing company product types on farmer import - #8
Open
candreszg wants to merge 1 commit into
Open
Add validation for missing company product types on farmer import#8candreszg wants to merge 1 commit into
candreszg wants to merge 1 commit into
Conversation
When a company has no value chains associated, readCompanyProductTypes returns an empty list, causing subList(0, 1) to throw IndexOutOfBoundsException (HTTP 500). Now an ApiException (HTTP 400) with a clear message is thrown instead, instructing the user to associate the company with a value chain first. Signed-off-by: Camilo <71578145+candreszg@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a pre-condition check in
UserCustomerImportService.importFarmersSpreadsheet()so that when a company has no product types configured (no value chains associated), the endpoint returns a clearINVALID_REQUESTerror (HTTP400) instead of crashing with
IndexOutOfBoundsException(HTTP 500).Root cause
readCompanyProductTypes()derives product types from the company's value chains. If none are associated, thelist is empty. The subsequent
companyProductTypes.subList(0, 1)then throwsIndexOutOfBoundsException: toIndex= 1, which the generic exception handler surfaces as an unhelpful"Uncaught exception java.lang.IndexOutOfBoundsException".Fix
Added an early validation after
readCompanyProductTypes()that throwsApiException(ApiStatus.INVALID_REQUEST, ...)with an actionable message, consistent with other pre-condition checks in the same class.How to test
.xlsxfarmers spreadsheet and call the import endpoint."Uncaught exception java.lang.IndexOutOfBoundsException"."Company has no product types configured. Please associate the company with a value chain before importing farmers.".Closes #7