Insert pdf report in Sonar DB

8 messages Options
Embed this post
Permalink
Antonio Manuel Muñiz () Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
Hello.

I'm working now for insert pdf report in Sonar DB and serve it through the UI.
I have do the first step: insert pdf (base64 encoded) in DB as blob. I'm using executeOn method available in PostJob for the insert:

Measure measure = new Measure(ReportDataMetric.PDF_DATA);
byte[] encoded = Base64.encodeBase64(loadFile(pdf));
String data = new String(encoded);
measure.setData(data);
context.saveMeasure(measure);

I don´t know if this is the best way to do it, this code involves storing all data in memory (as String) and store it as a measure.
Is there another approach?

Thanks,
Antonio.

--
* Antonio Manuel Muñiz
* amunizmartin.wordpress.com
* [hidden email]
Simon Brandhof () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
To avoid the measure to be kept in memory, add the following before executing the method saveMeasure() :
measure.setPersistenceMode(PersistenceMode.DATABASE);

The current version of the API does not allow to inject/load binary measures. Like you suggested, the workaround is :
  • encode data in base64
  • develop a web service which directly returns data, with correct HTTP headers (mime type). Use the new extension point RubyRailsWebservice of API 1.11. Some examples are available in the plugins radiator and motionchart.
But the best solution is to improve the API (see issue SONAR-1174), at least the missing method setData(byte[] data, String mime). Unfortunatly I can't give any release planning.

Simon
Antonio Manuel Muñiz () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
Ok Simon.

Thanks for this info.

Antonio.

2009/9/30 Simon Brandhof <[hidden email]>
To avoid the measure to be kept in memory, add the following before executing the method saveMeasure() :
measure.setPersistenceMode(PersistenceMode.DATABASE);

The current version of the API does not allow to inject/load binary measures. Like you suggested, the workaround is :
  • encode data in base64
  • develop a web service which directly returns data, with correct HTTP headers (mime type). Use the new extension point RubyRailsWebservice of API 1.11. Some examples are available in the plugins radiator and motionchart.
But the best solution is to improve the API (see issue SONAR-1174), at least the missing method setData(byte[] data, String mime). Unfortunatly I can't give any release planning.

Simon



--
* Antonio Manuel Muñiz
* amunizmartin.wordpress.com
* [hidden email]
Antonio Manuel Muñiz () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
In reply to this post by Simon Brandhof
Hello Simon,

I need some help to retrieve the saved pdf from database. This is my Ruby web service:

class Api::PdfreportController < ApplicationController
  def hola
    send_data(get_pdf_data(), :filename => "sonar-report.pdf", :type => "text/pdf")
  end
end

Could you guide me on implementing get_pdf_data function?

Thanks,
Antonio.

2009/9/30 Simon Brandhof <[hidden email]>
To avoid the measure to be kept in memory, add the following before executing the method saveMeasure() :
measure.setPersistenceMode(PersistenceMode.DATABASE);

The current version of the API does not allow to inject/load binary measures. Like you suggested, the workaround is :
  • encode data in base64
  • develop a web service which directly returns data, with correct HTTP headers (mime type). Use the new extension point RubyRailsWebservice of API 1.11. Some examples are available in the plugins radiator and motionchart.
But the best solution is to improve the API (see issue SONAR-1174), at least the missing method setData(byte[] data, String mime). Unfortunatly I can't give any release planning.

Simon



--
* Antonio Manuel Muñiz
* amunizmartin.wordpress.com
* [hidden email]
Simon Brandhof () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
Hi Antonio,
Is your file encoded in base64 ?
Antonio Manuel Muñiz () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
Hi Simon,
Yes, is it.

2009/11/5 Simon Brandhof <[hidden email]>
Hi Antonio,
Is your file encoded in base64 ?



--
* Antonio Manuel Muñiz
* amunizmartin.wordpress.com
* [hidden email]
Simon Brandhof () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
You can try something like :

require "base64"
class Api::PdfreportController < ApplicationController
  def hola
    project=Project.by_key(params[:resource])
    measure=project.last_snapshot.measure('pdfreport')
    send_data(Base64.decode64(measure.data), :filename => "sonar-report.pdf", :type => "text/pdf")
  end
end

The HTTP parameter 'resource' is the id or key of the project. Note that I did not test this code !
Antonio Manuel Muñiz () Re: Insert pdf report in Sonar DB
Reply Threaded More More options
Print post
Permalink
Ok Simon, I will give a try to your code.

Thanks!

2009/11/5 Simon Brandhof <[hidden email]>
You can try something like :

require "base64"

class Api::PdfreportController < ApplicationController
  def hola
    project=Project.by_key(params[:resource])
    measure=project.last_snapshot.measure('pdfreport')
    send_data(Base64.decode64(measure.data), :filename => "sonar-report.pdf", :type => "text/pdf")
  end
end

The HTTP parameter 'resource' is the id or key of the project. Note that I did not test this code !



--
* Antonio Manuel Muñiz
* amunizmartin.wordpress.com
* [hidden email]