Skip to content

Commit 9759117

Browse files
committed
[KNOWAGE-9908] implement top level likeSelections in dashboard export
(cherry picked from commit e82fa4a)
1 parent 011d181 commit 9759117

2 files changed

Lines changed: 95 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,15 @@ public JSONObject getDataStoreForDashboardWidget(JSONObject widget, int offset,
878878
dashboardSelections.put("selections", effectiveSelections);
879879
dashboardSelections.put("parameters", parameters);
880880
dashboardSelections.put("drivers", drivers);
881+
addWidgetLikeSelections(dashboardSelections, widget);
881882

882883
if (isSolrDataset(dataset) && !widget.getString("type").equalsIgnoreCase("discovery")) {
883884
JSONObject jsOptions = new JSONObject();
884885
jsOptions.put("solrFacetPivot", true);
885886
dashboardSelections.put("options", jsOptions);
886887
}
887888

888-
if (isSolrDataset(dataset) && widget.getString("type").equalsIgnoreCase("discovery")) {
889+
if (!dashboardSelections.has("likeSelections") && isSolrDataset(dataset) && widget.getString("type").equalsIgnoreCase("discovery")) {
889890
buildLikeSelections(dashboardSelections, widget);
890891
}
891892

@@ -1080,6 +1081,13 @@ protected boolean isSolrDataset(IDataSet dataSet) {
10801081
return dataSet instanceof SolrDataSet;
10811082
}
10821083

1084+
protected void addWidgetLikeSelections(JSONObject dashboardSelections, JSONObject widget) throws JSONException {
1085+
JSONObject likeSelections = widget.optJSONObject("likeSelections");
1086+
if (likeSelections != null && likeSelections.length() > 0) {
1087+
dashboardSelections.put("likeSelections", new JSONObject(likeSelections.toString()));
1088+
}
1089+
}
1090+
10831091
private void buildLikeSelections(JSONObject dashboardSelections, JSONObject widget) {
10841092
try {
10851093
JSONObject likeSelections = new JSONObject();

knowage-export/src/test/java/it/eng/knowage/engine/api/export/dashboard/DashboardExporterTest.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@
77

88
import static org.junit.Assert.assertEquals;
99
import static org.junit.Assert.assertFalse;
10+
import static org.junit.Assert.assertTrue;
1011

1112
public class DashboardExporterTest {
1213

14+
private static class TestableDashboardExporter extends DashboardExporter {
15+
16+
private TestableDashboardExporter() {
17+
super("test-user", null);
18+
}
19+
20+
@Override
21+
protected String getInternationalizedHeader(String columnName) {
22+
return columnName;
23+
}
24+
25+
private String resolveColumnDisplayName(JSONObject settings, JSONObject column, JSONArray variables) throws JSONException {
26+
return getDashboardColumnDisplayName(settings, column, variables);
27+
}
28+
29+
private void copyWidgetLikeSelections(JSONObject dashboardSelections, JSONObject widget) throws JSONException {
30+
addWidgetLikeSelections(dashboardSelections, widget);
31+
}
32+
}
33+
1334
@Test
1435
public void shouldPreserveOrderBySummaryPathInPivotAggregations() throws JSONException {
1536
DashboardExporter exporter = new DashboardExporter("test-user", null);
@@ -101,4 +122,69 @@ public void shouldPreserveRowSummaryPathWhenSortingPivotColumns() throws JSONExc
101122
assertFalse(categories.getJSONObject(1).has("orderBySummaryPath"));
102123
assertFalse(categories.getJSONObject(2).has("orderBySummaryPath"));
103124
}
125+
126+
@Test
127+
public void shouldResolveVariablePlaceholderInCustomHeaderLabel() throws JSONException {
128+
TestableDashboardExporter exporter = new TestableDashboardExporter();
129+
130+
JSONObject settings = new JSONObject()
131+
.put("configuration", new JSONObject()
132+
.put("headers", new JSONObject()
133+
.put("custom", new JSONObject()
134+
.put("enabled", true)
135+
.put("rules", new JSONArray()
136+
.put(new JSONObject()
137+
.put("action", "setLabel")
138+
.put("value", "$V{QQ}")
139+
.put("target", new JSONArray().put("quarter-column")))))));
140+
JSONObject column = new JSONObject()
141+
.put("id", "quarter-column")
142+
.put("alias", "Quarter");
143+
JSONArray variables = new JSONArray()
144+
.put(new JSONObject()
145+
.put("name", "QQ")
146+
.put("value", "Q1 2026"));
147+
148+
assertEquals("Q1 2026", exporter.resolveColumnDisplayName(settings, column, variables));
149+
}
150+
151+
@Test
152+
public void shouldResolveDirectVariableNameInCustomHeaderLabel() throws JSONException {
153+
TestableDashboardExporter exporter = new TestableDashboardExporter();
154+
155+
JSONObject settings = new JSONObject()
156+
.put("configuration", new JSONObject()
157+
.put("headers", new JSONObject()
158+
.put("custom", new JSONObject()
159+
.put("enabled", true)
160+
.put("rules", new JSONArray()
161+
.put(new JSONObject()
162+
.put("action", "setLabel")
163+
.put("value", "QQ")
164+
.put("target", new JSONArray().put("quarter-column")))))));
165+
JSONObject column = new JSONObject()
166+
.put("id", "quarter-column")
167+
.put("alias", "Quarter");
168+
JSONArray variables = new JSONArray()
169+
.put(new JSONObject()
170+
.put("name", "QQ")
171+
.put("value", "Q1 2026"));
172+
173+
assertEquals("Q1 2026", exporter.resolveColumnDisplayName(settings, column, variables));
174+
}
175+
176+
@Test
177+
public void shouldCopyIncomingWidgetLikeSelections() throws JSONException {
178+
TestableDashboardExporter exporter = new TestableDashboardExporter();
179+
JSONObject dashboardSelections = new JSONObject();
180+
JSONObject widget = new JSONObject()
181+
.put("likeSelections", new JSONObject()
182+
.put("sales", new JSONObject()
183+
.put("COUNTRY,REGION", "it")));
184+
185+
exporter.copyWidgetLikeSelections(dashboardSelections, widget);
186+
187+
assertTrue(dashboardSelections.has("likeSelections"));
188+
assertEquals("it", dashboardSelections.getJSONObject("likeSelections").getJSONObject("sales").getString("COUNTRY,REGION"));
189+
}
104190
}

0 commit comments

Comments
 (0)