Home
Analytics
Automatically create daily reports by using a Java Application
Jochen
Hi everbody,
I posted this in the Eclipse Community Forums: BIRT last friday but no one answered so far.
Therefore I will post it here aswell.
Currently I am using the Birt Designer to manually create daily reports out of .csv Flat Files. Therefore I change the Flat-File name in the Query of the Data Set which can be found in the Properties of the Data Set. I cannot change the Flat-File name in the "Edit Data Set"-Window at the tab "Select Columns", because Birt will delete all existing columns from the old file but I want to keep these columns due to their name change and further use in the report.
My aim is to automatically create daily reports by using a Java Application that initiates that process. The short graphic of how the process should look is available in the file attachments.
Is there a possibility in Java to automatically change the Flat-File name in the Query and save the new report with a report name that includes the date used in the Flat-File name (or the current date)?
Or is there another solution?
Thank you,
Jochen
Find more posts tagged with
Comments
mwilliams
Hi Jochen,
So, you're going to have the same columns and the same report, but you just want it to call a different CSV file? And for saving the report, are you talking about the ran report or about the design using the new file?
Jochen
Thank you for your reply.<br />
<br />
Exactly, I just want to call a different CSV File and save the design using the new file.<br />
<br />
Jason Weathersby attached code on the eclipse.org forums. I used it and changed the defaults but Iam getting an Exception.<br />
Link to the topic: <a class='bbc_url' href='
http://www.eclipse.org/forums/index.php/m/671904/#msg_671904'>http://www.eclipse.org/forums/index.php/m/671904/#msg_671904</a><br
/>
<br />
<blockquote class='ipsBlockquote' ><p>You can change the csv file with a little de api. take a look at the<br />
attached.<br />
<br />
Jason<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import com.ibm.icu.util.ULocale;
public class ChangeFlatFile {
public void runReport() throws EngineException
{
IDesignEngine dengine=null;
try{
DesignConfig dconfig = new DesignConfig( );
dconfig.setBIRTHome("C:/birt/birt-runtime-2_6_1/birt-runtime-2_6_1/ReportEngine ");
Platform.startup( dconfig );
IDesignEngineFactory dfactory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
dengine = dfactory.createDesignEngine( dconfig );
IReportRunnable design = null;
//Open the report design
SessionHandle session = dengine.newSessionHandle( ULocale.ENGLISH );
ReportDesignHandle report =
session.openDesign("Reports/FlatFile.rptdesign");
DataSetHandle dsh = report.findDataSet("Data Set");
String currentquery = (String) dsh.getProperty("queryText");
currentquery.replaceFirst("chart1.csv", "chart2.csv");
report.saveAs("output/desample/FlatFile2.rptdesign" );
report.close( );
session.closeAll(false);
Platform.shutdown();
System.out.println("Finished");
}catch( Exception ex){
ex.printStackTrace();
}
}
/**
*
@param
args
*/
public static void main(String[] args) {
try
{
ChangeFlatFile ex = new ChangeFlatFile( );
ex.runReport();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}</pre></p></blockquote>
<br />
My reply to his post:<br />
<br />
<blockquote class='ipsBlockquote' ><p>
Thank you, Jason.<br />
<br />
I used the attached and changed the directory, rptdesgin name, data set name and source-flat-file names.<br />
In debug mode, everything is working fine (queryText is changed correctly) until the report.saveAs("..") line.<br />
<br />
I get the following Exception:<br />
<br />
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64<br />
at org.eclipse.birt.report.model.writer.ModuleWriterImpl.<clinit>(ModuleWriterImpl.java:241)<br />
at org.eclipse.birt.report.model.elements.ReportDesign.getWriter(ReportDesign.java:90)<br />
at org.eclipse.birt.report.model.api.ModuleHandle.save(ModuleHandle.java:1440)<br />
at org.eclipse.birt.report.model.api.ModuleHandle.saveAs(ModuleHandle.java:1460)<br />
at testsection.ChangeFlatFile.runReport(ChangeFlatFile.java:48)<br />
at testsection.ChangeFlatFile.main(ChangeFlatFile.java:64)<br />
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64<br />
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)<br />
at java.security.AccessController.doPrivileged(Native Method)<br />
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)<br />
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)<br />
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)<br />
... 6 more<br />
<br />
Any idea how to solve this?<br />
<br />
Best regards,<br />
Jochen<br /></p></blockquote>
<br />
Do you have any idea how to solve the Exception.<br />
<br />
Or maybe another solution for my request?<br />
<br />
Best regards,<br />
Jochen
Jochen
Problem and request solved.
Forgot to add all .jars to my classpath.
Topic can be closed.
Best regards,
Jochen
mwilliams
I was gonna say. The error looks to be that your java files are either not deployed or not in the classpath. Glad you found it! Good luck. Let us know whenever you have questions!