|
18 | 18 |
|
19 | 19 | package it.eng.knowage.engine.api.excel.export.dashboard.exporters; |
20 | 20 |
|
| 21 | +import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | 22 | import it.eng.knowage.engine.api.excel.export.IWidgetExporter; |
22 | 23 | import it.eng.knowage.engine.api.excel.export.dashboard.DashboardExcelExporter; |
23 | 24 | import it.eng.knowage.engine.api.excel.export.dashboard.DatastoreUtils; |
|
26 | 27 | import org.apache.poi.ss.usermodel.Sheet; |
27 | 28 | import org.apache.poi.ss.usermodel.Workbook; |
28 | 29 | import org.json.JSONArray; |
| 30 | +import org.json.JSONException; |
29 | 31 | import org.json.JSONObject; |
30 | 32 |
|
| 33 | +import java.util.LinkedHashMap; |
31 | 34 | import java.util.Map; |
32 | 35 |
|
33 | 36 | class GenericDashboardWidgetExporter implements IWidgetExporter { |
@@ -62,6 +65,7 @@ public int export() { |
62 | 65 | JSONObject settings = widget.getJSONObject("settings"); |
63 | 66 | JSONObject dataStore = datastoreUtils.getDataStoreforDashboardSingleWidget(widget, selections, drivers, parameters); |
64 | 67 | String widgetName = getDashboardWidgetName(widget); |
| 68 | + widgetName = replacePlaceholderIfPresent(widgetName); |
65 | 69 | if (dataStore != null) { |
66 | 70 | String dashboardSheetName = documentName != null ? documentName : "Dashboard"; |
67 | 71 | Sheet sheet = excelExporter.createUniqueSafeSheet(wb, widgetName, dashboardSheetName); |
@@ -92,4 +96,22 @@ protected String getDashboardWidgetName(JSONObject widget) { |
92 | 96 | private static String getWidgetGenericName(JSONObject widget) { |
93 | 97 | return widget.optString("type").concat(" ").concat(widget.optString("id")); |
94 | 98 | } |
| 99 | + |
| 100 | + protected String replacePlaceholderIfPresent(String widgetName) { |
| 101 | + if (widgetName.contains("$P{")) { |
| 102 | + String placeholder = widgetName.substring(widgetName.indexOf("$P{") + 3, widgetName.indexOf("}")); |
| 103 | + if (drivers.has(placeholder)) { |
| 104 | + try { |
| 105 | + JSONArray valuesArray = drivers.getJSONArray(placeholder); |
| 106 | + if (valuesArray.length() > 0) { |
| 107 | + JSONObject value = valuesArray.getJSONObject(0); |
| 108 | + widgetName = widgetName.replace("$P{" + placeholder + "}", value.getString("value")); |
| 109 | + } |
| 110 | + } catch (JSONException e) { |
| 111 | + throw new SpagoBIRuntimeException("Unable to replace placeholder in widget name", e); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + return widgetName; |
| 116 | + } |
95 | 117 | } |
0 commit comments