use of com.haulmont.yarg.exception.DataLoadingException in project jmix by jmix-framework.
the class JmixGroovyDataLoader method loadData.
@Override
public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) {
try {
String script = reportQuery.getScript();
Map<String, Object> scriptParams = groovyScriptParametersProvider.prepareParameters(reportQuery, parentBand, params);
script = StringUtils.trim(script);
if (script.endsWith(".groovy")) {
script = resources.getResourceAsString(script);
}
return scripting.evaluateGroovy(script, scriptParams);
} catch (ValidationException e) {
throw e;
} catch (Throwable e) {
throw new DataLoadingException(String.format("An error occurred while loading data for data set [%s]", reportQuery.getName()), e);
}
}
use of com.haulmont.yarg.exception.DataLoadingException in project jmix by jmix-framework.
the class JpqlDataLoader method loadData.
@Override
public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) {
String storeName = StoreUtils.getStoreName(reportQuery);
String query = reportQuery.getScript();
if (StringUtils.isBlank(query)) {
return Collections.emptyList();
}
try {
if (Boolean.TRUE.equals(reportQuery.getProcessTemplate())) {
query = processQueryTemplate(query, parentBand, params);
}
List<OutputValue> outputParameters = parseQueryOutputParametersNames(query);
// replaces [as alias_name], entries except last
query = query.replaceAll("(?i)" + ALIAS_PATTERN + ",", ",");
// replaces last [as alias_name] entry
query = query.replaceAll("(?i)" + ALIAS_PATTERN, " ");
List queryResult = executeQuery(parentBand, params, storeName, query);
if (CollectionUtils.isNotEmpty(queryResult) && queryResult.get(0) instanceof Entity) {
List<Map<String, Object>> wrappedResults = new ArrayList<>();
for (Object theResult : queryResult) {
wrappedResults.add(new EntityMap((Entity) theResult, beanFactory));
}
return wrappedResults;
} else {
return fillOutputData(queryResult, outputParameters);
}
} catch (Throwable e) {
throw new DataLoadingException(String.format("An error occurred while loading data for data set [%s]", reportQuery.getName()), e);
}
}
Aggregations