diff --git a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPITrialService.java b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPITrialService.java index 6b8a3f233..a383a96a0 100644 --- a/src/main/java/org/breedinginsight/brapi/v2/services/BrAPITrialService.java +++ b/src/main/java/org/breedinginsight/brapi/v2/services/BrAPITrialService.java @@ -228,14 +228,19 @@ public DownloadFile exportObservations( } } + //dynamically append observation level to obsUnitID column header + String observationLvl = ous.get(0).getAdditionalInfo().get(BrAPIAdditionalInfoFields.OBSERVATION_LEVEL).getAsString(); + columns = dynamicUpdateObsUnitIDLabel(columns, observationLvl); + log.debug(logHash + ": writing data to file for export"); // If one or more envs requested, create a separate file for each env, then zip if there are multiple. if (!requestedEnvIds.isEmpty()) { // This will hold a list of rows for each study, each list will become a separate file. Map>> rowsByStudyId = new HashMap<>(); + String obsUnitIDLabel = observationLvl + " " + ExperimentObservation.Columns.OBS_UNIT_ID; for (Map row: rowByOUId.values()) { - String studyId = studyDbIdByOUId.get((String)row.get(ExperimentObservation.Columns.OBS_UNIT_ID)); + String studyId = studyDbIdByOUId.get((String)row.get(obsUnitIDLabel)); // Initialize key with empty list if it is not present. if (!rowsByStudyId.containsKey(studyId)) { @@ -306,6 +311,19 @@ private StreamedFile zipFiles(List files) throws IOException { return new StreamedFile(in, new MediaType(MediaType.APPLICATION_OCTET_STREAM)); } + public List dynamicUpdateObsUnitIDLabel(List columns, String observationLvl){ + Column oldObsUnitIDCol = new Column(ExperimentObservation.Columns.OBS_UNIT_ID, Column.ColumnDataType.STRING); + String dynamicLabel = observationLvl + " " + ExperimentObservation.Columns.OBS_UNIT_ID; + Column dynamicLabelObsUnitIDCol = new Column(dynamicLabel, Column.ColumnDataType.STRING); + //need to check index of is valid + int index = columns.indexOf(oldObsUnitIDCol); + //find item in cols with val ExperimentObservation.Columns.OBS_UNIT_ID + if (index != -1) { + columns.set(index, dynamicLabelObsUnitIDCol); + } + return columns; + } + public Dataset getDatasetData(Program program, UUID experimentId, UUID datasetId, Boolean stats) throws ApiException, DoesNotExistException { log.debug("fetching dataset: " + datasetId + " for experiment: " + experimentId + ". including stats: " + stats); log.debug("fetching observationUnits for dataset: " + datasetId); @@ -785,7 +803,10 @@ private Map createExportRow( } else { row.put(ExperimentObservation.Columns.TREATMENT_FACTORS, null); } - row.put(ExperimentObservation.Columns.OBS_UNIT_ID, ouId); + + //Append observation level to obsUnitID + String observationLvl = ou.getAdditionalInfo().getAsJsonObject().get(BrAPIAdditionalInfoFields.OBSERVATION_LEVEL).getAsString(); + row.put(observationLvl + " " + ExperimentObservation.Columns.OBS_UNIT_ID, ouId); return row; } diff --git a/src/main/java/org/breedinginsight/model/Column.java b/src/main/java/org/breedinginsight/model/Column.java index 054dcb435..52b4a9de3 100644 --- a/src/main/java/org/breedinginsight/model/Column.java +++ b/src/main/java/org/breedinginsight/model/Column.java @@ -21,6 +21,8 @@ import lombok.experimental.Accessors; import lombok.experimental.SuperBuilder; +import java.util.Objects; + @Getter @Setter @Accessors(chain=true) @@ -46,4 +48,17 @@ public enum ColumnDataType { INTEGER, DOUBLE } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Column that = (Column) o; + return Objects.equals(getValue(), that.getValue()) && Objects.equals(getDataType(), that.getDataType()); + } + + @Override + public int hashCode() { + return Objects.hash(getValue(), getDataType()); + } } diff --git a/src/main/java/org/breedinginsight/model/Country.java b/src/main/java/org/breedinginsight/model/Country.java index e2d93dbfe..4cbe21997 100644 --- a/src/main/java/org/breedinginsight/model/Country.java +++ b/src/main/java/org/breedinginsight/model/Country.java @@ -81,4 +81,9 @@ public boolean equals(Object o) { Country that = (Country) o; return Objects.equals(getId(), that.getId()) && Objects.equals(getName(), that.getName()); } + + @Override + public int hashCode() { + return Objects.hash(getId(), getName()); + } } diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index be65b691c..7d37e46f7 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -14,5 +14,6 @@ # limitations under the License. # + version=v1.2.0+961 -versionInfo=https://github.com/Breeding-Insight/bi-api/commit/06df6ae9acb10d77620dc978d8f1c290dab21324 \ No newline at end of file +versionInfo=https://github.com/Breeding-Insight/bi-api/commit/06df6ae9acb10d77620dc978d8f1c290dab21324 diff --git a/src/test/java/org/breedinginsight/api/v1/controller/ExperimentControllerIntegrationTest.java b/src/test/java/org/breedinginsight/api/v1/controller/ExperimentControllerIntegrationTest.java index a3c47e573..9adb44425 100644 --- a/src/test/java/org/breedinginsight/api/v1/controller/ExperimentControllerIntegrationTest.java +++ b/src/test/java/org/breedinginsight/api/v1/controller/ExperimentControllerIntegrationTest.java @@ -987,10 +987,11 @@ private void checkDownloadTable( } assertEquals(requestedImportRows.size(),matchingImportRows.size()); + //Observation level for tests should be "Plot" // Observation units populated. - assertEquals(0, table.column("ObsUnitID").countMissing()); + assertEquals(0, table.column("Plot ObsUnitID").countMissing()); // Observation Unit IDs are assigned. - assertEquals(requestedImportRows.size(), table.column("ObsUnitID").countUnique()); + assertEquals(requestedImportRows.size(), table.column("Plot ObsUnitID").countUnique()); } private boolean isMatchedRow(Map importRow, Row downloadRow) {