summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-03-03 18:37:37 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2010-03-03 18:37:37 +0100
commite93ada015dbe91cff5b72eb8628c4f52814e3bdb (patch)
tree43c91ee73c2fe5a814cb3e1f02dbcc0c3b0fc50c
parentb7efeaaf79233de8bbc173fa426e4561c458d44f (diff)
added css formating for reports
-rw-r--r--EXAMPLES17
-rw-r--r--example.rb2
-rw-r--r--report/report_application.rb20
-rw-r--r--report/report_format.rb13
-rw-r--r--report/report_persistance.rb13
-rw-r--r--report/report_service.rb9
-rw-r--r--report/report_test.rb9
-rw-r--r--validation/validation_test.rb2
8 files changed, 63 insertions, 22 deletions
diff --git a/EXAMPLES b/EXAMPLES
index 664fb54..a14649c 100644
--- a/EXAMPLES
+++ b/EXAMPLES
@@ -234,4 +234,19 @@ result example (accept-header: application/rdf-xml)
<<< not yet supported
result example (accept-header: text/uri-list)
-<<< <validation_service>/report/crossvalidation/id_i \ No newline at end of file
+<<< <validation_service>/report/crossvalidation/id_i
+
+
+manually format html report
+-------------------------------------------------------------------
+
+>>> curl -X POST -d css_style_sheet=<css_file> \
+ <validation_service>/report/crossvalidation/<crossvalidation_report_id>/format_html
+
+This explicity invokes the report convertion to html, with css-style-sheet as parameter.
+
+result example (accept-header: application/rdf-xml)
+<<< not yet supported
+
+result example (accept-header: text/uri-list)
+<<< <validation_service>/report/crossvalidation/id_i
diff --git a/example.rb b/example.rb
index d9a1657..d0ab22d 100644
--- a/example.rb
+++ b/example.rb
@@ -9,6 +9,7 @@ class Example
@@data=File.join @@config[:services]["opentox-dataset"],"1"
@@train_data=File.join @@config[:services]["opentox-dataset"],"2"
@@test_data=File.join @@config[:services]["opentox-dataset"],"3"
+ @@css_file="http://apps.ideaconsult.net:8180/ToxPredict/style/global.css"
@@summary=""
@@ -34,6 +35,7 @@ class Example
"crossvalidation_id" => "1",
"validation_report_id" => "1",
"crossvalidation_report_id" => "1",
+ "css_file" => @@css_file,
}
sub.each do |k,v|
diff --git a/report/report_application.rb b/report/report_application.rb
index 4346f7f..629b411 100644
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -15,6 +15,13 @@ def perform
end
end
+get '/report/:type/css_style_sheet/?' do
+ perform do |rs|
+ "@import \""+params[:css_style_sheet]+"\";"
+ end
+end
+
+
get '/report/?' do
perform do |rs|
content_type "text/uri-list"
@@ -29,11 +36,22 @@ get '/report/:type' do
end
end
+post '/report/:type/:id/format_html' do
+
+ perform do |rs|
+ rs.get_report(params[:type],params[:id],"text/html",true,params)
+ content_type "text/uri-list"
+ rs.get_uri(params[:type],params[:id])
+ end
+end
+
+
get '/report/:type/:id' do
+
perform do |rs|
accept_header = request.env['HTTP_ACCEPT']
- if request.env['HTTP_USER_AGENT'] =~ /MSIE/
+ if accept_header =~ /MSIE/
LOGGER.info "Changing MSIE accept-header to text/html"
accept_header = "text/html"
end
diff --git a/report/report_format.rb b/report/report_format.rb
index 941a6d3..421f5b5 100644
--- a/report/report_format.rb
+++ b/report/report_format.rb
@@ -31,18 +31,18 @@ module Reports::ReportFormat
# formats a report from xml into __format__
# * xml report must be in __directory__ with filename __xml_filename__
# * the new format can be found in __dest_filame__
- def self.format_report(directory, xml_filename, dest_filename, format)
+ def self.format_report(directory, xml_filename, dest_filename, format, overwrite=false, params={})
raise "cannot format to XML" if format==RF_XML
raise "directory does not exist: "+directory.to_s unless File.directory?directory.to_s
xml_file = directory.to_s+"/"+xml_filename.to_s
raise "xml file not found: "+xml_file unless File.exist?xml_file
dest_file = directory.to_s+"/"+dest_filename.to_s
- raise "destination file already exists: "+dest_file if File.exist?dest_file
+ raise "destination file already exists: "+dest_file if (File.exist?(dest_file) && !overwrite)
case format
when RF_HTML
- format_report_to_html(directory, xml_filename, dest_filename)
+ format_report_to_html(directory, xml_filename, dest_filename, params[:css_style_sheet])
when RF_PDF
raise "pdf conversion not supported yet"
else
@@ -51,10 +51,11 @@ module Reports::ReportFormat
end
private
- def self.format_report_to_html(directory, xml_filename, html_filename)
-
+ def self.format_report_to_html(directory, xml_filename, html_filename, css_style_sheet)
+ css = css_style_sheet ? " html.stylesheet=css_style_sheet?css_style_sheet="+URI.encode(css_style_sheet.to_s) : nil
+
cmd = "java -jar "+ENV['SAXON_JAR']+" -o:" + File.join(directory,html_filename.to_s)+
- " -s:"+File.join(directory,xml_filename.to_s)+" -xsl:"+ENV['REPORT_XSL']+" -versionmsg:off"
+ " -s:"+File.join(directory,xml_filename.to_s)+" -xsl:"+ENV['REPORT_XSL']+" -versionmsg:off"+css.to_s
LOGGER.debug "converting report to html: '"+cmd+"'"
IO.popen(cmd.to_s) do |f|
while line = f.gets do
diff --git a/report/report_persistance.rb b/report/report_persistance.rb
index 0a072dc..b6c4077 100644
--- a/report/report_persistance.rb
+++ b/report/report_persistance.rb
@@ -31,7 +31,7 @@ class Reports::ReportPersistance
# call-seq:
# get_report(type, id, format) => string
#
- def get_report(type, id, format)
+ def get_report(type, id, format, force_formating, params)
raise "not implemented"
end
@@ -111,7 +111,7 @@ class Reports::FileReportPersistance < Reports::ReportPersistance
return id
end
- def get_report(type, id, format)
+ def get_report(type, id, format, force_formating, params)
report_dir = report_directory(type, id)
raise_report_not_found(type, id) unless File.directory?(report_dir)
@@ -119,11 +119,10 @@ class Reports::FileReportPersistance < Reports::ReportPersistance
filename = "report."+format
file_path = report_dir+"/"+filename
- if !File.exist?(file_path)
- Reports::ReportFormat.format_report(report_dir, "report.xml", filename, format)
- raise "formated file not found '"+file_path+"'" unless File.exist?(file_path)
- end
-
+ return file_path if File.exist?(file_path) && !force_formating
+
+ Reports::ReportFormat.format_report(report_dir, "report.xml", filename, format, force_formating, params)
+ raise "formated file not found '"+file_path+"'" unless File.exist?(file_path)
return file_path
end
diff --git a/report/report_service.rb b/report/report_service.rb
index 43b9992..bcb2e1d 100644
--- a/report/report_service.rb
+++ b/report/report_service.rb
@@ -69,12 +69,13 @@ module Reports
# call-seq:
# get_report( type, id, accept_header_value ) => string
#
- def get_report( type, id, accept_header_value="text/xml" )
+ def get_report( type, id, accept_header_value="text/xml", force_formating=false, params={} )
- LOGGER.info "get report '"+id.to_s+"' of type '"+type.to_s+"' (accept-header-value: '"+accept_header_value.to_s+"')"
+ LOGGER.info "get report '"+id.to_s+"' of type '"+type.to_s+"' (accept-header-value: '"+
+ accept_header_value.to_s+"', force-formating:"+force_formating.to_s+" params: '"+params.inspect+"')"
check_report_type(type)
format = Reports::ReportFormat.get_format(accept_header_value)
- return @persistance.get_report(type, id, format)
+ return @persistance.get_report(type, id, format, force_formating, params)
end
# returns a report resource (i.e. image)
@@ -126,11 +127,11 @@ module Reports
return id
end
- protected
def get_uri(type, id=nil)
@home_uri+"/"+type.to_s+(id!=nil ? "/"+id.to_s : "")
end
+ protected
def check_report_type(type)
raise Reports::NotFound.new("report type not found '"+type.to_s+"'") unless Reports::ReportFactory::REPORT_TYPES.index(type)
end
diff --git a/report/report_test.rb b/report/report_test.rb
index ed6b377..a75dd76 100644
--- a/report/report_test.rb
+++ b/report/report_test.rb
@@ -17,9 +17,14 @@ class Reports::ApplicationTest < Test::Unit::TestCase
def test_nothing
- get '/report/validation/1'
+ #uri = '/report/css_style_sheet?css_style_sheet='+CGI.escape("http://apps.ideaconsult.net:8180/ToxPredict/style/global.css")
+ #puts uri
+ #get uri
- puts last_response.body
+ #get '/report/validation/1',nil,'HTTP_ACCEPT' => "text/html"
+ post '/report/validation/1/format_html',:css_style_sheet=>"http://apps.ideaconsult.net:8180/ToxPredict/style/global.css"
+
+ puts last_response.body.to_s.gsub(/\n.*/,"")
end
#
# def test_webservice
diff --git a/validation/validation_test.rb b/validation/validation_test.rb
index 643ea81..b854f0c 100644
--- a/validation/validation_test.rb
+++ b/validation/validation_test.rb
@@ -197,7 +197,7 @@ class ValidationTest < Test::Unit::TestCase
#get '/crossvalidation/1',nil,'HTTP_ACCEPT' => "application/rdf+xml"
- get '/crossvalidation/1/statistics',nil,'HTTP_ACCEPT' => "text/x-yaml"
+ get '/crossvalidation/1/statistics',:bla=>blub,'HTTP_ACCEPT' => "text/x-yaml"
puts last_response.body
end