lib/rgeoserver/catalog.rb in rgeoserver-0.5.6 vs lib/rgeoserver/catalog.rb in rgeoserver-0.5.7

- old
+ new

@@ -4,11 +4,10 @@ # - http://geoserver.org/display/GEOS/Catalog+Design # - http://docs.geoserver.org/stable/en/user/restconfig/rest-config-api.html#workspaces class Catalog include RGeoServer::RestApiClient - include ActiveSupport::Benchmarkable attr_reader :config # @param [OrderedHash] options # @option options [String] :url @@ -20,15 +19,10 @@ def to_s "Catalog: #{@config[:url]}" end - def client config = {} - c = self.config.merge(config) - @client ||= RestClient::Resource.new(c[:url], :user => c[:user], :password => c[:password], :headers => c[:headers]) - end - def headers format sym = :xml || format.to_sym {:accept => sym, :content_type=> sym} end @@ -65,18 +59,24 @@ return Workspace.new self, :name => name.text if name end # @return [RGeoServer::Workspace] def get_default_workspace - dw = Workspace.new self, :name => 'default' - w = Workspace.new self, :name => w.name - raise "No default workspace is available in the catalog" unless w.new? - w + response = self.search :workspaces => 'default' + doc = Nokogiri::XML(response) + name = doc.at_xpath("#{Workspace.member_xpath}/name/text()").to_s + return Workspace.new self, :name => name end - def set_default_workspace - raise NotImplementedError + # Assign default workspace + # @param [String] workspace name + def set_default_workspace workspace + raise TypeError, "Workspace name must be a string" unless workspace.instance_of? String + dws = Workspace.new self, :name => 'default' + dws.name = workspace # This creates a new workspace if name is new + dws.save + dws end # @param [String] store # @param [String] workspace def reassign_workspace store, workspace @@ -97,12 +97,12 @@ # @param [String] layer name # @return [RGeoServer::Layer] def get_layer layer response = self.search :layers => layer doc = Nokogiri::XML(response) - name = doc.at_xpath(Layer.member_xpath) - return Layer.new self, :name => name.text if name + name = doc.at_xpath("#{Layer.member_xpath}/name/text()").to_s + return Layer.new self, :name => name end #= Styles (SLD Style Layer Descriptor) # List of available styles @@ -117,12 +117,12 @@ # @param [String] style name # @return [RGeoServer::Style] def get_style style response = self.search :styles => style doc = Nokogiri::XML(response) - name = doc.at_xpath(Style.member_xpath) - return Style.new self, :name => name.text if name + name = doc.at_xpath("#{Style.member_xpath}/name/text()").to_s + return Style.new self, :name => name end #= Namespaces @@ -130,12 +130,17 @@ # @return [Array<RGeoServer::Namespace>] def get_namespaces raise NotImplementedError end + # @return [RGeoServer::Namespace] def get_default_namespace - raise NotImplementedError + response = self.search :namespaces => 'default' + doc = Nokogiri::XML(response) + name = doc.at_xpath("#{Namespace.member_xpath}/prefix/text()").to_s + uri = doc.at_xpath("#{Namespace.member_xpath}/uri/text()").to_s + return Namespace.new self, :name => name, :uri => uri end def set_default_namespace id, prefix, uri raise NotImplementedError end @@ -227,16 +232,16 @@ end #= Configuration reloading # Reloads the catalog and configuration from disk. This operation is used to reload GeoServer in cases where an external tool has modified the on disk configuration. This operation will also force GeoServer to drop any internal caches and reconnect to all data stores. def reload - do_url 'reload', method = :put + do_url 'reload', :put end #= Resource reset # Resets all store/raster/schema caches and starts fresh. This operation is used to force GeoServer to drop all caches and stores and reconnect fresh to each of them first time they are needed by a request. This is useful in case the stores themselves cache some information about the data structures they manage that changed in the meantime. def reset - do_url 'reset', method = :put + do_url 'reset', :put end end end