Skip to content

Commit

Permalink
[KNOWAGE-8581] Fixed columns order into discovery widget excel export
Browse files Browse the repository at this point in the history
(cherry picked from commit f35ad94)
  • Loading branch information
leonegiorgia committed Nov 28, 2024
1 parent 00a510c commit b6a0738
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ protected JSONArray getTableOrderedColumns(JSONArray columnsNew, JSONArray colum
return new JSONArray();
}
}

protected JSONArray getDiscoveryOrderedColumns(JSONArray columnsNew, JSONArray columnsOld) {
JSONArray columnsOrdered = new JSONArray();
// new columns are in the correct order
// for each of them we have to find the correspondent old column and push it into columnsOrdered
try {
for (int i = 0; i < columnsNew.length(); i++) {

JSONObject columnNew = columnsNew.getJSONObject(i);

for (int j = 0; j < columnsOld.length(); j++) {
JSONObject columnOld = columnsOld.getJSONObject(j);
if (columnOld.getString("header").equals(columnNew.getString("name"))) {

columnsOrdered.put(columnOld);
break;
}
}
}
return columnsOrdered;
} catch (Exception e) {
LOGGER.error("Error retrieving ordered columns");
return new JSONArray();
}
}

protected String getTableColumnHeaderValue(JSONObject column) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ public void fillSheetWithData(JSONObject dataStore, Workbook wb, Sheet sheet, St
if (widgetData.getString("type").equalsIgnoreCase("table") && widgetContent.has("columnSelectedOfDataset")) {
hiddenColumns = getHiddenColumnsList(columnSelectedOfDataset);
columnsOrdered = getTableOrderedColumns(columnSelectedOfDataset, columns);
} else if (widgetData.getString("type").equalsIgnoreCase("discovery") && widgetContent.has("columnSelectedOfDataset")) {
columnsOrdered = getDiscoveryOrderedColumns(columnSelectedOfDataset, columns);
} else {
columnsOrdered = columns;
}
Expand Down

0 comments on commit b6a0738

Please sign in to comment.