protected List<Map<String, Object>> loadDataFromScript(ReportQuery reportQuery, Map<String, Object> currentParams, Matcher matcher, Object parameterValue) { List<Map<String, Object>> result; String json = parameterValue.toString(); String script = matcher.replaceAll(""); if (StringUtils.isBlank(script)) { throw new DataLoadingException( String.format("The script doesn't contain json path expression. " + "Script [%s]", reportQuery.getScript())); } matcher = AbstractDbDataLoader.COMMON_PARAM_PATTERN.matcher(script); while (matcher.find()) { String parameter = matcher.group(1); script = matcher.replaceAll(String.valueOf(currentParams.get(parameter))); } result = extractScriptResult(json, script, reportQuery); return result; }
protected List<Map<String, Object>> loadDataFromScript(ReportQuery reportQuery, Map<String, Object> currentParams, Matcher matcher, Object parameterValue) { List<Map<String, Object>> result; String json = parameterValue.toString(); String script = matcher.replaceAll(""); if (StringUtils.isBlank(script)) { throw new DataLoadingException( String.format("The script doesn't contain json path expression. " + "Script [%s]", reportQuery.getScript())); } matcher = AbstractDbDataLoader.COMMON_PARAM_PATTERN.matcher(script); while (matcher.find()) { String parameter = matcher.group(1); script = matcher.replaceAll(String.valueOf(currentParams.get(parameter))); } result = extractScriptResult(json, script, reportQuery); return result; }
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) { try { String script = reportQuery.getScript(); Map<String, Object> scriptParams = new HashMap<String, Object>(); scriptParams.put("reportQuery", reportQuery); scriptParams.put("parentBand", parentBand); scriptParams.put("params", params); return scripting.evaluateGroovy(script, scriptParams); } catch (Throwable e) { throw new DataLoadingException(String.format("An error occurred while loading data for data set [%s]", reportQuery.getName()), e); } } }
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) { try { String script = reportQuery.getScript(); Map<String, Object> scriptParams = new HashMap<String, Object>(); scriptParams.put("reportQuery", reportQuery); scriptParams.put("parentBand", parentBand); scriptParams.put("params", params); return scripting.evaluateGroovy(script, scriptParams); } catch (Throwable e) { throw new DataLoadingException(String.format("An error occurred while loading data for data set [%s]", reportQuery.getName()), e); } } }
protected List<Map<String, Object>> extractScriptResult(String jsonData, String jsonPathScript, ReportQuery reportQuery) { List<Map<String, Object>> result = new ArrayList<>(); try { Object scriptResult = JsonPath.read(jsonData, jsonPathScript); parseScriptResult(result, jsonPathScript, scriptResult); } catch (com.jayway.jsonpath.PathNotFoundException e) { return Collections.emptyList(); } catch (Throwable e) { throw new DataLoadingException( String.format("An error occurred while loading data with script [%s]", reportQuery.getScript()), e); } return result; }
BiFunction<ReportQuery, Map<String, Object>, List<Map<String, Object>>> after) { Multimap<String, String> references = HashMultimap.create(); Matcher matcher = REF_PATTERN.matcher(checkNotNull(reportQuery.getScript())); StringBuffer sb = new StringBuffer(); while (matcher.find()) {
protected List<Map<String, Object>> extractScriptResult(String jsonData, String jsonPathScript, ReportQuery reportQuery) { List<Map<String, Object>> result = new ArrayList<>(); try { Object scriptResult = JsonPath.read(jsonData, jsonPathScript); parseScriptResult(result, jsonPathScript, scriptResult); } catch (com.jayway.jsonpath.PathNotFoundException e) { return Collections.emptyList(); } catch (Throwable e) { throw new DataLoadingException( String.format("An error occurred while loading data with script [%s]", reportQuery.getScript()), e); } return result; }
BiFunction<ReportQuery, Map<String, Object>, List<Map<String, Object>>> after) { Multimap<String, String> references = HashMultimap.create(); Matcher matcher = REF_PATTERN.matcher(checkNotNull(reportQuery.getScript())); StringBuffer sb = new StringBuffer(); while (matcher.find()) {
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> reportParams) { Map<String, Object> currentParams = copyParameters(reportParams); Matcher matcher = parameterPattern.matcher(reportQuery.getScript()); String parameterName = getParameterName(matcher); addParentBandDataToParametersRecursively(parentBand, currentParams); List<Map<String, Object>> result; if (parameterName != null) { Object parameterValue = currentParams.get(parameterName); if (parameterValue != null && StringUtils.isNotBlank(parameterValue.toString())) { result = loadDataFromScript(reportQuery, currentParams, matcher, parameterValue); } else { return Collections.emptyList(); } } else { throw new DataLoadingException(String.format("Query string doesn't contain link to parameter. " + "Script [%s]", reportQuery.getScript())); } return result; }
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> reportParams) { Map<String, Object> currentParams = copyParameters(reportParams); Matcher matcher = parameterPattern.matcher(reportQuery.getScript()); String parameterName = getParameterName(matcher); addParentBandDataToParametersRecursively(parentBand, currentParams); List<Map<String, Object>> result; if (parameterName != null) { Object parameterValue = currentParams.get(parameterName); if (parameterValue != null && StringUtils.isNotBlank(parameterValue.toString())) { result = loadDataFromScript(reportQuery, currentParams, matcher, parameterValue); } else { return Collections.emptyList(); } } else { throw new DataLoadingException(String.format("Query string doesn't contain link to parameter. " + "Script [%s]", reportQuery.getScript())); } return result; }
@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); } } }
public ReportQueryImpl(ReportQuery reportQuery) { this(reportQuery.getName(), reportQuery.getScript(), reportQuery.getLoaderType(), reportQuery.getLinkParameterName(), reportQuery.getAdditionalParams()); }
public ReportQueryImpl(ReportQuery reportQuery) { this(reportQuery.getName(), reportQuery.getScript(), reportQuery.getLoaderType(), reportQuery.getLinkParameterName(), reportQuery.getAdditionalParams()); }
@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 (Transaction tx = persistence.createTransaction(storeName)) { if (Boolean.TRUE.equals(reportQuery.getProcessTemplate())) { query = processQueryTemplate(query, parentBand, params); } List<OutputValue> outputParameters = parseQueryOutputParametersNames(query); query = query.replaceAll("(?i)" + ALIAS_PATTERN + ",", ",");//replaces [as alias_name], entries except last query = query.replaceAll("(?i)" + ALIAS_PATTERN, " ");//replaces last [as alias_name] entry Query select = insertParameters(trimQuery(query), storeName, parentBand, params); List queryResult = select.getResultList(); tx.commit(); if (queryResult.size() > 0 && queryResult.get(0) instanceof Entity) { List<Map<String, Object>> wrappedResults = new ArrayList<>(); for (Object theResult : queryResult) { wrappedResults.add(new EntityMap((Entity) theResult)); } 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); } }
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) { try { String query = reportQuery.getScript(); if (StringUtils.isBlank(query)) { return Collections.emptyList();
@Override public List<Map<String, Object>> loadData(ReportQuery reportQuery, BandData parentBand, Map<String, Object> params) { try { String query = reportQuery.getScript(); if (StringUtils.isBlank(query)) { return Collections.emptyList();
protected void writeBandDefinition(Element element, ReportBand bandDefinition) { element.addAttribute("name", bandDefinition.getName()); element.addAttribute("orientation", bandDefinition.getBandOrientation().id); Element childrenBandsElement = element.addElement("bands"); Element reportQueriesElement = element.addElement("queries"); if (bandDefinition.getReportQueries() != null) { for (ReportQuery reportQuery : bandDefinition.getReportQueries()) { Element reportQueryElement = reportQueriesElement.addElement("query"); reportQueryElement.addAttribute("name", reportQuery.getName()); reportQueryElement.addAttribute("type", reportQuery.getLoaderType()); reportQueryElement.addElement("script").setText(reportQuery.getScript()); } } if (bandDefinition.getChildren() != null) { for (ReportBand childBandDefinition : bandDefinition.getChildren()) { Element childBandElement = childrenBandsElement.addElement("band"); writeBandDefinition(childBandElement, childBandDefinition); } } } }
protected void writeBandDefinition(Element element, ReportBand bandDefinition) { element.addAttribute("name", bandDefinition.getName()); element.addAttribute("orientation", bandDefinition.getBandOrientation().id); Element childrenBandsElement = element.addElement("bands"); Element reportQueriesElement = element.addElement("queries"); if (bandDefinition.getReportQueries() != null) { for (ReportQuery reportQuery : bandDefinition.getReportQueries()) { Element reportQueryElement = reportQueriesElement.addElement("query"); reportQueryElement.addAttribute("name", reportQuery.getName()); reportQueryElement.addAttribute("type", reportQuery.getLoaderType()); reportQueryElement.addElement("script").setText(reportQuery.getScript()); } } if (bandDefinition.getChildren() != null) { for (ReportBand childBandDefinition : bandDefinition.getChildren()) { Element childBandElement = childrenBandsElement.addElement("band"); writeBandDefinition(childBandElement, childBandDefinition); } } } }