March 9, 2006
Using Jasper Reports with Hibernate and Teamwork
Jasper Reports is the perfect open source reporting tool for the masses, heres a code snippet to generate the "Operator by Worklog" sample report using Jasper Report in Teamwork 3
CompanyCalendar cc = new CompanyCalendar();
cc.set(CompanyCalendar.YEAR, cc.get(CompanyCalendar.YEAR) – 1);
cc.set(CompanyCalendar.MONTH, CompanyCalendar.JANUARY);
cc.set(CompanyCalendar.DAY_OF_MONTH, 1);
OqlQuery oql = new OqlQuery(“select new map(r.id as id, r.personName as personName , r.personSurname as personSurname, sum(w.duration) as worklog_total) from com.twproject.resource.Resource r, com.twproject.worklog.Worklog w where w.assig = r.myself and w.inserted > :paramInserted and r.myself is not null group by r.id”);
oql.setParameter(“paramInserted”,cc.getTime());
List persLog = oql.list();
Map parameters = new HashMap();
InputStream reportStream = new FileInputStream(
request.getRealPath(“applications/teamwork/reports/jrxml/new_worklog.jrxml”));
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(persLog);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);
//—- Export PDF —-
JasperManager.printReportToPdfFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.pdf”);
//—- Export HTML —-
JasperExportManager.exportReportToHtmlFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.html”);
cc.set(CompanyCalendar.YEAR, cc.get(CompanyCalendar.YEAR) – 1);
cc.set(CompanyCalendar.MONTH, CompanyCalendar.JANUARY);
cc.set(CompanyCalendar.DAY_OF_MONTH, 1);
OqlQuery oql = new OqlQuery(“select new map(r.id as id, r.personName as personName , r.personSurname as personSurname, sum(w.duration) as worklog_total) from com.twproject.resource.Resource r, com.twproject.worklog.Worklog w where w.assig = r.myself and w.inserted > :paramInserted and r.myself is not null group by r.id”);
oql.setParameter(“paramInserted”,cc.getTime());
List persLog = oql.list();
Map parameters = new HashMap();
InputStream reportStream = new FileInputStream(
request.getRealPath(“applications/teamwork/reports/jrxml/new_worklog.jrxml”));
JasperDesign jasperDesign = JasperManager.loadXmlDesign(reportStream);
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(persLog);
JasperPrint jasperPrint = JasperManager.fillReport(jasperReport, parameters, ds);
//—- Export PDF —-
JasperManager.printReportToPdfFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.pdf”);
//—- Export HTML —-
JasperExportManager.exportReportToHtmlFile(jasperPrint, request.getRealPath(“”) + “/applications/teamwork/reports/output/report.html”);
Comments(2)

Hi,
we’ve seen your nice post on “Using Jasper Reports with Hibernate and Teamwork” . Could you be interested in producing a set of such reports ? We could give you a free license in exchange; we would of course provide you with all support and needed sources. Would that be of interest to you ?
Thanks and best regards,
Pietro Polsinelli
Teamwork Development Director
can u specify a few more links where oql’s are used with jasper reports???
can multiple oql’s be used with jasper??