jasperreports framework
jasperreports framework
- Subject: jasperreports framework
- From: Theodore Petrosky <email@hidden>
- Date: Sat, 11 Aug 2012 07:03:50 -0700 (PDT)
I was playing around with Kieran's framework and I wanted to create a JasperReport from an EO. So, I created a new class that creates a 'reportTask' from an EO.
This is the first time I am attempting to alter for add to a someone else's framework. Could you look this over? The only caveat that I can find is that I must create a local instance in a new EC of the EO before passing it into the class. I think Kieran mentions that in his comments in: ERJRFetchSpecificationReportTask.
I am calling it with:
public static Callable<File> createMeetingCheckListReportTaskFromEO(MeetingChecklist checklist) {
/*
* let's create a localinstance so we are clear of any other
* connections to theEO
* if we don't the process gets hung up and will not complete
*/
EOEditingContext ec = ERXEC.newEditingContext();
MeetingChecklist theSafeObject = checklist.localInstanceIn(ec);
String reportDescription = "Printed Meeting Checklist";
HashMap<String, Object> parameters = new HashMap<String, Object>();
parameters.put("reportDescription", reportDescription);
parameters.put("userName", "User From session");
ERJRReportTaskFromEO reportTask = new ERJRReportTaskFromEO(theSafeObject, jasperMCLCompiledReportFileName, parameters);
return reportTask;
}
it works, but should the creation of the new editing context be in the class ERJasperReportTaskFromEO?
here is my new class:
package er.jasperreports;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import org.apache.commons.lang.exception.NestableRuntimeException;
import org.apache.log4j.Logger;
import er.jasperreports.ERJRFoundationDataSource;
import er.jasperreports.ERJRUtilities;
import com.webobjects.eoaccess.EOEntity;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.eocontrol.EOFetchSpecification;
import com.webobjects.eocontrol.EOQualifier;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSLog;
import er.extensions.appserver.ERXApplication;
import er.extensions.concurrency.ERXTaskPercentComplete;
import er.extensions.eof.ERXEC;
import er.extensions.eof.ERXEOAccessUtilities;
import er.extensions.foundation.ERXAssert;
/**
* A background task class that creates a JasperReports report in the context
* of a WebObjects application. Sensible defaults are used. It creates the JasperReport
* after passing in a EO.
*
* @author Ted P
*
*/
public class ERJRReportTaskFromEO implements Callable<File>, ERXTaskPercentComplete {
private static final Logger log = Logger.getLogger(ERJRReportTaskFromEO.class);
private File reportFile;
private final String frameworkName;
private final String jasperCompiledReportFileName;
private Map<String, Object> parameters;
private EOEnterpriseObject theObject;
// iVar so we can get percentage complete
private ERJRFoundationDataSource jrDataSource;
public ERJRReportTaskFromEO(EOEnterpriseObject theObject, String jasperCompiledReportFileName) {
this(theObject, jasperCompiledReportFileName, null, null);
}
public ERJRReportTaskFromEO(EOEnterpriseObject theObject, String jasperCompiledReportFileName, HashMap<String, Object> parameters) {
this(theObject, jasperCompiledReportFileName, null, parameters);
}
public ERJRReportTaskFromEO(EOEnterpriseObject theObject, String jasperCompiledReportFileName, String frameworkName, HashMap<String, Object> parameters) {
ERXAssert.PRE.notNull(theObject);
ERXAssert.PRE.notNull(jasperCompiledReportFileName);
this.jasperCompiledReportFileName = jasperCompiledReportFileName;
this.frameworkName = frameworkName;
this.parameters = parameters;
this.theObject = theObject;
if (this.parameters == null) {
this.parameters = new HashMap<String, Object>();
}
}
/**
* Callable interface implementation
*
* @throws Exception
*/
public File call() throws Exception {
ERXApplication._startRequest();
try {
return _call();
} catch (Exception e) {
log.error("Error in JR task", e);
throw e;
} finally {
// Unlocks any locked editing contexts
ERXApplication._endRequest();
}
}
private File _call() {
// If development
if (ERXApplication.isDevelopmentModeSafe()) {
parameters.put("_isDevelopmentMode", Boolean.TRUE);
} else {
parameters.put("_isDevelopmentMode", Boolean.FALSE );
}
reportFile = null;
if (log.isDebugEnabled())
log.debug("Starting JasperReportTask: " + this.toString());
try {
jrDataSource = new ERJRFoundationDataSource(new NSArray<EOEnterpriseObject>(theObject));
if (jasperCompiledReportFileName != null) {
reportFile = ERJRUtilities.runCompiledReportToPDFFile(jasperCompiledReportFileName, frameworkName, parameters, jrDataSource);
}
} catch (Exception e) {
throw new NestableRuntimeException(e);
} finally {
// ec.unlock();
}
return reportFile;
}
public File file() {
return reportFile;
}
/* (non-Javadoc)
* @see wk.foundation.concurrent.TaskPercentComplete#percentComplete()
*
* Some whacky logic just so the user can be comfortable that we are making some progress.
*/
public Double percentComplete() {
if (jrDataSource == null) {
return Double.valueOf(0.1);
} else {
double percent = 0.1 + jrDataSource.percentProcessed() * 0.8;
return Double.valueOf(percent);
}
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden