Reporting from a Naked Objects Application

Mar 2, 2012 at 12:08 PM

I'm interested in different ways people have gone around generating printable and electronic ie excel, pdf, word etc report type output from Naked Objects applications.

I'm currently building a school management application and need functionality to print items such as class rolls, and fees statements.

I'm at a bit of a loss on how to go about this, I've looked at contributed actions or custom controllers and views, but am wondering if it might not be better to create a system service to an outside application for this reporting, either that or have I missed some funtionality inside the Naked Objects framework.

Mar 2, 2012 at 12:49 PM
Hi there.
I had the same requirement last year; needed to get a list of people out of the system as an Excel file.

I only have about 2 to 3 hours to implement the whole thing, so quickest solution I came up with was an Action that emailed the exported Excel file to the currently logged in user.

Works well enough, but I would also like to know how to do it properly. :)
Coordinator
Mar 2, 2012 at 1:04 PM

There is no specific support for either printing or electronic file generation within Naked Objects  - so you will need to roll-your-own somehow.  I would recomend implementing it as a service.  This could either be injected into any object that needed it and the service called programmatically from within the object's methods, or you could create some contributed actions on the service (or on a separate service that delegated to it) -  contributed to interfaces such as IPrintableObject, or IExportableAsCSV.

The service could well delegate much of its responsibility to existing external services.

If you intend to write one, and make it generic in design, why not share it as an open source project, and installable as a NuGet package?

 

Editor
Mar 2, 2012 at 1:24 PM
I'd recommend the same general approach as Richard - write a "technical" domain service, and inject into domain objects.

On the big NO system over in Ireland, there have been several ways of doing this in the 7 or 8 years that this project has been running. The latest incarnation is to use the OpenXmlDocument APIs, ie the APIs that let you programmatically build or "mail-merge" into .docx docs.

I designed a little "OpenXmlDocumentService" service that takes in an XML document such as:

<fields>
<firstname type="plain">Joe</field>
<lastname type="plain">Bloggs</field>
<ssn type="plain">1234567A</ssn>
<createdOn type="date">10-feb-2012</createdOn>
<recentPayments type="table">
<dateOfPayment>9-feb-2012</dateOfPayment>
<amount>123.00</amount>
<dateOfPayment>2-feb-2012</dateOfPayment>
<amount>123.00</amount>
<dateOfPayment>26-jan-2012</dateOfPayment>
<amount>118.00</amount>
<dateOfPayment>19-jan-2012</dateOfPayment>
<amount>118.00</amount>
</recentPayments>
</fields>


The service interprets XML to do a mail merge into relevant fields, with the "type" attribute telling it the strategy to do the mail merge. The result of calling the service is a byte[] array of the .docx.

One other thing: in order to generate the input XML, you could have the domain object just build up the XML by hand, or you might want to use the NO-provided XmlSnapshot class to generate an XML snapshot of the domain object, and the use an XsltService to transform that XML into the input as required by the OpenXmlDocumentService.

Hope that makes some sort of sense. As Richard says, this'd make a nice open source contribution; I'd be happy to collaborate if you want.

Cheers
Dan


On 2 March 2012 12:09, PatInABox <notifications@codeplex.com> wrote:

From: PatInABox

I'm interested in different ways people have gone around generating printable and electronic ie excel, pdf, word etc report type output from Naked Objects applications.

I'm currently building a school management application and need functionality to print items such as class rolls, and fees statements.

I'm at a bit of a loss on how to go about this, I've looked at contributed actions or custom controllers and views, but am wondering if it might not be better to create a system service to an outside application for this reporting, either that or have I missed some funtionality inside the Naked Objects framework.

Read the full discussion online.

To add a post to this discussion, reply to this email (nakedobjects@discussions.codeplex.com)

To start a new discussion for this project, email nakedobjects@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Mar 2, 2012 at 1:49 PM

Just want to point out, Dan, that the XmlSnaphot class that you refer to, and as used at DSP, is not currently part of the public (open source) framework.  The latter only defines the interfaces, IXmlSnapshot and IXmlSnapshotService, which the classes you refer to implement.

We would have no problem making the code from those implementation classes available, open source. The only reason they aren't currently, is that the particular XML format that those classes implement was designed for compatibility with DSP's (SDM 2) implementation and therefore we don't want it accidentally broken.  I think the obvious thing to do is for us simply to clone this code  -  and keep the DSP and the public implementations separate, so that the latter can evolve. I will add a ticket to do that -  in the meantime, I will happily pass on a copy of that code to anyone who wants to play with it.

For the benefit of the other participants in this discussion:  the snapshot service can take any domain object and turn it into an XML representation in a defined format  -  this could then be subequently transformed by some external service for the purpose of printing, or creating another electronic representation such as CSV.  You can easily control the extent to which the snapshot follows associated objects and includes them.

Mar 2, 2012 at 1:52 PM
Sounds interesting. Tnx
Editor
Mar 2, 2012 at 2:06 PM
Ah, I wasn't aware of that. My bad.

But, yes, the XmlSnapshot service has been of use over the years, so it would definitely be nice to see it as open source.

Dan


On 2 March 2012 13:49, richardpawson <notifications@codeplex.com> wrote:

From: richardpawson

Just want to point out, Dan, that the XmlSnaphot class that you refer to, and as used at DSP, is not currently part of the public (open source) framework. The latter only defines the interfaces, IXmlSnapshot and IXmlSnapshotService, which the classes you refer to implement.

We would have no problem making the code from those implementation classes available, open source. The only reason they aren't currently, is that the particular XML format that those classes implement was designed for compatibility with DSP's (SDM 2) implementation and therefore we don't want it accidentally broken. I think the obvious thing to do is for us simply to clone this code - and keep the DSP and the public implementations separate, so that the latter can evolve. I will add a ticket to do that - in the meantime, I will happily pass on a copy of that code to anyone who wants to play with it.

For the benefit of the other participants in this discussion: the snapshot service can take any domain object and turn it into an XML representation in a defined format - this could then be subequently transformed by some external service for the purpose of printing, or creating another electronic representation such as CSV. You can easily control the extent to which the snapshot follows associated objects and includes them.

Read the full discussion online.

To add a post to this discussion, reply to this email (nakedobjects@discussions.codeplex.com)

To start a new discussion for this project, email nakedobjects@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Mar 4, 2012 at 2:55 AM

Thanks guys for pointing in which direction to go.

Looks like I'll try and adapt an excel exporter I created for a previous webforms project to my needs. That just outputs an html table with the mime type set to an excel file, excel has a small complaint that the contents of the file don't match the type, but it opens fine. For Word output I'll keep working on an XML exporter, I'd not thought of using OpenDoc XML and had been trying to export a Word XML file, so I'll have a look at that avenue.

When I get something that works I'm definitely happy to get it up as a package on NuGet.