Skip to content

[BI-1720] - Export Multiple Environment Datasets as Zip#263

Merged
mlm483 merged 29 commits intodevelopfrom
feature/BI-1720
Jul 28, 2023
Merged

[BI-1720] - Export Multiple Environment Datasets as Zip#263
mlm483 merged 29 commits intodevelopfrom
feature/BI-1720

Conversation

@mlm483
Copy link
Contributor

@mlm483 mlm483 commented Jun 13, 2023

Description

Story: https://breedinginsight.atlassian.net/browse/BI-1720

See details of UI changes on the bi-web PR: Breeding-Insight/bi-web#320.

The behavior of the /${micronaut.bi.api.version}/programs/{programId}/experiments/{experimentId}/export{?queryParams*} endpoint was extended to handle the case when one or more environmentIds are sent in the environments query param. When multiple separate files are required to satisfy a request, they are returned as a zip file.

environments selection (UI): environments query param: expected output file:
"All Environments" not sent CSV/Excel with all environments
an individual environment contains 1 environmentId CSV/Excel with selected environment
multiple individual environments contains multiple environmentIds Zip containing CSV/Excel, one for each selected environment

I implemented a GET controller method for Study (StudyController::getStudies) which returns studies with the Program Key stripped from Trial, Study and Location names, as this was needed to correctly display the Study (aka Environment) names on the frontend.

I stripped the Program Key and any characters that may cause issues on different operating systems from the filenames generated for the file export.

Dependencies

Accompanying UI changes are in the bi-web feature/BI-1720 branch.

Testing

Try uploading experiments with multiple locations, with or without phenotypic data. Then, download experiment data with different options selected for "Environments", "File Format", and "With Timestamps?". Make sure the output file is the expected type (CSV/Excel/Zip) and the contents are consistent with what was uploaded. Note that ordering of rows in the output is not yet expected to be preserved, same goes for the ordering of phenotypic columns https://breedinginsight.atlassian.net/browse/BI-1819.

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 tested that my code works with both the brapi-java-server and BreedBase
  • 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: https://github.com/Breeding-Insight/taf/actions/runs/5592771430

@mlm483 mlm483 force-pushed the feature/BI-1720 branch from e1c5fa5 to c6a6cbf Compare July 5, 2023 19:56
@mlm483 mlm483 marked this pull request as ready for review July 5, 2023 20:12
@mlm483 mlm483 requested review from a team, dmeidlin and timparsons and removed request for a team July 5, 2023 20:19
@mlm483

This comment was marked as outdated.

import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
import io.micronaut.http.server.exceptions.InternalServerException;
Copy link
Contributor

Choose a reason for hiding this comment

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

this import is unused and can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 47af603.

import org.breedinginsight.brapi.v1.controller.BrapiVersion;
import org.breedinginsight.brapi.v2.model.request.query.StudyQuery;
import org.breedinginsight.brapi.v2.services.BrAPIStudyService;
import org.breedinginsight.services.exceptions.DoesNotExistException;
Copy link
Contributor

Choose a reason for hiding this comment

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

this import can also be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 47af603.

import org.breedinginsight.daos.cache.ProgramCacheProvider;
import org.breedinginsight.model.Program;
import org.breedinginsight.services.brapi.BrAPIEndpointProvider;
import org.breedinginsight.services.exceptions.DoesNotExistException;
Copy link
Contributor

Choose a reason for hiding this comment

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

import is unused and can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 47af603.

Comment on lines +131 to +133
Map<String, BrAPIStudy> programStudyByFullName = new HashMap<>();
for (BrAPIStudy study: programStudy) {
programStudyByFullName.put(study.getStudyName(), study);
Copy link
Contributor

Choose a reason for hiding this comment

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

programStudyByFullName isn't used after storing study refs and updating the studies. Can it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 47af603.

return downloadFile;
}

private StreamedFile writeToStreamedFile(List<Column> columns, List<Map<String, Object>> data, FileType extension, String sheetName) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

The only value passed in for sheetName is "Experiment Data'. Can this arg be removed from the method signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's worth keeping the sheetName parameter for extensibility.


private final String defaultSortField = "studyName";
private final SortOrder defaultSortOrder = SortOrder.ASC;
private Map<String, Function<BrAPIStudy, ?>> fields;
Copy link
Contributor

Choose a reason for hiding this comment

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

The field can be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 47af603.

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.

If I created a new environment in a second upload, that environment didn't show up to choose on the experiment download modal until I cleared the cache. Once you merge the BrAPIStudyDAO you created with the existing one (org.breedinginsight.brapps.importer.daos.BrAPIStudyDAO), then you should update the createBrAPIStudies method to create the records via the cache (example implementation is in BrAPITrialDAOImpl#createBrAPITrials).


@Getter
@Introspected
public class StudyQuery extends BrapiQuery {
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 externalReferenceId and externalReferenceSource should be added to the query param, and probably change the frontend to send the request using those params instead of trialDbId

Copy link
Member

Choose a reason for hiding this comment

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

There is already a BrAPIStudyDAO in the org.breedinginsight.brapps.importer.daos package. I think this code should be merged into that class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, 024f4e6.

@mlm483
Copy link
Contributor Author

mlm483 commented Jul 27, 2023

If I created a new environment in a second upload, that environment didn't show up to choose on the experiment download modal until I cleared the cache. Once you merge the BrAPIStudyDAO you created with the existing one (org.breedinginsight.brapps.importer.daos.BrAPIStudyDAO), then you should update the createBrAPIStudies method to create the records via the cache (example implementation is in BrAPITrialDAOImpl#createBrAPITrials).

Thanks for this! Implemented, 88a4cd5.

@mlm483 mlm483 requested a review from timparsons July 27, 2023 21:28
@mlm483
Copy link
Contributor Author

mlm483 commented Jul 27, 2023

@timparsons I updated the naming to mirror BrAPITrialDAOImpl::experimentById more closely in 6aa7cc8, what do you think of the use of Environment vs. Study?

@mlm483 mlm483 merged commit c2aa223 into develop Jul 28, 2023
@mlm483 mlm483 deleted the feature/BI-1720 branch July 28, 2023 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants