From 971155a2f06266ffb5fa1234d4901a174dac5a3a Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 3 Sep 2010 17:33:34 +0200 Subject: add metadata functionality --- application.rb | 35 ++++++++++++++++++++++++++++++----- 1 file 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 -- cgit v1.2.3