Search in sources :

Example 1 with DataLoadingException

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);
    }
}
Also used : DataLoadingException(com.haulmont.yarg.exception.DataLoadingException) ValidationException(com.haulmont.yarg.exception.ValidationException)

Example 2 with DataLoadingException

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);
    }
}
Also used : DataLoadingException(com.haulmont.yarg.exception.DataLoadingException) EntityMap(io.jmix.reports.app.EntityMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EntityMap(io.jmix.reports.app.EntityMap) Map(java.util.Map)

Aggregations

DataLoadingException (com.haulmont.yarg.exception.DataLoadingException)2 ValidationException (com.haulmont.yarg.exception.ValidationException)1 EntityMap (io.jmix.reports.app.EntityMap)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1