rgeoserver 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+
2
+ module RGeoServer
3
+
4
+ class CoverageStore < ResourceInfo
5
+
6
+ OBJ_ATTRIBUTES = {:catalog => 'catalog', :workspace => 'workspace', :url => 'url', :data_type => 'type', :name => 'name', :enabled => 'enabled', :description => 'description'}
7
+ OBJ_DEFAULT_ATTRIBUTES = {:catalog => nil, :workspace => nil, :url => '', :data_type => 'GeoTIFF', :name => nil, :enabled => true, :description=>nil}
8
+ define_attribute_methods OBJ_ATTRIBUTES.keys
9
+ update_attribute_accessors OBJ_ATTRIBUTES
10
+
11
+ @@r = Confstruct::Configuration.new(
12
+ #:route => "workspaces/%s/coveragestores",
13
+ :route => "workspaces/%s/coveragestores/%s",
14
+ #:root => "coverageStores",
15
+ :root => "coverageStore",
16
+ :resource_name => "coverageStore"
17
+ )
18
+
19
+ def self.root
20
+ @@r.root
21
+ end
22
+
23
+ def self.method
24
+ :put
25
+ end
26
+
27
+ def self.resource_name
28
+ @@r.resource_name
29
+ end
30
+
31
+ def self.root_xpath
32
+ "//#{root}/#{resource_name}"
33
+ end
34
+
35
+ def self.member_xpath
36
+ "//#{resource_name}"
37
+ end
38
+
39
+ def route
40
+ #@@r.route % @workspace.name
41
+ @@r.route % [@workspace.name , @name]
42
+ end
43
+
44
+ def message
45
+ builder = Nokogiri::XML::Builder.new do |xml|
46
+ xml.coverageStore {
47
+ xml.name @name
48
+ xml.enabled profile['enabled']
49
+ xml.type_ @data_type if data_type_changed?
50
+ xml.description @description if description_changed?
51
+ xml.url @url if url_changed?
52
+ }
53
+ end
54
+ return builder.doc.to_xml
55
+ end
56
+
57
+ # @param [RGeoServer::Catalog] catalog
58
+ # @param [RGeoServer::Workspace|String] workspace
59
+ # @param [String] name
60
+ def initialize catalog, options
61
+ super({})
62
+ _run_initialize_callbacks do
63
+ @catalog = catalog
64
+ workspace = options[:workspace] || 'default'
65
+ if workspace.instance_of? String
66
+ @workspace = @catalog.get_workspace(workspace)
67
+ elsif workspace.instance_of? Workspace
68
+ @workspace = workspace
69
+ else
70
+ raise "Not a valid workspace"
71
+ end
72
+ @name = options[:name].strip
73
+ @route = route
74
+ end
75
+ end
76
+
77
+ def coverages
78
+ profile[:coverages].collect{ |name|
79
+ Coverage.new @catalog, :workspace => @workspace, :coverage_store => self, :name => name if name
80
+ }
81
+ end
82
+
83
+ def profile_xml_to_ng1 profile_xml
84
+ Nokogiri::XML(profile_xml).xpath(self.member_xpath)
85
+ end
86
+
87
+ def profile_xml_to_hash profile_xml
88
+ doc = profile_xml_to_ng profile_xml
89
+ {
90
+ 'name' => doc.at_xpath('//name').text.strip,
91
+ 'workspace' => @workspace.name,
92
+ 'type' => doc.at_xpath('//type/text()').to_s,
93
+ 'enabled' => doc.at_xpath('//enabled/text()').to_s,
94
+ 'description' => doc.at_xpath('//description/text()').to_s,
95
+ 'url' => doc.at_xpath('//url/text()').to_s
96
+ }
97
+ end
98
+
99
+ def profile_xml_to_hash1 profile_xml
100
+ doc = profile_xml_to_ng profile_xml
101
+ h = {:name => doc.at_xpath('//name').text.strip, :workspace => @workspace.name, :coverages => [] }
102
+ doc.xpath('//coverages/atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
103
+ h[:coverages] << {
104
+ :name => l.parent.parent.at_xpath('//name/text()').to_s,
105
+ :type => l.parent.parent.at_xpath('//type/text()').to_s,
106
+ :enabled => l.parent.parent.at_xpath('//enabled/text()').to_s,
107
+ :description => l.parent.parent.at_xpath('//description/text()').to_s,
108
+ :url => l.parent.parent.at_xpath('//url/text()').to_s
109
+ }
110
+ }
111
+ h
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,111 @@
1
+
2
+ module RGeoServer
3
+
4
+ class CoverageStore < ResourceInfo
5
+
6
+ OBJ_ATTRIBUTES = {:catalog => 'catalog', :workspace => 'workspace', :url => 'url', :data_type => 'type', :name => 'name', :enabled => 'enabled', :description => 'description'}
7
+ OBJ_DEFAULT_ATTRIBUTES = {:catalog => nil, :workspace => nil, :url => '', :data_type => 'GeoTIFF', :name => nil, :enabled => true, :description=>nil}
8
+ define_attribute_methods OBJ_ATTRIBUTES.keys
9
+ update_attribute_accessors OBJ_ATTRIBUTES
10
+
11
+ @@r = Confstruct::Configuration.new(
12
+ :route => "workspaces/%s/coveragestores",
13
+ :root => "coverageStores",
14
+ :resource_name => "coverageStore"
15
+ )
16
+
17
+ def self.root
18
+ @@r.root
19
+ end
20
+
21
+ def self.method
22
+ :put
23
+ end
24
+
25
+ def self.resource_name
26
+ @@r.resource_name
27
+ end
28
+
29
+ def self.root_xpath
30
+ "//#{root}/#{resource_name}"
31
+ end
32
+
33
+ def self.member_xpath
34
+ "//#{resource_name}"
35
+ end
36
+
37
+ def route
38
+ @@r.route % @workspace.name
39
+ end
40
+
41
+ def message
42
+ builder = Nokogiri::XML::Builder.new do |xml|
43
+ xml.coverageStore {
44
+ xml.name @name
45
+ xml.enabled profile['enabled']
46
+ xml.type_ @data_type if data_type_changed?
47
+ xml.description @description if description_changed?
48
+ xml.url @url if url_changed?
49
+ }
50
+ end
51
+ @message = builder.doc.to_xml
52
+ end
53
+
54
+ # @param [RGeoServer::Catalog] catalog
55
+ # @param [RGeoServer::Workspace|String] workspace
56
+ # @param [String] name
57
+ def initialize catalog, options
58
+ super({})
59
+ _run_initialize_callbacks do
60
+ @catalog = catalog
61
+ workspace = options[:workspace] || 'default'
62
+ if workspace.instance_of? String
63
+ @workspace = @catalog.get_workspace(workspace)
64
+ elsif workspace.instance_of? Workspace
65
+ @workspace = workspace
66
+ else
67
+ raise "Not a valid workspace"
68
+ end
69
+ @name = options[:name].strip
70
+ @route = route
71
+ end
72
+ end
73
+
74
+ def coverages
75
+ profile["coverages"].collect{ |name|
76
+ Coverage.new @catalog, :workspace => @workspace, :coverage_store => self, :name => name if name
77
+ }
78
+ end
79
+
80
+ def profile_xml_to_ng1 profile_xml
81
+ Nokogiri::XML(profile_xml).xpath(self.member_xpath)
82
+ end
83
+
84
+ def profile_xml_to_hash2 profile_xml
85
+ doc = profile_xml_to_ng profile_xml
86
+ {
87
+ 'name' => doc.at_xpath('//name').text.strip,
88
+ 'workspace' => @workspace.name,
89
+ 'type' => doc.at_xpath('//type/text()').to_s,
90
+ 'enabled' => doc.at_xpath('//enabled/text()').to_s,
91
+ 'description' => doc.at_xpath('//description/text()').to_s,
92
+ 'url' => doc.at_xpath('//url/text()').to_s
93
+ }
94
+ end
95
+
96
+ def profile_xml_to_hash1 profile_xml
97
+ doc = profile_xml_to_ng profile_xml
98
+ h = {:name => doc.at_xpath('//name').text.strip, :workspace => @workspace.name, :coverages => [] }
99
+ doc.xpath('//coverages/atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
100
+ h[:coverages] << {
101
+ :name => l.parent.parent.at_xpath('//name/text()').to_s,
102
+ :type => l.parent.parent.at_xpath('//type/text()').to_s,
103
+ :enabled => l.parent.parent.at_xpath('//enabled/text()').to_s,
104
+ :description => l.parent.parent.at_xpath('//description/text()').to_s,
105
+ :url => l.parent.parent.at_xpath('//url/text()').to_s
106
+ }
107
+ }
108
+ h
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,110 @@
1
+
2
+ module RGeoServer
3
+
4
+ class DataStore < ResourceInfo
5
+
6
+ OBJ_ATTRIBUTES = {:enabled => "enabled", :catalog => "catalog", :workspace => "workspace", :name => "name", :connection_parameters => "connectionParameters"}
7
+ OBJ_DEFAULT_ATTRIBUTES = {:enabled => true, :catalog => nil, :workspace => nil, :name => nil, :connection_parameters => {}}
8
+ define_attribute_methods OBJ_ATTRIBUTES.keys
9
+ update_attribute_accessors OBJ_ATTRIBUTES
10
+
11
+ attr_accessor :message
12
+
13
+ @@r = Confstruct::Configuration.new(
14
+ :route => "workspaces/%s/datastores",
15
+ :root => "dataStores",
16
+ :resource_name => "dataStore"
17
+ )
18
+
19
+ def self.root
20
+ @@r.root
21
+ end
22
+
23
+ def self.method
24
+ :put
25
+ end
26
+
27
+ def self.resource_name
28
+ @@r.resource_name
29
+ end
30
+
31
+ def self.root_xpath
32
+ "//#{root}/#{resource_name}"
33
+ end
34
+
35
+ def self.member_xpath
36
+ "//#{resource_name}"
37
+ end
38
+
39
+ def route
40
+ @@r.route % @workspace.name
41
+ end
42
+
43
+ def update_route
44
+ "#{route}/#{@name}"
45
+ end
46
+
47
+ def message
48
+ builder = Nokogiri::XML::Builder.new do |xml|
49
+ xml.dataStore {
50
+ xml.enabled 'true'
51
+ xml.name @name
52
+ xml.connectionParameters { # this could be empty
53
+ @connection_parameters.each_pair { |k,v|
54
+ xml.entry(:key => k) {
55
+ xml.text v
56
+ }
57
+ } unless @connection_parameters.empty?
58
+ }
59
+ }
60
+ end
61
+ builder.doc.to_xml
62
+ end
63
+
64
+ # @param [RGeoServer::Catalog] catalog
65
+ # @param [RGeoServer::Workspace|String] workspace
66
+ # @param [String] name
67
+ def initialize catalog, options
68
+ super({})
69
+ _run_initialize_callbacks do
70
+ @catalog = catalog
71
+ workspace = options[:workspace] || 'default'
72
+ if workspace.instance_of? String
73
+ @workspace = @catalog.get_workspace(workspace)
74
+ elsif workspace.instance_of? Workspace
75
+ @workspace = workspace
76
+ else
77
+ raise "Not a valid workspace"
78
+ end
79
+ @name = options[:name].strip
80
+ @connection_parameters = options[:connection_parameters] || {}
81
+ @route = route
82
+ end
83
+ end
84
+
85
+ def featuretypes
86
+ profile["featureTypes"].collect{ |name|
87
+ FeatureType.new @catalog, :workspace => @workspace, :data_store => self, :name => name
88
+ }
89
+ end
90
+
91
+ def profile_xml_to_hash profile_xml
92
+ doc = profile_xml_to_ng profile_xml
93
+ h = {
94
+ "name" => doc.at_xpath('//name').text.strip,
95
+ "enabled" => doc.at_xpath('//enabled/text()').to_s,
96
+ "connectionParameters" => doc.xpath('//connectionParameters/entry').inject({}){ |h, e| h.merge(e['key']=> e.text.to_s) }
97
+ }
98
+ doc.xpath('//featureTypes/atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
99
+ h["featureTypes"] = begin
100
+ response = @catalog.fetch_url l.text
101
+ Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text }
102
+ rescue RestClient::ResourceNotFound
103
+ []
104
+ end.freeze
105
+
106
+ }
107
+ h
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,97 @@
1
+
2
+ module RGeoServer
3
+
4
+ class DataStores < ResourceInfo
5
+
6
+ OBJ_ATTRIBUTES = {:enabled => "enabled", :catalog => "catalog", :workspace => "workspace", :name => "name"}
7
+ OBJ_DEFAULT_ATTRIBUTES = {:enabled => true, :catalog => nil, :workspace => nil, :name => nil, }
8
+ define_attribute_methods OBJ_ATTRIBUTES.keys
9
+ update_attribute_accessors OBJ_ATTRIBUTES
10
+
11
+ @@r = Confstruct::Configuration.new(
12
+ :route => "workspaces/%s/datastores",
13
+ :root => "dataStores",
14
+ :resource_name => "dataStore"
15
+ )
16
+
17
+ def self.root
18
+ @@r.root
19
+ end
20
+
21
+ def self.method
22
+ :put
23
+ end
24
+
25
+ def self.resource_name
26
+ @@r.resource_name
27
+ end
28
+
29
+ def self.root_xpath
30
+ "//#{root}/#{resource_name}"
31
+ end
32
+
33
+ def self.member_xpath
34
+ "//#{resource_name}"
35
+ end
36
+
37
+ def route
38
+ @@r.route % @workspace.name
39
+ end
40
+
41
+ def message
42
+ builder = Nokogiri::XML::Builder.new do |xml|
43
+ xml.dataStore {
44
+ xml.enabled @enabled
45
+ xml.name @name
46
+ }
47
+ end
48
+ return builder.doc.to_xml
49
+ end
50
+
51
+ # @param [RGeoServer::Catalog] catalog
52
+ # @param [RGeoServer::Workspace|String] workspace
53
+ # @param [String] name
54
+ def initialize catalog, options
55
+ super({})
56
+ _run_initialize_callbacks do
57
+ @catalog = catalog
58
+ workspace = options[:workspace] || 'default'
59
+ if workspace.instance_of? String
60
+ @workspace = @catalog.get_workspace(workspace)
61
+ elsif workspace.instance_of? Workspace
62
+ @workspace = workspace
63
+ else
64
+ raise "Not a valid workspace"
65
+ end
66
+ @name = options[:name].strip
67
+ @connection_parameters = options[:connection_parameters] || {}
68
+ @route = route
69
+ end
70
+ end
71
+
72
+ def data_stores
73
+ profile['dataStores'].collect{ |name|
74
+ DataStore.new @catalog, :workspace => @workspace, :data_store => self, :name => name
75
+ }
76
+ end
77
+
78
+ def profile_xml_to_hash1 profile_xml
79
+ doc = profile_xml_to_ng profile_xml
80
+ h = {
81
+ "name" => doc.at_xpath('//name').text.strip,
82
+ "enabled" => doc.at_xpath('//enabled/text()').to_s,
83
+ "connectionParameters" => doc.xpath('//connectionParameters/entry').collect{ |e| {e['key'].to_sym => e.text.to_s} }
84
+ }
85
+ doc.xpath('//featureTypes/atom:link/@href', "xmlns:atom"=>"http://www.w3.org/2005/Atom" ).each{ |l|
86
+ h[:featuretypes] = begin
87
+ response = @catalog.fetch_url l.text
88
+ Nokogiri::XML(response).xpath('//name/text()').collect{ |a| a.text }
89
+ rescue RestClient::ResourceNotFound
90
+ []
91
+ end.freeze
92
+
93
+ }
94
+ h
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,136 @@
1
+
2
+ module RGeoServer
3
+
4
+ class FeatureType < ResourceInfo
5
+
6
+ define_attribute_methods [:catalog, :workspace, :data_store, :name]
7
+
8
+ @@r = Confstruct::Configuration.new(
9
+ :route => "workspaces/%s/datastores/%s/featuretypes",
10
+ :root => "featureTypes",
11
+ :resource_name => "featureType"
12
+ )
13
+
14
+ def self.root
15
+ @@r.root
16
+ end
17
+
18
+ def self.method
19
+ :put
20
+ end
21
+
22
+ def self.resource_name
23
+ @@r.resource_name
24
+ end
25
+
26
+ def self.root_xpath
27
+ "//#{root}/#{resource_name}"
28
+ end
29
+
30
+ def self.member_xpath
31
+ "//#{resource_name}"
32
+ end
33
+
34
+ def route
35
+ @@r.route % [@workspace.name , @data_store.name ]
36
+ end
37
+
38
+ def xml options = nil
39
+ <<-ds
40
+ <dataStore>
41
+ <enabled>true</enabled>
42
+ <name>#{name}</name>
43
+ <workspace><name>#{workspace_name}</name></workspace>
44
+ <connectionParameters>
45
+ <entry key="url">file:data/shapefiles/states.shp</entry>
46
+ <entry key="namespace">http://www.openplans.org/topp</entry>
47
+ </connectionParameters>
48
+ <__default>false</__default>
49
+ <featureTypes>
50
+ <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/topp/datastores/states_shapefile/featuretypes.xml" type="application/xml"/>
51
+ </featureTypes>
52
+ </dataStore>
53
+ ds
54
+ end
55
+
56
+ def name
57
+ @name
58
+ end
59
+
60
+ def workspace
61
+ @workspace
62
+ end
63
+
64
+ def data_store
65
+ @data_store
66
+ end
67
+
68
+ def catalog
69
+ @catalog
70
+ end
71
+
72
+ def workspace_name
73
+ @workspace.name
74
+ end
75
+
76
+ def data_store_name
77
+ @data_store.name
78
+ end
79
+
80
+ # @param [RGeoServer::Catalog] catalog
81
+ # @param [Hash] options
82
+ def initialize catalog, options
83
+ super({})
84
+ _run_initialize_callbacks do
85
+ @catalog = catalog
86
+ workspace = options[:workspace] || 'default'
87
+ if workspace.instance_of? String
88
+ @workspace = @catalog.get_workspace(workspace)
89
+ elsif workspace.instance_of? Workspace
90
+ @workspace = workspace
91
+ else
92
+ raise "Not a valid workspace"
93
+ end
94
+ data_store = options[:data_store]
95
+ if data_store.instance_of? String
96
+ @data_store = DataStore.new @catalog, :workspace => @workspace, :name => data_store
97
+ elsif data_store.instance_of? DataStore
98
+ @data_store = data_store
99
+ else
100
+ raise "Not a valid data store"
101
+ end
102
+
103
+ @name = options[:name].strip
104
+ @enabled = options[:enabled] || true
105
+ @route = route
106
+ end
107
+ end
108
+
109
+ def name= val
110
+ name_will_change! unless val == @name
111
+ @name = val
112
+ end
113
+
114
+ def workspace= val
115
+ workspace_will_change! unless val == @workspace
116
+ @workspace = val
117
+ end
118
+
119
+ def catalog= val
120
+ catalog_will_change! unless val == @catalog
121
+ @catalog = val
122
+ end
123
+
124
+ def profile_xml_to_hash profile_xml
125
+ doc = profile_xml_to_ng profile_xml
126
+ h = {
127
+ :name => doc.at_xpath('//name').text.strip,
128
+ :workspace => workspace_name,
129
+ :nativeName => doc.at_xpath('//nativeName').text.to_s
130
+ }.freeze
131
+ h
132
+ end
133
+
134
+
135
+ end
136
+ end