summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-02-11 10:47:35 +0100
committermguetlein <martin.guetlein@gmail.com>2011-02-11 10:47:35 +0100
commitd5e00cf1cdd7a5029e7ecedda2508a14cf4657e0 (patch)
treebb9853380b2f5a3e498714259eb4eb40cc956601
parent86ef144e4e16d108c0aafaf1c672e82233e98cdf (diff)
fix correct setting of subjecit and read rack.input only once
-rw-r--r--application.rb30
1 files changed, 18 insertions, 12 deletions
diff --git a/application.rb b/application.rb
index 61889c1..b5d8cf7 100644
--- a/application.rb
+++ b/application.rb
@@ -14,20 +14,22 @@ class Dataset
after :save, :check_policy
- def load(params,request)
+ # subjectid ist stored as memeber variable, not in params
+ def load(params,content_type,input_data)
+
+ raise "store subject-id in dataset-object, not in params" if
+ params.has_key?(:subjectid) and @subjectid==nil
- data = request.env["rack.input"].read
- content_type = request.content_type
content_type = "application/rdf+xml" if content_type.nil?
- dataset = OpenTox::Dataset.new(nil, params[:subjectid])
+ dataset = OpenTox::Dataset.new(nil, @subjectid)
case content_type
when /yaml/
- dataset.load_yaml(data)
+ dataset.load_yaml(input_data)
- when "application/rdf+xml"
- dataset.load_rdfxml(data)
+ when /application\/rdf\+xml/
+ dataset.load_rdfxml(input_data)
when /multipart\/form-data/ , "application/x-www-form-urlencoded" # file uploads
@@ -266,14 +268,17 @@ post '/?' do
response['Content-Type'] = 'text/uri-list'
@dataset.subjectid = @subjectid
@dataset.update(:uri => url_for("/#{@dataset.id}", :full))
-
- token_present = params.member?("subjectid") ? 1 : 0
- if params.size - token_present < 1 # and request.env["rack.input"].read.empty? # mr to fix
+
+ # it could be that the read function works only once!, store in varible
+ input_data = request.env["rack.input"].read
+ # make sure subjectid is not included in params, subjectid is set as member variable
+ params.delete(:subjectid)
+ if params.size == 0 and input_data.size==0
@dataset.update(:yaml => OpenTox::Dataset.new(@dataset.uri).to_yaml)
@dataset.uri
else
task = OpenTox::Task.create("Converting and saving dataset ", @dataset.uri) do
- @dataset.load params, request
+ @dataset.load params, request.content_type, input_data
@dataset.uri
end
halt 503,task.uri+"\n" if task.status == "Cancelled"
@@ -294,10 +299,11 @@ end
# @return [text/uri-list] Task ID
post '/:id' do
@dataset = Dataset.get(params[:id])
+ @dataset.subjectid = @subjectid
halt 404, "Dataset #{params[:id]} not found." unless @dataset
response['Content-Type'] = 'text/uri-list'
task = OpenTox::Task.create("Converting and saving dataset ", @dataset.uri) do
- @dataset.load params, request
+ @dataset.load params, request.content_type, request.env["rack.input"].read
FileUtils.rm Dir["public/#{params[:id]}.*"]
@dataset.uri
end