Skip to content

Commit d652a49

Browse files
committed
[KNOWAGE-9771] conditionally remove style from excel export: change condition strategy
1 parent 03a4a55 commit d652a49

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

  • knowage-export/src/main/java/it/eng/knowage/engine/api/export/dashboard/excel
  • knowage/src/main/resources/it/eng/spagobi/commons/initializers/metadata/config

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public class DashboardExcelExporter extends DashboardExporter {
6060
private static final String CONFIG_NAME_FOR_EXPORT_SCRIPT_PATH = "internal.nodejs.chromium.export.path";
6161
private static final String CONFIG_NAME_FOR_DRIVERS_SHEET_EXPORT = "DASHBOARD.EXPORT.SHOW_DRIVERS_SHEET";
6262
private static final String CONFIG_NAME_FOR_SELECTIONS_SHEET_EXPORT = "DASHBOARD.EXPORT.SHOW_SELECTIONS_SHEET";
63-
private static final String CONFIG_NAME_FOR_DISABLE_STYLE = "DASHBOARD.XLSX.EXPORT.DISABLE_STYLE";
6463
private static final String SCRIPT_NAME = "cockpit-export-xls.js";
6564
private static final String DOCUMENT_NAME = "";
65+
private static final String XLSX_STYLE_ENABLED = "xlsxStyleEnabled";
6666
private String role;
6767
private String requestURL = "";
6868
private String organization = "";
@@ -91,6 +91,24 @@ public DashboardExcelExporter(JSONObject body, String role, String requestUrl, S
9191
this.organization = organization;
9292
}
9393

94+
static boolean isXlsxStyleEnabled(JSONObject body, boolean isDashboardSingleWidgetExport) {
95+
if (body == null) {
96+
return true;
97+
}
98+
if (isDashboardSingleWidgetExport) {
99+
return body.optBoolean(XLSX_STYLE_ENABLED, true);
100+
}
101+
JSONObject configuration = body.optJSONObject("configuration");
102+
if (configuration == null) {
103+
return true;
104+
}
105+
JSONObject menuWidgets = configuration.optJSONObject("menuWidgets");
106+
if (menuWidgets == null) {
107+
return true;
108+
}
109+
return menuWidgets.optBoolean(XLSX_STYLE_ENABLED, true);
110+
}
111+
94112
public byte[] getScheduledBinaryData(String documentLabel) throws IOException, InterruptedException {
95113
try {
96114
Path outputDir;
@@ -214,12 +232,7 @@ public byte[] getDashboardBinaryData(JSONObject body, boolean isDashboardSingleW
214232
JSONArray driversFromBody = getDrivers(body);
215233
JSONObject drivers = transformDriversForDatastore(driversFromBody);
216234
JSONArray parameters = getParametersFromBody(body);
217-
218-
IConfigDAO configsDao = DAOFactory.getSbiConfigDAO();
219-
Optional<Config> disableStyleCfg = configsDao.loadConfigParametersByLabelIfExist(CONFIG_NAME_FOR_DISABLE_STYLE);
220-
if (disableStyleCfg.isPresent() && disableStyleCfg.get().isActive()) {
221-
this.disableBasicStyle = Boolean.parseBoolean(disableStyleCfg.get().getValueCheck());
222-
}
235+
this.disableBasicStyle = !isXlsxStyleEnabled(body, isDashboardSingleWidgetExport);
223236

224237
if (isDashboardSingleWidgetExport) {
225238
if (body.has("datasetDrivers") && body.getJSONArray("datasetDrivers") != null && body.getJSONArray("datasetDrivers").length() > 0) {
@@ -233,6 +246,7 @@ public byte[] getDashboardBinaryData(JSONObject body, boolean isDashboardSingleW
233246
}
234247

235248

249+
IConfigDAO configsDao = DAOFactory.getSbiConfigDAO();
236250
Optional<Config> selectionsCfg = configsDao.loadConfigParametersByLabelIfExist(CONFIG_NAME_FOR_SELECTIONS_SHEET_EXPORT);
237251

238252
if (selectionsCfg.isPresent() && selectionsCfg.get().isActive() && Boolean.parseBoolean(selectionsCfg.get().getValueCheck()) && !selections.isEmpty()) {
@@ -280,6 +294,7 @@ public byte[] getPivotBinaryData(JSONObject body) {
280294
throw new SpagoBIRuntimeException("Unable to get template for dashboard");
281295
}
282296
try {
297+
this.disableBasicStyle = !isXlsxStyleEnabled(body, true);
283298
Map<String, Map<String, Object>> selections = getSelections(body);
284299

285300
JSONArray driversFromBody = getDrivers(body);

knowage/src/main/resources/it/eng/spagobi/commons/initializers/metadata/config/configs.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,5 @@
682682
description="If true, drivers and selections sheet will be included in the exported workbook (cockpit xlsx export)" isActive="true"
683683
valueCheck="false" valueType="STRING" category="GENERIC_CONFIGURATION" />
684684

685-
<CONFIG label="DASHBOARD.XLSX.EXPORT.DISABLE_STYLE" name="Disables style in dashboard xlsx export"
686-
description="If true, it disables the basic style from the xlsx export of a dashboard (this config does not affect conditional style)" isActive="true"
687-
valueCheck="false" valueType="STRING" category="GENERIC_CONFIGURATION" />
688685
</CONFIGS>
689686

0 commit comments

Comments
 (0)