Skip to content

[BI-1339] Germplasm Details page#176

Merged
HMS17 merged 12 commits intodevelopfrom
feature/BI-1339
Apr 14, 2022
Merged

[BI-1339] Germplasm Details page#176
HMS17 merged 12 commits intodevelopfrom
feature/BI-1339

Conversation

@HMS17
Copy link
Contributor

@HMS17 HMS17 commented Apr 5, 2022

Description

Story: BI-1339 - Germplasm Details page

Updates to enable display of individual germplasm details

  • Created endpoint in GermplasmController to fetch an individual germplasm record
  • Refactored ProgramCache to be a Map<K, R> instead of a list in order to more easily have the UUID for each germplasm entry be retrieved
  • Added logic to fetch individual germplasm record information from the cache
  • Added an additional info field "pedigreeByName" for germplasm to aid in displaying germplasm pedigree info

Dependencies

bi-web/feature/BI-1339

Testing

See testing for bi-web

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 tests to cover this change
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to documentation
  • I have run TAF: <link to TAF run>

@HMS17 HMS17 requested review from ctucker3 and timparsons April 7, 2022 19:00
@HMS17 HMS17 marked this pull request as ready for review April 7, 2022 19:01
@Get("/${micronaut.bi.api.version}/programs/{programId}" + BrapiVersion.BRAPI_V2 + "/germplasm/{germplasmId}")
@Produces(MediaType.APPLICATION_JSON)
@ProgramSecured(roleGroups = {ProgramSecuredRoleGroup.ALL})
public HttpResponse<BrAPIGermplasm> getSingleGermplasm(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be HttpResponse<Response<BrAPIGermplasm>> to get the right return type.

public class ProgramCache<K, R> {

private final FetchFunction<UUID, List<R>> fetchMethod;
private final FetchFunction<UUID, Map<K, R>> fetchMethod;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not clearly explained that K should be the object id, it took me a bit to figure out what K was supposed to be. Maybe a class header comment for explanation?

}

public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException {
return programGermplasmCache.get(programId).get(germplasmId);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the germplasmId doesn't exist in the returned map?

@HMS17 HMS17 requested a review from ctucker3 April 13, 2022 15:51
public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException {
return programGermplasmCache.get(programId).get(germplasmId);
public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException, DoesNotExistException {
BrAPIGermplasm germplasm = programGermplasmCache.get(programId).get(germplasmId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test this out? I thought in java the exception is thrown here on the map access if the key doesn't exist rather than it returning a null.

Copy link
Member

Choose a reason for hiding this comment

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

There probably should be a null check for what's returned from programGermplasmCache.get(programId) as there could be some programs don't have germplasm in the cache...either they don't have any in the system yet, or the cache loading failed, or is in progress.

try {
return germplasmDAO.getGermplasmByUUID(germplasmId, programId);
} catch (ApiException e) {
} catch (ApiException | DoesNotExistException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If a germplasm is requested that doesn't exist it seems like that is a 404 rather than a 500.

@HMS17 HMS17 requested a review from ctucker3 April 13, 2022 18:54
Copy link
Member

@timparsons timparsons left a comment

Choose a reason for hiding this comment

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

Testing passed. Have a few code changes, however

germplasm.setPedigree(newPedigreeString);
}

BrAPIExternalReference extRef = germplasm.getExternalReferences().stream().filter(reference -> referenceSource.equals(reference.getReferenceSource())).findFirst().orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

I think you should specify the error to throw in the .orElseThrow method call, for example: .orElseThrow(() -> new IllegalStateException("No BI external reference found"))

import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.Property;
import io.micronaut.http.server.exceptions.InternalServerException;
import it.unimi.dsi.fastutil.Hash;
Copy link
Member

Choose a reason for hiding this comment

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

This import is not used and can be removed

public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException {
return programGermplasmCache.get(programId).get(germplasmId);
public BrAPIGermplasm getGermplasmByUUID(String germplasmId, UUID programId) throws ApiException, DoesNotExistException {
BrAPIGermplasm germplasm = programGermplasmCache.get(programId).get(germplasmId);
Copy link
Member

Choose a reason for hiding this comment

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

There probably should be a null check for what's returned from programGermplasmCache.get(programId) as there could be some programs don't have germplasm in the cache...either they don't have any in the system yet, or the cache loading failed, or is in progress.

}
}

public BrAPIGermplasm getGermplasmByUUID(UUID programId, String germplasmId) throws ApiException, DoesNotExistException {
Copy link
Member

Choose a reason for hiding this comment

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

Given that you're catching an ApiException, you don't need to specify that an ApiException will be thrown.

Comment on lines +65 to +67
} catch (DoesNotExistException e) {
throw e;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is redundant and can be removed as the method declares it can throw a DoesNotExistException

@HMS17 HMS17 requested a review from timparsons April 14, 2022 20:38
@HMS17 HMS17 merged commit cc9eb0e into develop Apr 14, 2022
@HMS17 HMS17 deleted the feature/BI-1339 branch April 14, 2022 22:56
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.

3 participants