JasperReports Gem for Hobo

62 views
Skip to first unread message

Bob Sleys

unread,
Jan 11, 2012, 11:13:49 AM1/11/12
to hobo...@googlegroups.com
I needed reporting for a Hobo app I was working on and after reading over http://oldwiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports I was able to get JasperReports working with Hobo.  I needed to update a few things for the current versions and then Hoboize it all to make it work with Hobo.  I then decided to turn it all into a Gem to make it easier to add to my next project.  I still need to add a lot of documentation and do more testing but if you'd like to give it a try you can get it from the below link.


Bob

Daniel M

unread,
Jan 12, 2012, 5:54:23 PM1/12/12
to Hobo Users
Great news.
Thank you for your time and attention.

On Jan 11, 4:13 pm, Bob Sleys <bsl...@gmail.com> wrote:
> I needed reporting for a Hobo app I was working on and after reading
> overhttp://oldwiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports

Owen Dall

unread,
Jan 13, 2012, 9:20:55 AM1/13/12
to hobo...@googlegroups.com
Very nice, Bob!


Bob

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/hobousers/-/3q6qKaVvNOoJ.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.



--
-Owen
 
Owen Dall, Chief Systems Architect
Barquin International

Bob Sleys

unread,
Jan 13, 2012, 3:49:42 PM1/13/12
to hobo...@googlegroups.com
Perhaps you guys can help me out on something to do with this.

I'd like to allow the end user to adjust the where clause and includes to the query.  The where clause is simple unless they want to filter on sub tables.  Thats where the includes clause comes into play.

Say we have 3 modles all associated in one-many relationship.  IE

Model1
  has_many :model2
end

Model2
  belongs_to :model1
  has_many :model3
end

Model3
  belongs_to :model2
end

I know in code I can do the following

Model1.find(:all, :where => "model3.name = 'test'", :includes => [:model2, {:model2 => :model3}]

The where clause is a string so allowing the use to specify this for a report and save it to the db is easy.  I can use the following in my report controller to put it to use.

      query = Kernel.const_get(@report.modelname).scoped
      query = query.where(@report.whereclause) if !@report.whereclause.blank?
      @robj = query.all

The problem is the includes.  Since it uses symbols, hashes etc. I can't figure out how to pass a string the user enters that is stored in the db to the :includes clause.

If I only include model2 (ie a direct relationship) I can use a simple string with the relationship name but anything further I can't get to work.

Bob

kevinpfromnm

unread,
Jan 13, 2012, 4:57:02 PM1/13/12
to hobo...@googlegroups.com
the simple way is to use an eval or the like, but it's terrible security wise.  There may be a way to sanitize input so it can only create a hash but uncertain if there's an easy way for it.

Probably would be better to have a serialized hash for includes and a custom form that lets you build it.

Bob Sleys

unread,
Jan 13, 2012, 5:58:24 PM1/13/12
to hobo...@googlegroups.com
I'm not too concerned with security since it only on the admin sub site that can enter it.

Thanks for the tips

Bob

Bob Sleys

unread,
Jan 13, 2012, 6:44:55 PM1/13/12
to hobo...@googlegroups.com
what about using a text filed instead of a string field and using Yaml to load it into a hash and pass off to the include?

Would that be a bit more secure since I doesn't use an eval?

It still allows the end user some direct input into the sql but I'm already allowing that with the where clause part anyway.

This is only meant to be used by an administrator and not the average user so I'm ok with some risks.

Bob

Bob Sleys

unread,
Jan 14, 2012, 12:08:48 AM1/14/12
to hobo...@googlegroups.com
Well the YAML method works with one oddity.  If I don't also have a where clause on the last table I get an error undefined method `name' for nil:NilClass.

Say for example if I have the following YAML

buildings:
   floors:
      spaces:
         locations:
            location_materials: material

It converts to the following Hash
{"buildings"=>{"floors"=>{"spaces"=>{"locations"=>{"location_materials"=>"material"}}}}}

Which only works if I also include a .where("materials.name like '%'") without the where clause I get the above error.

Bob

Bob Sleys

unread,
Jan 14, 2012, 1:23:46 PM1/14/12
to hobo...@googlegroups.com
Ok first off I solved the problem with the error message.

Second I came to the conclusion that reports are generally going to require eager loading of the relationships or you are going to end up with hundreds or thousands of queries being run to generate a single report.  To encourage eager loading for all reports I've moved the includes to a hash right in the reports model.  This takes it out of the end users responsibility and puts it back on the developer to setup when designing the xml data source.

Bob

Bob Sleys

unread,
Jan 14, 2012, 3:31:02 PM1/14/12
to hobo...@googlegroups.com
Ok I've pushed this to 1.0.0.  It's working fine for me in multiple projects.  I've also added some documentation to the wiki at github.  If you have any problems with this please let me know.

Bob

jhstephenson

unread,
May 1, 2012, 4:04:51 PM5/1/12
to hobo...@googlegroups.com
Bob,

I am just getting started with this hobo stuff and ran across your addition to it. I am a little confused though about a couple of fields on the report create screen. There are 3 fields named: Jasperreport file name, Jasperreport content type, and Jasperreport file size. But, there isn't any documentation on what goes in them. Do you have some additional documentation for them?

Also, for starters I am just trying to do a simple list from one of my models. It only has a Category name and Description in it. Do you have any simple examples of how to set something like that up?

Thanks,
Jim

Bob Sleys

unread,
May 4, 2012, 9:16:39 AM5/4/12
to hobo...@googlegroups.com
The jasperreport fields are used by the paperclip gem, see the requirements.  You should never see those fields on the report form, they get used by the paperclip_with_hobo gem. In a nutshell they are for uploading your reports.

Did you look over the wiki pages on Githup?  https://github.com/bsleys/hobo-jasper-reports/wiki 

For a simple single model report you can skip the  REPORT_INCLUDES part as it's only needed to eager load models that are included via relationships, ie parent->child stuff.

It also helps to review the work I used to develop the gem.   http://oldwiki.rubyonrails.org/rails/pages/HowtoIntegrateJasperReports he explains a lot in there.  I just wrapped up most of what he said into a gem for hobo but you can learn a lot about whats going on by reading that over.

Bob
Reply all
Reply to author
Forward
0 new messages