diff options
author | mguetlein <martin.guetlein@gmail.com> | 2010-08-18 17:53:46 +0200 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2010-08-18 17:53:46 +0200 |
commit | 0f5cc11dcecf6eda0a7230d69aa346cfb86c6a49 (patch) | |
tree | 664f6f902f7150969474e7e76a159623de230c5b /reach_reports/reach_application.rb | |
parent | 4e596159e74dea2124b89f1beb1dab01a97b0242 (diff) |
first version reach reporting
Diffstat (limited to 'reach_reports/reach_application.rb')
-rw-r--r-- | reach_reports/reach_application.rb | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb index 96b6b37..596bae2 100644 --- a/reach_reports/reach_application.rb +++ b/reach_reports/reach_application.rb @@ -1,13 +1,10 @@ -[ 'rubygems', 'sinatra', 'sinatra/url_for', 'active_record', 'ar-extensions', 'opentox-ruby-api-wrapper' ].each do |lib| +[ 'rubygems', 'sinatra', 'sinatra/url_for', 'opentox-ruby-api-wrapper' ].each do |lib| require lib end -require 'reach_reports/reach_properties.rb' require 'reach_reports/reach_persistance.rb' require 'reach_reports/reach_service.rb' -require 'reach_reports/reach_to_xml.rb' - require "lib/format_util.rb" @@ -27,7 +24,7 @@ post '/reach_report/:type' do content_type "text/uri-list" type = extract_type(params) LOGGER.info "creating "+type+" report "+params.inspect - ReachReports.create_report(type,params) + ReachReports.create_report(type,params,request.env["rack.input"]) end get '/reach_report/:type/:id' do @@ -38,32 +35,49 @@ get '/reach_report/:type/:id' do case request.env['HTTP_ACCEPT'].to_s when "application/rdf+xml" - owl = OpenTox::Owl.create(rep.type+"Report",rep.report_uri) + halt 400, "application/rdf+xml not yet supported" + owl = OpenTox::Owl.create(type+"Report",rep.report_uri) owl.set_data( rep.get_content.keys_to_rdf_format ) result = owl.rdf when "application/qmrf-xml" content_type "application/qmrf-xml" - result = ReachReports.reach_report_to_xml(rep) + result = rep.to_xml + #f = File.new("/home/martin/info_home/.public_html/qmrf.out.xml","w") + #f.puts result when /application\/x-yaml|\*\/\*|^$/ # matches 'application/x-yaml', '*/*', '' content_type "application/x-yaml" - result = rep.get_content.to_yaml + result = rep.to_yaml else halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\", \"application/x-yaml\", \"application/qmrf-xml\"." end + result end -get '/reach_report/:type/:id/:section' do +post '/reach_report/:type/:id' do type = extract_type(params) - LOGGER.info "get "+type+" report section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'" - ReachReports.get_report(type, params[:id], params[:section]).to_yaml -end + LOGGER.info "set "+type+" report with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'" + rep = ReachReports.get_report(type, params[:id]) -get '/reach_report/:type/:id/:section/:subsection' do - - type = extract_type(params) - LOGGER.info "get "+type+" report subsection '"+params[:subsection].to_s+"', section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'" - ReachReports.get_report(type, params[:id], params[:section], params[:subsection]).to_yaml + input = request.env["rack.input"].read + halt 400, "no xml data specified" unless input && input.to_s.size>0 + ReachReports::QmrfReport.from_xml(rep,input) + #f = File.new("/home/martin/info_home/.public_html/qmrf.out.xml","w") + #f.puts rep.to_xml end +#get '/reach_report/:type/:id/:section' do +# +# type = extract_type(params) +# LOGGER.info "get "+type+" report section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'" +# ReachReports.get_report(type, params[:id], params[:section]).to_yaml +#end +# +#get '/reach_report/:type/:id/:section/:subsection' do +# +# type = extract_type(params) +# LOGGER.info "get "+type+" report subsection '"+params[:subsection].to_s+"', section '"+params[:section].to_s+"', with id "+params[:id].to_s+"' "+request.env['HTTP_ACCEPT'].to_s+"'" +# ReachReports.get_report(type, params[:id], params[:section], params[:subsection]).to_yaml +#end + |