summaryrefslogtreecommitdiff
path: root/report/report_application.rb
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-10-06 12:09:08 +0200
committermguetlein <martin.guetlein@gmail.com>2010-10-06 12:09:08 +0200
commitf72a88dcb8fd18778445b4e6678cdfdee7feda28 (patch)
tree84c65896bf2a049db5b48f4dabd2b6e2b6a3b646 /report/report_application.rb
parent18e1ec84378d711b36b1a77b29baa9b5ef664faa (diff)
add text/html support, remove delete disabling, add new line to uri-list returns
Diffstat (limited to 'report/report_application.rb')
-rw-r--r--report/report_application.rb79
1 files changed, 37 insertions, 42 deletions
diff --git a/report/report_application.rb b/report/report_application.rb
index 5c8c1c8..95913cd 100644
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -43,15 +43,38 @@ end
get '/report/?' do
perform do |rs|
- content_type "text/uri-list"
- rs.get_report_types
+ case request.env['HTTP_ACCEPT'].to_s
+ when /text\/html/
+ related_links =
+ "All validations: "+$sinatra.url_for("/",:full)
+ description =
+ "A list of all report types."
+ content_type "text/html"
+ OpenTox.text_to_html rs.get_report_types,related_links,description
+ else
+ content_type "text/uri-list"
+ rs.get_report_types
+ end
end
end
get '/report/:report_type' do
perform do |rs|
- content_type "text/uri-list"
- rs.get_all_reports(params[:report_type], params)
+ case request.env['HTTP_ACCEPT'].to_s
+ when /text\/html/
+ related_links =
+ "Available report types: "+$sinatra.url_for("/report",:full)+"\n"+
+ "Single validations: "+$sinatra.url_for("/",:full)+"\n"+
+ "Crossvalidations: "+$sinatra.url_for("/crossvalidation",:full)
+ description =
+ "A list of all "+params[:report_type]+" reports. To create a report, use the POST method."
+ post_params = [[:validation_uris]]
+ content_type "text/html"
+ OpenTox.text_to_html rs.get_all_reports(params[:report_type], params),related_links,description,post_params
+ else
+ content_type "text/uri-list"
+ rs.get_all_reports(params[:report_type], params)
+ end
end
end
@@ -60,7 +83,7 @@ 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])
+ rs.get_uri(params[:type],params[:id])+"\n"
end
end
@@ -70,27 +93,14 @@ get '/report/:type/:id' do
perform do |rs|
accept_header = request.env['HTTP_ACCEPT']
- if accept_header =~ /MSIE/
- LOGGER.info "Changing MSIE accept-header to text/html"
- accept_header = "text/html"
- end
- #request.env['HTTP_ACCEPT'] = "application/pdf"
-
- #QMRF-STUB
- if params[:type] == Reports::ReportFactory::RT_QMRF
- #raise Reports::BadRequest.new("only 'application/qmrf-xml' provided so far") if accept_header != "application/qmrf-xml"
- content_type "application/qmrf-xml"
- result = body(OpenTox::RestClientWrapper.get("http://ecb.jrc.ec.europa.eu/qsar/qsar-tools/qrf/QMRF_v1.2_FishTox.xml"))
+ report = rs.get_report(params[:type],params[:id],accept_header)
+ format = Reports::ReportFormat.get_format(accept_header)
+ content_type format
+ #PENDING: get_report should return file or string, check for result.is_file instead of format
+ if format=="application/x-yaml" or format=="application/rdf+xml"
+ report
else
- report = rs.get_report(params[:type],params[:id],accept_header)
- format = Reports::ReportFormat.get_format(accept_header)
- content_type format
- #PENDING: get_report should return file or string, check for result.is_file instead of format
- if format=="application/x-yaml" or format=="application/rdf+xml"
- report
- else
- result = body(File.new(report))
- end
+ result = body(File.new(report))
end
end
end
@@ -107,7 +117,6 @@ get '/report/:type/:id/:resource' do
end
delete '/report/:type/:id' do
- halt 400,"delete temporarily disabled"
perform do |rs|
content_type "text/plain"
rs.delete_report(params[:type],params[:id])
@@ -117,23 +126,9 @@ end
post '/report/:type' do
task_uri = OpenTox::Task.as_task("Create report",url_for("/report/"+params[:type], :full), params) do
perform do |rs|
- content_type "text/uri-list"
rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split(/\n|,/):nil)
end
end
- halt 202,task_uri
-end
-
-
-post '/report/:type/:id' do
- perform do |rs|
- #QMRF-STUB
- if params[:type] == Reports::ReportFactory::RT_QMRF
- #raise Reports::BadRequest.new("only 'application/qmrf-xml' provided so far") if request.content_type != "application/qmrf-xml"
- input = request.env["rack.input"].read
- "save qmrf would have been successfull, received data with "+input.to_s.size.to_s+" characters, this is just a stub, changes discarded"
- else
- "operation not supported yet"
- end
- end
+ content_type "text/uri-list"
+ halt 202,task_uri+"\n"
end