diff options
author | Christoph Helma <helma@in-silico.ch> | 2013-05-29 15:08:37 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2013-05-29 15:08:37 +0200 |
commit | b3f82247d347429a30881ac7f35677f87f503976 (patch) | |
tree | 9e70fddc7c4090b18cff1b6be1e4dda8301d2ba1 | |
parent | 2ae4341e7e35f9ce4a059712cbb559a7544ee98e (diff) | |
parent | e904ce55da3d59744a5345f9c0b56f9c35971844 (diff) |
Merge branch 'development' of github.com:opentox/opentox-server into development
Conflicts:
lib/4store.rb
-rw-r--r-- | lib/4store.rb | 18 | ||||
-rw-r--r-- | lib/opentox.rb | 7 |
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/4store.rb b/lib/4store.rb index 13f5fd2..b8aaca9 100644 --- a/lib/4store.rb +++ b/lib/4store.rb @@ -15,6 +15,13 @@ module OpenTox query sparql, mime_type end + def self.head uri + sparql = "SELECT DISTINCT ?g WHERE {GRAPH ?g {<#{uri}> <#{RDF::DC.modified}> ?o.} }" + rdf = query sparql, 'application/sparql-results+xml' + resource_not_found_error "#{uri} not found." unless rdf.match("#{uri}") + rdf + end + def self.get uri, 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 sparql = "CONSTRUCT {?s ?p ?o.} FROM <#{uri}> WHERE { ?s ?p ?o. }" @@ -36,7 +43,13 @@ module OpenTox bad_request_error "Reqest body empty." unless rdf mime_type = "application/x-turtle" if mime_type == "text/plain" RestClientWrapper.put File.join(four_store_uri,"data",uri), rdf, :content_type => mime_type +# update moved to opentox-client to improve performance #update "INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }" +# RestClientWrapper.put File.join(four_store_uri,"data",uri), rdf, :content_type => mime_type +# update "WITH <#{uri}> +# DELETE {<#{uri}> <{RDF::DC.modified}> ?o} +# WHERE {<#{uri}> <{RDF::DC.modified}> ?o}; +# INSERT DATA { GRAPH <#{uri}> { <#{uri}> <#{RDF::DC.modified}> \"#{DateTime.now}\" } }" end def self.delete uri @@ -62,7 +75,7 @@ module OpenTox if sparql =~ /SELECT/i # return list unless mime_type case mime_type - when 'application/sparql-results+xml' + when 'application/sparql-results+xml' RestClient.get(sparql_uri, :params => { :query => sparql }, :accept => mime_type).body when 'application/json' RestClient.get(sparql_uri, :params => { :query => sparql }, :accept => mime_type).body @@ -80,7 +93,6 @@ module OpenTox when /html|turtle/ # TODO: fix and improve nt = RestClient.get(sparql_uri, :params => { :query => sparql }, :accept => "text/plain").body # 4store returns ntriples for turtle - rdf = RDF::Graph.new RDF::Reader.for(:ntriples).new(nt) do |reader| reader.each_statement { |statement| rdf << statement } @@ -88,7 +100,7 @@ module OpenTox prefixes = {:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"} ['OT', 'DC', 'XSD', 'OLO'].each{|p| prefixes[p.downcase.to_sym] = eval("RDF::#{p}.to_s") } # TODO: fails for large datasets?? multi_cell_call - turtle = RDF::N3::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| + turtle = RDF::Turtle::Writer.for(:turtle).buffer(:prefixes => prefixes) do |writer| rdf.each{|statement| writer << statement} end regex = Regexp.new '(https?:\/\/[\S]+)([>"])' diff --git a/lib/opentox.rb b/lib/opentox.rb index 06026be..0869262 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -144,7 +144,12 @@ module OpenTox # HEAD route for service check # algorithm, compound and validation overwrite this head "/#{SERVICE}/?" do - #$logger.debug "#{SERVICE.capitalize} service is running." + end + + # HEAD request for object in backend + # algorithm, dataset, compound and validation overwrite this + head "/#{SERVICE}/:id/?" do + resource_not_found_error "#{uri} not found." unless FourStore.head(@uri.split('?').first) end # Get a list of objects at the server or perform a SPARQL query |