class RGeoServer::Catalog

This class represents the main class of the data model, and provides all REST APIs to GeoServer. Refer to

Attributes

config[R]

Public Class Methods

new(options = nil) click to toggle source

@param [OrderedHash] options, if nil, uses RGeoServer::Config loaded from $RGEOSERVER_CONFIG or config/defaults.yml @param [String] options :url @param [String] options :user @param [String] options :password

# File lib/rgeoserver/catalog.rb, line 16
def initialize options = nil
  @config = options || RGeoServer::Config[:geoserver]
  unless config.include?(:url)
    raise ArgumentError.new("Catalog: Requires :url option: #{config}") 
  end
  RestClient.log = config[:logfile] || nil
end

Public Instance Methods

each_layer(options = {}) { |get_layer l.strip| ... } click to toggle source

List of available layers @return [Array<RGeoServer::Layer>]

# File lib/rgeoserver/catalog.rb, line 95
def each_layer options = {}
  doc = Nokogiri::XML(self.search :layers => nil)
  ap({:each_layer_doc => doc, :xpath => Layer.root_xpath}) if $DEBUG
  doc.xpath(Layer.root_xpath + '/name/text()').each { |l|
    ap({:layer => l.to_s.strip}) if $DEBUG
    yield get_layer l.to_s.strip unless l.nil?
  }
end
get_coverage(workspace, coverage_store, coverage) click to toggle source
# File lib/rgeoserver/catalog.rb, line 225
def get_coverage workspace, coverage_store, coverage
  c = Coverage.new self, 
                   :workspace => workspace, 
                   :coverage_store => coverage_store, 
                   :name => coverage
  return c.new?? nil : c
end
get_coverage_store(workspace, coveragestore) click to toggle source

@param [String] workspace @param [String] coveragestore @return [RGeoServer::CoverageStore]

# File lib/rgeoserver/catalog.rb, line 220
def get_coverage_store workspace, coveragestore
  cs = CoverageStore.new self, :workspace => workspace, :name => coveragestore
  return cs.new?? nil : cs
end
get_coverage_stores(workspace = nil) click to toggle source

List of coverage stores @param [String] workspace @return [Array<RGeoServer::CoverageStore>]

# File lib/rgeoserver/catalog.rb, line 212
def get_coverage_stores workspace = nil
  ws = workspace.nil?? get_workspaces : [get_workspace(workspace)]
  ws.map { |w| w.coverage_stores }.flatten
end
get_data_store(workspace, datastore) click to toggle source

@param [String] workspace @param [String] datastore @return [RGeoServer::DataStore]

# File lib/rgeoserver/catalog.rb, line 185
def get_data_store workspace, datastore
  doc = Nokogiri::XML(search :workspaces => workspace, :datastores => datastore)
  DataStore.new self, :workspace => workspace, 
                      :name => parse_name(doc, DataStore)
end
get_data_stores(workspace = nil) click to toggle source

List of vector based spatial data @param [String] workspace @return [Array<RGeoServer::DataStore>]

# File lib/rgeoserver/catalog.rb, line 177
def get_data_stores workspace = nil
  ws = workspace.nil?? get_workspaces : [get_workspace(workspace)]
  ws.map { |w| w.data_stores }.flatten
end
get_default_namespace() click to toggle source

@return [RGeoServer::Namespace]

# File lib/rgeoserver/catalog.rb, line 162
def get_default_namespace
  doc = Nokogiri::XML(search :namespaces => 'default')
  Namespace.new self, :name => parse_name(doc, Namespace, 'prefix'), 
                      :uri => parse_name(doc, Namespace, 'uri')
end
get_default_workspace() click to toggle source

@return [RGeoServer::Workspace] get_workspace('default')

# File lib/rgeoserver/catalog.rb, line 70
def get_default_workspace
  get_workspace 'default'
end
get_feature_type(workspace, datastore, featuretype_id) click to toggle source

@param [String] workspace @param [String] datastore @param [String] featuretype_id @return [RGeoServer::FeatureType]

# File lib/rgeoserver/catalog.rb, line 203
def get_feature_type workspace, datastore, featuretype_id
  raise NotImplementedError
end
get_feature_types(workspace, datastore, &block) click to toggle source

List of feature types @param [String] workspace @param [String] datastore @return [Array<RGeoServer::FeatureType>]

# File lib/rgeoserver/catalog.rb, line 195
def get_feature_types workspace, datastore, &block
  raise NotImplementedError
end
get_layer(layername) click to toggle source

@param [String] layername @return [RGeoServer::Layer]

# File lib/rgeoserver/catalog.rb, line 106
def get_layer layername
  raise ArgumentError, "#get_layer requires String #{layername}" unless layername.is_a? String
  ap({:layers => layername}) if $DEBUG
  doc = Nokogiri::XML(search :layers => layername)
  Layer.new self, :name => layername
end
get_layergroup(layergroup) click to toggle source

@param [String] layer group name @return [RGeoServer::LayerGroup]

# File lib/rgeoserver/catalog.rb, line 130
def get_layergroup layergroup
  doc = Nokogiri::XML(search :layergroups => layergroup)
  LayerGroup.new self, :name => parse_name(doc, LayerGroup)
end
get_layergroups(options = {}) click to toggle source

List of available layer groups @return [Array<RGeoServer::LayerGroup>]

# File lib/rgeoserver/catalog.rb, line 117
def get_layergroups options = {}
  response = unless options[:workspace]
               self.search :layergroups => nil
             else
               self.search :workspaces => options[:workspace], :layergroups => nil
             end
  doc = Nokogiri::XML(response)
  layer_groups = doc.xpath(LayerGroup.root_xpath).collect{|l| l.text.to_s }.map(&:strip)
  list LayerGroup, layer_groups, :workspace => options[:workspace]
end
get_namespaces() click to toggle source

List of available namespaces @return [Array<RGeoServer::Namespace>]

# File lib/rgeoserver/catalog.rb, line 157
def get_namespaces
  raise NotImplementedError
end
get_style(style) click to toggle source

@param [String] style name @return [RGeoServer::Style]

# File lib/rgeoserver/catalog.rb, line 147
def get_style style
  doc = Nokogiri::XML(search :styles => style)
  Style.new self, :name => parse_name(doc, Style)
end
get_styles() click to toggle source

List of available styles @return [Array<RGeoServer::Style>]

# File lib/rgeoserver/catalog.rb, line 139
def get_styles
  doc = Nokogiri::XML(search :styles => nil)
  styles = doc.xpath("#{Style.root_xpath}/name/text()").collect {|s| s.to_s }
  list Style, styles
end
get_wms_store(workspace, wmsstore) click to toggle source

@param [String] workspace @param [String] wmsstore @return [RGeoServer::WmsStore]

# File lib/rgeoserver/catalog.rb, line 246
def get_wms_store workspace, wmsstore
  doc = Nokogiri::XML(search :workspaces => workspace, :name => wmsstore)
  WmsStore.new self, workspace, parse_name(doc, WmsStore)
end
get_wms_stores(workspace = nil) click to toggle source

List of WMS stores. @param [String] workspace @return [Array<RGeoServer::WmsStore>]

# File lib/rgeoserver/catalog.rb, line 238
def get_wms_stores workspace = nil
  ws = workspace.nil?? get_workspaces : [get_workspace(workspace)]
  ws.map { |w| w.wms_stores }.flatten
end
get_workspace(ws) click to toggle source

@param ws [String] workspace name @return [RGeoServer::Workspace]

# File lib/rgeoserver/catalog.rb, line 63
def get_workspace ws
  doc = Nokogiri::XML(search :workspaces => ws)
  Workspace.new self, :name => parse_name(doc, Workspace)
end
get_workspaces() click to toggle source

List of available workspaces @return [Array<RGeoServer::Workspace>]

# File lib/rgeoserver/catalog.rb, line 55
def get_workspaces
  doc = Nokogiri::XML(search :workspaces => nil)
  workspaces = doc.xpath("#{Workspace.root_xpath}/name/text()").collect {|w| w.to_s }
  list Workspace.class, workspaces
end
headers(format = :xml) click to toggle source
# File lib/rgeoserver/catalog.rb, line 28
def headers format = :xml
  { 
    :accept => format.to_sym, 
    :content_type => format.to_sym
  }
end
list(klass, names, options = {}) click to toggle source

Shortcut to ResourceInfo.list to this catalog. See ResourceInfo#list @param [RGeoServer::ResourceInfo.class] klass @param [RGeoServer::Catalog] catalog @param [Array<String>] names @param [Hash] options @param [bool] check_remote if already exists in catalog and cache it @yield [RGeoServer::ResourceInfo]

# File lib/rgeoserver/catalog.rb, line 44
def list klass, names, options = {}, check_remote = false, &block
  unless names.is_a? Array and not names.empty?
    raise ArgumentError, "Missing names #{names}" 
  end
  ResourceInfo.list klass, self, names, options, check_remote, &block
end
reassign_workspace(store, workspace) click to toggle source

@deprecated see RGeoServer::Workspace @param [String] store @param [String] workspace

# File lib/rgeoserver/catalog.rb, line 87
def reassign_workspace store, workspace
  raise NotImplementedError
end
reload() click to toggle source

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.
# File lib/rgeoserver/catalog.rb, line 253
def reload
  do_url 'reload', :put
end
reset() click to toggle source

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.
# File lib/rgeoserver/catalog.rb, line 259
def reset
  do_url 'reset', :put
end
set_default_namespace(id, prefix, uri) click to toggle source
# File lib/rgeoserver/catalog.rb, line 168
def set_default_namespace id, prefix, uri
  raise NotImplementedError
end
set_default_workspace(workspace) click to toggle source

Assign default workspace @param [String] workspace name

# File lib/rgeoserver/catalog.rb, line 76
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
to_s() click to toggle source
# File lib/rgeoserver/catalog.rb, line 24
def to_s
  "Catalog: #{config[:url]}"
end

Private Instance Methods

parse_name(doc, klass, k = 'name') click to toggle source
# File lib/rgeoserver/catalog.rb, line 264
def parse_name doc, klass, k = 'name'
  name = doc.at_xpath("#{klass.member_xpath}/#{k}/text()")
  name = name.to_s unless name.nil?
  name
end