IDEMPIERE-4907 : Jasper Report using Dashboard Content (#2037)

* IDEMPIERE-4907 : Jasper Report using Dashboard Content

* IDEMPIERE-4907 : Jasper Report using Dashboard Content

- remove unnecessary code
- added runtime exception if jasper report is null

* IDEMPIERE-4907 : Jasper Report using Dashboard Content
This commit is contained in:
Zuhri Utama 2023-10-04 11:29:59 +07:00 committed by GitHub
parent 3ffdd2be0c
commit c4e7e0abaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 10 deletions

View File

@ -84,6 +84,7 @@ import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
import org.compiere.process.ProcessInfo; import org.compiere.process.ProcessInfo;
import org.compiere.process.ServerProcessCtl;
import org.compiere.tools.FileUtil; import org.compiere.tools.FileUtil;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
@ -834,7 +835,7 @@ public class DashboardController implements EventListener<Event> {
btn.setLabel(Msg.getMsg(Env.getCtx(), "OpenRunDialog")); btn.setLabel(Msg.getMsg(Env.getCtx(), "OpenRunDialog"));
toolbar.appendChild(btn); toolbar.appendChild(btn);
if(iframe.getContent() != null) { if(iframe.getContent() != null && reportData.getRowCount() >= 0) {
btn = new ToolBarButton(); btn = new ToolBarButton();
btn.setAttribute("AD_Process_ID", AD_Process_ID); btn.setAttribute("AD_Process_ID", AD_Process_ID);
btn.setAttribute("ProcessParameters", processParameters); btn.setAttribute("ProcessParameters", processParameters);
@ -853,15 +854,18 @@ public class DashboardController implements EventListener<Event> {
btn.setImage(ThemeManager.getThemeResource("images/Refresh16.png")); btn.setImage(ThemeManager.getThemeResource("images/Refresh16.png"));
toolbar.appendChild(btn); toolbar.appendChild(btn);
Label rowCountLabel = new Label(Msg.getMsg(Env.getCtx(), "RowCount", new Object[] {reportData.getRowCount()})); Label rowCountLabel = new Label(Msg.getMsg(Env.getCtx(), "RowCount", new Object[] {reportData.getRowCount()}));
LayoutUtils.addSclass("rowcount-label", rowCountLabel); if(reportData.getRowCount() >= 0) {
toolbar.appendChild(rowCountLabel); LayoutUtils.addSclass("rowcount-label", rowCountLabel);
toolbar.appendChild(rowCountLabel);
}
btn.addEventListener(Events.ON_CLICK, e -> { btn.addEventListener(Events.ON_CLICK, e -> {
ReportData refreshedData = generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, parentComponent, contextPath); ReportData refreshedData = generateReport(AD_Process_ID, dashboardContent.getAD_PrintFormat_ID(), processParameters, parentComponent, contextPath);
iframe.setContent(refreshedData.getContent()); iframe.setContent(refreshedData.getContent());
rowCountLabel.setValue(Msg.getMsg(Env.getCtx(), "RowCount", new Object[] {refreshedData.getRowCount()})); if(refreshedData.getRowCount() >= 0)
rowCountLabel.setValue(Msg.getMsg(Env.getCtx(), "RowCount", new Object[] {refreshedData.getRowCount()}));
}); });
} }
else else
@ -1589,6 +1593,8 @@ public class DashboardController implements EventListener<Event> {
return htmlString; return htmlString;
} }
/** /**
* Run report * Run report
* @param AD_Process_ID * @param AD_Process_ID
@ -1643,13 +1649,46 @@ public class DashboardController implements EventListener<Event> {
* @throws Exception * @throws Exception
*/ */
private ReportData generateReport(int AD_Process_ID, int AD_PrintFormat_ID, String parameters, Component component, String contextPath) throws Exception { private ReportData generateReport(int AD_Process_ID, int AD_PrintFormat_ID, String parameters, Component component, String contextPath) throws Exception {
MProcess process = MProcess.get(Env.getCtx(), AD_Process_ID);
File file = null;
if(process.getJasperReport() != null) {
file = runJasperReport(process, parameters);
return new ReportData(new AMedia(process.getName(), "html", "text/html", file, false), -1);
}
ReportEngine re = runReport(AD_Process_ID, AD_PrintFormat_ID, parameters); ReportEngine re = runReport(AD_Process_ID, AD_PrintFormat_ID, parameters);
if(re == null) if(re == null)
return null; return null;
File file = FileUtil.createTempFile(re.getName(), ".html"); file = FileUtil.createTempFile(re.getName(), ".html");
re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(contextPath, "rp", re.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(contextPath, "rp",
component.getUuid(), String.valueOf(AD_Process_ID))); component.getUuid(), String.valueOf(AD_Process_ID)));
return new ReportData(new AMedia(re.getName(), "html", "text/html", file, false), re); return new ReportData(new AMedia(process.getName(), "html", "text/html", file, false), re.getPrintData() != null ? re.getPrintData().getRowCount(false) : 0);
}
private File runJasperReport(MProcess process, String parameters) {
MPInstance pInstance = new MPInstance(Env.getCtx(), process.getAD_Process_ID(), 0, 0, null);
pInstance.setIsProcessing(true);
pInstance.saveEx();
try {
if(!fillParameter(pInstance, parameters))
return null;
//
ProcessInfo pi = new ProcessInfo (process.getName(), process.getAD_Process_ID(), 0, 0);
pi.setExport(true);
pi.setExportFileExtension("html");
pi.setAD_User_ID(Env.getAD_User_ID(Env.getCtx()));
pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
// Report
ServerProcessCtl.process(pi, null);
return pi.getExportFile();
}catch(Exception ex) {
throw new IllegalStateException("Cannot create Report AD_Process_ID=" + process.getAD_Process_ID()
+ " - " + process.getName());
}
} }
/** /**
@ -1948,10 +1987,9 @@ public class DashboardController implements EventListener<Event> {
* @param content * @param content
* @param rowCount * @param rowCount
*/ */
public ReportData(AMedia content, ReportEngine reportEngine) { public ReportData(AMedia content, int rowCount) {
this.content = content; this.content = content;
if(reportEngine.getPrintData() != null) this.rowCount = rowCount;
this.rowCount = reportEngine.getPrintData().getRowCount(false);
} }
/** /**