gb_mapfish_appserver 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/apps_controller.rb +9 -1
- data/app/controllers/apps_controller.rb~ +66 -0
- data/app/controllers/groups_users_controller.rb +73 -14
- data/app/controllers/print_controller.rb +97 -5
- data/app/controllers/print_controller.rb~ +95 -3
- data/app/controllers/registrations_controller.rb +11 -2
- data/app/controllers/topics_controller.rb +53 -2
- data/app/controllers/topics_controller.rb~ +133 -0
- data/app/controllers/wms_controller.rb +1 -1
- data/app/models/ability.rb +15 -6
- data/app/models/geo_model.rb +27 -4
- data/app/models/geo_model.rb~ +183 -0
- data/app/models/layer.rb +18 -14
- data/app/models/permission.rb +22 -18
- data/app/models/search_model.rb +5 -2
- data/app/models/tool.rb +1 -1
- data/app/models/topic.rb +46 -44
- data/app/models/topic.rb~ +182 -0
- data/app/models/user.rb +13 -1
- data/app/views/devise/mailer/reset_password_instructions.html.erb +11 -4
- data/app/views/groups_users/mails/_default.html.erb +3 -0
- data/app/views/registrations/confirm.html.erb +6 -0
- data/app/views/registrations/edit.html.erb +0 -9
- data/app/views/registrations/new.html.erb +17 -1
- data/lib/gb_mapfish_appserver/engine.rb +2 -0
- data/lib/gb_mapfish_appserver/version.rb +1 -1
- data/lib/generators/mapfish/install/templates/initializer.rb +6 -0
- data/lib/tasks/mapfile.rake +2 -2
- metadata +4475 -4476
- data/app/models/layer.rb~ +0 -283
@@ -1,7 +1,8 @@
|
|
1
1
|
class AppsController < ApplicationController
|
2
2
|
|
3
3
|
def show
|
4
|
-
|
4
|
+
@current_roles = current_roles.roles.collect(&:name)
|
5
|
+
|
5
6
|
@topic_name = params['topic'] || DEFAULT_TOPIC[@zone].name
|
6
7
|
@main_default_topic = DEFAULT_TOPIC[@zone].name
|
7
8
|
@offlayers = params['offlayers'].blank? ? [] : params['offlayers'].split(',')
|
@@ -16,6 +17,9 @@ class AppsController < ApplicationController
|
|
16
17
|
@selvalues = params['selvalues'].nil? ? [] : params['selvalues'].split('$')
|
17
18
|
|
18
19
|
@redlining = params['redlining'].blank? ? nil : params['redlining']
|
20
|
+
@centermarker = params['centermarker']
|
21
|
+
|
22
|
+
@markers = params['markers']
|
19
23
|
|
20
24
|
if params['locate']
|
21
25
|
rule = LOCATERULES[params['locate']]
|
@@ -27,6 +31,7 @@ class AppsController < ApplicationController
|
|
27
31
|
@seltopic = model.selection_topic
|
28
32
|
@sellayer = model.selection_layer
|
29
33
|
@selproperty = model.primary_key
|
34
|
+
@selscalerange = model.selection_scalerange
|
30
35
|
search_locs = model.search_locations(params['locations'])
|
31
36
|
model.locate(search_locs)
|
32
37
|
else
|
@@ -34,6 +39,7 @@ class AppsController < ApplicationController
|
|
34
39
|
@seltopic = @topic_name
|
35
40
|
@sellayer = layer.name
|
36
41
|
@selproperty = layer.feature_class.primary_key
|
42
|
+
@selscalerange = model.selection_scalerange
|
37
43
|
search_locs = params['locations'].split(',')
|
38
44
|
model.layer_locate(layer, rule.search_field, search_locs)
|
39
45
|
end
|
@@ -43,6 +49,8 @@ class AppsController < ApplicationController
|
|
43
49
|
#Selection
|
44
50
|
@selbbox = model.bbox(features)
|
45
51
|
@selvalues = features.collect {|f| f.send(model.primary_key) }
|
52
|
+
else
|
53
|
+
logger.info "no features found."
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class AppsController < ApplicationController
|
2
|
+
|
3
|
+
def show
|
4
|
+
logger.debug "Site: '#{@zone}'"
|
5
|
+
@current_roles = current_roles.roles.collect(&:name)
|
6
|
+
@topic_name = params['topic'] || DEFAULT_TOPIC[@zone].name
|
7
|
+
@main_default_topic = DEFAULT_TOPIC[@zone].name
|
8
|
+
@offlayers = params['offlayers'].blank? ? [] : params['offlayers'].split(',')
|
9
|
+
|
10
|
+
@scale = params['scale'].nil? ? DEFAULT_SCALE : params['scale'].to_i
|
11
|
+
@x = params['x'].nil? ? DEFAULT_X : params['x'].to_f
|
12
|
+
@y = params['y'].nil? ? DEFAULT_Y : params['y'].to_f
|
13
|
+
|
14
|
+
@seltopic = params['seltopic']
|
15
|
+
@sellayer = params['sellayer']
|
16
|
+
@selproperty = params['selproperty']
|
17
|
+
@selvalues = params['selvalues'].nil? ? [] : params['selvalues'].split('$')
|
18
|
+
|
19
|
+
@redlining = params['redlining'].blank? ? nil : params['redlining']
|
20
|
+
@centermarker = params['centermarker']
|
21
|
+
|
22
|
+
@markers = params['markers']
|
23
|
+
|
24
|
+
if params['locate']
|
25
|
+
rule = LOCATERULES[params['locate']]
|
26
|
+
if rule.nil?
|
27
|
+
logger.info "Locate rule not found: {params['locate']}"
|
28
|
+
else
|
29
|
+
model = rule.model.constantize
|
30
|
+
features = if rule.layer.nil?
|
31
|
+
@seltopic = model.selection_topic
|
32
|
+
@sellayer = model.selection_layer
|
33
|
+
@selproperty = model.primary_key
|
34
|
+
@selscalerange = model.selection_scalerange
|
35
|
+
search_locs = model.search_locations(params['locations'])
|
36
|
+
model.locate(search_locs)
|
37
|
+
else
|
38
|
+
layer = Layer.find_by_name(rule.layer)
|
39
|
+
@seltopic = @topic_name
|
40
|
+
@sellayer = layer.name
|
41
|
+
@selproperty = layer.feature_class.primary_key
|
42
|
+
@selscalerange = model.selection_scalerange
|
43
|
+
search_locs = params['locations'].split(',')
|
44
|
+
model.layer_locate(layer, rule.search_field, search_locs)
|
45
|
+
end
|
46
|
+
if features.present?
|
47
|
+
@x, @y, scale = model.map_center(features)
|
48
|
+
@scale = params['scale'].nil? ? scale : params['scale'].to_i
|
49
|
+
#Selection
|
50
|
+
@selbbox = model.bbox(features)
|
51
|
+
@selvalues = features.collect {|f| f.send(model.primary_key) }
|
52
|
+
else
|
53
|
+
logger.info "no features found."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
@selection_valid = !(@seltopic.nil? || @sellayer.nil? || @selproperty.nil? || @selvalues.empty?)
|
59
|
+
@app = params[:app]
|
60
|
+
|
61
|
+
session[:map_ts] = Time.now # Used for checking access to non-public WMS
|
62
|
+
|
63
|
+
render :action => @app, :layout => false
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
class GroupsUsersController < ApplicationController
|
2
3
|
#authorize_resource
|
4
|
+
before_filter :authenticate_user!
|
3
5
|
before_filter :accessible_groups
|
4
6
|
|
5
7
|
# GET /groups_users
|
6
8
|
# GET /groups_users.json
|
7
9
|
def index
|
8
|
-
@
|
10
|
+
@groups = admin_groups(@groups)
|
11
|
+
@groups_users = GroupsUser.where(:group_id => @groups).joins(:group, :user).order('groups.name,users.login')
|
9
12
|
respond_to do |format|
|
10
13
|
format.html # index.html.erb
|
11
14
|
format.json { render :json => @groups_users }
|
@@ -15,6 +18,7 @@ class GroupsUsersController < ApplicationController
|
|
15
18
|
# GET /groups_users/1
|
16
19
|
# GET /groups_users/1.json
|
17
20
|
def show
|
21
|
+
@groups = admin_groups(@groups)
|
18
22
|
@groups_user = GroupsUser.where(:group_id => @groups).find(params[:id])
|
19
23
|
|
20
24
|
respond_to do |format|
|
@@ -26,7 +30,9 @@ class GroupsUsersController < ApplicationController
|
|
26
30
|
# GET /groups_users/new
|
27
31
|
# GET /groups_users/new.json
|
28
32
|
def new
|
29
|
-
@
|
33
|
+
@group = @groups.find(params[:group])
|
34
|
+
raise CanCan::AccessDenied.new("Permission error") unless current_user.group_admin?(@group)
|
35
|
+
@groups_user = GroupsUser.new(:group => @group)
|
30
36
|
|
31
37
|
respond_to do |format|
|
32
38
|
format.html # new.html.erb
|
@@ -38,7 +44,9 @@ class GroupsUsersController < ApplicationController
|
|
38
44
|
|
39
45
|
# GET /groups_users/1/edit
|
40
46
|
def edit
|
47
|
+
@groups = admin_groups(@groups)
|
41
48
|
@groups_user = GroupsUser.where(:group_id => @groups).find(params[:id])
|
49
|
+
@mail_body = mail_body
|
42
50
|
rescue
|
43
51
|
raise CanCan::AccessDenied.new("Permission error")
|
44
52
|
end
|
@@ -46,22 +54,39 @@ class GroupsUsersController < ApplicationController
|
|
46
54
|
# POST /groups_users
|
47
55
|
# POST /groups_users.json
|
48
56
|
def create
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
@group = @groups.find(params[:groups_user][:group_id])
|
58
|
+
raise CanCan::AccessDenied.new("Permission error") unless current_user.group_admin?(@group)
|
59
|
+
@groups_user = GroupsUser.new(params[:groups_user])
|
60
|
+
|
61
|
+
user = User.find_by_email(params[:user_email])
|
62
|
+
if user.nil?
|
63
|
+
flash[:error] = "Kein Benutzer mit dieser E-Mail gefunden"
|
64
|
+
render :action => "new"
|
65
|
+
return
|
66
|
+
elsif @group.groups_users.where("groups_users.user_id = ?", user.id).any?
|
67
|
+
flash[:error] = "Benutzer gehört schon zu dieser Gruppe"
|
68
|
+
render :action => "new"
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
@groups_user.user = user
|
73
|
+
@groups_user.granted = true
|
74
|
+
|
75
|
+
respond_to do |format|
|
76
|
+
if @groups_user.save
|
77
|
+
format.html { redirect_to groups_users_url, :notice => 'Benutzer wurde erfolgreich zur Gruppe hinzugefügt.' }
|
78
|
+
format.json { render :json => @groups_user, :status => :created, :location => @groups_user }
|
79
|
+
else
|
80
|
+
format.html { render :action => "new" }
|
81
|
+
format.json { render :json => @groups_user.errors, :status => :unprocessable_entity }
|
82
|
+
end
|
83
|
+
end
|
60
84
|
end
|
61
85
|
|
62
86
|
# PUT /groups_users/1
|
63
87
|
# PUT /groups_users/1.json
|
64
88
|
def update
|
89
|
+
@groups = admin_groups(@groups)
|
65
90
|
@groups_user = GroupsUser.where(:group_id => @groups).find(params[:id])
|
66
91
|
|
67
92
|
respond_to do |format|
|
@@ -78,6 +103,7 @@ class GroupsUsersController < ApplicationController
|
|
78
103
|
# DELETE /groups_users/1
|
79
104
|
# DELETE /groups_users/1.json
|
80
105
|
def destroy
|
106
|
+
@groups = admin_groups(@groups)
|
81
107
|
@groups_user = GroupsUser.where(:group_id => @groups).find(params[:id])
|
82
108
|
@groups_user.destroy
|
83
109
|
|
@@ -87,10 +113,43 @@ class GroupsUsersController < ApplicationController
|
|
87
113
|
end
|
88
114
|
end
|
89
115
|
|
116
|
+
# registration of existing user from signup page
|
117
|
+
def register
|
118
|
+
@group = Group.find(params[:group][:requested_group]) if params[:group][:requested_group]
|
119
|
+
@groups_user = GroupsUser.where(:group_id => @group.id, :user_id => current_user.id).first_or_create
|
120
|
+
|
121
|
+
unless params[:group][:app_infos].blank?
|
122
|
+
# merge non-empty app_infos
|
123
|
+
new_app_infos = params[:group][:app_infos].reject {|key, value| value.blank? }
|
124
|
+
current_user.merge_app_infos(new_app_infos)
|
125
|
+
end
|
126
|
+
|
127
|
+
# send mail to group admins
|
128
|
+
Registrations.group_user_registration_email(
|
129
|
+
@group, current_user, edit_groups_user_url(@groups_user)
|
130
|
+
).deliver
|
131
|
+
|
132
|
+
redirect_to user_confirm_path
|
133
|
+
end
|
134
|
+
|
90
135
|
private
|
91
136
|
|
92
137
|
def accessible_groups
|
93
|
-
@groups = Group.accessible_by(current_ability)
|
138
|
+
@groups = Group.accessible_by(current_ability).order(:name)
|
139
|
+
end
|
140
|
+
|
141
|
+
# return groups where user is admin
|
142
|
+
def admin_groups(groups)
|
143
|
+
groups.reject {|g| !current_user.group_admin?(g)}
|
144
|
+
end
|
145
|
+
|
146
|
+
def mail_body
|
147
|
+
mail_body_file = File.join(Rails.root, 'app', 'views', 'groups_users', 'mails', "_#{@groups_user.group.name}.html.erb")
|
148
|
+
if File.exist?(mail_body_file)
|
149
|
+
"groups_users/mails/#{@groups_user.group.name}"
|
150
|
+
else
|
151
|
+
'groups_users/mails/default'
|
152
|
+
end
|
94
153
|
end
|
95
154
|
|
96
155
|
end
|
@@ -22,7 +22,7 @@ class PrintController < ApplicationController
|
|
22
22
|
@configFile = "#{Rails.root}/config/print.yml"
|
23
23
|
end
|
24
24
|
|
25
|
-
TMP_PREFIX = "/
|
25
|
+
TMP_PREFIX = "#{PRINT_TMP_PATH}/mfPrintTempFile"
|
26
26
|
TMP_SUFFIX = ".pdf"
|
27
27
|
TMP_PURGE_SECONDS = 600
|
28
28
|
|
@@ -91,6 +91,7 @@ class PrintController < ApplicationController
|
|
91
91
|
if style["externalGraphic"]
|
92
92
|
style["externalGraphic"].gsub!(LOCAL_GRAPHICS_HOST, '127.0.0.1')
|
93
93
|
style["externalGraphic"].gsub!(/^https:/, 'http:')
|
94
|
+
style["externalGraphic"].gsub!(/^\//, 'http://127.0.0.1/')
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
@@ -98,9 +99,12 @@ class PrintController < ApplicationController
|
|
98
99
|
# remove inaccessible layers
|
99
100
|
request.parameters["layers"] -= layers_to_delete
|
100
101
|
|
102
|
+
scales = []
|
101
103
|
request.parameters["pages"].each do |page|
|
102
104
|
# round center coordinates
|
103
105
|
page["center"].collect! {|coord| (coord * 100.0).round / 100.0 }
|
106
|
+
# round extent coordinates
|
107
|
+
page["extent"].collect! {|coord| (coord * 100.0).round / 100.0 } unless page["extent"].nil?
|
104
108
|
# add blank user strings if missing
|
105
109
|
page["user_title"] = " " if page["user_title"].blank?
|
106
110
|
page["user_comment"] = " " if page["user_comment"].blank?
|
@@ -109,15 +113,30 @@ class PrintController < ApplicationController
|
|
109
113
|
# disclaimer
|
110
114
|
topic = Topic.accessible_by(current_ability).where(:name => page["topic"]).first
|
111
115
|
page["disclaimer"] = topic.nil? ? Topic.default_print_disclaimer : topic.print_disclaimer
|
116
|
+
# scale
|
117
|
+
scales << page["scale"]
|
112
118
|
end
|
113
119
|
|
114
120
|
logger.info request.parameters.to_yaml
|
115
121
|
|
116
|
-
if
|
122
|
+
if request.parameters["report"]
|
123
|
+
# JasperReport
|
124
|
+
call_report(request)
|
125
|
+
elsif PRINT_URL.present?
|
126
|
+
# MapFish
|
127
|
+
# FIXME: add custom scales to config file
|
117
128
|
call_servlet(request)
|
118
129
|
else
|
130
|
+
# MapFish
|
119
131
|
#print-standalone
|
120
132
|
tempId = SecureRandom.random_number(2**31)
|
133
|
+
|
134
|
+
# use temp config file with added custom scales
|
135
|
+
print_config = File.read(@configFile)
|
136
|
+
print_config.gsub!(/scales:/, "scales:\n#{ scales.collect {|s| " - #{s.to_s}"}.join("\n") }")
|
137
|
+
config_file = TMP_PREFIX + tempId.to_s + "print.yaml"
|
138
|
+
File.open(config_file, "w") { |file| file << print_config }
|
139
|
+
|
121
140
|
temp = TMP_PREFIX + tempId.to_s + TMP_SUFFIX
|
122
141
|
cmd = baseCmd + " --output=" + temp
|
123
142
|
result = ""
|
@@ -141,8 +160,8 @@ class PrintController < ApplicationController
|
|
141
160
|
|
142
161
|
def show
|
143
162
|
output_format = params[:format]
|
163
|
+
type = nil
|
144
164
|
if OUTPUT_FORMATS.include?(output_format)
|
145
|
-
temp = TMP_PREFIX + params[:id] + ".#{output_format}"
|
146
165
|
case output_format
|
147
166
|
when "pdf"
|
148
167
|
type = 'application/x-pdf'
|
@@ -155,7 +174,25 @@ class PrintController < ApplicationController
|
|
155
174
|
when "gif"
|
156
175
|
type = 'image/gif'
|
157
176
|
end
|
177
|
+
end
|
178
|
+
is_mapfish_print_id = (params[:id] =~ /^[0-9]+$/)
|
179
|
+
if is_mapfish_print_id
|
180
|
+
temp = TMP_PREFIX + params[:id] + ".#{output_format}"
|
158
181
|
send_file temp, :type => type, :disposition => 'attachment', :filename => params[:id] + ".#{output_format}"
|
182
|
+
else
|
183
|
+
params['report'] = params[:id]
|
184
|
+
result = create_report(request)
|
185
|
+
if result.nil?
|
186
|
+
render :nothing => true, :status => 500
|
187
|
+
return
|
188
|
+
end
|
189
|
+
|
190
|
+
if result.kind_of? Net::HTTPSuccess
|
191
|
+
send_data result.body, :type => type, :disposition => 'attachment', :filename => "#{params[:report]}.pdf"
|
192
|
+
else
|
193
|
+
logger.info "#{result.code}: #{result.body}"
|
194
|
+
render :nothing => true, :status => result.code
|
195
|
+
end
|
159
196
|
end
|
160
197
|
end
|
161
198
|
|
@@ -169,7 +206,7 @@ class PrintController < ApplicationController
|
|
169
206
|
localwms = LOCAL_WMS.any? { |ref| uri.host =~ ref }
|
170
207
|
if localwms
|
171
208
|
topic = File.basename(uri.path)
|
172
|
-
localhost =
|
209
|
+
localhost = 'localhost' #TODO: site specific configuration
|
173
210
|
out = "http://#{localhost}#{use_cgi ? MAPSERV_CGI_URL : MAPSERV_URL}?MAP=#{MAPPATH}/#{@zone}/#{topic}.map&"
|
174
211
|
#out = "http://#{localhost}:#{request.port}/wms/#{topic}"
|
175
212
|
end
|
@@ -182,7 +219,7 @@ class PrintController < ApplicationController
|
|
182
219
|
|
183
220
|
def cleanupTempFiles
|
184
221
|
minTime = Time.now - TMP_PURGE_SECONDS;
|
185
|
-
OUTPUT_FORMATS.each do |output_format|
|
222
|
+
(OUTPUT_FORMATS + ["yaml"]).each do |output_format|
|
186
223
|
Dir.glob(TMP_PREFIX + "*." + output_format).each do |path|
|
187
224
|
if File.mtime(path) < minTime
|
188
225
|
File.delete(path)
|
@@ -240,4 +277,59 @@ class PrintController < ApplicationController
|
|
240
277
|
end
|
241
278
|
end
|
242
279
|
|
280
|
+
# forward to JasperReport
|
281
|
+
def create_report(request)
|
282
|
+
report = request.parameters["report"]
|
283
|
+
call_params = {
|
284
|
+
:j_username => JASPER_USER,
|
285
|
+
:j_password => JASPER_PASSWORD
|
286
|
+
}
|
287
|
+
if request.parameters["pages"]
|
288
|
+
page = request.parameters["pages"].first
|
289
|
+
%w(scale rotation base_url user_title user_comment).each do |mfparam|
|
290
|
+
call_params[mfparam.upcase] = page[mfparam]
|
291
|
+
end
|
292
|
+
call_params[:MAP_BBOX] = page["extent"].join(',')
|
293
|
+
call_params[:MAP_CENTER] = page["center"].join(',')
|
294
|
+
end
|
295
|
+
request.parameters.each do |name, val|
|
296
|
+
if name =~ /^REP_/
|
297
|
+
call_params[name] = val
|
298
|
+
end
|
299
|
+
end
|
300
|
+
pdfid = Time.now.strftime("%Y%m%d%H%M%S") + rand.to_s[2..4]
|
301
|
+
call_params['REP_PDFID'] = pdfid
|
302
|
+
report_url = "#{JASPER_URL}/#{report}.pdf?#{ call_params.to_param }"
|
303
|
+
|
304
|
+
begin
|
305
|
+
logger.info "Forward request: #{report_url}"
|
306
|
+
result = Net::HTTP.get_response(URI.parse(URI.decode(report_url)))
|
307
|
+
result["pdfid"] = pdfid
|
308
|
+
rescue => err
|
309
|
+
logger.info("#{err.class}: #{err.message}")
|
310
|
+
return nil
|
311
|
+
end
|
312
|
+
result
|
313
|
+
end
|
314
|
+
|
315
|
+
#Mapfish print comaptible report delivery
|
316
|
+
def call_report(request)
|
317
|
+
result = create_report(request)
|
318
|
+
if result.nil?
|
319
|
+
render :nothing => true, :status => 500
|
320
|
+
return
|
321
|
+
end
|
322
|
+
|
323
|
+
if result.kind_of? Net::HTTPSuccess
|
324
|
+
temp_id = SecureRandom.random_number(2**31)
|
325
|
+
temp = TMP_PREFIX + temp_id.to_s + TMP_SUFFIX
|
326
|
+
File.open(temp, 'w') {|f| f.write(result.body) }
|
327
|
+
|
328
|
+
render :json=>{ 'getURL' => url_for(:action=> 'show', :id=> temp_id) + ".pdf" }
|
329
|
+
else
|
330
|
+
logger.info "#{result.code}: #{result.body}"
|
331
|
+
render :nothing => true, :status => result.code
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
243
335
|
end
|
@@ -91,6 +91,7 @@ class PrintController < ApplicationController
|
|
91
91
|
if style["externalGraphic"]
|
92
92
|
style["externalGraphic"].gsub!(LOCAL_GRAPHICS_HOST, '127.0.0.1')
|
93
93
|
style["externalGraphic"].gsub!(/^https:/, 'http:')
|
94
|
+
style["externalGraphic"].gsub!(/^\//, 'http://127.0.0.1/')
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
@@ -98,9 +99,12 @@ class PrintController < ApplicationController
|
|
98
99
|
# remove inaccessible layers
|
99
100
|
request.parameters["layers"] -= layers_to_delete
|
100
101
|
|
102
|
+
scales = []
|
101
103
|
request.parameters["pages"].each do |page|
|
102
104
|
# round center coordinates
|
103
105
|
page["center"].collect! {|coord| (coord * 100.0).round / 100.0 }
|
106
|
+
# round extent coordinates
|
107
|
+
page["extent"].collect! {|coord| (coord * 100.0).round / 100.0 } unless page["extent"].nil?
|
104
108
|
# add blank user strings if missing
|
105
109
|
page["user_title"] = " " if page["user_title"].blank?
|
106
110
|
page["user_comment"] = " " if page["user_comment"].blank?
|
@@ -109,15 +113,30 @@ class PrintController < ApplicationController
|
|
109
113
|
# disclaimer
|
110
114
|
topic = Topic.accessible_by(current_ability).where(:name => page["topic"]).first
|
111
115
|
page["disclaimer"] = topic.nil? ? Topic.default_print_disclaimer : topic.print_disclaimer
|
116
|
+
# scale
|
117
|
+
scales << page["scale"]
|
112
118
|
end
|
113
119
|
|
114
120
|
logger.info request.parameters.to_yaml
|
115
121
|
|
116
|
-
if
|
122
|
+
if request.parameters["report"]
|
123
|
+
# JasperReport
|
124
|
+
call_report(request)
|
125
|
+
elsif PRINT_URL.present?
|
126
|
+
# MapFish
|
127
|
+
# FIXME: add custom scales to config file
|
117
128
|
call_servlet(request)
|
118
129
|
else
|
130
|
+
# MapFish
|
119
131
|
#print-standalone
|
120
132
|
tempId = SecureRandom.random_number(2**31)
|
133
|
+
|
134
|
+
# use temp config file with added custom scales
|
135
|
+
print_config = File.read(@configFile)
|
136
|
+
print_config.gsub!(/scales:/, "scales:\n#{ scales.collect {|s| " - #{s.to_s}"}.join("\n") }")
|
137
|
+
config_file = TMP_PREFIX + tempId.to_s + "print.yaml"
|
138
|
+
File.open(config_file, "w") { |file| file << print_config }
|
139
|
+
|
121
140
|
temp = TMP_PREFIX + tempId.to_s + TMP_SUFFIX
|
122
141
|
cmd = baseCmd + " --output=" + temp
|
123
142
|
result = ""
|
@@ -141,8 +160,8 @@ class PrintController < ApplicationController
|
|
141
160
|
|
142
161
|
def show
|
143
162
|
output_format = params[:format]
|
163
|
+
type = nil
|
144
164
|
if OUTPUT_FORMATS.include?(output_format)
|
145
|
-
temp = TMP_PREFIX + params[:id] + ".#{output_format}"
|
146
165
|
case output_format
|
147
166
|
when "pdf"
|
148
167
|
type = 'application/x-pdf'
|
@@ -155,7 +174,25 @@ class PrintController < ApplicationController
|
|
155
174
|
when "gif"
|
156
175
|
type = 'image/gif'
|
157
176
|
end
|
177
|
+
end
|
178
|
+
is_mapfish_print_id = (params[:id] =~ /^[0-9]+$/)
|
179
|
+
if is_mapfish_print_id
|
180
|
+
temp = TMP_PREFIX + params[:id] + ".#{output_format}"
|
158
181
|
send_file temp, :type => type, :disposition => 'attachment', :filename => params[:id] + ".#{output_format}"
|
182
|
+
else
|
183
|
+
params['report'] = params[:id]
|
184
|
+
result = create_report(request)
|
185
|
+
if result.nil?
|
186
|
+
render :nothing => true, :status => 500
|
187
|
+
return
|
188
|
+
end
|
189
|
+
|
190
|
+
if result.kind_of? Net::HTTPSuccess
|
191
|
+
send_data result.body, :type => type, :disposition => 'attachment', :filename => "#{params[:report]}.pdf"
|
192
|
+
else
|
193
|
+
logger.info "#{result.code}: #{result.body}"
|
194
|
+
render :nothing => true, :status => result.code
|
195
|
+
end
|
159
196
|
end
|
160
197
|
end
|
161
198
|
|
@@ -182,7 +219,7 @@ class PrintController < ApplicationController
|
|
182
219
|
|
183
220
|
def cleanupTempFiles
|
184
221
|
minTime = Time.now - TMP_PURGE_SECONDS;
|
185
|
-
OUTPUT_FORMATS.each do |output_format|
|
222
|
+
(OUTPUT_FORMATS + ["yaml"]).each do |output_format|
|
186
223
|
Dir.glob(TMP_PREFIX + "*." + output_format).each do |path|
|
187
224
|
if File.mtime(path) < minTime
|
188
225
|
File.delete(path)
|
@@ -240,4 +277,59 @@ class PrintController < ApplicationController
|
|
240
277
|
end
|
241
278
|
end
|
242
279
|
|
280
|
+
# forward to JasperReport
|
281
|
+
def create_report(request)
|
282
|
+
report = request.parameters["report"]
|
283
|
+
call_params = {
|
284
|
+
:j_username => JASPER_USER,
|
285
|
+
:j_password => JASPER_PASSWORD
|
286
|
+
}
|
287
|
+
if request.parameters["pages"]
|
288
|
+
page = request.parameters["pages"].first
|
289
|
+
%w(scale rotation base_url user_title user_comment).each do |mfparam|
|
290
|
+
call_params[mfparam.upcase] = page[mfparam]
|
291
|
+
end
|
292
|
+
call_params[:MAP_BBOX] = page["extent"].join(',')
|
293
|
+
call_params[:MAP_CENTER] = page["center"].join(',')
|
294
|
+
end
|
295
|
+
request.parameters.each do |name, val|
|
296
|
+
if name =~ /^REP_/
|
297
|
+
call_params[name] = val
|
298
|
+
end
|
299
|
+
end
|
300
|
+
pdfid = Time.now.strftime("%Y%m%d%H%M%S") + rand.to_s[2..4]
|
301
|
+
call_params['REP_PDFID'] = pdfid
|
302
|
+
report_url = "#{JASPER_URL}/#{report}.pdf?#{ call_params.to_param }"
|
303
|
+
|
304
|
+
begin
|
305
|
+
logger.info "Forward request: #{report_url}"
|
306
|
+
result = Net::HTTP.get_response(URI.parse(URI.decode(report_url)))
|
307
|
+
result["pdfid"] = pdfid
|
308
|
+
rescue => err
|
309
|
+
logger.info("#{err.class}: #{err.message}")
|
310
|
+
return nil
|
311
|
+
end
|
312
|
+
result
|
313
|
+
end
|
314
|
+
|
315
|
+
#Mapfish print comaptible report delivery
|
316
|
+
def call_report(request)
|
317
|
+
result = create_report(request)
|
318
|
+
if result.nil?
|
319
|
+
render :nothing => true, :status => 500
|
320
|
+
return
|
321
|
+
end
|
322
|
+
|
323
|
+
if result.kind_of? Net::HTTPSuccess
|
324
|
+
temp_id = SecureRandom.random_number(2**31)
|
325
|
+
temp = TMP_PREFIX + temp_id.to_s + TMP_SUFFIX
|
326
|
+
File.open(temp, 'w') {|f| f.write(result.body) }
|
327
|
+
|
328
|
+
render :json=>{ 'getURL' => url_for(:action=> 'show', :id=> temp_id) + ".pdf" }
|
329
|
+
else
|
330
|
+
logger.info "#{result.code}: #{result.body}"
|
331
|
+
render :nothing => true, :status => result.code
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
243
335
|
end
|