File tree Expand file tree Collapse file tree
knowage-core/src/main/java/it/eng/knowage/dashboardexport
knowage-export/src/main/java/it/eng/knowage/engine/api/export/dashboard
knowageutils/src/main/java/it/eng/spagobi/utilities/rest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import it .eng .spagobi .utilities .mime .MimeUtils ;
99import it .eng .spagobi .utilities .rest .RestUtilities ;
1010import org .apache .log4j .Logger ;
11+ import org .json .JSONException ;
1112import org .json .JSONObject ;
1213
1314import 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 ) {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 );
You can’t perform that action at this time.
0 commit comments