On Aug 13, 2012, at 10:34 AM, Theodore Petrosky <[email protected]> wrote:
> Kieran, > > would you like to add this to the Jasper framework? Add what? > the only 'change' I had to make was from your comment: > > this.theObjectGID = theObject.globalID() // or use > theObject.editingContext().globalIDForObject( theObject ); > > I had to use: theObject.editingContext().globalIDForObject( theObject ); > > or it complained. > > Ted > > --- On Mon, 8/13/12, Kieran Kelleher <[email protected]> wrote: > >> From: Kieran Kelleher <[email protected]> >> Subject: Re: jasperreports framework >> To: "Theodore Petrosky" <[email protected]> >> Cc: [email protected] >> Date: Monday, August 13, 2012, 8:24 AM >> I made a few tweaks >> to your code in bold font below - hope those come through - >> otherwise just compare to your original code. In case you >> find a typo, this is OTOH without code-completion >> ..... >> HTH, Kieran >> PS. Look at the BackgroundTasks presentation from >> WOWODC and you will see the pattern of EO handling below >> explained there and will also see how to use a different OSC >> for your background task. >> On Aug 11, 2012, at 10:03 AM, Theodore Petrosky >> <[email protected]> >> wrote: >> >> 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) { >> >> 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(checklist, >> 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 EOGlobalID theObjectGID; >> // Use threadsafe global IDs for background >> task ivars >> >> // 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; >> // grab the >> global ID in the constructor. The constructor executes in >> the thread that creates the task instance >> >> this.theObjectGID = >> theObject.globalID() // or use >> theObject.editingContext().globalIDForObject( theObject >> ); >> >> ERXAssert.PRE.notNull(theObjectGID); // If >> the object is new, this will be null. test and >> throw. >> 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()); >> EOEditingContext ec = >> ERXEC.newEditingContext(); >> ec.lock(); >> >> try { >> >> EOEnterpriseObject theObject = ec.faultForGlobalID( >> theObjectGID, ec); >> >> 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 protected]) >> Help/Unsubscribe/Update your Subscription: >> https://lists.apple.com/mailman/options/webobjects-dev/kelleherk%40gmail.com >> >> This email sent to [email protected] >> _______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [email protected]
