Skip to content

Commit f77e7f6

Browse files
committed
remove redundant cells from filter sheet in dashboard excel export
(cherry picked from commit 170d506)
1 parent b2cbe8f commit f77e7f6

File tree

2 files changed

+11
-129
lines changed

2 files changed

+11
-129
lines changed

knowage-export/src/main/java/it/eng/knowage/engine/api/export/dashboard/DashboardExporter.java

Lines changed: 8 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,72 +1405,6 @@ public void fillDashboardSelectionsSheetWithData(Map<String, Map<String, JSONArr
14051405
}
14061406
}
14071407

1408-
public void transformDatasetDriversForExcelSheet(JSONObject body, JSONArray driversFromBody, JSONArray parameters) {
1409-
try {
1410-
if (body.has("datasetDrivers") && body.getJSONArray("datasetDrivers") != null && body.getJSONArray("datasetDrivers").length() > 0) {
1411-
for (int i = 0; i < body.getJSONArray("datasetDrivers").length(); i++) {
1412-
JSONObject datasetDriver = body.getJSONArray("datasetDrivers").getJSONObject(i);
1413-
getParameterValuesFromDatasetDriver(driversFromBody, datasetDriver);
1414-
}
1415-
1416-
} else if (body.has("configuration") && body.getJSONObject("configuration") != null && body.getJSONObject("configuration").has("datasets") && body.getJSONObject("configuration").getJSONArray("datasets") != null && body.getJSONObject("configuration").getJSONArray("datasets").length() > 0) {
1417-
for (int i = 0; i < body.getJSONObject("configuration").getJSONArray("datasets").length(); i++) {
1418-
JSONObject dataset = body.getJSONObject("configuration").getJSONArray("datasets").getJSONObject(i);
1419-
if (dataset.has("drivers") && dataset.getJSONArray("drivers") != null && dataset.getJSONArray("drivers").length() > 0) {
1420-
for (int j = 0; j < dataset.getJSONArray("drivers").length(); j++) {
1421-
JSONObject datasetDriver = dataset.getJSONArray("drivers").getJSONObject(j);
1422-
getParameterValuesFromDatasetDriver(driversFromBody, datasetDriver);
1423-
}
1424-
}
1425-
}
1426-
}
1427-
1428-
transformParametersForExcelSheet(parameters, driversFromBody);
1429-
} catch (JSONException jsonException) {
1430-
LOGGER.error("Unable to transform driver", jsonException);
1431-
throw new SpagoBIRuntimeException("Unable to transform driver", jsonException);
1432-
}
1433-
}
1434-
1435-
public void transformParametersForExcelSheet(JSONArray parameters, JSONArray driversFromBody) {
1436-
if (parameters != null && parameters.length() > 0) {
1437-
for (int i = 0; i < parameters.length(); i++) {
1438-
try {
1439-
JSONObject parameter = parameters.getJSONObject(i);
1440-
try {
1441-
parameter.put("value", parameter.getString("value"));
1442-
} catch (JSONException e) {
1443-
parameter.put("value", parameter.getJSONArray("value").toString());
1444-
}
1445-
parameter.put("description", "NOT APPLICABLE");
1446-
parameter.put("driverLabel", "NOT APPLICABLE");
1447-
parameter.put("type", "NOT APPLICABLE");
1448-
parameter.put("urlName", "NOT APPLICABLE");
1449-
driversFromBody.put(parameter);
1450-
1451-
} catch (JSONException e) {
1452-
LOGGER.error("Unable to transform parameter", e);
1453-
}
1454-
}
1455-
}
1456-
}
1457-
1458-
private void getParameterValuesFromDatasetDriver(JSONArray driversFromBody, JSONObject datasetDriver) throws JSONException {
1459-
JSONArray parameterValues = datasetDriver.getJSONArray("parameterValue");
1460-
if (parameterValues != null && parameterValues.length() > 0) {
1461-
for (int k = 0; k < parameterValues.length(); k++) {
1462-
JSONObject parameterValue = parameterValues.getJSONObject(k);
1463-
if (!datasetDriver.has("value")) {
1464-
datasetDriver.put("value", parameterValue.getString("value"));
1465-
} else {
1466-
datasetDriver.put("value","," + parameterValue.getString("value"));
1467-
}
1468-
}
1469-
}
1470-
datasetDriver.put("name", datasetDriver.getString("driverLabel"));
1471-
driversFromBody.put(datasetDriver);
1472-
}
1473-
14741408
public void fillDashboardDriversSheetWithData(JSONArray drivers, Sheet sheet) {
14751409

14761410
try {
@@ -1500,59 +1434,28 @@ public void fillDashboardDriversSheetWithData(JSONArray drivers, Sheet sheet) {
15001434
DOCUMENT_NAME,
15011435
sheet.getSheetName());
15021436

1503-
newheader = sheet.createRow((short) headerIndex + 1); // first row
1437+
newheader = sheet.createRow((short) headerIndex + 1);
15041438

15051439
Cell cell = newheader.createCell(0);
15061440
cell.setCellValue("Name");
15071441
CellStyle headerCellStyle = buildCellStyle(sheet, true, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, (short) 11);
15081442
cell.setCellStyle(headerCellStyle);
15091443

15101444
Cell cell2 = newheader.createCell(1);
1511-
cell2.setCellValue("Type");
1445+
cell2.setCellValue("Value");
15121446
cell2.setCellStyle(headerCellStyle);
15131447

1514-
Cell cell3 = newheader.createCell(2);
1515-
cell3.setCellValue("Multivalue");
1516-
cell3.setCellStyle(headerCellStyle);
1517-
1518-
Cell cell4 = newheader.createCell(3);
1519-
cell4.setCellValue("Value");
1520-
cell4.setCellStyle(headerCellStyle);
1521-
1522-
Cell cell5 = newheader.createCell(4);
1523-
cell5.setCellValue("Url Name");
1524-
cell5.setCellStyle(headerCellStyle);
1525-
1526-
Cell cell6 = newheader.createCell(5);
1527-
cell6.setCellValue("Driver label");
1528-
cell6.setCellStyle(headerCellStyle);
1529-
1530-
Cell cell7 = newheader.createCell(6);
1531-
cell7.setCellValue("Driver type");
1532-
cell7.setCellStyle(headerCellStyle);
1533-
15341448
int j = headerIndex + 2;
15351449

15361450
for (int i = 0; i < drivers.length(); i++) {
15371451
JSONObject driver = drivers.getJSONObject(i);
1538-
Row newRow = sheet.createRow(j);
1539-
newRow.createCell(0).setCellValue(driver.getString("name"));
1540-
newRow.createCell(1).setCellValue(driver.getString("type"));
1541-
try {
1542-
newRow.createCell(2).setCellValue(driver.getBoolean("multivalue"));
1543-
} catch (JSONException e) {
1544-
try {
1545-
newRow.createCell(2).setCellValue(driver.getString("multivalue"));
1546-
} catch (JSONException ex) {
1547-
newRow.createCell(2).setCellValue(false);
1548-
}
1452+
String value = driver.getString("value");
1453+
if (value != null && !value.isEmpty()) {
1454+
Row newRow = sheet.createRow(j);
1455+
newRow.createCell(0).setCellValue(driver.getString("name"));
1456+
newRow.createCell(1).setCellValue(driver.getString("value"));
1457+
j++;
15491458
}
1550-
newRow.createCell(3).setCellValue(driver.getString("value"));
1551-
newRow.createCell(4).setCellValue(driver.getString("urlName"));
1552-
newRow.createCell(5).setCellValue(driver.getString("driverLabel"));
1553-
newRow.createCell(6).setCellValue(setDriverType(driver));
1554-
1555-
j++;
15561459
}
15571460

15581461
} catch (Exception e) {
@@ -1562,22 +1465,6 @@ public void fillDashboardDriversSheetWithData(JSONArray drivers, Sheet sheet) {
15621465

15631466
}
15641467

1565-
private String setDriverType(JSONObject driver) {
1566-
if (driver.has("parameterValue")) {
1567-
return "DATASET DRIVER";
1568-
} else {
1569-
try {
1570-
if (driver.getString("description").equals("NOT APPLICABLE")) {
1571-
return "DATASET PARAMETER";
1572-
} else {
1573-
return "DOCUMENT DRIVER";
1574-
}
1575-
} catch (JSONException e) {
1576-
throw new RuntimeException(e);
1577-
}
1578-
}
1579-
}
1580-
15811468

15821469

15831470
}

knowage-export/src/main/java/it/eng/knowage/engine/api/export/dashboard/excel/DashboardExcelExporter.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public byte[] getScheduledBinaryData(String documentLabel) throws IOException, I
107107
// avoid sonar security hotspot issue
108108
String cockpitExportExternalProcessName = SingletonConfig.getInstance()
109109
.getConfigValue("KNOWAGE.DASHBOARD.EXTERNAL_PROCESS_NAME");
110-
LOGGER.info("CONFIG label=\"KNOWAGE.DASHBOARD.EXTERNAL_PROCESS_NAME\": " + cockpitExportExternalProcessName);
110+
LOGGER.info("CONFIG label=\"KNOWAGE.DASHBOARD.EXTERNAL_PROCESS_NAME\": {}", cockpitExportExternalProcessName);
111111

112112
String stringifiedRequestUrl = url.toString();
113113
ProcessBuilder processBuilder = new ProcessBuilder(cockpitExportExternalProcessName, exportScriptFullPath.toString(),
@@ -208,8 +208,6 @@ public byte[] getDashboardBinaryData(JSONObject body, boolean isDashboardSingleW
208208
exportedSheets++;
209209
}
210210

211-
transformDatasetDriversForExcelSheet(body, driversFromBody, parameters);
212-
213211
if (driversFromBody != null && driversFromBody.length() > 0) {
214212
Sheet driversSheet = createUniqueSafeSheetForSelections(wb, "Filters");
215213
fillDashboardDriversSheetWithData(driversFromBody, driversSheet);
@@ -265,8 +263,6 @@ public byte[] getPivotBinaryData(JSONObject body) {
265263
fillDashboardSelectionsSheetWithData(selections, selectionsSheet);
266264
}
267265

268-
transformDatasetDriversForExcelSheet(body, driversFromBody, parameters);
269-
270266
if (driversFromBody != null && driversFromBody.length() > 0) {
271267
Sheet driversSheet = createUniqueSafeSheetForSelections(wb, "Filters");
272268
fillDashboardDriversSheetWithData(driversFromBody, driversSheet);
@@ -598,7 +594,7 @@ void buildFirstPageHeaders(Workbook wb, Sheet sheet, String widgetName, int offs
598594
Row header = createHeader(sheet, startRow, rowHeight, rowspan, startCol, colWidth, colspan, namespan, dataspan, widgetName, groupsAndColumnsMap, columnsOrdered);
599595
for (int i = 0; i < columnsOrdered.length(); i++) {
600596
JSONObject column = columnsOrdered.getJSONObject(i);
601-
String columnName = "";
597+
String columnName;
602598
try {
603599
columnName = column.getString("alias");
604600
} catch (JSONException e) {
@@ -686,9 +682,8 @@ private void buildRowsAndCols(Workbook wb, Sheet sheet, int offset, JSONObject s
686682
String defaultRowBackgroundColor = getDefaultRowBackgroundColor(alternatedRows, rowIsEven);
687683

688684
boolean styleAlreadyAppliedToPreviousCells = false;
689-
String styleKeyToApplyToTheEntireRow = null;
690685
List<Boolean> styleCanBeOverriddenByWholeRowStyle = new ArrayList<>();
691-
cellStyle = buildCols(wb, sheet, settings, rows, columnsOrdered, columnStylesMap, cellStyle, columnsCellStyles, numberOfSummaryRows, summaryRowsLabels, row, rowObject, r, styleCanBeOverriddenByWholeRowStyle, rawCurrentNumberType, styleAlreadyAppliedToPreviousCells, defaultRowBackgroundColor, styleKeyToApplyToTheEntireRow);
686+
cellStyle = buildCols(wb, sheet, settings, rows, columnsOrdered, columnStylesMap, cellStyle, columnsCellStyles, numberOfSummaryRows, summaryRowsLabels, row, rowObject, r, styleCanBeOverriddenByWholeRowStyle, rawCurrentNumberType, styleAlreadyAppliedToPreviousCells, defaultRowBackgroundColor, null);
692687
}
693688
}
694689

0 commit comments

Comments
 (0)