summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-03-18 20:54:24 +0100
committerChristoph Helma <helma@in-silico.de>2010-03-18 20:54:24 +0100
commit6840f6003af7c4317583350c2e50804a448ae8b6 (patch)
treecedacd6bc7b590a9f7a63fabd1056eee8f0b69cd
parent08f484d69ba8538570692c9cbca9a29bffa4e70a (diff)
more detailed model information in toxcreate
-rw-r--r--application.rb27
1 files changed, 22 insertions, 5 deletions
diff --git a/application.rb b/application.rb
index 18a21d7..cffcf6b 100644
--- a/application.rb
+++ b/application.rb
@@ -1,6 +1,9 @@
require 'rubygems'
gem 'opentox-ruby-api-wrapper', '= 1.3.1'
require 'opentox-ruby-api-wrapper'
+#require 'sinatra/respond_to'
+#Sinatra::Application.register Sinatra::RespondTo
+
LOGGER.progname = File.expand_path(__FILE__)
@@ -10,12 +13,13 @@ class Dataset
property :uri, String, :length => 255
property :file, String, :length => 255
property :yaml, Text, :length => 2**32-1
+ property :owl, Text, :length => 2**32-1
property :created_at, DateTime
def to_owl
data = YAML.load(yaml)
owl = OpenTox::Owl.new 'Dataset', uri
- ['title', 'source', 'identifier'].each do |method|
+ ['title', 'source'].each do |method|
eval "owl.#{method} = data.#{method}"
end
data.data.each do |compound,features|
@@ -38,7 +42,18 @@ get '/?' do
Dataset.all.collect{|d| d.uri}.join("\n") + "\n"
end
-get '/:id/?' do
+get '/:id' do
+ accept = request.env['HTTP_ACCEPT']
+ accept = 'application/rdf+xml' if accept == '*/*' or accept == '' or accept.nil?
+ # workaround for browser links
+ case params[:id]
+ when /.yaml$/
+ params[:id].sub!(/.yaml$/,'')
+ accept = 'application/x-yaml'
+ when /.rdf$/
+ params[:id].sub!(/.rdf$/,'')
+ accept = 'application/rdf+xml'
+ end
begin
dataset = Dataset.get(params[:id])
rescue => e
@@ -46,12 +61,14 @@ get '/:id/?' do
LOGGER.warn e.backtrace
halt 404, "Dataset #{params[:id]} not found."
end
- 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.to_owl
+ unless dataset.owl # lazy owl creation
+ dataset.owl = dataset.to_owl
+ dataset.save
+ end
+ dataset.owl
when /yaml/
response['Content-Type'] = 'application/x-yaml'
dataset.yaml