From 018c39fc95e6525ce10cc73167aab57ce0ae8de9 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Sun, 27 Feb 2011 09:32:57 +0100 Subject: code cleanup --- application.rb | 46 ---------------------------------------------- lazar.rb | 20 -------------------- 2 files changed, 66 deletions(-) diff --git a/application.rb b/application.rb index 79063f5..ff3abe7 100644 --- a/application.rb +++ b/application.rb @@ -3,31 +3,8 @@ gem "opentox-ruby", "~> 0" require 'opentox-ruby' set :lock, true -=begin -class ModelStore - include DataMapper::Resource - attr_accessor :prediction_dataset, :subjectid - property :id, Serial - property :uri, String, :length => 255 - property :yaml, Text, :length => 2**32-1 - property :created_at, DateTime - - @subjectid = nil - - after :save, :check_policy - - private - def check_policy - OpenTox::Authorization.check_policy(uri, subjectid) - end - -end -=end class PredictionCache < Ohm::Model - # cache predictions - #include DataMapper::Resource - #attribute :id, Serial attribute :compound_uri attribute :model_uri attribute :dataset_uri @@ -36,8 +13,6 @@ class PredictionCache < Ohm::Model index :model_uri end -#DataMapper.auto_upgrade! - before do @accept = request.env['HTTP_ACCEPT'] @accept = 'application/rdf+xml' if @accept == '*/*' or @accept == '' or @accept.nil? @@ -116,26 +91,6 @@ delete '/:id/?' do rescue halt 404, "Model #{@id} does not exist." end -=begin - begin - uri = ModelStore.get(params[:id]).uri - ModelStore.get(params[:id]).destroy! - "Model #{params[:id]} deleted." - - 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}" - rescue - LOGGER.warn "Policy delete error for Model URI: #{uri}" - end - end - response['Content-Type'] = 'text/plain' - "Model #{params[:id]} deleted." - rescue - halt 404, "Model #{params[:id]} does not exist." - end -=end end @@ -143,7 +98,6 @@ delete '/?' do # TODO delete datasets FileUtils.rm Dir["public/*.yaml"] PredictionCache.all.each {|cache| cache.delete } - #PredictionCache.auto_migrate! response['Content-Type'] = 'text/plain' "All models and cached predictions deleted." end diff --git a/lazar.rb b/lazar.rb index 74680dd..ba85784 100644 --- a/lazar.rb +++ b/lazar.rb @@ -3,20 +3,6 @@ require "haml" # Get model representation # @return [application/rdf+xml,application/x-yaml] Model representation get '/:id/?' do - -=begin - 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 -=end halt 404, "Model #{params[:id]} not found." unless File.exists? @yaml_file response['Content-Type'] = @accept case @accept @@ -37,9 +23,7 @@ get '/:id/?' do end get '/:id/metadata.?:ext?' do - metadata = YAML.load_file(@yaml_file).metadata - response['Content-Type'] = @accept case @accept when /yaml/ @@ -49,7 +33,6 @@ get '/:id/metadata.?:ext?' do serializer.add_metadata @uri, metadata serializer.to_rdfxml end - end # Store a lazar model. This method should not be called directly, use OpenTox::Algorithm::Lazr to create a lazar model @@ -57,9 +40,6 @@ end # @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 = @subjectid - #model.uri = url_for("/#{model.id}", :full) @id = next_id @uri = uri @id @yaml_file = "public/#{@id}.yaml" -- cgit v1.2.3