branch develop updated (f0bfb8a -> 515be56)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository echobase. See http://git.codelutin.com/echobase.git from f0bfb8a fixes #6053: On peut importer plusieurs fois les mêmes résultats voyage pour un même voyage new 515be56 fixes #6507: Impossible de voir la page des données spatiales The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 515be56c8c243d7038471958fb1104402c331277 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Jan 21 21:13:12 2015 +0100 fixes #6507: Impossible de voir la page des données spatiales Summary of changes: .../services/service/spatial/LizmapRepository.java | 31 +++++++------- .../service/spatial/LizmapRepositoryTest.java | 47 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 echobase-services/src/test/java/fr/ifremer/echobase/services/service/spatial/LizmapRepositoryTest.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository echobase. See http://git.codelutin.com/echobase.git commit 515be56c8c243d7038471958fb1104402c331277 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Jan 21 21:13:12 2015 +0100 fixes #6507: Impossible de voir la page des données spatiales --- .../services/service/spatial/LizmapRepository.java | 31 +++++++------- .../service/spatial/LizmapRepositoryTest.java | 47 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/LizmapRepository.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/LizmapRepository.java index abea447..8ca7a32 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/LizmapRepository.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/spatial/LizmapRepository.java @@ -42,6 +42,8 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Created on 1/14/15. @@ -102,13 +104,18 @@ public class LizmapRepository { } } + private static final String[] TO_REPLACE = new String[]{"-", "."}; + + private static final String[] REPLACEMENT_LIST = new String[]{"", ""}; + + private static final Pattern URL_PATTERN = Pattern.compile("jdbc:postgresql://([^:]+)(:(.+)){0,1}/(.+)"); + private final LizmapRepositoryConfiguration configuration; - private static final String START_JDBC_URL = "jdbc:postgresql://"; + private String repositoryName; - private static final String[] TO_REPLACE = new String[]{"-", "."}; + private File repositoryDirectory; - private static final String[] REPLACEMENT_LIST = new String[]{"", ""}; public static LizmapRepository newLizmapRepository(EchoBaseConfiguration configuration, JdbcConfiguration conf) { @@ -131,24 +138,20 @@ public class LizmapRepository { } - private String repositoryName; - - private File repositoryDirectory; - public String getRepositoryName() { if (repositoryName == null) { String url = configuration.getUrl(); - //TODO Use a regex - int hostIndex = START_JDBC_URL.length() - 1; - int portIndex = url.indexOf(':', hostIndex); - int dbnameIndex = url.indexOf("/", portIndex); + Matcher matcher = URL_PATTERN.matcher(url); - String dbname = url.substring(dbnameIndex + 1); - String host = url.substring(hostIndex + 1, portIndex); - String port = url.substring(portIndex + 1, dbnameIndex); + if (!matcher.matches()) { + throw new EchoBaseTechnicalException(url + " is not a jdbc postgresql url!"); + } + String host = matcher.group(1); + String port = matcher.group(3); + String dbname = matcher.group(4); repositoryName = configuration.getLizmapRepositoryName() + host + port + dbname; repositoryName = StringUtils.replaceEach(repositoryName, TO_REPLACE, REPLACEMENT_LIST); diff --git a/echobase-services/src/test/java/fr/ifremer/echobase/services/service/spatial/LizmapRepositoryTest.java b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/spatial/LizmapRepositoryTest.java new file mode 100644 index 0000000..daf091b --- /dev/null +++ b/echobase-services/src/test/java/fr/ifremer/echobase/services/service/spatial/LizmapRepositoryTest.java @@ -0,0 +1,47 @@ +package fr.ifremer.echobase.services.service.spatial; + +import fr.ifremer.echobase.config.EchoBaseConfiguration; +import fr.ifremer.echobase.entities.DriverType; +import fr.ifremer.echobase.io.EchoBaseIOUtil; +import fr.ifremer.echobase.persistence.JdbcConfiguration; +import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import org.junit.Assert; +import org.junit.Test; + +public class LizmapRepositoryTest extends EchoBaseTestServiceSupport { + + @Override + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(null); + } + + @Test + public void testGetRepositoryName() throws Exception { + + EchoBaseConfiguration configuration = getConfiguration(); + EchoBaseIOUtil.forceMkdir(configuration.getLizmapProjectsDirectory()); + + { + + JdbcConfiguration jdbcConfiguration = JdbcConfiguration.newConfig(DriverType.POSTGRESQL, "jdbc:postgresql://localhost/Echobase-test", "login", "password"); + LizmapRepository lizmapRepository = LizmapRepository.newLizmapRepository(configuration, jdbcConfiguration); + String repositoryName = lizmapRepository.getRepositoryName(); + Assert.assertNotNull(repositoryName); + Assert.assertEquals("echobaselocalhostnullEchobasetest", repositoryName); + + } + + { + + JdbcConfiguration jdbcConfiguration = JdbcConfiguration.newConfig(DriverType.POSTGRESQL, "jdbc:postgresql://localhost:5432/Echobase-test", "login", "password"); + LizmapRepository lizmapRepository = LizmapRepository.newLizmapRepository(configuration, jdbcConfiguration); + String repositoryName = lizmapRepository.getRepositoryName(); + Assert.assertNotNull(repositoryName); + Assert.assertEquals("echobaselocalhost5432Echobasetest", repositoryName); + + } + + } + +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm