Skip to content

Commit

Permalink
[ALS-7179] Bug fixes for dashboard
Browse files Browse the repository at this point in the history
- flipped key value pair
- better result set extractor
  • Loading branch information
Luke Sikina authored and Luke-Sikina committed Sep 19, 2024
1 parent b414666 commit 07d8d70
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package edu.harvard.dbmi.avillach.dictionary.dashboard;

public record DashboardColumn(String label, String dataElement) {
public record DashboardColumn(String dataElement, String label) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dataset_meta.KEY IN (:keys)
ORDER BY name ASC, abbreviation ASC
""";
List<String> keys = columns.stream()
.map(DashboardColumn::label)
.map(DashboardColumn::dataElement)
.filter(Predicate.not(nonMetaColumns::contains))
.toList();
MapSqlParameterSource params = new MapSqlParameterSource().addValue("keys", keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,38 @@ public DashboardRowResultSetExtractor(List<DashboardColumn> columns) {

@Override
public List<Map<String, String>> extractData(ResultSet rs) throws SQLException, DataAccessException {
String currentRow = "";
String currentName = "";
String currentAbbreviation = "";
boolean beforeStart = true;
Map<String, String> row = new HashMap<>(template);
List<Map<String, String>> rows = new ArrayList<>();
while (rs.next()) {
String abbreviation = rs.getString("abbreviation");
String name = rs.getString("name");
if (!currentRow.equals(name + abbreviation)) {
currentRow = name + abbreviation;
if (!row.isEmpty()) {
row.put("abbreviation", abbreviation);
row.put("name", name);
rows.add(row);
row = new HashMap<>(template);
}
if (beforeStart) {
currentName = name;
currentAbbreviation = abbreviation;
beforeStart = false;
}
// start of new row
if (!currentAbbreviation.equals(abbreviation) || !currentName.equals(name)) {
// finish up the old row by adding non-meta fields
row.put("abbreviation", currentAbbreviation);
row.put("name", currentName);
rows.add(row);
// start new row
currentName = name;
currentAbbreviation = abbreviation;
row = new HashMap<>(template);
}
row.put(rs.getString("key"), rs.getString("value"));
}
// add the last row to the response only if there has been at least one set in the result set
if (!beforeStart) {
row.put("abbreviation", currentAbbreviation);
row.put("name", currentName);
rows.add(row);
}
return rows;
}
}

0 comments on commit 07d8d70

Please sign in to comment.