summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-03-10 19:17:46 +0100
committerChristoph Helma <helma@in-silico.de>2010-03-10 19:17:46 +0100
commit1d3d1a8b9a88639e28663ee7cd505331edd77f78 (patch)
treedefc673804ff4463cd75273cb44151f3cf5eef9d
parent864c6b88ca3f1709e84e0ce2b4c7147d874ea6e6 (diff)
owl-dl (temporarily) removed, switched to YAML representation
-rw-r--r--application.rb36
1 files changed, 19 insertions, 17 deletions
diff --git a/application.rb b/application.rb
index 58cfbd4..70ceeee 100644
--- a/application.rb
+++ b/application.rb
@@ -9,6 +9,7 @@ class Dataset
property :id, Serial
property :uri, String, :length => 255
property :file, String, :length => 255
+ property :yaml, Text, :length => 2**32-1
#property :owl, Text, :length => 1000000
property :created_at, DateTime
@@ -42,12 +43,13 @@ get '/:id/?' do
accept = request.env['HTTP_ACCEPT']
accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil?
case accept
- when /rdf/ # redland sends text/rdf instead of application/rdf+xml
- response['Content-Type'] = 'application/rdf+xml'
- dataset.owl
+# when /rdf/ # redland sends text/rdf instead of application/rdf+xml
+# response['Content-Type'] = 'application/rdf+xml'
+# dataset.owl
when /yaml/
response['Content-Type'] = 'application/x-yaml'
- OpenTox::Dataset.find(dataset.uri).to_yaml
+ #OpenTox::Dataset.find(dataset.uri).to_yaml
+ dataset.yaml
else
halt 400, "Unsupported MIME type '#{accept}'"
end
@@ -58,7 +60,8 @@ get '/:id/features/:feature_id/?' do
end
get '/:id/features/?' do
- OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).features
+ YAML.load(Dataset.get(params[:id]).yaml).features.join("\n") + "\n"
+ #OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).features
end
post '/?' do
@@ -70,41 +73,40 @@ post '/?' do
dataset = Dataset.new
dataset.save
- uri = url_for("/#{dataset.id}", :full)
+ dataset.uri = url_for("/#{dataset.id}", :full)
content_type = request.content_type
content_type = "application/rdf+xml" if content_type.nil?
case request.content_type
+ when /yaml/
+ dataset.yaml = request.env["rack.input"].read
+ when /csv/
+ dataset.yaml = csv2yaml request.env["rack.input"].read
when "application/rdf+xml"
- rdf = request.env["rack.input"].read
- d= OpenTox::Dataset.new
- d.rdf = rdf
- d.uri = uri
+ dataset.yaml = owl2yaml request.env["rack.input"].read
else
halt 404, "MIME type \"#{request.content_type}\" not supported."
end
- LOGGER.debug "Saving dataset #{uri}."
+ LOGGER.debug "Saving dataset #{dataset.uri}."
begin
- dataset.owl = d.rdf
- dataset.uri = uri
dataset.save
- task.completed(uri)
+ task.completed(dataset.uri)
rescue => e
LOGGER.error e.message
LOGGER.info e.backtrace
- halt 500, "Could not save dataset #{uri}."
+ halt 500, "Could not save dataset #{dataset.uri}."
end
LOGGER.debug "#{dataset.uri} saved."
end
task.pid = pid
#status 303 # rest client tries to redirect
response['Content-Type'] = 'text/uri-list'
- task.uri
+ task.uri + "\n"
end
delete '/:id/?' do
begin
dataset = Dataset.get(params[:id])
- File.delete dataset.file
+ #File.delete dataset.file
dataset.destroy!
response['Content-Type'] = 'text/plain'
"Dataset #{params[:id]} deleted."