From 0fdf7ed7fb5b80c78aaa16f8c75ce11dc3840d6e Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 18 Jan 2011 11:29:42 +0100 Subject: get subjectid from api-wrapper helper --- application.rb | 9 ++++----- lazar.rb | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/application.rb b/application.rb index 4fc749d..ae4d064 100644 --- a/application.rb +++ b/application.rb @@ -61,12 +61,11 @@ delete '/:id/?' do uri = ModelStore.get(params[:id]).uri ModelStore.get(params[:id]).destroy! "Model #{params[:id]} deleted." - subjectid = params[:subjectid] if params[:subjectid] - subjectid = request.env['HTTP_SUBJECTID'] if !subjectid and request.env['HTTP_SUBJECTID'] - if subjectid and !ModelStore.get(params[:id]) and uri + + if @subjectid and !ModelStore.get(params[:id]) and uri begin - res = OpenTox::Authorization.delete_policies_from_uri(uri, subjectid) - LOGGER.debug "Policy deleted for Model URI: #{uri} with subjectid: #{subjectid} with result: #{res}" + res = OpenTox::Authorization.delete_policies_from_uri(uri, @subjectid) + LOGGER.debug "Policy deleted for Model URI: #{uri} with subjectid: #{@subjectid} with result: #{res}" rescue LOGGER.warn "Policy delete error for Model URI: #{uri}" end diff --git a/lazar.rb b/lazar.rb index 460050a..16327d8 100644 --- a/lazar.rb +++ b/lazar.rb @@ -3,15 +3,13 @@ require "haml" helpers do def uri_available?(urlStr) url = URI.parse(urlStr) - subjectid = params[:subjectid] if params[:subjectid] - subjectid = request.env['HTTP_SUBJECTID'] if !subjectid and request.env['HTTP_SUBJECTID'] - unless subjectid + unless @subjectid Net::HTTP.start(url.host, url.port) do |http| return http.head(url.request_uri).code == "200" end else Net::HTTP.start(url.host, url.port) do |http| - return http.post(url.request_uri, "subjectid=#{subjectid}").code == "202" + return http.post(url.request_uri, "subjectid=#{@subjectid}").code == "202" end end end @@ -74,21 +72,19 @@ get '/:id/metadata.?:ext?' do end - # Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model # @param [Body] lazar Model representation in YAML format # @return [String] Model URI post '/?' do # create model - halt 400, "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) - model = ModelStore.create - model.subjectid = params[:subjectid] if params[:subjectid] - model.subjectid = request.env["HTTP_SUBJECTID"] if !model.subjectid and request.env["HTTP_SUBJECTID"] - model.uri = url_for("/#{model.id}", :full) - lazar = YAML.load request.env["rack.input"].read + halt 400, "MIME type \"#{request.content_type}\" not supported." unless request.content_type.match(/yaml/) + model = ModelStore.create + model.subjectid = @subjectid + model.uri = url_for("/#{model.id}", :full) + lazar = YAML.load request.env["rack.input"].read lazar.uri = model.uri - model.yaml = lazar.to_yaml - model.save - model.uri + model.yaml = lazar.to_yaml + model.save + model.uri end # Make a lazar prediction. Predicts either a single compound or all compounds from a dataset @@ -97,8 +93,6 @@ end # @param [optional,Header] Accept Content-type of prediction, can be either `application/rdf+xml or application/x-yaml` # @return [text/uri-list] URI of prediction task (dataset prediction) or prediction dataset (compound prediction) post '/:id/?' do - subjectid = params[:subjectid] if params[:subjectid] - subjectid = request.env["HTTP_SUBJECTID"] if !subjectid and request.env["HTTP_SUBJECTID"] @lazar = YAML.load ModelStore.get(params[:id]).yaml @@ -111,7 +105,7 @@ post '/:id/?' do cache = PredictionCache.first(:model_uri => @lazar.uri, :compound_uri => compound_uri) return cache.dataset_uri if cache and uri_available?(cache.dataset_uri) begin - prediction_uri = @lazar.predict(compound_uri,true,subjectid).uri + 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 @@ -120,7 +114,7 @@ post '/:id/?' do end elsif dataset_uri task = OpenTox::Task.create("Predict dataset",url_for("/#{@lazar.id}", :full)) do - @lazar.predict_dataset(dataset_uri, subjectid).uri + @lazar.predict_dataset(dataset_uri, @subjectid).uri end halt 503,task.uri+"\n" if task.status == "Cancelled" halt 202,task.uri -- cgit v1.2.3