Skip to content

Commit 972a33d

Browse files
committed
[KNOWAGE-9530] fix drilldown
1 parent 151a00c commit 972a33d

2 files changed

Lines changed: 62 additions & 12 deletions

File tree

knowage-core/src/main/java/it/eng/spagobi/api/common/AbstractDataSetResource.java

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@
2525
import java.nio.file.Paths;
2626
import java.nio.file.SimpleFileVisitor;
2727
import java.nio.file.attribute.BasicFileAttributes;
28-
import java.util.ArrayList;
29-
import java.util.Arrays;
30-
import java.util.HashMap;
31-
import java.util.Iterator;
32-
import java.util.List;
33-
import java.util.Map;
34-
import java.util.Set;
28+
import java.util.*;
3529
import java.util.regex.Matcher;
3630
import java.util.regex.Pattern;
3731

@@ -174,19 +168,19 @@ protected Integer[] getIdsAsIntegers(String ids) {
174168
public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections,
175169
String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
176170
Boolean isNearRealtime, Set<String> indexes, String widgetName, boolean useGroupBy) {
177-
return getDataStore(label, parameters, drivers, selections, likeSelections, maxRowCount, aggregations,
171+
return getDataStore(label, parameters, drivers, selections, likeSelections, null, maxRowCount, aggregations,
178172
summaryRow, offset, fetchSize, isNearRealtime, null, indexes, widgetName, useGroupBy);
179173
}
180174

181175
public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections,
182176
String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
183177
Set<String> indexes, String widgetName, boolean useGroupBy) {
184-
return getDataStore(label, parameters, drivers, selections, likeSelections, maxRowCount, aggregations,
178+
return getDataStore(label, parameters, drivers, selections, likeSelections, null, maxRowCount, aggregations,
185179
summaryRow, offset, fetchSize, null, null, indexes, widgetName, useGroupBy);
186180
}
187181

188182
public String getDataStore(String label, String parameters, Map<String, Object> drivers, String selections,
189-
String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
183+
String likeSelections, String drilldown, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
190184
Boolean isNearRealtime, String options, Set<String> indexes, String widgetName, boolean useGroupBy) {
191185
LOGGER.debug("IN");
192186
DatasetManagementAPI datasetManagementAPI = getDatasetManagementAPI();
@@ -290,12 +284,22 @@ public String getDataStore(String label, String parameters, Map<String, Object>
290284
}
291285
}
292286

287+
List<Filter> drilldownFilters = new ArrayList<>(0);
288+
if (drilldown != null && !drilldown.equals("")) {
289+
JSONObject drilldownObject = new JSONObject(drilldown);
290+
if (drilldownObject.names() != null) {
291+
drilldownFilters.addAll(getDrilldownFilters(label, drilldownObject, columnAliasToName));
292+
}
293+
}
294+
293295
Monitor timingMinMax = MonitorFactory.start("Knowage.AbstractDataSetResource.getDataStore:calculateMinMax");
294296
Map<String, String> parametersMap = DataSetUtilities.getParametersMap(parameters);
295297
filters = datasetManagementAPI.calculateMinMaxFilters(dataSet, isNearRealtime, parametersMap, filters,
296298
likeFilters, indexes);
297299
timingMinMax.stop();
298300

301+
filters.addAll(drilldownFilters);
302+
299303
Filter where = datasetManagementAPI.getWhereFilter(filters, likeFilters);
300304

301305
timing.stop();
@@ -346,7 +350,8 @@ public String getDataStore(String label, String parameters, Map<String, Object>
346350
}
347351
}
348352

349-
public String getDataStoreAI(String label, String parameters, Map<String, Object> drivers, String selections,
353+
354+
public String getDataStoreAI(String label, String parameters, Map<String, Object> drivers, String selections,
350355
String likeSelections, Integer maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize, Integer maxRows,
351356
Boolean isNearRealtime, String options, Set<String> indexes) {
352357
LOGGER.debug("IN");
@@ -1126,6 +1131,47 @@ protected List<SimpleFilter> getLikeFilters(String datasetLabel, JSONObject like
11261131
return likeFilters;
11271132
}
11281133

1134+
1135+
private List<Filter> getDrilldownFilters(String datasetLabel, JSONObject drilldownObject, Map<String, String> columnAliasToName) throws JSONException {
1136+
1137+
List<Filter> drilldownFilters = new ArrayList<>(0);
1138+
1139+
if (drilldownObject.has(datasetLabel)) {
1140+
IDataSet dataSet = getDataSetDAO().loadDataSetByLabel(datasetLabel);
1141+
boolean isAnEmptySelection = false;
1142+
1143+
JSONObject drilldownObjectJSONObject = drilldownObject.getJSONObject(datasetLabel);
1144+
Iterator<String> it = drilldownObjectJSONObject.keys();
1145+
while (it.hasNext()) {
1146+
String columns = it.next();
1147+
String value = drilldownObjectJSONObject.getString(columns);
1148+
if (value == null || value.isEmpty()) {
1149+
isAnEmptySelection = true;
1150+
break;
1151+
}
1152+
1153+
List<String> columnsList = getColumnList(columns, dataSet, columnAliasToName);
1154+
List<Projection> projections = new ArrayList<>(columnsList.size());
1155+
for (String columnName : columnsList) {
1156+
projections.add(new Projection(dataSet, columnName));
1157+
}
1158+
1159+
for (Projection projection : projections) {
1160+
SimpleFilter filter = new InFilter(projection, value);
1161+
drilldownFilters.add(filter);
1162+
}
1163+
}
1164+
1165+
if (isAnEmptySelection) {
1166+
drilldownFilters.clear();
1167+
drilldownFilters.add(new UnsatisfiedFilter());
1168+
}
1169+
}
1170+
1171+
return drilldownFilters;
1172+
}
1173+
1174+
11291175
protected List<String> getColumnList(String columns, IDataSet dataSet,
11301176
Map<String, String> columnAliasToColumnName) {
11311177
List<String> columnList = new ArrayList<>(Arrays.asList(columns.trim().replaceAll("\\s+", " ").split("\\s?,\\s?")));

knowage-core/src/main/java/it/eng/spagobi/api/v2/DataSetResource.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ public String getDataStorePostWithJsonInBody(@PathParam("label") String label, S
718718
Map<String, Object> driversRuntimeMap = null;
719719
String selections = null;
720720
String likeSelections = null;
721+
String drilldown = null;
721722
String aggregations = null;
722723
String summaryRow = null;
723724
String options = null;
@@ -738,6 +739,9 @@ public String getDataStorePostWithJsonInBody(@PathParam("label") String label, S
738739
JSONObject jsonLikeSelections = jsonBody.optJSONObject("likeSelections");
739740
likeSelections = jsonLikeSelections != null ? jsonLikeSelections.toString() : null;
740741

742+
JSONObject jsonDrilldown = jsonBody.optJSONObject("drilldown");
743+
drilldown = jsonDrilldown != null ? jsonDrilldown.toString() : null;
744+
741745
JSONObject jsonAggregations = jsonBody.optJSONObject("aggregations");
742746
aggregations = jsonAggregations != null ? jsonAggregations.toString() : null;
743747

@@ -771,7 +775,7 @@ public String getDataStorePostWithJsonInBody(@PathParam("label") String label, S
771775
}
772776
}
773777
timing.stop();
774-
return getDataStore(label, parameters, driversRuntimeMap, selections, likeSelections, maxRowCount,
778+
return getDataStore(label, parameters, driversRuntimeMap, selections, likeSelections, drilldown, maxRowCount,
775779
aggregations, summaryRow, offset, fetchSize, isNearRealtime, options, columns, widgetName, useGroupBy);
776780
} catch (CatalogFunctionException e) {
777781
throw e;

0 commit comments

Comments
 (0)