Skip to content

Commit dee613d

Browse files
committed
AI data service set configurable max rows limit
1 parent 9169513 commit dee613d

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public String getDataStore(String label, String parameters, Map<String, Object>
348348
}
349349

350350
public String getDataStoreAI(String label, String parameters, Map<String, Object> drivers, String selections,
351-
String likeSelections, int maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
351+
String likeSelections, Integer maxRowCount, String aggregations, String summaryRow, int offset, int fetchSize,
352352
Boolean isNearRealtime, String options, Set<String> indexes, String widgetName) {
353353
LOGGER.debug("IN");
354354
DatasetManagementAPI datasetManagementAPI = getDatasetManagementAPI();
@@ -358,8 +358,14 @@ public String getDataStoreAI(String label, String parameters, Map<String, Object
358358

359359
int maxResults = Integer
360360
.parseInt(SingletonConfig.getInstance().getConfigValue("SPAGOBI.API.DATASET.MAX_ROWS_NUMBER"));
361+
361362
LOGGER.debug("Offset {}, fetch size {}, max results {}", offset, fetchSize, maxResults);
362363

364+
365+
if (maxRowCount == null) {
366+
maxRowCount = maxResults;
367+
}
368+
363369
if (maxResults <= 0) {
364370
throw new SpagoBIRuntimeException(
365371
"SPAGOBI.API.DATASET.MAX_ROWS_NUMBER value cannot be a non-positive integer");
@@ -371,7 +377,7 @@ public String getDataStoreAI(String label, String parameters, Map<String, Object
371377
}
372378
if (maxRowCount > maxResults) {
373379
throw new IllegalArgumentException(
374-
"The dataset requested is too big. Max row count is equals to [" + maxResults + "]");
380+
"The requested number of rows is too big [ " + maxRowCount + " ]. The limit is [ " + maxResults + " ]");
375381
}
376382

377383
IDataSetDAO dataSetDao = DAOFactory.getDataSetDAO();
@@ -491,6 +497,8 @@ public String getDataStoreAI(String label, String parameters, Map<String, Object
491497
return gridDataFeed.toString();
492498
} catch (ValidationException v) {
493499
throw v;
500+
} catch (IllegalArgumentException i) {
501+
throw i;
494502
} catch (ParametersNotValorizedException p) {
495503
throw p;
496504
} catch (CatalogFunctionException c) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.ws.rs.core.Response.ResponseBuilder;
5151
import javax.ws.rs.core.Response.Status;
5252

53+
import it.eng.spagobi.commons.SingletonConfig;
5354
import org.apache.commons.lang3.StringUtils;
5455
import org.apache.log4j.LogMF;
5556
import org.apache.log4j.Logger;
@@ -787,7 +788,7 @@ public String getDataStorePostWithJsonInBody(@PathParam("label") String label, S
787788
@Produces(MediaType.APPLICATION_JSON)
788789
@UserConstraint(functionalities = { CommunityFunctionalityConstants.SELF_SERVICE_DATASET_MANAGEMENT })
789790
public String getAIDataStorePostWithJsonInBody(@PathParam("label") String label, String body,
790-
@QueryParam("widgetName") String widgetName) {
791+
@QueryParam("widgetName") String widgetName, @QueryParam("maxRows") Integer maxRows) {
791792
try {
792793
Monitor timing = MonitorFactory.start("Knowage.DataSetResource.getDataStorePostWithJsonInBody:parseInputs");
793794

@@ -799,7 +800,7 @@ public String getAIDataStorePostWithJsonInBody(@PathParam("label") String label,
799800
String summaryRow = null;
800801
String options = null;
801802
JSONArray jsonIndexes = null;
802-
int maxRowCount = 5000;
803+
Integer maxRowCount = maxRows;
803804
int fetchSize = 5000;
804805
boolean isNearRealtime = true;
805806
int offset = 0;
@@ -858,7 +859,7 @@ public String getAIDataStorePostWithJsonInBody(@PathParam("label") String label,
858859
throw e;
859860
} catch (Exception e) {
860861
logger.error("Error loading dataset data from " + label, e);
861-
throw new SpagoBIRestServiceException(buildLocaleFromSession(), e);
862+
throw new SpagoBIRuntimeException(e.getMessage(), e);
862863
}
863864
}
864865

0 commit comments

Comments
 (0)