Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java @ 3918:2fdbe78a8fc2
Fixed various projection issues during map creation.
flys-artifacts/trunk@5598 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 26 Sep 2012 08:00:44 +0000 |
parents | b0ba96bbf01d |
children | 9fac337192c9 |
comparison
equal
deleted
inserted
replaced
3917:1ff257ab38ca | 3918:2fdbe78a8fc2 |
---|---|
40 | 40 |
41 private static final Logger logger = Logger.getLogger(WMSDBArtifact.class); | 41 private static final Logger logger = Logger.getLogger(WMSDBArtifact.class); |
42 | 42 |
43 public static final Pattern DB_URL_PATTERN = | 43 public static final Pattern DB_URL_PATTERN = |
44 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z]+)"); | 44 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z]+)"); |
45 | |
46 public static final Pattern DB_PSQL_URL_PATTERN = | |
47 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z0-9]+)"); | |
45 | 48 |
46 | 49 |
47 @Override | 50 @Override |
48 public void setup( | 51 public void setup( |
49 String identifier, | 52 String identifier, |
146 | 149 |
147 String name = type + "-" + artifact.identifier(); | 150 String name = type + "-" + artifact.identifier(); |
148 | 151 |
149 facet.addLayer(name); | 152 facet.addLayer(name); |
150 facet.setExtent(getExtent()); | 153 facet.setExtent(getExtent()); |
154 facet.setOriginalExtent(getExtent(true)); | |
151 facet.setSrid(getSrid()); | 155 facet.setSrid(getSrid()); |
152 facet.setData(getDataString()); | 156 facet.setData(getDataString()); |
153 facet.setFilter(getFilter()); | 157 facet.setFilter(getFilter()); |
154 facet.setGeometryType(getGeometryType()); | 158 facet.setGeometryType(getGeometryType()); |
155 facet.setConnection(getConnection()); | 159 facet.setConnection(getConnection()); |
177 | 181 |
178 logger.debug("Parse connection url: " + url); | 182 logger.debug("Parse connection url: " + url); |
179 | 183 |
180 Matcher m = DB_URL_PATTERN.matcher(url); | 184 Matcher m = DB_URL_PATTERN.matcher(url); |
181 if (!m.matches()) { | 185 if (!m.matches()) { |
182 logger.warn("Could not parse Connection string."); | 186 logger.warn("Could not parse Connection string." + |
183 return null; | 187 "Try to parse PostgreSQL string."); |
188 // maybe this is a PostgreSQL connection... | |
189 return getPostgreSQLConnection(); | |
184 } | 190 } |
185 | 191 |
186 logger.debug("Groups for connection string: " + m.groupCount()); | 192 logger.debug("Groups for connection string: " + m.groupCount()); |
187 int groups = m.groupCount(); | 193 int groups = m.groupCount(); |
188 | 194 |
220 sb.append("password='" + pass + "'"); | 226 sb.append("password='" + pass + "'"); |
221 sb.append("sslmode=disable"); | 227 sb.append("sslmode=disable"); |
222 | 228 |
223 connection = sb.toString(); | 229 connection = sb.toString(); |
224 } | 230 } |
231 | |
232 logger.debug("Created connection: '" + connection + "'"); | |
233 | |
234 return connection; | |
235 } | |
236 | |
237 protected String getPostgreSQLConnection() { | |
238 SessionFactoryImpl sf = (SessionFactoryImpl) | |
239 SessionFactoryProvider.getSessionFactory(); | |
240 | |
241 String user = SessionFactoryProvider.getUser(sf); | |
242 String pass = SessionFactoryProvider.getPass(sf); | |
243 String url = SessionFactoryProvider.getURL(sf); | |
244 | |
245 Matcher m = DB_PSQL_URL_PATTERN.matcher(url); | |
246 if (!m.matches()) { | |
247 logger.warn("Could not parse PostgreSQL Connection string."); | |
248 return null; | |
249 } | |
250 | |
251 int groups = m.groupCount(); | |
252 logger.debug("Groups for PostgreSQL connection string: " + groups); | |
253 | |
254 if (logger.isDebugEnabled()) { | |
255 for (int i = 0; i <= groups; i++) { | |
256 logger.debug("Group " + i + ": " + m.group(i)); | |
257 } | |
258 } | |
259 | |
260 String connection = null; | |
261 | |
262 if (groups < 4) { | |
263 logger.warn("Could only partially parse connection string."); | |
264 return null; | |
265 } | |
266 | |
267 String host = m.group(2); | |
268 String port = m.group(3); | |
269 String db = m.group(4); | |
270 | |
271 StringBuilder sb = new StringBuilder(); | |
272 sb.append("dbname=" + db); | |
273 sb.append(" host='" + host + "'"); | |
274 sb.append(" port=" + port); | |
275 sb.append(" user=" + user); | |
276 sb.append(" password='" + pass + "'"); | |
277 sb.append(" sslmode=disable"); | |
278 | |
279 connection = sb.toString(); | |
225 | 280 |
226 logger.debug("Created connection: '" + connection + "'"); | 281 logger.debug("Created connection: '" + connection + "'"); |
227 | 282 |
228 return connection; | 283 return connection; |
229 } | 284 } |
307 | 362 |
308 FileTools.deleteRecursive(dir); | 363 FileTools.deleteRecursive(dir); |
309 MapfileGenerator.getInstance().update(); | 364 MapfileGenerator.getInstance().update(); |
310 } | 365 } |
311 } | 366 } |
367 | |
368 /** | |
369 * This method returns the extent of a DB layer in the projection of the | |
370 * database. | |
371 * | |
372 * @return the extent of the DB layer in the projection of the database. | |
373 */ | |
374 protected Envelope getExtent() { | |
375 return getExtent(false); | |
376 } | |
312 | 377 |
313 | 378 |
314 protected abstract String getFacetType(); | 379 protected abstract String getFacetType(); |
315 | 380 |
316 protected abstract String getUrl(); | 381 protected abstract String getUrl(); |
317 | 382 |
318 protected abstract String getSrid(); | 383 protected abstract String getSrid(); |
319 | 384 |
320 protected abstract Envelope getExtent(); | 385 /** |
386 * This method returns the extent of the DB layer. The projection of the | |
387 * extent depends on the <i>reproject</i> parameter. If reproject is set, | |
388 * the extent is reprojected into the original projection which is | |
389 * specified in the configuration. Otherwise, the projection of the | |
390 * database is used. | |
391 * | |
392 * @param reproject True, to reproject the extent into the projection | |
393 * specified in the configuration. | |
394 * | |
395 * @return the extent of the database layer. | |
396 */ | |
397 protected abstract Envelope getExtent(boolean reproject); | |
321 | 398 |
322 protected abstract String getFilter(); | 399 protected abstract String getFilter(); |
323 | 400 |
324 protected abstract String getDataString(); | 401 protected abstract String getDataString(); |
325 | 402 |