Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial implementation of layers. Not saving yet

  • Loading branch information...
commit 2ef85ea25c10440b74c05fc49dcd074e91bb844d 1 parent f04437e
Renzo Sanchez-Silva authored
View
1  lib/rgeoserver.rb
@@ -14,6 +14,7 @@ module RGeoServer
autoload :DataStore, "rgeoserver/datastore"
autoload :CoverageStore, "rgeoserver/coveragestore"
autoload :WmsStore, "rgeoserver/wmsstore"
+ autoload :Layer, "rgeoserver/layer"
require 'restclient'
require 'nokogiri'
View
30 lib/rgeoserver/catalog.rb
@@ -41,7 +41,7 @@ def get_workspaces &block
ResourceInfo.list Workspace, self, workspaces, {}, &block
end
- # @param [String] workspace
+ # @param [String] workspace name
# @return [<RGeoServer::Workspace]
def get_workspace workspace
response = self.search :workspaces => workspace
@@ -52,7 +52,10 @@ def get_workspace workspace
# @return [<RGeoServer::Workspace]
def get_default_workspace
- return Workspace.new self, :name => 'default'
+ 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
end
def set_default_workspace
@@ -65,9 +68,28 @@ def reassign_workspace store, workspace
pass
end
- # List of feature types
+
+ # List of available layers
+ # @return [Array<RGeoServer::Layer>]
+ def get_layers &block
+ response = self.search :layers => nil
+ doc = Nokogiri::XML(response)
+ layers = doc.xpath(Layer.root_xpath).collect{|l| l.text.to_s }
+ ResourceInfo.list Layer, self, layers, {}, &block
+ end
+
+ # @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 Workspace.new self, :name => name.text if name
+ end
+
+
+ # List of available namespaces
# @return [Array<RGeoServer::Namespace>]
- # TODO: Implement when the stable release includes it
def get_namespaces
raise NotImplementedError
end
View
2  lib/rgeoserver/coverage.rb
@@ -75,7 +75,7 @@ def profile_xml_to_hash profile_xml
h = {
"coverage_store" => @coverage_store.name,
"workspace" => @workspace.name,
- "name" => doc.at_xpath('//name/text()').text.strip,
+ "name" => doc.at_xpath('//name/text()').text.strip,,
"nativeName" => doc.at_xpath('//nativeName/text()').to_s,
"title" => doc.at_xpath('//title/text()').to_s,
"supportedFormats" => doc.xpath('//supportedFormats/string/text()').collect{ |t| t.to_s }
View
6 lib/rgeoserver/featuretype.rb
@@ -92,9 +92,9 @@ def catalog= val
def profile_xml_to_hash profile_xml
doc = profile_xml_to_ng profile_xml
h = {
- :name => doc.at_xpath('//name').text.strip,
- :workspace => @workspace.name,
- :nativeName => doc.at_xpath('//nativeName').text.to_s
+ "name" => doc.at_xpath('//name').text.strip,
+ "workspace" => @workspace.name,
+ "nativeName" => doc.at_xpath('//nativeName').to_s
}.freeze
h
end
View
108 lib/rgeoserver/layer.rb
@@ -0,0 +1,108 @@
+
+module RGeoServer
+
+ class Layer < ResourceInfo
+
+ OBJ_ATTRIBUTES = {:enabled => 'enabled', :catalog => 'catalog', :name => 'name', :default_style => 'default_style', :alternative_style => 'alternative_style' }
+ OBJ_DEFAULT_ATTRIBUTES = {:enabled => 'true', :catalog => nil, :name => nil, :default_style => nil, :alternative_styles => [] }
+
+ define_attribute_methods OBJ_ATTRIBUTES.keys
+ update_attribute_accessors OBJ_ATTRIBUTES
+
+ @@r = Confstruct::Configuration.new(:route => 'layers', :resource_name => 'layer')
+
+ def self.resource_name
+ @@r.resource_name
+ end
+
+ def self.create_method
+ :post
+ end
+
+ def self.update_method
+ :put
+ end
+
+ def self.root_xpath
+ "//#{@@r.route}/#{@@r.resource_name}"
+ end
+
+ def self.member_xpath
+ "//#{resource_name}"
+ end
+
+ def route
+ @@r.route
+ end
+
+ def message
+ builder = Nokogiri::XML::Builder.new do |xml|
+ xml.layer {
+ xml.enabled @enabled if enabled_changed?
+ xml.name @name
+ }
+ end
+ return builder.doc.to_xml
+ end
+
+ # @param [RGeoServer::Catalog] catalog
+ # @param [Hash] options
+ def initialize catalog, options
+ super({})
+ _run_initialize_callbacks do
+ @catalog = catalog
+ @name = options[:name].strip
+ end
+ @route = route
+ end
+
+ def resource
+ unless profile['resource'].empty?
+ data_type = profile['resource']['type']
+ workspace = profile['resource']['workspace']
+ name = profile['resource']['name']
+ store = profile['resource']['store']
+
+ case data_type
+ when 'coverage'
+ return RGeoServer::Coverage.new @catalog, :workspace => workspace, :coverage_store => store, :name => name
+ when 'featureType'
+ return RGeoServer::FeatureType.new @catalog, :workspace => workspace, :data_store => store, :name => name
+ else
+ nil
+ end
+ else
+ nil
+ end
+ end
+
+ def profile_xml_to_hash profile_xml
+ doc = profile_xml_to_ng profile_xml
+ name = doc.at_xpath('//name/text()').text.strip
+ link = doc.at_xpath('//resource//atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom").text.strip
+ workspace, _, store = link.match(/workspaces\/(.*?)\/(.*?)\/(.*?)\/(.*?)\/#{name}.xml$/).to_a[1,3]
+
+ h = {
+ "name" => name,
+ "path" => doc.at_xpath('//path/text()').to_s,
+ "defaultstyle" => doc.at_xpath('//defaultStyle/name/text()').to_s,
+ "styles" => doc.xpath('//styles/style/name/text()').collect{ |s| s.to_s},
+ "type" => doc.at_xpath('//type/text()').to_s,
+ "enabled" => doc.at_xpath('//enabled/text()').to_s,
+ "attribution" => {
+ "logoWidth" => doc.at_xpath('//attribution/logoWidth/text()').to_s,
+ "logoHeight" => doc.at_xpath('//attribution/logoHeight/text()').to_s
+ },
+ "resource" => {
+ "type" => doc.at_xpath('//resource/@class').to_s,
+ "name" => doc.at_xpath('//resource/name').to_s,
+ "store" => store,
+ "workspace" => workspace
+ },
+ "metadata" => doc.xpath('//metadata/entry').inject({}){ |h, e| h.merge(e['key']=> e.text.to_s) }
+ }.freeze
+ h
+ end
+
+ end
+end
View
23 lib/rgeoserver/resource.rb
@@ -131,28 +131,9 @@ def profile= profile_xml
def profile_xml_to_ng profile_xml
Nokogiri::XML(profile_xml).xpath(self.class.member_xpath)
end
-
+
def profile_xml_to_hash profile_xml
- doc = profile_xml_to_ng profile_xml
- h = {'name' => doc.at_xpath('//name').text.strip, 'enabled' => @enabled }
- doc.xpath('//atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
- target = l.text.match(/([a-zA-Z]+)\.xml$/)[1]
- if !target.nil? && target != l.parent.parent.name.to_s.downcase
- begin
- h[l.parent.parent.name.to_s] << target
- rescue
- h[l.parent.parent.name.to_s] = []
- end
- else
- h[l.parent.parent.name.to_s] = begin
- response = @catalog.fetch_url l.text
- Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text }
- rescue RestClient::ResourceNotFound
- []
- end.freeze
- end
- }
- h
+ raise NotImplementedError
end
end
View
5 lib/rgeoserver/wmsstore.rb
@@ -99,6 +99,11 @@ def catalog= val
catalog_will_change! unless val == @catalog
@catalog = val
end
+
+ def profile_xml_to_hash profile_xml
+ doc = profile_xml_to_ng profile_xml
+ return {'name' => doc.at_xpath('//name').text.strip, 'enabled' => @enabled }
+ end
end
end
View
23 lib/rgeoserver/workspace.rb
@@ -68,5 +68,28 @@ def wms_stores &block
self.class.list WmsStore, @catalog, profile['wmsStores'], {:workspace => self}, check_remote = true, &block
end
+ def profile_xml_to_hash profile_xml
+ doc = profile_xml_to_ng profile_xml
+ h = {'name' => doc.at_xpath('//name').text.strip, 'enabled' => @enabled }
+ doc.xpath('//atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
+ target = l.text.match(/([a-zA-Z]+)\.xml$/)[1]
+ if !target.nil? && target != l.parent.parent.name.to_s.downcase
+ begin
+ h[l.parent.parent.name.to_s] << target
+ rescue
+ h[l.parent.parent.name.to_s] = []
+ end
+ else
+ h[l.parent.parent.name.to_s] = begin
+ response = @catalog.fetch_url l.text
+ Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text }
+ rescue RestClient::ResourceNotFound
+ []
+ end.freeze
+ end
+ }
+ h
+ end
+
end
end
View
10 spec/lib/integration_test_spec.rb
@@ -7,6 +7,7 @@
@catalog = RGeoServer.catalog
end
+
context "Workspaces" do
it "should list workspaces" do
@catalog.get_workspaces.each{ |obj|
@@ -73,6 +74,14 @@
end
end
+ context "Layers" do
+ it "shoult list layers" do
+ @catalog.get_layers.each { |l|
+ l.profile.should_not be_empty
+ }
+ end
+ end
+
context "Stores" do
before :all do
@ws = RGeoServer::Workspace.new @catalog, :name => 'test_workspace_for_stores'
@@ -114,6 +123,7 @@
ds.delete
end
end
+
context "CoverageStores" do
it "should create a coverage store under existing workspace, update and delete it right after" do
cs = RGeoServer::CoverageStore.new @catalog, :workspace => @ws, :name => 'test_coverage_store'

0 comments on commit 2ef85ea

Please sign in to comment.
Something went wrong with that request. Please try again.