diff options
-rw-r--r-- | application.rb | 2 | ||||
-rw-r--r-- | lib/validation_db.rb | 4 | ||||
-rw-r--r-- | report/report_application.rb | 21 | ||||
-rw-r--r-- | validation/validation_application.rb | 13 |
4 files changed, 36 insertions, 4 deletions
diff --git a/application.rb b/application.rb index bbd599f..55a7598 100644 --- a/application.rb +++ b/application.rb @@ -16,10 +16,12 @@ get '/examples/?' do end get '/prepare_examples/?' do + content_type "text/plain" Example.prepare_example_resources end get '/test_examples/?' do + content_type "text/plain" Example.test_examples end diff --git a/lib/validation_db.rb b/lib/validation_db.rb index 702fef5..30a0bda 100644 --- a/lib/validation_db.rb +++ b/lib/validation_db.rb @@ -80,6 +80,10 @@ end # end #end +raise "':database:' configuration missing in config file" unless @@config.has_key?(:database) +[ "adapter","database","username","password","host" ].each do |field| + raise "field '"+field+":' missing in database configuration" unless @@config[:database].has_key?(field) +end DataMapper.setup(:default, { :adapter => @@config[:database]["adapter"], :database => @@config[:database]["database"], diff --git a/report/report_application.rb b/report/report_application.rb index 1c92172..c68df11 100644 --- a/report/report_application.rb +++ b/report/report_application.rb @@ -16,16 +16,23 @@ def perform end get '/report/?' do - perform{ |rs| rs.get_report_types } + perform do |rs| + content_type "text/uri-list" + rs.get_report_types + end end get '/report/:type' do - perform{ |rs| rs.get_all_reports(params[:type]) } + perform do |rs| + content_type "text/uri-list" + rs.get_all_reports(params[:type]) + end end get '/report/:type/:id' do perform do |rs| #request.env['HTTP_ACCEPT'] = "application/pdf" + content_type Reports::ReportFormat.get_format(request.env['HTTP_ACCEPT']) result = body(File.new( rs.get_report(params[:type],params[:id],request.env['HTTP_ACCEPT']) )) end end @@ -42,9 +49,15 @@ get '/report/:type/:id/:resource' do end delete '/report/:type/:id' do - perform{ |rs| rs.delete_report(params[:type],params[:id]) } + perform do |rs| + content_type "text/plain" + rs.delete_report(params[:type],params[:id]) + end end post '/report/:type' do - perform{ |rs| rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split("\n"):nil) } + perform do |rs| + content_type "text/uri-list" + rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split("\n"):nil) + end end diff --git a/validation/validation_application.rb b/validation/validation_application.rb index a7cdc18..2c5806e 100644 --- a/validation/validation_application.rb +++ b/validation/validation_application.rb @@ -25,6 +25,8 @@ end ## REST API get '/crossvalidation/?' do LOGGER.info "list all crossvalidations" + + content_type "text/uri-list" Validation::Crossvalidation.all.collect{ |d| url_for("/crossvalidation/", :full) + d.id.to_s }.join("\n") end @@ -34,8 +36,10 @@ get '/crossvalidation/:id' do case request.env['HTTP_ACCEPT'].to_s when "application/rdf+xml" + content_type "application/rdf+xml" result = crossvalidation.to_rdf when /text\/x-yaml|\*\/\*|/ # matches 'text/x-yaml', '*/*', '' + content_type "text/x-yaml" result = crossvalidation.to_yaml else halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported." @@ -47,6 +51,7 @@ end delete '/crossvalidation/:id/?' do LOGGER.info "delete crossvalidation with id "+params[:id].to_s + content_type "text/plain" halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.get(params[:id]) crossvalidation.delete end @@ -54,6 +59,7 @@ end get '/crossvalidation/:id/validations' do LOGGER.info "get all validations for crossvalidation with id "+params[:id].to_s halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.get(params[:id]) + content_type "text/uri-list" Validation::Validation.all(:crossvalidation_id => params[:id]).collect{ |v| v.uri.to_s }.join("\n")+"\n" end @@ -68,11 +74,13 @@ post '/crossvalidation/?' do cv = Validation::Crossvalidation.new cv_params cv.create_cv_datasets( params[:prediction_feature] ) cv.perform_cv( params[:algorithm_params]) + content_type "text/uri-list" cv.uri end get '/?' do LOGGER.info "list all validations" + content_type "text/uri-list" Validation::Validation.all.collect{ |d| url_for("/", :full) + d.id.to_s }.join("\n") end @@ -82,8 +90,10 @@ get '/:id' do case request.env['HTTP_ACCEPT'].to_s when "application/rdf+xml" + content_type "application/rdf+xml" result = validation.to_rdf when /text\/x-yaml|\*\/\*|/ # matches 'text/x-yaml', '*/*', '' + content_type "text/x-yaml" result = validation.to_yaml else halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported." @@ -126,6 +136,7 @@ post '/training_test_split' do :test_dataset_uri => params[:test_dataset_uri], :prediction_feature => params[:prediction_feature] v.validate_algorithm( params[:algorithm_uri], params[:algorithm_params]) + content_type "text/uri-list" v.uri end @@ -137,11 +148,13 @@ get '/:id/:attribute' do rescue halt 400, "Not a validation attribute: "+params[:attribute].to_s end + content_type "text/plain" return validation.send(params[:attribute]) end delete '/:id' do LOGGER.info "delete validation with id "+params[:id].to_s halt 404, "Validation #{params[:id]} not found." unless validation = Validation::Validation.get(params[:id]) + content_type "text/plain" validation.delete end
\ No newline at end of file |