summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application.rb2
-rw-r--r--lazar.rb19
2 files changed, 13 insertions, 8 deletions
diff --git a/application.rb b/application.rb
index 72e4254..8c241b4 100644
--- a/application.rb
+++ b/application.rb
@@ -23,7 +23,7 @@ before do
@uri = uri @id
@yaml_file = "public/#{@id}.yaml"
- halt 404, "Dataset #{@id} not found." unless File.exists? @yaml_file
+ halt 404, "Model #{@id} not found." unless File.exists? @yaml_file
end
# make sure subjectid is not included in params, subjectid is set as member variable
diff --git a/lazar.rb b/lazar.rb
index 5ade3c6..d297ccf 100644
--- a/lazar.rb
+++ b/lazar.rb
@@ -80,6 +80,7 @@ post '/?' do # create model
lazar = YAML.load request.env["rack.input"].read
lazar.uri = @uri
File.open(@yaml_file,"w+"){|f| f.puts lazar.to_yaml}
+ OpenTox::Authorization.check_policy(@uri, @subjectid) if File.exists? @yaml_file
response['Content-Type'] = 'text/uri-list'
@uri
end
@@ -101,13 +102,17 @@ post '/:id/?' do
if compound_uri
cache = PredictionCache.find(:model_uri => @lazar.uri, :compound_uri => compound_uri).first
return cache.dataset_uri if cache and uri_available?(cache.dataset_uri)
- begin
- prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri
- PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri)
- prediction_uri
- rescue
- LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} "
- halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed."
+ if cache and uri_available?(cache.dataset_uri)
+ return cache.dataset_uri
+ else
+ begin
+ prediction_uri = @lazar.predict(compound_uri,true,@subjectid).uri
+ PredictionCache.create(:model_uri => @lazar.uri, :compound_uri => compound_uri, :dataset_uri => prediction_uri)
+ prediction_uri
+ rescue
+ LOGGER.error "Lazar prediction failed for #{compound_uri} with #{$!} "
+ halt 500, "Prediction of #{compound_uri} with #{@lazar.uri} failed."
+ end
end
elsif dataset_uri
task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do |task|