summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-09-03 17:33:34 +0200
committermguetlein <martin.guetlein@gmail.com>2010-09-03 17:33:34 +0200
commit971155a2f06266ffb5fa1234d4901a174dac5a3a (patch)
treede11c08a3220e9099c56f65475b3255bbaf409e4
parent6e02e9ff6d9c11defae77dda533fc71518bd5b2c (diff)
add metadata functionality
-rwxr-xr-xapplication.rb35
1 files changed, 30 insertions, 5 deletions
diff --git a/application.rb b/application.rb
index 7494748..fea6755 100755
--- a/application.rb
+++ b/application.rb
@@ -36,7 +36,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
@@ -59,14 +63,27 @@ get '/:id' do
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% 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
@@ -104,6 +121,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