Skip to content

Commit b4b207d

Browse files
committed
[KNOWAGE-9583] set widget name in single widget xls export
1 parent fd425ac commit b4b207d

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

knowage-core/src/main/java/it/eng/knowage/dashboardexport/DashboardExportResource.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import it.eng.spagobi.utilities.mime.MimeUtils;
99
import it.eng.spagobi.utilities.rest.RestUtilities;
1010
import org.apache.log4j.Logger;
11+
import org.json.JSONException;
1112
import org.json.JSONObject;
1213

1314
import javax.servlet.http.HttpServletRequest;
@@ -60,6 +61,7 @@ public void downloadExcel(@Context HttpServletRequest req) {
6061
} else {
6162
String widgetName = body.getJSONObject("settings").getJSONObject("style").getJSONObject("title")
6263
.optString("text");
64+
widgetName = getWidgetName(widgetName, body);
6365
response.setHeader("Content-Disposition", "attachment; fileName=" + widgetName + "." + "xlsx");
6466
}
6567
response.setContentType(MediaType.APPLICATION_OCTET_STREAM);
@@ -78,6 +80,32 @@ public void downloadExcel(@Context HttpServletRequest req) {
7880
}
7981
}
8082

83+
private static String getWidgetName(String widgetName, JSONObject body) throws JSONException {
84+
85+
if (widgetName == null || widgetName.trim().isEmpty()) {
86+
switch (body.getString("type")) {
87+
case "highcharts":
88+
widgetName = "chart";
89+
break;
90+
case "static-pivot-table":
91+
widgetName = "pivot";
92+
break;
93+
case "map":
94+
widgetName = "map";
95+
break;
96+
case "table":
97+
widgetName = "table";
98+
break;
99+
case "customchart":
100+
widgetName = "custom_chart";
101+
break;
102+
default:
103+
widgetName = "widget";
104+
}
105+
}
106+
return widgetName;
107+
}
108+
81109
@POST
82110
@Path("/pdf")
83111
public void downloadPdf(@Context HttpServletRequest req) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,10 @@ protected void replaceWithThemeSettingsIfPresent(JSONObject settings) throws JSO
458458
Optional<SbiDashboardTheme> optionalTheme = dao.readByThemeName(settings.getJSONObject("style").optString("themeName"));
459459
if (optionalTheme.isPresent()) {
460460
SbiDashboardTheme dashboardTheme = optionalTheme.get();
461+
String widgetName = settings.getJSONObject("style").optJSONObject("title").optString("text");
461462
settings.remove("style");
462463
settings.put("style", dashboardTheme.getConfig().getJSONObject("table").getJSONObject("style"));
464+
settings.getJSONObject("style").getJSONObject("title").put("text", widgetName);
463465
}
464466
}
465467

@@ -495,7 +497,6 @@ protected Locale getLocaleFromBody(JSONObject body) {
495497
String country = body.getString(SpagoBIConstants.SBI_COUNTRY);
496498
return new Locale(language, country);
497499
} catch (Exception e) {
498-
LOGGER.warn("Cannot get locale information from input parameters body", e);
499500
return Locale.ENGLISH;
500501
}
501502

knowageutils/src/main/java/it/eng/spagobi/utilities/rest/RestUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static String readBodyXSSUnsafe(HttpServletRequest request) throws IOExce
186186
*/
187187
public static JSONObject readBodyAsJSONObject(HttpServletRequest request) throws IOException, JSONException {
188188
String requestBody = RestUtilities.readBodyXSSUnsafe(request);
189-
if (requestBody == null || requestBody.equals("")) {
189+
if (requestBody.isEmpty()) {
190190
return new JSONObject();
191191
}
192192
final JSONObject jsonObject = new JSONObject(requestBody);

0 commit comments

Comments
 (0)