Quantcast

[ANN] Export plugin 0.7 released

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[ANN] Export plugin 0.7 released

Andreas Schmitt
Hi,

Export plugin 0.7 has been released. This plugin allows you to export
domain objects to CSV, Excel, ODS (Open Document Spreadsheet), RTF,
PDF and XML and can be extended to support additional formats.

Version 0.7 contains multiple bug fixes, enhanced formatter closures,
new parameters for PDF, RTF and XML export
and support for asian characters.

All formatter closures now take two arguments and offer access to the
domain object, e.g. to combine two attributes.
Existing formatter closures must be changed by adding the additional argument.

Previous versions

def date = { value ->
  if(value instanceof Date){
    return new java.text.SimpleDateFormat("dd.MM.yyyy").format(value)
   }
                       
   return value
}

Version 0.7

def date = { domain, value ->
  if(value instanceof Date){
    return new java.text.SimpleDateFormat("dd.MM.yyyy").format(value)
   }
                       
   return value
}

- PDF
        - font.family (global font family setting)
        - title.encoding (encoding for title font)
        - header.encoding (encoding for header font)
        - text.encoding (encoding for text font)
        - pdf.encoding (global font encoding)
        - column.widths (allows to set different column widths)
- RTF
        - font.family (global font family setting)
        - title.encoding (encoding for title font)
        - header.encoding (encoding for header font)
        - text.encoding (encoding for text font)
        - rtf.encoding (global font encoding)
        - column.widths (allows to set different column widths)
- XML
        - xml.root (specify root element name)
        - depth (depth for building tree affects how collections and
relationships are exported)

I would like to thank everybody for reporting bugs or suggesting improvements.

For further information check out http://www.grails.org/plugin/export

Best regards,
Andreas

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

inabramova
Hi,

Thank you for your plugin, it's been great!

I have few suggestions and I am wondering whether these features will be available to the plugin users soon..

I am currently using the plugin to export a domain class with many nested associations.. For example, I have a list of locations  associated with an object. I would very much like to be able to export a singe location, email or website into it's own cell. But right now I am limited to stuffing all the associated object into one cell (list of locations, list of emails etc.. ) Are you planning to implement a solution to that?

Thanks for reading!

Irina
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

Andreas Schmitt

Hi Irina,

sorry for the delay. Do you mean wether nested associations e.g. "locations.name" can be used as fields for export or
individual tables for asscociations? The former is already implemented, that means you can specify "locations.name"
for example as field. I need to update the documentation concerning this feature.

Best regards,
Andreas

2010/6/29 inabramova <[hidden email]>:
>
> Hi,
>
> Thank you for your plugin, it's been great!
>
> I have few suggestions and I am wondering whether these features will be
> available to the plugin users soon..
>
> I am currently using the plugin to export a domain class with many nested
> associations.. For example, I have a list of locations  associated with an
> object. I would very much like to be able to export a singe location, email
> or website into it's own cell. But right now I am limited to stuffing all
> the associated object into one cell (list of locations, list of emails etc..
> ) Are you planning to implement a solution to that?
>
> Thanks for reading!
>
> Irina
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Export-plugin-0-7-released-tp1835347p2272635.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

inabramova
Hi Andreas!

My original question was about having a list of objects and trying to export every associated object into it's own cell.
for example, I have an object with multiple locations, so I wanted to have a resulting table look like the following: (in my domain class I specified list of locations as "hasMany = [ locations : Location ] "

Name | Location 1 | Location 2 | Location 3 .. etc
-------------------------------------------------
        |                |                |                

I realized that using my list of domain objects I could create a new list of map objects where each location would be mapped to it's own key (location1, location2, location3..) That's what I did, and used my newly obtained map for exporting. (Worked out very nice!)

Thanks for your reply, it's also nice to know that if I needed specific fields from my associations, I can just specify them right away instead of passing a formatter closure asking for those few fields.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

msloan
This post has NOT been accepted by the mailing list yet.
inabramova wrote
             

I realized that using my list of domain objects I could create a new list of map objects where each location would be mapped to it's own key (location1, location2, location3..) That's what I did, and used my newly obtained map for exporting. (Worked out very nice!)
Hi Irina,

I just started using the export plugin and have a similar use case to your locations.  Any chance you can post up some code for the new map used for exporting?

Thanks!

Matt
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

inabramova
Hi Matt. This is the approximate code I used..

def resultListWithExtraColumns = []
                 
def maxLocationIndex=0;
                 
resultList.each{it->
          def expanded_record = ["name": it.name]
          it?.locations.eachWithIndex{location, index->
                  expanded_record["location${index+1}"]=location
                  if ((index+1) > maxLocationIndex)
                          maxLocationIndex = index+1
          }  
resultListWithExtraColumns.add(expanded_record)
}
 
if (maxLocationIndex > 0){    
  for (i in 1..maxLocationIndex){
          def location_field = "location${i}"
                  fields.add(location_field)
                  labels[(location_field)]= "Location ${i}"
                  formatters[(location_field)] = locationFormatter
          }
  }
 
  //pass in the new list instead to the exportService
  resultList = resultListWithExtraColumns
         
exportService.export(params.format, outputStream, resultList, fields, labels, formatters, [:])
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] Export plugin 0.7 released

msloan
This post has NOT been accepted by the mailing list yet.
Irina - thanks for the sample code!  

I went ahead and took the code Irina provided and made it a little more flexible and figured I'd post up incase anyone esle could use it.

here's the controller

def expandedRecord = [:];
                        def fields = [];
                        def labels = [:];
                       
                        def processRecord;
                        def buildExpandList;
                        def checkChildren;
                       
                        //add the fields and lables from the domain class
                        processRecord = { Object rec ->
                                println "Process Record " + rec
                                if(!fields.containsAll(rec.fields)) {
                                        fields.addAll(rec.fields);
                                }
                                if(!labels.keySet().containsAll(rec.labels.keySet())) {
                                        labels.putAll(rec.labels);
                                }
                        }
                        //add the domain class specified fields to the new list
                        buildExpandList = { Object rec ->
                                println "Build Expand List " + rec
                                rec.properties.each{property ->
                                        if(fields.contains(property.key as String)) {
                                                expandedRecord[(property.key as String)] = property.value as String;
                                        }
                                }
                                expandedList.add(expandedRecord);
                                expandedRecord = [:] //reset
                        }
                        //closure to see if domain object hasMany
                        checkChildren = { Object rec ->
                                println "Check Children" + rec
                                try {
                                        def map = rec.getProperty("hasMany")
                                        if(map != null) {
                                                def keySet = map.keySet();
                                                keySet.each{key ->
                                                        def objs = rec.getProperty(key)
                                                        objs.each{obj ->
                                                                processRecord(obj)
                                                                buildExpandList(obj);
                                                                checkChildren(obj);
                                                        }
                                                }
                                        }
                                } catch (groovy.lang.MissingPropertyException mpe) {
                                        //do nothing, property doesn't exist
                                        println mpe
                                }
                        }
                       
                       
                       
                        def resultList = Person.list();
                        resultList.each {rec ->
                                println "Result List " + rec
                                expandedRecord = [:] //reset
                                processRecord(rec);
                                buildExpandList(rec);
                                checkChildren(rec);
                        }
                       
                        exportService.export(params.format, response.outputStream, expandedList, fields, labels, [:], [:])

Then, in my domain classes, I defined 2 static variables - fields and labels:

        def labels = ["name":"Address Name", "street":"Address Street", "city":"City", "state":"State", "zip":"Zip"]
        def fields = ["name", "street", "city", "state", "zip"]

What this allows for is any domain object (and it's children and their children and so on) to be broken out and exported in the desired format (I only tested this code with excel as that is what my need is).  Couple of points - the list of labels and fields must be uinque - next I'll work on making that part a little more flexible.

Anyways, hope this helps!

Matt
Loading...