Class: RGeoServer::Catalog

Inherits:
Object
  • Object
show all
Includes:
RestApiClient
Defined in:
lib/rgeoserver/catalog.rb

Overview

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

Constant Summary

Constants included from GeoServerUrlHelpers

GeoServerUrlHelpers::URI_FORMATS, GeoServerUrlHelpers::URI_REGEX, GeoServerUrlHelpers::URI_SEQUENCES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RestApiClient

#add, #client, #do_url, #gwc_client, #modify, #purge, #rest_client, #search

Methods included from GeoServerUrlHelpers

#url_for

Constructor Details

#initialize(options = nil) ⇒ Catalog

Returns a new instance of Catalog.

Parameters:

  • options, (OrderedHash)

    if nil, uses RGeoServer::Config loaded from $RGEOSERVER_CONFIG or config/defaults.yml

  • options (String) (defaults to: nil)

    :url

  • options (String) (defaults to: nil)

    :user

  • options (String) (defaults to: nil)

    :password



16
17
18
19
20
21
22
# 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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/rgeoserver/catalog.rb', line 10

def config
  @config
end

Instance Method Details

#each_layer(options = {}) ⇒ Array<RGeoServer::Layer>

List of available layers

Returns:



95
96
97
98
99
100
101
102
# 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) ⇒ Object



225
226
227
228
229
230
231
# 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) ⇒ RGeoServer::CoverageStore

Parameters:

  • workspace (String)
  • coveragestore (String)

Returns:



220
221
222
223
# 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) ⇒ Array<RGeoServer::CoverageStore>

List of coverage stores

Parameters:

  • workspace (String) (defaults to: nil)

Returns:



212
213
214
215
# 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) ⇒ RGeoServer::DataStore

Parameters:

  • workspace (String)
  • datastore (String)

Returns:



185
186
187
188
189
# 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) ⇒ Array<RGeoServer::DataStore>

List of vector based spatial data

Parameters:

  • workspace (String) (defaults to: nil)

Returns:



177
178
179
180
# 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_namespaceRGeoServer::Namespace



162
163
164
165
166
# 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_workspaceRGeoServer::Workspace

Returns get_workspace(‘default’).

Returns:



70
71
72
# File 'lib/rgeoserver/catalog.rb', line 70

def get_default_workspace
  get_workspace 'default'
end

#get_feature_type(workspace, datastore, featuretype_id) ⇒ RGeoServer::FeatureType

Parameters:

  • workspace (String)
  • datastore (String)
  • featuretype_id (String)

Returns:

Raises:

  • (NotImplementedError)


203
204
205
# File 'lib/rgeoserver/catalog.rb', line 203

def get_feature_type workspace, datastore, featuretype_id
  raise NotImplementedError
end

#get_feature_types(workspace, datastore, &block) ⇒ Array<RGeoServer::FeatureType>

List of feature types

Parameters:

  • workspace (String)
  • datastore (String)

Returns:

Raises:

  • (NotImplementedError)


195
196
197
# File 'lib/rgeoserver/catalog.rb', line 195

def get_feature_types workspace, datastore, &block
  raise NotImplementedError
end

#get_layer(layername) ⇒ RGeoServer::Layer

Parameters:

  • layername (String)

Returns:

Raises:

  • (ArgumentError)


106
107
108
109
110
111
# 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) ⇒ RGeoServer::LayerGroup

Parameters:

  • layer (String)

    group name

Returns:



130
131
132
133
# 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 = {}) ⇒ Array<RGeoServer::LayerGroup>

List of available layer groups

Returns:



117
118
119
120
121
122
123
124
125
126
# 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_namespacesArray<RGeoServer::Namespace>

List of available namespaces

Returns:

Raises:

  • (NotImplementedError)


157
158
159
# File 'lib/rgeoserver/catalog.rb', line 157

def get_namespaces
  raise NotImplementedError
end

#get_style(style) ⇒ RGeoServer::Style

Parameters:

  • style (String)

    name

Returns:



147
148
149
150
# 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_stylesArray<RGeoServer::Style>

List of available styles

Returns:



139
140
141
142
143
# 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) ⇒ RGeoServer::WmsStore

Parameters:

  • workspace (String)
  • wmsstore (String)

Returns:



246
247
248
249
# 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) ⇒ Array<RGeoServer::WmsStore>

List of WMS stores.

Parameters:

  • workspace (String) (defaults to: nil)

Returns:



238
239
240
241
# 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) ⇒ RGeoServer::Workspace

Parameters:

  • ws (String)

    workspace name

Returns:



63
64
65
66
# 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_workspacesArray<RGeoServer::Workspace>

List of available workspaces

Returns:



55
56
57
58
59
# 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) ⇒ Object



28
29
30
31
32
33
# 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 = {}, check_remote = false) {|RGeoServer::ResourceInfo| ... } ⇒ Object

Shortcut to ResourceInfo.list to this catalog. See ResourceInfo#list

Parameters:

Yields:



44
45
46
47
48
49
# 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) ⇒ Object

Deprecated.

see RGeoServer::Workspace

Parameters:

  • store (String)
  • workspace (String)

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/rgeoserver/catalog.rb', line 87

def reassign_workspace store, workspace
  raise NotImplementedError
end

#reloadObject

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.



253
254
255
# File 'lib/rgeoserver/catalog.rb', line 253

def reload
  do_url 'reload', :put
end

#resetObject

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.



259
260
261
# File 'lib/rgeoserver/catalog.rb', line 259

def reset
  do_url 'reset', :put
end

#set_default_namespace(id, prefix, uri) ⇒ Object

Raises:

  • (NotImplementedError)


168
169
170
# File 'lib/rgeoserver/catalog.rb', line 168

def set_default_namespace id, prefix, uri
  raise NotImplementedError
end

#set_default_workspace(workspace) ⇒ Object

Assign default workspace

Parameters:

  • workspace (String)

    name

Raises:

  • (TypeError)


76
77
78
79
80
81
82
# 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_sObject



24
25
26
# File 'lib/rgeoserver/catalog.rb', line 24

def to_s
  "Catalog: #{config[:url]}"
end