use of io.jmix.reports.entity.ReportOutputType in project jmix by jmix-framework.
the class ReportRunnerImpl method createReportDocumentInternal.
protected ReportOutputDocument createReportDocumentInternal(ReportRunContext context) {
Report report = context.getReport();
ReportTemplate template = context.getReportTemplate();
ReportOutputType outputType = context.getOutputType();
Map<String, Object> params = context.getParams();
String outputNamePattern = context.getOutputNamePattern();
StopWatch stopWatch = null;
MDC.put("user", SecurityContextHolder.getContext().getAuthentication().getName());
// executions.startExecution(report.getId().toString(), "Reporting");
try {
// TODO Slf4JStopWatch
// stopWatch = new Slf4JStopWatch("Reporting#" + report.getName());
Map<String, Object> resultParams = new HashMap<>(params);
params.entrySet().stream().filter(param -> param.getValue() instanceof ParameterPrototype).forEach(param -> {
ParameterPrototype prototype = (ParameterPrototype) param.getValue();
List data = prototypesLoader.loadData(prototype);
resultParams.put(param.getKey(), data);
});
if (template.isCustom()) {
CustomFormatter customFormatter = applicationContext.getBean(CustomFormatter.class, report, template);
template.setCustomReport(customFormatter);
}
com.haulmont.yarg.structure.ReportOutputType resultOutputType = (outputType != null) ? outputType.getOutputType() : template.getOutputType();
return reportingAPI.runReport(new RunParams(report).template(template).params(resultParams).output(resultOutputType).outputNamePattern(outputNamePattern));
} catch (NoFreePortsException nfe) {
throw new NoOpenOfficeFreePortsException(nfe.getMessage());
} catch (OpenOfficeException ooe) {
throw new FailedToConnectToOpenOfficeException(ooe.getMessage());
} catch (com.haulmont.yarg.exception.UnsupportedFormatException fe) {
throw new UnsupportedFormatException(fe.getMessage());
} catch (com.haulmont.yarg.exception.ValidationException ve) {
throw new ValidationException(ve.getMessage());
} catch (ReportingInterruptedException ie) {
throw new ReportCanceledException(String.format("Report is canceled. %s", ie.getMessage()));
} catch (com.haulmont.yarg.exception.ReportingException re) {
// todo https://github.com/Haulmont/jmix-reports/issues/22
// Throwable rootCause = ExceptionUtils.getRootCause(re);
// if (rootCause instanceof ResourceCanceledException) {
// throw new ReportCanceledException(String.format("Report is canceled. %s", rootCause.getMessage()));
// }
// noinspection unchecked
List<Throwable> list = ExceptionUtils.getThrowableList(re);
StringBuilder sb = new StringBuilder();
for (Iterator<Throwable> it = list.iterator(); it.hasNext(); ) {
// noinspection ThrowableResultOfMethodCallIgnored
sb.append(it.next().getMessage());
if (it.hasNext())
sb.append("\n");
}
throw new ReportingException(sb.toString());
} finally {
// todo https://github.com/Haulmont/jmix-reports/issues/22
// executions.endExecution();
MDC.remove("user");
MDC.remove("webContextName");
if (stopWatch != null) {
stopWatch.stop();
}
}
}
use of io.jmix.reports.entity.ReportOutputType in project jmix by jmix-framework.
the class SaveStepFragment method updateCorrectReportOutputType.
protected void updateCorrectReportOutputType() {
ReportOutputType outputFileFormatPrevValue = outputFileFormat.getValue();
outputFileFormat.setValue(null);
Map<String, ReportOutputType> optionsMap = outputFormatTools.getOutputAvailableFormats(reportDataDc.getItem().getTemplateFileType());
outputFileFormat.setOptionsMap(optionsMap);
if (outputFileFormatPrevValue != null) {
if (optionsMap.containsKey(outputFileFormatPrevValue.toString())) {
outputFileFormat.setValue(outputFileFormatPrevValue);
}
}
if (outputFileFormat.getValue() == null) {
if (optionsMap.size() > 1) {
outputFileFormat.setValue(optionsMap.get(reportDataDc.getItem().getTemplateFileType().toString()));
} else if (optionsMap.size() == 1) {
outputFileFormat.setValue(optionsMap.values().iterator().next());
}
}
}
use of io.jmix.reports.entity.ReportOutputType in project jmix by jmix-framework.
the class TemplateEditor method onAfterInit.
@Subscribe
protected void onAfterInit(AfterInitEvent event) {
templateDc.addItemPropertyChangeListener(e -> {
ReportTemplate reportTemplate = getEditedEntity();
switch(e.getProperty()) {
case REPORT_OUTPUT_TYPE:
{
ReportOutputType prevOutputType = (ReportOutputType) e.getPrevValue();
ReportOutputType newOutputType = (ReportOutputType) e.getValue();
setupVisibility(reportTemplate.getCustom(), newOutputType);
if (hasHtmlCsvTemplateOutput(prevOutputType) && !hasTemplateOutput(newOutputType)) {
dialogs.createMessageDialog().withCaption(messages.getMessage(getClass(), "templateEditor.warning")).withMessage(messages.getMessage(getClass(), "templateEditor.clearTemplateMessage")).show();
}
break;
}
case CUSTOM:
{
setupVisibility(Boolean.TRUE.equals(e.getValue()), reportTemplate.getReportOutputType());
break;
}
case CUSTOM_DEFINE_BY:
{
boolean isGroovyScript = hasScriptCustomDefinedBy(reportTemplate.getCustomDefinedBy());
fullScreenLinkButton.setVisible(isGroovyScript);
customDefinitionHelpLinkButton.setVisible(isGroovyScript);
break;
}
}
});
initOutputTypeList();
}
use of io.jmix.reports.entity.ReportOutputType in project jmix by jmix-framework.
the class TemplateEditor method onBeforeCommit.
@Subscribe
protected void onBeforeCommit(BeforeCommitChangesEvent event) {
if (!validateTemplateFile() || !validateInputOutputFormats()) {
event.preventCommit();
}
ReportTemplate reportTemplate = getEditedEntity();
for (DescriptionEditFragment fragment : getDescriptionEditFragments()) {
if (fragment.isApplicable(reportTemplate.getReportOutputType())) {
if (!fragment.applyChanges()) {
event.preventCommit();
}
}
}
if (!Boolean.TRUE.equals(reportTemplate.getCustom())) {
reportTemplate.setCustomDefinition("");
}
String extension = FilenameUtils.getExtension(templateUploadField.getFileName());
if (extension != null) {
ReportOutputType outputType = ReportOutputType.getTypeFromExtension(extension.toUpperCase());
if (hasHtmlCsvTemplateOutput(outputType)) {
byte[] bytes = templateFileEditor.getValue() == null ? new byte[0] : templateFileEditor.getValue().getBytes(StandardCharsets.UTF_8);
reportTemplate.setContent(bytes);
}
}
}
use of io.jmix.reports.entity.ReportOutputType in project jmix by jmix-framework.
the class TemplateEditor method initTemplateEditor.
protected void initTemplateEditor(ReportTemplate reportTemplate) {
templateFileEditor.setMode(SourceCodeEditor.Mode.HTML);
String extension = FilenameUtils.getExtension(templateUploadField.getFileName());
if (extension == null) {
visibleTemplateEditor(null);
return;
}
ReportOutputType outputType = ReportOutputType.getTypeFromExtension(extension.toUpperCase());
visibleTemplateEditor(outputType);
if (hasHtmlCsvTemplateOutput(outputType)) {
String templateContent = new String(reportTemplate.getContent(), StandardCharsets.UTF_8);
templateFileEditor.setValue(templateContent);
}
templateFileEditor.setEditable(secureOperations.isEntityUpdatePermitted(metadata.getClass(reportTemplate), policyStore));
}
Aggregations