diff 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
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Sep 26 07:36:28 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WMSDBArtifact.java	Wed Sep 26 08:00:44 2012 +0000
@@ -42,6 +42,9 @@
 
     public static final Pattern DB_URL_PATTERN =
         Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z]+)");
+    
+    public static final Pattern DB_PSQL_URL_PATTERN =
+        Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([a-zA-Z0-9]+)");
 
 
     @Override
@@ -148,6 +151,7 @@
 
             facet.addLayer(name);
             facet.setExtent(getExtent());
+            facet.setOriginalExtent(getExtent(true));
             facet.setSrid(getSrid());
             facet.setData(getDataString());
             facet.setFilter(getFilter());
@@ -179,8 +183,10 @@
 
             Matcher m = DB_URL_PATTERN.matcher(url);
             if (!m.matches()) {
-                logger.warn("Could not parse Connection string.");
-                return null;
+                logger.warn("Could not parse Connection string." +
+                	"Try to parse PostgreSQL string.");
+                // maybe this is a PostgreSQL connection...
+                return getPostgreSQLConnection();
             }
 
             logger.debug("Groups for connection string: " + m.groupCount());
@@ -227,6 +233,55 @@
 
             return connection;
         }
+        
+        protected String getPostgreSQLConnection() {
+            SessionFactoryImpl sf = (SessionFactoryImpl)
+                SessionFactoryProvider.getSessionFactory();
+            
+            String user = SessionFactoryProvider.getUser(sf);
+            String pass = SessionFactoryProvider.getPass(sf);
+            String url  = SessionFactoryProvider.getURL(sf);
+            
+            Matcher m = DB_PSQL_URL_PATTERN.matcher(url);
+            if (!m.matches()) {
+                logger.warn("Could not parse PostgreSQL Connection string.");
+                return null;
+            }
+
+            int groups = m.groupCount();
+            logger.debug("Groups for PostgreSQL connection string: " + groups);
+
+            if (logger.isDebugEnabled()) {
+                for (int i = 0; i <= groups; i++) {
+                    logger.debug("Group " + i + ": " + m.group(i));
+                }
+            }
+
+            String connection = null;
+
+            if (groups < 4) {
+                logger.warn("Could only partially parse connection string.");
+                return null;
+            }
+
+            String host = m.group(2);
+            String port = m.group(3);
+            String db   = m.group(4);
+
+            StringBuilder sb = new StringBuilder();
+            sb.append("dbname=" + db);
+            sb.append(" host='" + host + "'");
+            sb.append(" port=" + port);
+            sb.append(" user=" + user);
+            sb.append(" password='" + pass + "'");
+            sb.append(" sslmode=disable");
+
+            connection = sb.toString();
+
+            logger.debug("Created connection: '" + connection + "'");
+
+            return connection;
+        }
 
         protected String getConnectionType() {
             return FLYSUtils.isUsingOracle() ? "oraclespatial" : "postgis";
@@ -309,6 +364,16 @@
                 MapfileGenerator.getInstance().update();
             }
         }
+        
+        /**
+         * This method returns the extent of a DB layer in the projection of the
+         * database.
+         * 
+         * @return the extent of the DB layer in the projection of the database.
+         */
+        protected Envelope getExtent() {
+            return getExtent(false);
+        }
 
 
         protected abstract String getFacetType();
@@ -317,7 +382,19 @@
 
         protected abstract String getSrid();
 
-        protected abstract Envelope getExtent();
+        /**
+         * This method returns the extent of the DB layer. The projection of the
+         * extent depends on the <i>reproject</i> parameter. If reproject is set,
+         * the extent is reprojected into the original projection which is
+         * specified in the configuration. Otherwise, the projection of the
+         * database is used.
+         * 
+         * @param reproject True, to reproject the extent into the projection
+         * specified in the configuration.
+         * 
+         * @return the extent of the database layer.
+         */
+        protected abstract Envelope getExtent(boolean reproject);
 
         protected abstract String getFilter();
 

http://dive4elements.wald.intevation.org