Skip to content

[BI-2931] Address final areas where brapi programDbId can be used instead of BI id - #583

Open
jloux-brapi wants to merge 5 commits into
epic/BI-2862from
feature/BI-2931
Open

jloux-brapi wants to merge 5 commits into
epic/BI-2862from
feature/BI-2931

Conversation

@jloux-brapi

@jloux-brapi jloux-brapi commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Story: BI-2931

  • Removed setDbIds() usage in BrAPITrialsController
  • Removed setDbIds() usage in BrAPIObservationUnitsController
  • Updated BrAPIProgramsController to return brapiProgramDbId and also filter using the brapi id where applicable

Dependencies

Testing

This will involve testing the BI-BrAPI endpoints. You will need a bearer token generated in DeltaBreed BrAPI tab to test these.

  • Test the GET trials endpoint (/programs/{biProgramId}/brapi/v2/trials and verify the programDbId in the response is the brapi program dbId and that it corresponds to the appropriate program
  • Utilize the trialDbId from an entry in the last response to test the GET trials by dbId endpoint (/programs/{biProgramId}/brapi/v2/trials/{brapiTrialDbId} and verify the programDbId in the response is the brapi programDbId and that it corresponds to the appropriate program.
  • Test the GET observationunits endpoint (/programs/{biProgramId}/brapi/v2/observationunits and verify the programDbId in the response is the brapi program dbId and that it corresponds to the appropriate program. Verify also that the germplasmDbId in the response is a brapi germplasm dbId.
  • Utilize the observationUnitDbId from an entry in the last response to test the GET observationunits by DbId endpoint (/programs/{biProgramId}/brapi/v2/observationunits/observationUnitDbId and verify the programDbId in the response is the brapi program dbId and that it corresponds to the appropriate program. Verify also that the germplasmDbId in the response is a brapi germplasm dbId.
  • Test the GET programs endpoint (/programs/{biProgramId}/brapi/v2/programs) and verify the programDbId in the response is a brapi program dbId and that it corresponds to the appropriate program
  • Utilize the programDbId from an entry in the last response to test the GET programs endpoint (/programs/{biProgramId}/brapi/v2/programs/{programDbId}) and verify the programDbId in the response is a brapi program dbId and that it corresponds to the appropriate program

For the following two endpoints, for the bearer token it seems you can use one generated by any program.

  • Test the GET root programs endpoint (/brapi/v2/programs) and verify the programDbId in the response is a brapi program dbId and that it corresponds to the appropriate program
  • Test the GET root programs by DbId endpoint ( (/brapi/v2/programs/{brapiProgramDbId}) and verify the programDbId in the response is a brapi program dbId and that it corresponds to the appropriate program

Checklist:

  • I have performed a self-review of my own code
  • I have tested my code and ensured it meets the acceptance criteria of the story
  • I have create/modified unit and/or integration tests to cover this change or tests are not applicable
  • I have commented my code, particularly in hard-to-understand areas
  • I have either updated the source of truth or arranged for update with product owner if needed https://breedinginsight.atlassian.net/wiki/spaces/BI/pages/1559953409/Source+of+Truth

@humsika humsika left a comment

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.

I left an inline comment about error handling in the root programs endpoint.

for (Program program : programs) {
try {
program.setBrapiProgram(new BrAPIProgram().programDbId(programService.getBrAPIProgramDbId(program.getId())));
} catch (ApiException e) {

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.

getBrAPIProgramDbId() → getById() → ProgramDAOImpl.getProgramBrAPI() throws HttpServerException, not ApiException, when the BrAPI program is missing or the server can't be reached. This catch never runs. The exception goes to InternalServerErrorHandler and returns a generic 500. Since this endpoint now calls BrAPI for every program, one failing program fails the user's whole program list (and GET /brapi/v2/programs/{programDbId}, which calls it). Could we catch HttpServerException here, and decide whether to skip the failing program or fail the request?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think we can do that, but I also believe it's overkill. If we truly can't reach the server I would want requests to fail in this way, so I think a 500 is accurate.

It's unfortunate a single program could fail this, but if the server is unreachable in any case for a get I think a 500 is the appropriate response. This endpoint I believe is seldom used so risk overall is very low.

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.

Fair enough on a 500 being the right response here. But the new empty catch (Exception ex) at line 93 doesn't log or rethrow. It swallows the HttpServerException, brapiProgram stays null, and convertToBrAPI() (line 222) then throws an NPE. We still return a 500, but the logs only show the NPE, not the BrAPI failure.

Could we either remove the catch (so the original exception is logged and returns a 500, matching your reasoning), or log it and skip programs with a null brapiProgram? Either is fine with me; the empty catch is the only issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done, sorry, didn't mean to commit that.

@@ -127,7 +127,6 @@ public HttpResponse<BrAPIObservationUnitListResponse> observationunitsGet(@PathV
Optional.ofNullable(studyDbId),
Optional.ofNullable(germplasmDbId))

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.

With the override removed, OUs now return the BrAPI germplasmDbId, but the germplasmDbId filter in BrAPIObservationUnitDAO.getObservationUnits() (line 254) still compares against the BI UUID in additionalInfo.germplasmId. Filtering by the returned ID now gives no results. The TODO there points at BI-3006, which is closed. Can we change the filter to compare ou.getGermplasmDbId() (or pass germplasmDbIds in the search request) in this PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

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.

Thanks, looks good.

@jloux-brapi
jloux-brapi requested a review from humsika December 3, 2026 18:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants