require 'voruby/services/loader' module VORuby module Services module Gestalt class WesixException < RuntimeError; end class NoVotableException < WesixException def initialize super('VOTable missing from SOAP response. ' + 'Often this is caused by an overly large catalog. ' + 'Try increasing your detection threshold.') end end class Wesix attr_reader :factory, :driver, :allowed_in_params, :allowed_out_params, :in_params, :out_params def initialize(driver, bootstrap=true, debug=false) @driver = driver @driver.wiredump_dev = $stderr if debug @in_params = {} @out_params = {} define_accessors() bootstrap_params() if bootstrap end def self.from_wsdl(wsdl="http://nvogre.phyast.pitt.edu:8080/axis/services/WesixTest?wsdl", bootstrap=true, debug=false) return Wesix.new(SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver, bootstrap, debug) end def define_accessors @allowed_in_params = [] @allowed_out_params = [] @driver.proxy.literal_mapping_registry.definedtypes.each do |el| case el.name.name when 'SexParams' el.each_element do |ctype| @allowed_in_params.push(ctype.name.name) meta_def(ctype.name.name.downcase){get_in_param(ctype.name.name)} meta_def(ctype.name.name.downcase + '='){|value| set_in_param(ctype.name.name, value)} end when 'SexOutputParams' el.each_element do |ctype| @allowed_out_params.push(ctype.name.name) meta_def(ctype.name.name.downcase){get_out_param(ctype.name.name)} meta_def(ctype.name.name.downcase + '='){|value| set_out_param(ctype.name.name, value)} end end end end def bootstrap_params bootstrap_in_params bootstrap_out_params end def reset_params reset_in_params reset_out_params end def bootstrap_in_params in_params = @driver.getSexParams()[0] @allowed_in_params.each do |param_name| @in_params[param_name] = in_params[param_name] end end def reset_in_params @in_params = {} end def bootstrap_out_params out_params = @driver.getSexOutputParams()[0] @allowed_out_params.each do |param_name| @out_params[param_name] = out_params[param_name] end end def reset_out_params @out_params = {} end def set_in_param(name, value) if @allowed_in_params.include?(name) @in_params[name] = value else raise "Input parameter #{name} is not recognized" end end def get_in_param(name) @in_params[name] end def set_out_param(name, value) if @allowed_out_params.include?(name) @out_params[name] = value else raise "Output parameter #{name} is not recognized" end end def get_out_param(name) @out_params[name] end def _file_as_string(file) bytes = nil File.open(file){ |file_obj| bytes = file_obj.readlines.join() } return bytes end def wsextractor3VO(file, flag=0) response = @driver.wsextractor3VO(_file_as_string(file), @in_params.to_soap_map, @out_params.to_soap_map, flag) return VOTable::VOTable.from_soap_obj(response[0].vOTABLE) if response[0].respond_to?(:vOTABLE) raise NoVotableException end def wsextractor3VOXmatch(file, flag=0) response = @driver.wsextractor3VOXmatch(_file_as_string(file), @in_params.to_soap_map, @out_params.to_soap_map, flag) return VOTable::VOTable.from_soap_obj(response[0].vOTABLE) if response[0].respond_to?(:vOTABLE) raise NoVotableException end def wsextractorURL3VO(file, flag=0) response = @driver.wsextractorURL3VO(file, @in_params.to_soap_map, @out_params.to_soap_map, flag) return VOTables::VOTable::VOTable.from_soap_obj(response[0].vOTABLE) if response[0].respond_to?(:vOTABLE) raise NoVotableException end def wsextractorURL3VOXmatch(file, flag=0) response = @driver.wsextractorURL3VOXmatch(file, @in_params.to_soap_map, @out_params.to_soap_map, flag) return VOTable::VOTable.from_soap_obj(response[0].vOTABLE) if response[0].respond_to?(:vOTABLE) raise NoVotableException end private :define_accessors, :bootstrap_in_params, :bootstrap_out_params, :bootstrap_params, :_file_as_string end end end end