-
Notifications
You must be signed in to change notification settings - Fork 1
BI-2127 Position Information missing from exp download file #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e7e46b7
[BI-2127] return Lat, Long, Elevation, and RTK
davedrp 1a909b6
[BI-2127] protect against nulls
davedrp 5a2100c
[BI-2127] protect against a double beign NaN (not yet set) before con…
davedrp 4bcc841
Merge branch 'develop' into bug/BI-2127
davedrp 2e41d4c
[BI-2127] made code more readable
davedrp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| package org.breedinginsight.brapi.v2.services; | ||
|
|
||
| import com.github.filosganga.geogson.model.Coordinates; | ||
| import com.github.filosganga.geogson.model.positions.SinglePosition; | ||
| import com.google.gson.JsonObject; | ||
| import io.micronaut.context.annotation.Property; | ||
| import io.micronaut.http.MediaType; | ||
| import io.micronaut.http.server.exceptions.InternalServerException; | ||
|
|
@@ -465,6 +468,26 @@ private Map<String, Object> createExportRow( | |
| row.put(ExperimentObservation.Columns.EXP_TYPE, experiment.getAdditionalInfo().getAsJsonObject().get(BrAPIAdditionalInfoFields.EXPERIMENT_TYPE).getAsString()); | ||
| row.put(ExperimentObservation.Columns.ENV, Utilities.removeProgramKeyAndUnknownAdditionalData(study.getStudyName(), program.getKey())); | ||
| row.put(ExperimentObservation.Columns.ENV_LOCATION, Utilities.removeProgramKey(study.getLocationName(), program.getKey())); | ||
|
|
||
| // Lat, Long, Elevation | ||
| Coordinates coordinates = extractCoordinates(ou); | ||
| Optional.ofNullable(coordinates) | ||
| .map(c -> doubleToString(c.getLat())) | ||
| .ifPresent(lat -> row.put(ExperimentObservation.Columns.LAT, lat)); | ||
| Optional.ofNullable(coordinates) | ||
| .map(c -> doubleToString(c.getLon())) | ||
| .ifPresent(lon -> row.put(ExperimentObservation.Columns.LONG, lon)); | ||
| Optional.ofNullable(coordinates) | ||
| .map(c -> doubleToString(c.getAlt())) | ||
| .ifPresent(elevation -> row.put(ExperimentObservation.Columns.ELEVATION, elevation)); | ||
|
|
||
| // RTK | ||
| JsonObject additionalInfo = ou.getAdditionalInfo(); | ||
| String rtk = ( additionalInfo==null || additionalInfo.get(BrAPIAdditionalInfoFields.RTK) ==null ) | ||
| ? null | ||
| : additionalInfo.get(BrAPIAdditionalInfoFields.RTK).getAsString(); | ||
| row.put(ExperimentObservation.Columns.RTK, rtk); | ||
|
|
||
| BrAPISeason season = seasonDAO.getSeasonById(study.getSeasons().get(0), program.getId()); | ||
| row.put(ExperimentObservation.Columns.ENV_YEAR, season.getYear()); | ||
| row.put(ExperimentObservation.Columns.EXP_UNIT_ID, Utilities.removeProgramKeyAndUnknownAdditionalData(ou.getObservationUnitName(), program.getKey())); | ||
|
|
@@ -484,11 +507,13 @@ private Map<String, Object> createExportRow( | |
| .findFirst(); | ||
| blockLevel.ifPresent(brAPIObservationUnitLevelRelationship -> | ||
| row.put(ExperimentObservation.Columns.BLOCK_NUM, Integer.parseInt(brAPIObservationUnitLevelRelationship.getLevelCode()))); | ||
| if (ou.getObservationUnitPosition() != null && ou.getObservationUnitPosition().getPositionCoordinateX() != null && | ||
| ou.getObservationUnitPosition().getPositionCoordinateY() != null) { | ||
|
|
||
| //Row and Column | ||
| if ( ou.getObservationUnitPosition() != null ) { | ||
| row.put(ExperimentObservation.Columns.ROW, ou.getObservationUnitPosition().getPositionCoordinateX()); | ||
| row.put(ExperimentObservation.Columns.COLUMN, ou.getObservationUnitPosition().getPositionCoordinateY()); | ||
| } | ||
|
|
||
| if (ou.getTreatments() != null && !ou.getTreatments().isEmpty()) { | ||
| row.put(ExperimentObservation.Columns.TREATMENT_FACTORS, ou.getTreatments().get(0).getFactor()); | ||
| } else { | ||
|
|
@@ -499,7 +524,25 @@ private Map<String, Object> createExportRow( | |
| return row; | ||
| } | ||
|
|
||
|
|
||
| private String doubleToString(double val){ | ||
| return Double.isNaN(val) ? null : String.valueOf( val ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. |
||
| } | ||
| private Coordinates extractCoordinates(BrAPIObservationUnit ou){ | ||
| Coordinates coordinates = null; | ||
| if ( ou.getObservationUnitPosition()!=null | ||
| && ou.getObservationUnitPosition().getGeoCoordinates()!=null | ||
| && ou.getObservationUnitPosition().getGeoCoordinates().getGeometry()!=null | ||
| && ou.getObservationUnitPosition().getGeoCoordinates().getGeometry().positions()!=null | ||
| ) | ||
| { | ||
| Object o = ou.getObservationUnitPosition().getGeoCoordinates().getGeometry().positions(); | ||
| if (o instanceof SinglePosition){ | ||
| SinglePosition sp = (SinglePosition)o; | ||
| coordinates= sp.coordinates(); | ||
| } | ||
| } | ||
| return coordinates; | ||
| } | ||
|
|
||
| private void addObsVarColumns( | ||
| List<Column> columns, | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it allowed to upload a file that has row but not column data or vice versa? I think this change makes sense regardless.