From c118806d88e8009f27bda9b49876d3d14dd136aa Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Fri, 13 Jul 2012 12:23:44 +0200 Subject: tasks for datset services --- application.rb | 70 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/application.rb b/application.rb index 8b2fadf..a92affd 100644 --- a/application.rb +++ b/application.rb @@ -193,39 +193,43 @@ module OpenTox end def parse_put - case @content_type - when "text/plain", "text/turtle", "application/rdf+xml" # no conversion needed - when "text/csv" - @body = from_csv @body - @content_type = "text/plain" - when "application/vnd.ms-excel" - xls = params[:file][:tempfile].path + ".xls" - File.rename params[:file][:tempfile].path, xls # roo needs these endings - @body = from_csv Excel.new(xls).to_csv - @content_type = "text/plain" - when "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" - xlsx = params[:file][:tempfile].path + ".xlsx" - File.rename params[:file][:tempfile].path, xlsx # roo needs these endings - @body = from_csv Excelx.new(xlsx).to_csv - @content_type = "text/plain" - when "application/vnd.oasis.opendocument.spreadsheet" - ods = params[:file][:tempfile].path + ".ods" - File.rename params[:file][:tempfile].path, ods # roo needs these endings - @body = from_csv Excelx.new(ods).to_csv - @content_type = "text/plain" - # when "chemical/x-mdl-sdfile" - # @body = parse_sdf @body - # @content_type = "text/plain" - else - bad_request_error "#{@content_type} is not a supported content type." - end - FourStore.put @uri, @body, @content_type - if params[:file] - nt = "<#{@uri}> <#{RDF::DC.title}> \"#{params[:file][:filename]}\".\n<#{uri}> <#{RDF::OT.hasSource}> \"#{params[:file][:filename]}\"." - FourStore.post(uri, nt, "text/plain") + task = OpenTox::Task.create $task[:uri], nil, RDF::DC.description => "Dataset upload: #{@uri}" do + case @content_type + when "text/plain", "text/turtle", "application/rdf+xml" # no conversion needed + when "text/csv" + @body = from_csv @body + @content_type = "text/plain" + when "application/vnd.ms-excel" + xls = params[:file][:tempfile].path + ".xls" + File.rename params[:file][:tempfile].path, xls # roo needs these endings + @body = from_csv Excel.new(xls).to_csv + @content_type = "text/plain" + when "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + xlsx = params[:file][:tempfile].path + ".xlsx" + File.rename params[:file][:tempfile].path, xlsx # roo needs these endings + @body = from_csv Excelx.new(xlsx).to_csv + @content_type = "text/plain" + when "application/vnd.oasis.opendocument.spreadsheet" + ods = params[:file][:tempfile].path + ".ods" + File.rename params[:file][:tempfile].path, ods # roo needs these endings + @body = from_csv Excelx.new(ods).to_csv + @content_type = "text/plain" + # when "chemical/x-mdl-sdfile" + # @body = parse_sdf @body + # @content_type = "text/plain" + else + bad_request_error "#{@content_type} is not a supported content type." + end + FourStore.put @uri, @body, @content_type + if params[:file] + nt = "<#{@uri}> <#{RDF::DC.title}> \"#{params[:file][:filename]}\".\n<#{uri}> <#{RDF::OT.hasSource}> \"#{params[:file][:filename]}\"." + FourStore.post(uri, nt, "text/plain") + end + @uri end + response['Content-Type'] = "text/uri-list" + task.uri end - end before "/#{SERVICE}/:id/:property" do @@ -234,11 +238,8 @@ module OpenTox # Create a new resource post "/dataset/?" do - # TOD: task @uri = uri("/#{SERVICE}/#{SecureRandom.uuid}") parse_put - response['Content-Type'] = "text/uri-list" - @uri end get "/dataset/:id/?" do @@ -261,7 +262,6 @@ module OpenTox # Create or updata a resource put "/dataset/:id/?" do - # TOD: task parse_put end -- cgit v1.2.3