summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/4store.rb15
-rw-r--r--lib/opentox.rb36
2 files changed, 49 insertions, 2 deletions
diff --git a/lib/4store.rb b/lib/4store.rb
index 1377643..bb8abc8 100644
--- a/lib/4store.rb
+++ b/lib/4store.rb
@@ -8,7 +8,20 @@ module OpenTox
def self.list mime_type
bad_request_error "'#{mime_type}' is not a supported mime type. Please specify one of #{@@accept_formats.join(", ")} in the Accept Header." unless @@accept_formats.include? mime_type
if mime_type =~ /(uri-list|html)/
+ sparql = "SELECT DISTINCT ?g WHERE {GRAPH ?g {?g ?p ?o} }"
+=begin
sparql = "SELECT DISTINCT ?g WHERE {GRAPH ?g {?s <#{RDF.type}> <#{klass}>; <#{RDF::DC.date}> ?o.} } ORDER BY ?o"
+ #sparql = "SELECT DISTINCT ?g WHERE {GRAPH ?g {?s <#{RDF.type}> <#{klass}>; <#{RDF::DC.modified}> ?o.} } ORDER BY ?o"
+ # not working for multiple DC.modified
+ sparql = "SELECT DISTINCT ?g WHERE {
+ GRAPH ?g {
+ ?g <#{RDF.type}> <#{klass}>.
+ OPTIONAL {?g <#{RDF::DC.date}> ?date.}
+ OPTIONAL {?g <#{RDF::OT.created_at}> ?date.}
+ OPTIONAL {?g <#{RDF::DC.modified}> ?date.}
+ }
+ } ORDER BY ?date"
+=end
else
sparql = "CONSTRUCT {?s ?p ?o.} WHERE {?s <#{RDF.type}> <#{klass}>; ?p ?o. }"
end
@@ -34,7 +47,7 @@ module OpenTox
bad_request_error "'#{mime_type}' is not a supported content type. Please use one of #{@@content_type_formats.join(", ")}." unless @@content_type_formats.include? mime_type or mime_type == "multipart/form-data"
bad_request_error "Request body empty." unless rdf
mime_type = "application/x-turtle" if mime_type == "text/plain" # ntriples is turtle in 4store
- RestClient.post File.join(four_store_uri,"data")+"/", :data => rdf.gsub(/\\C/,'C'), :graph => uri, "mime-type" => mime_type # remove backslashes in SMILES (4store interprets them as UTF-8 \C even within single quoates)
+ RestClient.post File.join(four_store_uri,"data")+"/", :data => rdf.gsub(/\\C/,'C'), :graph => uri, "mime-type" => mime_type # remove backslashes in SMILES (4store interprets them as UTF-8 \C even within single quotes)
update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }"
end
diff --git a/lib/opentox.rb b/lib/opentox.rb
index e5305fd..b7b363c 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -28,7 +28,7 @@ module OpenTox
end
before do
- @uri = uri(request.env['REQUEST_URI'])
+ @uri = uri(request.env['PATH_INFO']) # prevent /algorithm/algorithm in algorithm service
get_subjectid if respond_to? :get_subjectid
# fix IE
request.env['HTTP_ACCEPT'] += ";text/html" if request.env["HTTP_USER_AGENT"]=~/MSIE/
@@ -45,6 +45,7 @@ module OpenTox
after do
Authorization.check_policy(@uri, @subjectid) if env['REQUEST_METHOD'].to_s == "POST" && $aa[:uri]
+
end
@@ -63,6 +64,39 @@ module OpenTox
@content_type = request.content_type
end
end
+
+ # format output according to accept header
+ def render object
+ if object.class == String
+ case @accept
+ when /text\/html/
+ content_type "text/html"
+ object.to_html
+ else
+ content_type 'text/uri-list'
+ object
+ end
+ elsif object.class == Array
+ content_type 'text/uri-list'
+ object.join "\n"
+ else
+ case @accept
+ when "application/rdf+xml"
+ content_type "application/rdf+xml"
+ object.to_rdfxml
+ when /text\/html/
+ content_type "text/html"
+ object.to_html
+ when /turtle/
+ content_type "text/turtle"
+ object.to_turtle
+ else
+ content_type "text/plain"
+ object.to_ntriples
+ end
+
+ end
+ end
end
# Attention: Error within tasks are catched by Task.run