IDEMPIERE-3520 Ability to merge several jasper reports in one run
This commit is contained in:
parent
840673e4e5
commit
4e1f52c9ca
|
@ -0,0 +1,11 @@
|
||||||
|
package org.adempiere.report.jasper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.sf.jasperreports.engine.JRException;
|
||||||
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
|
||||||
|
public interface JRViewerProviderList {
|
||||||
|
|
||||||
|
public void openViewer(List<JasperPrint> jasperPrintList, String title) throws JRException;
|
||||||
|
}
|
|
@ -35,6 +35,7 @@ import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -46,6 +47,34 @@ import javax.print.attribute.PrintRequestAttributeSet;
|
||||||
import javax.print.attribute.standard.Copies;
|
import javax.print.attribute.standard.Copies;
|
||||||
import javax.print.attribute.standard.JobName;
|
import javax.print.attribute.standard.JobName;
|
||||||
|
|
||||||
|
import org.adempiere.base.Service;
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.adempiere.exceptions.DBException;
|
||||||
|
import org.adempiere.util.IProcessUI;
|
||||||
|
import org.compiere.model.MAttachment;
|
||||||
|
import org.compiere.model.MAttachmentEntry;
|
||||||
|
import org.compiere.model.MProcess;
|
||||||
|
import org.compiere.model.MQuery;
|
||||||
|
import org.compiere.model.MSysConfig;
|
||||||
|
import org.compiere.model.MTable;
|
||||||
|
import org.compiere.model.PrintInfo;
|
||||||
|
import org.compiere.model.X_AD_PInstance_Para;
|
||||||
|
import org.compiere.print.MPrintFormat;
|
||||||
|
import org.compiere.print.PrintUtil;
|
||||||
|
import org.compiere.print.ServerReportCtl;
|
||||||
|
import org.compiere.process.ClientProcess;
|
||||||
|
import org.compiere.process.ProcessCall;
|
||||||
|
import org.compiere.process.ProcessInfo;
|
||||||
|
import org.compiere.process.ProcessInfoParameter;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Ini;
|
||||||
|
import org.compiere.util.Language;
|
||||||
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.Util;
|
||||||
|
import org.compiere.utils.DigestOfFile;
|
||||||
|
|
||||||
import net.sf.jasperreports.engine.DefaultJasperReportsContext;
|
import net.sf.jasperreports.engine.DefaultJasperReportsContext;
|
||||||
import net.sf.jasperreports.engine.JRException;
|
import net.sf.jasperreports.engine.JRException;
|
||||||
import net.sf.jasperreports.engine.JRParameter;
|
import net.sf.jasperreports.engine.JRParameter;
|
||||||
|
@ -87,34 +116,6 @@ import net.sf.jasperreports.export.SimpleWriterExporterOutput;
|
||||||
import net.sf.jasperreports.export.SimpleXlsExporterConfiguration;
|
import net.sf.jasperreports.export.SimpleXlsExporterConfiguration;
|
||||||
import net.sf.jasperreports.export.SimpleXmlExporterOutput;
|
import net.sf.jasperreports.export.SimpleXmlExporterOutput;
|
||||||
|
|
||||||
import org.adempiere.base.Service;
|
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
|
||||||
import org.adempiere.exceptions.DBException;
|
|
||||||
import org.adempiere.util.IProcessUI;
|
|
||||||
import org.compiere.model.MAttachment;
|
|
||||||
import org.compiere.model.MAttachmentEntry;
|
|
||||||
import org.compiere.model.MProcess;
|
|
||||||
import org.compiere.model.MQuery;
|
|
||||||
import org.compiere.model.MSysConfig;
|
|
||||||
import org.compiere.model.MTable;
|
|
||||||
import org.compiere.model.PrintInfo;
|
|
||||||
import org.compiere.model.X_AD_PInstance_Para;
|
|
||||||
import org.compiere.print.MPrintFormat;
|
|
||||||
import org.compiere.print.PrintUtil;
|
|
||||||
import org.compiere.print.ServerReportCtl;
|
|
||||||
import org.compiere.process.ClientProcess;
|
|
||||||
import org.compiere.process.ProcessCall;
|
|
||||||
import org.compiere.process.ProcessInfo;
|
|
||||||
import org.compiere.process.ProcessInfoParameter;
|
|
||||||
import org.compiere.util.CLogger;
|
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
|
||||||
import org.compiere.util.Ini;
|
|
||||||
import org.compiere.util.Language;
|
|
||||||
import org.compiere.util.Trx;
|
|
||||||
import org.compiere.util.Util;
|
|
||||||
import org.compiere.utils.DigestOfFile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author rlemeill
|
* @author rlemeill
|
||||||
* Originally coming from an application note from compiere.co.uk
|
* Originally coming from an application note from compiere.co.uk
|
||||||
|
@ -185,8 +186,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
log.warning("404 not found: Report cannot be found on server "+ e.getMessage());
|
log.warning("404 not found: Report cannot be found on server "+ e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.severe("I/O error when trying to download (sub)report from server "+ e.getMessage());
|
throw new AdempiereException("I/O error when trying to download (sub)report from server "+ e.getLocalizedMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,8 +285,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
log.severe("Unknown exception: "+ e.getMessage());
|
throw new AdempiereException("Unknown exception: "+ e.getLocalizedMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
return reportFile;
|
return reportFile;
|
||||||
}
|
}
|
||||||
|
@ -311,8 +310,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
String hash = new String(baos.toByteArray());
|
String hash = new String(baos.toByteArray());
|
||||||
return hash;
|
return hash;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.severe("I/O error when trying to download (sub)report from server "+ e.getMessage());
|
throw new AdempiereException("I/O error when trying to download (sub)report from server "+ e.getLocalizedMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +377,12 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reportPath = reportData.getReportFilePath();
|
List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
|
||||||
|
String reportFilePath = reportData.getReportFilePath();
|
||||||
|
String[] reportPathList = reportFilePath.split(";");
|
||||||
|
for (int idx = 0; idx < reportPathList.length; idx++) {
|
||||||
|
|
||||||
|
String reportPath = reportPathList[idx];
|
||||||
if (Util.isEmpty(reportPath, true))
|
if (Util.isEmpty(reportPath, true))
|
||||||
{
|
{
|
||||||
reportResult(AD_PInstance_ID, "Can not find report", trxName);
|
reportResult(AD_PInstance_ID, "Can not find report", trxName);
|
||||||
|
@ -702,9 +705,20 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (reportPathList.length == 1) {
|
||||||
if (log.isLoggable(Level.INFO)) log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
|
if (log.isLoggable(Level.INFO)) log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
|
||||||
JRViewerProvider viewerLauncher = Service.locator().locate(JRViewerProvider.class).getService();
|
JRViewerProvider viewerLauncher = Service.locator().locate(JRViewerProvider.class).getService();
|
||||||
viewerLauncher.openViewer(jasperPrint, pi.getTitle());
|
viewerLauncher.openViewer(jasperPrint, pi.getTitle());
|
||||||
|
} else {
|
||||||
|
jasperPrintList.add(jasperPrint);
|
||||||
|
if (idx+1 == reportPathList.length) {
|
||||||
|
JRViewerProviderList viewerLauncher = Service.locator().locate(JRViewerProviderList.class).getService();
|
||||||
|
if (viewerLauncher == null) {
|
||||||
|
throw new AdempiereException("Can not find a viewer provider for multiple jaspers");
|
||||||
|
}
|
||||||
|
viewerLauncher.openViewer(jasperPrintList, pi.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -786,7 +800,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JRException e) {
|
} catch (JRException e) {
|
||||||
log.severe("ReportStarter.startProcess: Can not run report - "+ e.getMessage());
|
throw new AdempiereException(e.getLocalizedMessage() + (e.getCause() != null ? " -> " + e.getCause().getLocalizedMessage() : ""));
|
||||||
} finally {
|
} finally {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -797,6 +811,8 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // for reportPathList
|
||||||
|
|
||||||
if (onrows != null && onrows instanceof Integer) {
|
if (onrows != null && onrows instanceof Integer) {
|
||||||
nrows = (Integer) onrows;
|
nrows = (Integer) onrows;
|
||||||
processInfo.setRowCount(nrows);
|
processInfo.setRowCount(nrows);
|
||||||
|
@ -1275,7 +1291,6 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
// log.severe("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage());
|
|
||||||
throw new DBException(e, sql);
|
throw new DBException(e, sql);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -1373,8 +1388,6 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
throw new DBException(e, sql);
|
throw new DBException(e, sql);
|
||||||
// log.severe("sql = "+sql+"; e.getMessage() = "+ e.getMessage());
|
|
||||||
// return null;
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,5 +3,6 @@
|
||||||
<implementation class="org.adempiere.webui.window.ZkJRViewerProvider"/>
|
<implementation class="org.adempiere.webui.window.ZkJRViewerProvider"/>
|
||||||
<service>
|
<service>
|
||||||
<provide interface="org.adempiere.report.jasper.JRViewerProvider"/>
|
<provide interface="org.adempiere.report.jasper.JRViewerProvider"/>
|
||||||
|
<provide interface="org.adempiere.report.jasper.JRViewerProviderList"/>
|
||||||
</service>
|
</service>
|
||||||
</scr:component>
|
</scr:component>
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
||||||
|
|
||||||
previewType.setMold("select");
|
previewType.setMold("select");
|
||||||
attachment = null; // Added by Martin Augustine - Ntier software Services 09/10/2013
|
attachment = null; // Added by Martin Augustine - Ntier software Services 09/10/2013
|
||||||
if (isCanExport && !isList) {
|
if (isCanExport) {
|
||||||
previewType.appendItem("PDF", "PDF");
|
previewType.appendItem("PDF", "PDF");
|
||||||
previewType.appendItem("HTML", "HTML");
|
previewType.appendItem("HTML", "HTML");
|
||||||
previewType.appendItem("Excel", "XLS");
|
previewType.appendItem("Excel", "XLS");
|
||||||
|
@ -318,7 +318,11 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
||||||
|
|
||||||
} else if ("HTML".equals(reportType)) {
|
} else if ("HTML".equals(reportType)) {
|
||||||
String path = System.getProperty("java.io.tmpdir");
|
String path = System.getProperty("java.io.tmpdir");
|
||||||
String prefix = makePrefix(jasperPrint.getName());
|
String prefix = null;
|
||||||
|
if (isList)
|
||||||
|
prefix = makePrefix(jasperPrintList.get(0).getName())+"_List";
|
||||||
|
else
|
||||||
|
prefix = makePrefix(jasperPrint.getName());
|
||||||
if (log.isLoggable(Level.FINE))
|
if (log.isLoggable(Level.FINE))
|
||||||
{
|
{
|
||||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||||
|
@ -340,7 +344,11 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
||||||
media = new AMedia(m_title, "html", "text/html", file, false);
|
media = new AMedia(m_title, "html", "text/html", file, false);
|
||||||
} else if ("XLS".equals(reportType)) {
|
} else if ("XLS".equals(reportType)) {
|
||||||
String path = System.getProperty("java.io.tmpdir");
|
String path = System.getProperty("java.io.tmpdir");
|
||||||
String prefix = makePrefix(jasperPrint.getName());
|
String prefix = null;
|
||||||
|
if (isList)
|
||||||
|
prefix = makePrefix(jasperPrintList.get(0).getName())+"_List";
|
||||||
|
else
|
||||||
|
prefix = makePrefix(jasperPrint.getName());
|
||||||
if (log.isLoggable(Level.FINE))
|
if (log.isLoggable(Level.FINE))
|
||||||
{
|
{
|
||||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||||
|
@ -365,7 +373,11 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
||||||
|
|
||||||
}else if ("CSV".equals(reportType)) {
|
}else if ("CSV".equals(reportType)) {
|
||||||
String path = System.getProperty("java.io.tmpdir");
|
String path = System.getProperty("java.io.tmpdir");
|
||||||
String prefix = makePrefix(jasperPrint.getName());
|
String prefix = null;
|
||||||
|
if (isList)
|
||||||
|
prefix = makePrefix(jasperPrintList.get(0).getName())+"_List";
|
||||||
|
else
|
||||||
|
prefix = makePrefix(jasperPrint.getName());
|
||||||
if (log.isLoggable(Level.FINE))
|
if (log.isLoggable(Level.FINE))
|
||||||
{
|
{
|
||||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||||
|
@ -385,7 +397,11 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
||||||
|
|
||||||
}else if ("SSV".equals(reportType)) {
|
}else if ("SSV".equals(reportType)) {
|
||||||
String path = System.getProperty("java.io.tmpdir");
|
String path = System.getProperty("java.io.tmpdir");
|
||||||
String prefix = makePrefix(jasperPrint.getName());
|
String prefix = null;
|
||||||
|
if (isList)
|
||||||
|
prefix = makePrefix(jasperPrintList.get(0).getName())+"_List";
|
||||||
|
else
|
||||||
|
prefix = makePrefix(jasperPrint.getName());
|
||||||
if (log.isLoggable(Level.FINE))
|
if (log.isLoggable(Level.FINE))
|
||||||
{
|
{
|
||||||
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
log.log(Level.FINE, "Path="+path + " Prefix="+prefix);
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
package org.adempiere.webui.window;
|
package org.adempiere.webui.window;
|
||||||
|
|
||||||
import net.sf.jasperreports.engine.JRException;
|
|
||||||
import net.sf.jasperreports.engine.JasperPrint;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.adempiere.report.jasper.JRViewerProvider;
|
import org.adempiere.report.jasper.JRViewerProvider;
|
||||||
|
import org.adempiere.report.jasper.JRViewerProviderList;
|
||||||
import org.adempiere.webui.apps.AEnv;
|
import org.adempiere.webui.apps.AEnv;
|
||||||
import org.adempiere.webui.component.Window;
|
import org.adempiere.webui.component.Window;
|
||||||
import org.adempiere.webui.part.WindowContainer;
|
import org.adempiere.webui.part.WindowContainer;
|
||||||
import org.adempiere.webui.session.SessionManager;
|
import org.adempiere.webui.session.SessionManager;
|
||||||
|
|
||||||
public class ZkJRViewerProvider implements JRViewerProvider {
|
import net.sf.jasperreports.engine.JRException;
|
||||||
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
|
||||||
|
public class ZkJRViewerProvider implements JRViewerProvider, JRViewerProviderList {
|
||||||
|
|
||||||
public void openViewer(final JasperPrint jasperPrint, final String title)
|
public void openViewer(final JasperPrint jasperPrint, final String title)
|
||||||
throws JRException {
|
throws JRException {
|
||||||
|
|
Loading…
Reference in New Issue