summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2010-09-06 10:48:23 +0200
committerChristoph Helma <helma@in-silico.ch>2010-09-06 10:48:23 +0200
commit95a0b8517737d70b4db4b525a0f1492b0c1a5983 (patch)
tree06f785ca53142d2da55b46fae2920ae30bf503d0
parent9817e9e9ad8ec1776ba7ee3d03635401f0ad0d2c (diff)
parent971155a2f06266ffb5fa1234d4901a174dac5a3a (diff)
Merge commit 'mguetlein/test' into development
Conflicts: application.rb
-rwxr-xr-xapplication.rb37
1 files changed, 31 insertions, 6 deletions
diff --git a/application.rb b/application.rb
index e7bf635..2ace1db 100755
--- a/application.rb
+++ b/application.rb
@@ -35,7 +35,11 @@ get '/?' do
Dataset.all(params).collect{|d| d.uri}.join("\n") + "\n"
end
-get '/:id' do
+# provides dataset in various formats
+#
+# only_metadata=true => compounds and features are removed
+#
+def get_dataset( params, request, response, only_metadata=false )
accept = request.env['HTTP_ACCEPT']
accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil?
# workaround for browser links
@@ -57,15 +61,28 @@ get '/:id' do
raise e.message + e.backtrace
halt 404, "Dataset #{params[:id]} not found."
end
- halt 404, "Dataset #{params[:id]} not found." if dataset.nil? # not sure how an empty cataset can be returned, but if this happens stale processes keep runing at 100% cpu
+ halt 404, "Dataset #{params[:id]} not found." if dataset.nil? # not sure how an empty cataset can be returned, but if this happens stale processes keep runing at 100% cpo
+
+ if only_metadata # remove compounds and feature data from yaml
+ d = YAML.load(dataset.yaml)
+ def d.to_yaml_properties
+ super - [ "@compounds", "@features", "@data"]
+ end
+ dataset.yaml = d.to_yaml
+ end
+
case accept
when /rdf/ # redland sends text/rdf instead of application/rdf+xml
response['Content-Type'] = 'application/rdf+xml'
- unless dataset.owl # lazy owl creation
- dataset.owl = dataset.to_owl
- dataset.save
+ if only_metadata
+ dataset.to_owl
+ else
+ unless dataset.owl # lazy owl creation
+ dataset.owl = dataset.to_owl
+ dataset.save
+ end
+ dataset.owl
end
- dataset.owl
when /yaml/
response['Content-Type'] = 'application/x-yaml'
dataset.yaml
@@ -103,6 +120,14 @@ get '/:id' do
end
end
+get '/:id' do
+ get_dataset(params, request, response)
+end
+
+get '/:id/metadata/?' do
+ get_dataset(params, request, response, true)
+end
+
get '/:id/features/:feature_id/?' do
OpenTox::Dataset.find(url_for("/#{params[:id]}", :full)).feature(params[:feature_id])
end