Iteration iteration = (Iteration)object;
try {
ds = new IterationDataSource(iteration, session);
} catch (HibernateException he) {
throw new ExportException(he);
}
reportStream = PdfReportExporter.class.getClassLoader().getResourceAsStream("org/nxplanner/export/reports/JRIteration.jasper");
parameters.put("IterationName", iteration.getName());
parameters.put("IterationStartDate", iteration.getStartDate());
parameters.put("IterationEndDate", iteration.getEndDate());
} else if (object instanceof UserStory) {
UserStory story = (UserStory)object;
try {
ds = new UserStoryDataSource(story, session);
} catch (HibernateException he) {
throw new ExportException(he);
}
reportStream = PdfReportExporter.class.getClassLoader().getResourceAsStream("org/nxplanner/export/reports/JRStory.jasper");
parameters.put("StoryName", story.getName());
Person cust = story.getCustomer(); parameters.put("StoryCustomerName", (cust != null) ? cust.getName() : null);
parameters.put("StoryEstimatedHours", new java.lang.Double(story.getEstimatedHours()));
parameters.put("StoryDescription", story.getDescription());
} else if (object instanceof Task) {
Task task = (Task)object;
try {
ds = new TaskDataSource(task, session);
} catch (HibernateException he) {
throw new ExportException(he);
}
reportStream = PdfReportExporter.class.getClassLoader().getResourceAsStream("org/nxplanner/export/reports/JRTask.jasper");
parameters.put("TaskName", task.getName());
parameters.put("TaskDescription", task.getDescription());
double actual = task.getActualHours();
parameters.put("TaskPercentage", new java.lang.Integer((int)((actual * 100) / (actual + task.getRemainingHours()))));
parameters.put("TaskDisposition", task.getDisposition());
parameters.put("TaskType", task.getType());
parameters.put("TaskAcceptor", getPersonName(session, new Integer(task.getAcceptorId())));
parameters.put("TaskEstimate", new java.lang.Double(task.getEstimatedHours()));
parameters.put("TaskCompleted", new java.lang.Boolean(task.isCompleted()));
} else if (object instanceof Person) {
Person person = (Person)object;
try {
ds = new PersonDataSource(person, session);
} catch (HibernateException he) {
throw new ExportException(he);
}
reportStream = PdfReportExporter.class.getClassLoader().getResourceAsStream("org/nxplanner/export/reports/JRPerson.jasper");
parameters.put("PersonName", person.getName());
}
if (ds == null) {
throw new ExportException("Could not instantiate data source");
}
if (reportStream == null) {
throw new ExportException("Could not open compiled report");
}
try {
JasperReport report = JasperManager.loadReport(reportStream);
return JasperManager.runReportToPdf(report, parameters, ds);
} catch (JRException jre) {
throw new ExportException(jre);
}
}