Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
214ebdde
by Tony CHEMIT at 2018-05-13T18:59:37Z
18 changed files:
- client/pom.xml
- client/src/test/java/fr/ird/observe/client/DataSourcesForTestManager.java
- persistence/pom.xml
- persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaApplicationContext.java
- persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaConfigurationFactory.java
- − persistence/src/main/java/fr/ird/observe/persistence/migration/ObserveMigrationConfigurationProvider.java
- persistence/src/main/java/fr/ird/observe/persistence/migration/ObserveTopiaMigrationServiceAskUserToMigrate.java
- pom.xml
- − services-local/src/main/java/fr/ird/observe/services/local/ObserveJdbcHelper.java
- services-local/src/main/java/fr/ird/observe/services/local/ObserveSecurityHelper.java
- services-local/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/sql/SqlScriptProducerServiceLocal.java
- services-local/src/test/java/fr/ird/observe/services/local/DataSourcesForTestManager.java
- services-local/src/test/java/fr/ird/observe/services/local/entity/ReplicateReferentialsTest.java
- services-local/src/test/java/fr/ird/observe/services/local/entity/ReplicateTestSupport.java
- services-local/src/test/java/fr/ird/observe/services/local/entity/ReplicateTripLonglineTest.java
- services-local/src/test/java/fr/ird/observe/services/local/entity/ReplicateTripSeineTest.java
- services-local/src/test/java/fr/ird/observe/services/local/service/RigthTest.java
Changes:
| ... | ... | @@ -375,6 +375,10 @@ |
| 375 | 375 |
<groupId>fr.ird.observe.toolkit</groupId>
|
| 376 | 376 |
<artifactId>common-service</artifactId>
|
| 377 | 377 |
</dependency>
|
| 378 |
+ <dependency>
|
|
| 379 |
+ <groupId>fr.ird.observe.toolkit</groupId>
|
|
| 380 |
+ <artifactId>topia-extension</artifactId>
|
|
| 381 |
+ </dependency>
|
|
| 378 | 382 |
|
| 379 | 383 |
<dependency>
|
| 380 | 384 |
<groupId>io.ultreia.java4all</groupId>
|
| ... | ... | @@ -10,23 +10,23 @@ package fr.ird.observe.client; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
|
|
| 26 | 25 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
|
| 27 | 26 |
import fr.ird.observe.test.TestHelper;
|
| 28 | 27 |
import org.apache.commons.logging.Log;
|
| 29 | 28 |
import org.apache.commons.logging.LogFactory;
|
| 29 |
+import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
|
|
| 30 | 30 |
import org.nuiton.version.Version;
|
| 31 | 31 |
|
| 32 | 32 |
import java.io.File;
|
| ... | ... | @@ -100,7 +100,7 @@ public class DataSourcesForTestManager { |
| 100 | 100 |
configurationTopiaH2.setDirectory(localDbFile);
|
| 101 | 101 |
configurationTopiaH2.setDbName("obstuna");
|
| 102 | 102 |
configurationTopiaH2.setAutoMigrate(true);
|
| 103 |
- configurationTopiaH2.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
|
|
| 103 |
+ configurationTopiaH2.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
|
|
| 104 | 104 |
return configurationTopiaH2;
|
| 105 | 105 |
|
| 106 | 106 |
}
|
| ... | ... | @@ -116,7 +116,7 @@ public class DataSourcesForTestManager { |
| 116 | 116 |
private void deleteDirectory(Path directory) {
|
| 117 | 117 |
try {
|
| 118 | 118 |
log.debug(String.format("Delete directory: %s", directory));
|
| 119 |
- Files.walk(directory).filter(f->!f.equals(directory)).forEach(f -> {
|
|
| 119 |
+ Files.walk(directory).filter(f -> !f.equals(directory)).forEach(f -> {
|
|
| 120 | 120 |
try {
|
| 121 | 121 |
if (Files.isDirectory(f)) {
|
| 122 | 122 |
deleteDirectory(f);
|
| ... | ... | @@ -52,7 +52,6 @@ |
| 52 | 52 |
<dependency>
|
| 53 | 53 |
<groupId>fr.ird.observe.toolkit</groupId>
|
| 54 | 54 |
<artifactId>topia-extension</artifactId>
|
| 55 |
- <version>${observeToolkitVersion}</version>
|
|
| 56 | 55 |
</dependency>
|
| 57 | 56 |
|
| 58 | 57 |
<dependency>
|
| ... | ... | @@ -37,10 +37,10 @@ import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; |
| 37 | 37 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| 38 | 38 |
import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport;
|
| 39 | 39 |
import org.nuiton.topia.service.migration.TopiaMigrationService;
|
| 40 |
-import org.nuiton.topia.service.sql.batch.TopiaSqlBatchService;
|
|
| 41 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable;
|
|
| 42 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables;
|
|
| 43 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTablesFactory;
|
|
| 40 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorService;
|
|
| 41 |
+import org.nuiton.topia.service.script.table.TopiaSqlTable;
|
|
| 42 |
+import org.nuiton.topia.service.script.table.TopiaSqlTables;
|
|
| 43 |
+import org.nuiton.topia.service.script.table.TopiaSqlTablesFactory;
|
|
| 44 | 44 |
import org.nuiton.util.StringUtil;
|
| 45 | 45 |
|
| 46 | 46 |
import java.io.BufferedInputStream;
|
| ... | ... | @@ -62,7 +62,7 @@ import java.util.zip.GZIPInputStream; |
| 62 | 62 |
public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicationContext implements TopiaMetadataModelSupport {
|
| 63 | 63 |
|
| 64 | 64 |
static final String MIGRATION_SERVICE_NAME = "migration";
|
| 65 |
- static final String SQL_BATCH_SERVICE_NAME = "sqlBatch";
|
|
| 65 |
+ static final String SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME = "sqlScriptGenerator";
|
|
| 66 | 66 |
/**
|
| 67 | 67 |
* Logger.
|
| 68 | 68 |
*/
|
| ... | ... | @@ -115,8 +115,8 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat |
| 115 | 115 |
return getServices(TopiaMigrationService.class).get(MIGRATION_SERVICE_NAME);
|
| 116 | 116 |
}
|
| 117 | 117 |
|
| 118 |
- public TopiaSqlBatchService getSqlBatchService() {
|
|
| 119 |
- return getServices(TopiaSqlBatchService.class).get(SQL_BATCH_SERVICE_NAME);
|
|
| 118 |
+ public TopiaSqlScriptGeneratorService getSqlScriptGeneratorService() {
|
|
| 119 |
+ return getServices(TopiaSqlScriptGeneratorService.class).get(SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME);
|
|
| 120 | 120 |
}
|
| 121 | 121 |
|
| 122 | 122 |
@Override
|
| ... | ... | @@ -27,7 +27,7 @@ import org.apache.commons.logging.LogFactory; |
| 27 | 27 |
import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
| 28 | 28 |
import org.nuiton.topia.persistence.jdbc.JdbcConfigurationBuilder;
|
| 29 | 29 |
import org.nuiton.topia.service.migration.TopiaMigrationService;
|
| 30 |
-import org.nuiton.topia.service.sql.batch.TopiaSqlBatchServiceImpl;
|
|
| 30 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorServiceImpl;
|
|
| 31 | 31 |
|
| 32 | 32 |
import java.io.File;
|
| 33 | 33 |
|
| ... | ... | @@ -134,7 +134,7 @@ public class ObserveTopiaConfigurationFactory { |
| 134 | 134 |
log.debug("jdbcUrl: " + topiaConfiguration.getJdbcConnectionUrl());
|
| 135 | 135 |
|
| 136 | 136 |
topiaConfiguration.addDeclaredService(ObserveTopiaApplicationContext.MIGRATION_SERVICE_NAME, TopiaMigrationService.class);
|
| 137 |
- topiaConfiguration.addDeclaredService(ObserveTopiaApplicationContext.SQL_BATCH_SERVICE_NAME, TopiaSqlBatchServiceImpl.class);
|
|
| 137 |
+ topiaConfiguration.addDeclaredService(ObserveTopiaApplicationContext.SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME, TopiaSqlScriptGeneratorServiceImpl.class);
|
|
| 138 | 138 |
|
| 139 | 139 |
return topiaConfiguration;
|
| 140 | 140 |
|
| 1 |
-package fr.ird.observe.persistence.migration;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.google.common.collect.ImmutableList;
|
|
| 26 |
-import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
|
|
| 27 |
-import org.nuiton.version.Version;
|
|
| 28 |
-import org.nuiton.version.VersionBuilder;
|
|
| 29 |
- |
|
| 30 |
-import java.util.List;
|
|
| 31 |
- |
|
| 32 |
-/**
|
|
| 33 |
- * Created on 01/08/16.
|
|
| 34 |
- *
|
|
| 35 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 36 |
- * @since 5.0
|
|
| 37 |
- */
|
|
| 38 |
-public final class ObserveMigrationConfigurationProvider {
|
|
| 39 |
- |
|
| 40 |
- private static ObserveMigrationConfigurationProvider INSTANCE;
|
|
| 41 |
- |
|
| 42 |
- private final MigrationVersionResourceProvider resourceProvider;
|
|
| 43 |
- |
|
| 44 |
- private ObserveMigrationConfigurationProvider() {
|
|
| 45 |
- resourceProvider = new MigrationVersionResourceProvider();
|
|
| 46 |
- }
|
|
| 47 |
- |
|
| 48 |
- public static ObserveMigrationConfigurationProvider get() {
|
|
| 49 |
- if (INSTANCE == null) {
|
|
| 50 |
- INSTANCE = new ObserveMigrationConfigurationProvider();
|
|
| 51 |
- }
|
|
| 52 |
- return INSTANCE;
|
|
| 53 |
- }
|
|
| 54 |
- |
|
| 55 |
- public List<Version> getAvailableVersions() {
|
|
| 56 |
- return resourceProvider.getAvailableVersions();
|
|
| 57 |
- }
|
|
| 58 |
- |
|
| 59 |
- public Version getLastVersion() {
|
|
| 60 |
- return resourceProvider.getLastVersion();
|
|
| 61 |
- }
|
|
| 62 |
- |
|
| 63 |
- public ImmutableList<Version> getVersionsAfter(Version current) {
|
|
| 64 |
- return resourceProvider.getVersionsAfter(current);
|
|
| 65 |
- }
|
|
| 66 |
- |
|
| 67 |
- public Version getMinimumVersion() {
|
|
| 68 |
- return VersionBuilder.create("3.0").build();
|
|
| 69 |
- }
|
|
| 70 |
- |
|
| 71 |
-}
|
| ... | ... | @@ -35,12 +35,13 @@ import java.util.List; |
| 35 | 35 |
* @author Tony Chemit - dev@tchemit.fr
|
| 36 | 36 |
*/
|
| 37 | 37 |
@AutoService(TopiaMigrationServiceAskUserToMigrate.class)
|
| 38 |
+@SuppressWarnings("WeakerAccess")
|
|
| 38 | 39 |
public class ObserveTopiaMigrationServiceAskUserToMigrate implements TopiaMigrationServiceAskUserToMigrate {
|
| 39 | 40 |
|
| 40 |
- private final Version minimumVersion = VersionBuilder.create("3.0").build();
|
|
| 41 |
+ private static final Version MINIMUM_VERSION = VersionBuilder.create("3.0").build();
|
|
| 41 | 42 |
|
| 42 |
- public Version getMinimumVersion() {
|
|
| 43 |
- return minimumVersion;
|
|
| 43 |
+ public static Version getMinimumVersion() {
|
|
| 44 |
+ return MINIMUM_VERSION;
|
|
| 44 | 45 |
}
|
| 45 | 46 |
|
| 46 | 47 |
@Override
|
| ... | ... | @@ -152,7 +152,7 @@ |
| 152 | 152 |
<maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
|
| 153 | 153 |
<buildDate>${maven.build.timestamp}</buildDate>
|
| 154 | 154 |
|
| 155 |
- <observeToolkitVersion>3.4-SNAPSHOT</observeToolkitVersion>
|
|
| 155 |
+ <observeToolkitVersion>3.5-SNAPSHOT</observeToolkitVersion>
|
|
| 156 | 156 |
|
| 157 | 157 |
<!--<lib.version.java4all.jaxx>3.0-alpha-31</lib.version.java4all.jaxx>-->
|
| 158 | 158 |
<!--<lib.version.nuiton.topia>3.4.2-SNAPSHOT</lib.version.nuiton.topia>-->
|
| 1 |
-package fr.ird.observe.services.local;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Services local implementation
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import com.google.common.collect.Lists;
|
|
| 26 |
-import com.google.common.collect.Sets;
|
|
| 27 |
-import fr.ird.observe.dto.ObserveDbRole;
|
|
| 28 |
-import fr.ird.observe.dto.db.ObserveDbUserDto;
|
|
| 29 |
-import org.apache.commons.lang3.tuple.Pair;
|
|
| 30 |
-import org.apache.commons.logging.Log;
|
|
| 31 |
-import org.apache.commons.logging.LogFactory;
|
|
| 32 |
-import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
|
| 33 |
-import org.nuiton.topia.persistence.jdbc.JdbcHelper;
|
|
| 34 |
-import org.nuiton.version.Version;
|
|
| 35 |
-import org.nuiton.version.Versions;
|
|
| 36 |
- |
|
| 37 |
-import java.sql.Connection;
|
|
| 38 |
-import java.sql.DatabaseMetaData;
|
|
| 39 |
-import java.sql.PreparedStatement;
|
|
| 40 |
-import java.sql.ResultSet;
|
|
| 41 |
-import java.sql.SQLException;
|
|
| 42 |
-import java.util.ArrayList;
|
|
| 43 |
-import java.util.Collections;
|
|
| 44 |
-import java.util.LinkedHashSet;
|
|
| 45 |
-import java.util.List;
|
|
| 46 |
-import java.util.Set;
|
|
| 47 |
- |
|
| 48 |
-/**
|
|
| 49 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 50 |
- */
|
|
| 51 |
-public class ObserveJdbcHelper extends JdbcHelper {
|
|
| 52 |
- |
|
| 53 |
- private static final Set<String> POSTGIS_TABLES = Sets.newHashSet("geometry_columns", "spatial_ref_sys");
|
|
| 54 |
- private static final Log log = LogFactory.getLog(ObserveJdbcHelper.class);
|
|
| 55 |
- |
|
| 56 |
- |
|
| 57 |
- public ObserveJdbcHelper(JdbcConfiguration jdbcConfiguration) {
|
|
| 58 |
- super(jdbcConfiguration);
|
|
| 59 |
- }
|
|
| 60 |
- |
|
| 61 |
- public Set<String> getTablePrivileges(String schema, String tableName) {
|
|
| 62 |
- Connection connection = null;
|
|
| 63 |
- try {
|
|
| 64 |
- connection = openConnection();
|
|
| 65 |
- DatabaseMetaData metaData = connection.getMetaData();
|
|
| 66 |
- ResultSet observerDataPrivilege = metaData.getTablePrivileges(null, schema, tableName);
|
|
| 67 |
- |
|
| 68 |
- Set<String> tablePrivileges = Sets.newHashSet();
|
|
| 69 |
- |
|
| 70 |
- while (observerDataPrivilege.next()) {
|
|
| 71 |
- String security = observerDataPrivilege.getString("PRIVILEGE");
|
|
| 72 |
- String grantor = observerDataPrivilege.getString("GRANTOR");
|
|
| 73 |
- String grantee = observerDataPrivilege.getString("GRANTEE");
|
|
| 74 |
- // Il se peut que le login soit echappe sous la forme \"login\"
|
|
| 75 |
- grantor= grantor.replaceAll("\\\\\"", "");
|
|
| 76 |
- grantee = grantee.replaceAll("\\\\\"", "");
|
|
| 77 |
- if (log.isDebugEnabled()) {
|
|
| 78 |
- log.debug(String.format("(security %s) - grantee (%s)", security, grantee));
|
|
| 79 |
- }
|
|
| 80 |
- if (grantor.equals(jdbcConfiguration.getJdbcConnectionUser())) {
|
|
| 81 |
- if (log.isDebugEnabled()) {
|
|
| 82 |
- log.debug("for " + tableName + " table " + grantor + '/' + security);
|
|
| 83 |
- }
|
|
| 84 |
- tablePrivileges.add(security);
|
|
| 85 |
- } else if (grantee.equals(jdbcConfiguration.getJdbcConnectionUser())) {
|
|
| 86 |
- if (log.isDebugEnabled()) {
|
|
| 87 |
- log.debug("for " + tableName + " table " + grantee + '/' + security);
|
|
| 88 |
- }
|
|
| 89 |
- tablePrivileges.add(security);
|
|
| 90 |
- }
|
|
| 91 |
- }
|
|
| 92 |
- |
|
| 93 |
- return tablePrivileges;
|
|
| 94 |
- |
|
| 95 |
- } catch (SQLException e) {
|
|
| 96 |
- throw new RuntimeException(e);
|
|
| 97 |
- } finally {
|
|
| 98 |
- closeQuietly(connection);
|
|
| 99 |
- }
|
|
| 100 |
- |
|
| 101 |
- }
|
|
| 102 |
- |
|
| 103 |
- public Version getVersion() {
|
|
| 104 |
- Version version = Version.VZERO;
|
|
| 105 |
- |
|
| 106 |
- Connection connection = null;
|
|
| 107 |
- PreparedStatement preparedStatement = null;
|
|
| 108 |
- try {
|
|
| 109 |
- connection = openConnection();
|
|
| 110 |
- // la connexion est reussie, on recherche les droits de
|
|
| 111 |
- // récupération de la version de la base
|
|
| 112 |
- preparedStatement = connection.prepareStatement("SELECT version FROM tms_version;");
|
|
| 113 |
- ResultSet resultSet = preparedStatement.executeQuery();
|
|
| 114 |
- |
|
| 115 |
- if (resultSet.next()) {
|
|
| 116 |
- String versionStr = resultSet.getString(1);
|
|
| 117 |
- version = Versions.valueOf(versionStr);
|
|
| 118 |
- }
|
|
| 119 |
- |
|
| 120 |
- } catch (SQLException e) {
|
|
| 121 |
- if (log.isErrorEnabled()) {
|
|
| 122 |
- log.error(e);
|
|
| 123 |
- }
|
|
| 124 |
- } finally {
|
|
| 125 |
- closeQuietly(preparedStatement);
|
|
| 126 |
- closeQuietly(connection);
|
|
| 127 |
- }
|
|
| 128 |
- |
|
| 129 |
- return version;
|
|
| 130 |
- |
|
| 131 |
- }
|
|
| 132 |
- |
|
| 133 |
- public List<ObserveDbUserDto> getUsers() {
|
|
| 134 |
- Connection connection = null;
|
|
| 135 |
- PreparedStatement preparedStatement = null;
|
|
| 136 |
- List<ObserveDbUserDto> users = Lists.newLinkedList();
|
|
| 137 |
- |
|
| 138 |
- try {
|
|
| 139 |
- connection = openConnection();
|
|
| 140 |
- // la connexion est reussie, on recherche les droits de
|
|
| 141 |
- // récupération de la version de la base
|
|
| 142 |
- preparedStatement = connection.prepareStatement("SELECT rolname FROM pg_catalog.pg_roles;");
|
|
| 143 |
- ResultSet resultSet = preparedStatement.executeQuery();
|
|
| 144 |
- |
|
| 145 |
- while (resultSet.next()) {
|
|
| 146 |
- String name = resultSet.getString(1);
|
|
| 147 |
- ObserveDbUserDto user = new ObserveDbUserDto();
|
|
| 148 |
- user.setName(name);
|
|
| 149 |
- if (jdbcConfiguration.getJdbcConnectionUser().equals(name)) {
|
|
| 150 |
- user.setRole(ObserveDbRole.ADMINISTRATOR);
|
|
| 151 |
- } else {
|
|
| 152 |
- user.setRole(ObserveDbRole.UNUSED);
|
|
| 153 |
- }
|
|
| 154 |
- |
|
| 155 |
- users.add(user);
|
|
| 156 |
- }
|
|
| 157 |
- |
|
| 158 |
- return users;
|
|
| 159 |
- |
|
| 160 |
- } catch (SQLException e) {
|
|
| 161 |
- throw new RuntimeException(e);
|
|
| 162 |
- } finally {
|
|
| 163 |
- closeQuietly(preparedStatement);
|
|
| 164 |
- closeQuietly(connection);
|
|
| 165 |
- }
|
|
| 166 |
- }
|
|
| 167 |
- |
|
| 168 |
- public List<Pair<String, String>> getTables(Set<String> schemas, Set<String> extraTables) {
|
|
| 169 |
- List<Pair<String, String>> result = new ArrayList<>();
|
|
| 170 |
- |
|
| 171 |
- Connection connection = null;
|
|
| 172 |
- ResultSet tables = null;
|
|
| 173 |
- |
|
| 174 |
- try {
|
|
| 175 |
- // recuperation des tables sur la base
|
|
| 176 |
- connection = openConnection();
|
|
| 177 |
- DatabaseMetaData data = connection.getMetaData();
|
|
| 178 |
- tables = data.getTables(null,
|
|
| 179 |
- null,
|
|
| 180 |
- null,
|
|
| 181 |
- new String[]{"TABLE"}
|
|
| 182 |
- );
|
|
| 183 |
- |
|
| 184 |
- int columnCount = tables.getMetaData().getColumnCount();
|
|
| 185 |
- |
|
| 186 |
- if (log.isDebugEnabled()) {
|
|
| 187 |
- StringBuilder builder = new StringBuilder();
|
|
| 188 |
- builder.append("\nheader");
|
|
| 189 |
- for (int i = 1; i <= columnCount; i++) {
|
|
| 190 |
- String columnName = tables.getMetaData().getColumnName(i);
|
|
| 191 |
- builder.append("\n [").append(i).append("] :").append(columnName);
|
|
| 192 |
- }
|
|
| 193 |
- log.debug(builder.toString());
|
|
| 194 |
- log.debug("fetchSize : " + tables.getFetchSize());
|
|
| 195 |
- }
|
|
| 196 |
- while (tables.next()) {
|
|
| 197 |
- String schemaName = tables.getString(2);
|
|
| 198 |
- String tableName = tables.getString(3);
|
|
| 199 |
- if (log.isDebugEnabled()) {
|
|
| 200 |
- log.debug(String.format("Discover table named %s", tables));
|
|
| 201 |
- }
|
|
| 202 |
- if (!extraTables.contains(tableName)) {
|
|
| 203 |
- |
|
| 204 |
- if (POSTGIS_TABLES.contains(tableName)) {
|
|
| 205 |
- continue;
|
|
| 206 |
- }
|
|
| 207 |
- |
|
| 208 |
- if (schemaName == null || !schemas.contains(schemaName.toLowerCase())) {
|
|
| 209 |
- continue;
|
|
| 210 |
- }
|
|
| 211 |
- |
|
| 212 |
- }
|
|
| 213 |
- |
|
| 214 |
- if (log.isDebugEnabled()) {
|
|
| 215 |
- log.debug(String.format("Keep table: %s", tables));
|
|
| 216 |
- }
|
|
| 217 |
- result.add(Pair.of(schemaName, tableName));
|
|
| 218 |
- }
|
|
| 219 |
- |
|
| 220 |
- Collections.sort(result);
|
|
| 221 |
- return result;
|
|
| 222 |
- } catch (SQLException e) {
|
|
| 223 |
- throw new RuntimeException(e);
|
|
| 224 |
- } finally {
|
|
| 225 |
- closeQuietly(connection);
|
|
| 226 |
- closeQuietly(tables);
|
|
| 227 |
- }
|
|
| 228 |
- }
|
|
| 229 |
- |
|
| 230 |
- public Set<String> getPostgisFunctions(String functionPattern) {
|
|
| 231 |
- |
|
| 232 |
- final Set<String> result = new LinkedHashSet<>();
|
|
| 233 |
- Connection connection = null;
|
|
| 234 |
- PreparedStatement preparedStatement = null;
|
|
| 235 |
- |
|
| 236 |
- String sql = String.format("SELECT ns.nspname::text || '.' || p.proname::text || '(' || oidvectortypes(p.proargtypes)::text || ')'" +
|
|
| 237 |
- " FROM pg_proc p INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)" +
|
|
| 238 |
- " WHERE ns.nspname = 'public' AND p.proname ILIKE '%s%%';", functionPattern);
|
|
| 239 |
- try {
|
|
| 240 |
- connection = openConnection();
|
|
| 241 |
- preparedStatement = connection.prepareStatement(sql);
|
|
| 242 |
- ResultSet set = preparedStatement.executeQuery();
|
|
| 243 |
- |
|
| 244 |
- while (set.next()) {
|
|
| 245 |
- String functionPrototype = set.getString(1);
|
|
| 246 |
- result.add(functionPrototype);
|
|
| 247 |
- }
|
|
| 248 |
- |
|
| 249 |
- } catch (SQLException e) {
|
|
| 250 |
- throw new RuntimeException(e);
|
|
| 251 |
- } finally {
|
|
| 252 |
- closeQuietly(connection);
|
|
| 253 |
- closeQuietly(preparedStatement);
|
|
| 254 |
- }
|
|
| 255 |
- return result;
|
|
| 256 |
- |
|
| 257 |
- }
|
|
| 258 |
- |
|
| 259 |
- public void loadScript(String scriptContent) {
|
|
| 260 |
- Connection connection = null;
|
|
| 261 |
- PreparedStatement preparedStatement = null;
|
|
| 262 |
- |
|
| 263 |
- try {
|
|
| 264 |
- connection = openConnection();
|
|
| 265 |
- |
|
| 266 |
- preparedStatement = connection.prepareStatement(scriptContent);
|
|
| 267 |
- |
|
| 268 |
- preparedStatement.executeUpdate();
|
|
| 269 |
- |
|
| 270 |
- } catch (SQLException e) {
|
|
| 271 |
- throw new RuntimeException(e);
|
|
| 272 |
- } finally {
|
|
| 273 |
- closeQuietly(connection);
|
|
| 274 |
- closeQuietly(preparedStatement);
|
|
| 275 |
- }
|
|
| 276 |
- }
|
|
| 277 |
- |
|
| 278 |
- |
|
| 279 |
-}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -32,9 +32,16 @@ import org.apache.commons.logging.Log; |
| 32 | 32 |
import org.apache.commons.logging.LogFactory;
|
| 33 | 33 |
import org.nuiton.topia.migration.mappings.TMSVersionHibernateDao;
|
| 34 | 34 |
import org.nuiton.topia.persistence.TopiaEntityEnum;
|
| 35 |
+import org.nuiton.topia.persistence.TopiaException;
|
|
| 35 | 36 |
import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
| 37 |
+import org.nuiton.topia.persistence.sql.PostgresJdbcHelper;
|
|
| 38 |
+import org.nuiton.topia.persistence.util.SqlScriptConsumer;
|
|
| 39 |
+import org.nuiton.topia.persistence.util.SqlScriptWriter;
|
|
| 36 | 40 |
import org.nuiton.util.StringUtil;
|
| 37 | 41 |
|
| 42 |
+import java.io.IOException;
|
|
| 43 |
+import java.nio.file.Files;
|
|
| 44 |
+import java.nio.file.Path;
|
|
| 38 | 45 |
import java.util.ArrayList;
|
| 39 | 46 |
import java.util.Arrays;
|
| 40 | 47 |
import java.util.Collection;
|
| ... | ... | @@ -53,64 +60,68 @@ public class ObserveSecurityHelper { |
| 53 | 60 |
|
| 54 | 61 |
public static final String OBSERVE_COMMON_SCHEMA_NAME = "observe_common";
|
| 55 | 62 |
public static final String OBSERVE_SEINE_SCHEMA_NAME = "observe_seine";
|
| 56 |
- public static final String OBSERVE_LONGLINE_SCHEMA_NAME = "observe_longline";
|
|
| 57 |
- public static final Function<String, String> ESCAPE_STRING = input -> "\"" + input + "\"";
|
|
| 58 |
- protected static final String DROP_TABLE_PATTERN = "DROP TABLE IF EXISTS %s.%s CASCADE;\n";
|
|
| 59 |
- protected static final String DROP_SCHEMA_PATTERN = "DROP SCHEMA IF EXISTS %s CASCADE;\n";
|
|
| 60 |
- protected static final String REVOKE_ON_TABLE_ALL_PATTERN = "REVOKE ALL ON %s.%s FROM %s CASCADE;\n";
|
|
| 61 |
- protected static final String SET_ON_TABLE_OWNER_PATTERN = "ALTER TABLE %s.%s OWNER TO %s;\n";
|
|
| 62 |
- protected static final String GRANT_ON_TABLE_READ_PATTERN = "GRANT SELECT ON %s.%s TO %s;\n";
|
|
| 63 |
- protected static final String GRANT_ON_TABLE_ALL_PATTERN = "GRANT ALL ON %s.%s TO %s;\n";
|
|
| 64 |
- protected static final String GRANT_ON_FUNCTION_PATTERN = "GRANT EXECUTE ON FUNCTION %s TO %s;\n";
|
|
| 65 |
- protected static final String REVOKE_ON_SCHEMA_ALL_PATTERN = "REVOKE ALL ON SCHEMA %s FROM %s CASCADE;\n";
|
|
| 66 |
- protected static final String REVOKE_ON_FUNCTIONS_PATTERN = "REVOKE EXECUTE ON FUNCTION %s FROM %s CASCADE;\n";
|
|
| 67 |
- protected static final String GRANT_ON_SCHEMA_ALL_PATTERN = "GRANT USAGE ON SCHEMA %s TO %s;\n";
|
|
| 68 |
- protected static final Set<String> EXTRA_TABLES = Sets.newHashSet(
|
|
| 63 |
+ private static final String OBSERVE_LONGLINE_SCHEMA_NAME = "observe_longline";
|
|
| 64 |
+ private static final Function<String, String> ESCAPE_STRING = input -> "\"" + input + "\"";
|
|
| 65 |
+ private static final String REVOKE_ON_TABLE_ALL_PATTERN = "REVOKE ALL ON %s.%s FROM %s CASCADE;";
|
|
| 66 |
+ private static final String SET_ON_TABLE_OWNER_PATTERN = "ALTER TABLE %s.%s OWNER TO %s;";
|
|
| 67 |
+ private static final String GRANT_ON_TABLE_READ_PATTERN = "GRANT SELECT ON %s.%s TO %s;";
|
|
| 68 |
+ private static final String GRANT_ON_TABLE_ALL_PATTERN = "GRANT ALL ON %s.%s TO %s;";
|
|
| 69 |
+ private static final String GRANT_ON_FUNCTION_PATTERN = "GRANT EXECUTE ON FUNCTION %s TO %s;";
|
|
| 70 |
+ private static final String REVOKE_ON_SCHEMA_ALL_PATTERN = "REVOKE ALL ON SCHEMA %s FROM %s CASCADE;";
|
|
| 71 |
+ private static final String REVOKE_ON_FUNCTIONS_PATTERN = "REVOKE EXECUTE ON FUNCTION %s FROM %s CASCADE;";
|
|
| 72 |
+ private static final String GRANT_ON_SCHEMA_ALL_PATTERN = "GRANT USAGE ON SCHEMA %s TO %s;";
|
|
| 73 |
+ private static final Set<String> EXTRA_TABLES = Sets.newHashSet(
|
|
| 69 | 74 |
TMSVersionHibernateDao.TABLE_NAME,
|
| 70 | 75 |
TMSVersionHibernateDao.LEGACY_TABLE_NAME);
|
| 71 |
- protected static final Set<String> FUNCTION_NAMES_PREFIXS = Sets.newHashSet("ST_MakePoint",
|
|
| 72 |
- "ST_SetSRID",
|
|
| 73 |
- "sync_",
|
|
| 74 |
- "tr_sync",
|
|
| 75 |
- "ot_enhanced_school_type",
|
|
| 76 |
- "observe_");
|
|
| 77 |
- protected static final String SCHEMA_PUBLIC = "public";
|
|
| 78 |
- protected static final Set<String> SCHEMAS = Sets.newHashSet(SCHEMA_PUBLIC,
|
|
| 79 |
- OBSERVE_COMMON_SCHEMA_NAME,
|
|
| 80 |
- OBSERVE_SEINE_SCHEMA_NAME,
|
|
| 81 |
- OBSERVE_LONGLINE_SCHEMA_NAME);
|
|
| 76 |
+ private static final Set<String> FUNCTION_NAMES_PREFIXS = Sets.newHashSet("ST_MakePoint",
|
|
| 77 |
+ "ST_SetSRID",
|
|
| 78 |
+ "sync_",
|
|
| 79 |
+ "tr_sync",
|
|
| 80 |
+ "ot_enhanced_school_type",
|
|
| 81 |
+ "observe_");
|
|
| 82 |
+ private static final String SCHEMA_PUBLIC = "public";
|
|
| 83 |
+ private static final Set<String> SCHEMAS = Sets.newHashSet(SCHEMA_PUBLIC,
|
|
| 84 |
+ OBSERVE_COMMON_SCHEMA_NAME,
|
|
| 85 |
+ OBSERVE_SEINE_SCHEMA_NAME,
|
|
| 86 |
+ OBSERVE_LONGLINE_SCHEMA_NAME);
|
|
| 82 | 87 |
private static final Log log = LogFactory.getLog(ObserveSecurityHelper.class);
|
| 83 |
- protected final ObserveJdbcHelper jdbcHelper;
|
|
| 84 |
- protected final JdbcConfiguration jdbcConfiguration;
|
|
| 88 |
+ private final PostgresJdbcHelper jdbcHelper;
|
|
| 85 | 89 |
|
| 86 | 90 |
|
| 87 | 91 |
public ObserveSecurityHelper(JdbcConfiguration jdbcConfiguration) {
|
| 88 |
- this.jdbcConfiguration = jdbcConfiguration;
|
|
| 89 |
- this.jdbcHelper = new ObserveJdbcHelper(jdbcConfiguration);
|
|
| 92 |
+ this.jdbcHelper = new PostgresJdbcHelper(jdbcConfiguration);
|
|
| 90 | 93 |
}
|
| 91 | 94 |
|
| 92 |
- public void applySecurity(Set<ObserveDbUserDto> users, boolean showSql) {
|
|
| 95 |
+ public void applySecurity(Set<ObserveDbUserDto> users) {
|
|
| 93 | 96 |
if (users == null) {
|
| 94 | 97 |
throw new NullPointerException("users can not be null");
|
| 95 | 98 |
}
|
| 96 | 99 |
|
| 97 |
- String script = createSecurityScript(users);
|
|
| 98 |
- |
|
| 99 |
- if (showSql && log.isInfoEnabled()) {
|
|
| 100 |
- log.info("SQL to execute :\n" + script);
|
|
| 100 |
+ Path scriptPath;
|
|
| 101 |
+ try {
|
|
| 102 |
+ scriptPath = Files.createTempFile("topia-sql-script-", ".sql");
|
|
| 103 |
+ } catch (IOException e) {
|
|
| 104 |
+ throw new IllegalStateException("Can't create temporary path", e);
|
|
| 101 | 105 |
}
|
| 102 | 106 |
|
| 103 |
- jdbcHelper.loadScript(script);
|
|
| 104 |
- |
|
| 107 |
+ try {
|
|
| 108 |
+ try (SqlScriptWriter sqlScriptWriter = SqlScriptWriter.of(scriptPath)) {
|
|
| 109 |
+ createSecurityScript(users, sqlScriptWriter);
|
|
| 110 |
+ log.info(String.format("Generate security script %d statements(s) at %s", sqlScriptWriter.getStatementCount(), scriptPath));
|
|
| 111 |
+ }
|
|
| 112 |
+ jdbcHelper.consume(SqlScriptConsumer.of(scriptPath));
|
|
| 113 |
+ } catch (IOException e) {
|
|
| 114 |
+ throw new TopiaException(String.format("Can't generate security script at %s", scriptPath), e);
|
|
| 115 |
+ }
|
|
| 105 | 116 |
}
|
| 106 | 117 |
|
| 107 |
- protected String createSecurityScript(Set<ObserveDbUserDto> users) {
|
|
| 118 |
+ private void createSecurityScript(Set<ObserveDbUserDto> users, SqlScriptWriter sqlScriptWriter) {
|
|
| 108 | 119 |
|
| 109 | 120 |
List<Pair<String, String>> tables = jdbcHelper.getTables(SCHEMAS, EXTRA_TABLES);
|
| 110 | 121 |
|
| 111 | 122 |
if (tables.isEmpty()) {
|
| 112 | 123 |
// no tables
|
| 113 |
- return "";
|
|
| 124 |
+ return;
|
|
| 114 | 125 |
}
|
| 115 | 126 |
|
| 116 | 127 |
String administratorName = Iterables.get(getUserNamesByRole(users, ObserveDbRole.ADMINISTRATOR), 0);
|
| ... | ... | @@ -130,16 +141,12 @@ public class ObserveSecurityHelper { |
| 130 | 141 |
|
| 131 | 142 |
List<Pair<String, String>> referentielTables = getReferentielTables(tables);
|
| 132 | 143 |
|
| 133 |
- getDataTables(tables, referentielTables);
|
|
| 134 |
- |
|
| 135 | 144 |
Set<String> allPostgisFunctions = new LinkedHashSet<>();
|
| 136 | 145 |
for (String postgisFunction : FUNCTION_NAMES_PREFIXS) {
|
| 137 | 146 |
Set<String> postgisFunctions = jdbcHelper.getPostgisFunctions(postgisFunction);
|
| 138 | 147 |
allPostgisFunctions.addAll(postgisFunctions);
|
| 139 | 148 |
}
|
| 140 | 149 |
|
| 141 |
- StringBuilder builder = new StringBuilder();
|
|
| 142 |
- |
|
| 143 | 150 |
String administratorEscapedName = ESCAPE_STRING.apply(administratorName);
|
| 144 | 151 |
Set<String> technicalEscapedNames = escapedNames(technicalNames);
|
| 145 | 152 |
Set<String> usersEscapedNames = escapedNames(usersNames);
|
| ... | ... | @@ -157,84 +164,66 @@ public class ObserveSecurityHelper { |
| 157 | 164 |
|
| 158 | 165 |
String roles = StringUtil.join(privateRoles, ",", true);
|
| 159 | 166 |
|
| 160 |
- addOnTablesForRole(REVOKE_ON_TABLE_ALL_PATTERN, builder, tables, roles);
|
|
| 161 |
- addOnSchemaForRole(REVOKE_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
|
|
| 162 |
- addOnFunctionForRole(REVOKE_ON_FUNCTIONS_PATTERN, builder, allPostgisFunctions, roles);
|
|
| 167 |
+ addOnTablesForRole(REVOKE_ON_TABLE_ALL_PATTERN, sqlScriptWriter, tables, roles);
|
|
| 168 |
+ addOnSchemaForRole(REVOKE_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
|
|
| 169 |
+ addOnFunctionForRole(REVOKE_ON_FUNCTIONS_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
|
|
| 163 | 170 |
|
| 164 | 171 |
}
|
| 165 | 172 |
|
| 166 | 173 |
// ajout propriétaire
|
| 167 |
- addOnTablesForRole(SET_ON_TABLE_OWNER_PATTERN, builder, tables, administratorEscapedName);
|
|
| 168 |
- addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, administratorEscapedName);
|
|
| 169 |
- addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, administratorEscapedName);
|
|
| 174 |
+ addOnTablesForRole(SET_ON_TABLE_OWNER_PATTERN, sqlScriptWriter, tables, administratorEscapedName);
|
|
| 175 |
+ addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, administratorEscapedName);
|
|
| 176 |
+ addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, administratorEscapedName);
|
|
| 170 | 177 |
|
| 171 | 178 |
// ajout administrateurs
|
| 172 | 179 |
if (!technicalEscapedNames.isEmpty()) {
|
| 173 | 180 |
String roles = StringUtil.join(technicalEscapedNames, ",", true);
|
| 174 |
- addOnTablesForRole(GRANT_ON_TABLE_ALL_PATTERN, builder, tables, roles);
|
|
| 175 |
- addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
|
|
| 176 |
- addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
|
|
| 181 |
+ addOnTablesForRole(GRANT_ON_TABLE_ALL_PATTERN, sqlScriptWriter, tables, roles);
|
|
| 182 |
+ addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
|
|
| 183 |
+ addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
|
|
| 177 | 184 |
}
|
| 178 | 185 |
|
| 179 | 186 |
// ajout utilisateur
|
| 180 | 187 |
if (!usersEscapedNames.isEmpty()) {
|
| 181 | 188 |
String roles = StringUtil.join(usersEscapedNames, ",", true);
|
| 182 |
- addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, builder, tables, roles);
|
|
| 183 |
- addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
|
|
| 184 |
- addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
|
|
| 189 |
+ addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, sqlScriptWriter, tables, roles);
|
|
| 190 |
+ addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
|
|
| 191 |
+ addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
|
|
| 185 | 192 |
}
|
| 186 | 193 |
|
| 187 | 194 |
// ajout referentiel
|
| 188 | 195 |
if (!referentialEscapedNames.isEmpty()) {
|
| 189 | 196 |
String roles = StringUtil.join(referentialEscapedNames, ",", true);
|
| 190 |
- addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, builder, referentielTables, roles);
|
|
| 191 |
- addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
|
|
| 192 |
- addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
|
|
| 197 |
+ addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, sqlScriptWriter, referentielTables, roles);
|
|
| 198 |
+ addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
|
|
| 199 |
+ addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
|
|
| 193 | 200 |
}
|
| 194 | 201 |
|
| 195 |
- String result = builder.toString();
|
|
| 196 |
- |
|
| 197 |
- if (log.isInfoEnabled()) {
|
|
| 198 |
- log.info("Security script :\n" + result);
|
|
| 199 |
- }
|
|
| 200 |
- return result;
|
|
| 201 |
- |
|
| 202 |
- |
|
| 203 | 202 |
}
|
| 204 | 203 |
|
| 205 |
- protected List<String> getUserNamesByRole(Set<ObserveDbUserDto> users, ObserveDbRole role) {
|
|
| 204 |
+ private List<String> getUserNamesByRole(Set<ObserveDbUserDto> users, ObserveDbRole role) {
|
|
| 206 | 205 |
return users.stream().filter(u -> u.getRole() == role).map(ObserveDbUserDto::getName).collect(Collectors.toList());
|
| 207 | 206 |
}
|
| 208 | 207 |
|
| 209 |
- protected Set<String> escapedNames(List<String> names) {
|
|
| 208 |
+ private Set<String> escapedNames(List<String> names) {
|
|
| 210 | 209 |
return names.stream().map(ESCAPE_STRING).collect(Collectors.toSet());
|
| 211 | 210 |
}
|
| 212 | 211 |
|
| 213 |
- protected List<Pair<String, String>> getReferentielTables(Iterable<Pair<String, String>> tables) {
|
|
| 214 |
- Set<TopiaEntityEnum> types = new HashSet<>();
|
|
| 215 |
- types.addAll(Arrays.asList(Entities.REFERENCE_ENTITIES));
|
|
| 212 |
+ private List<Pair<String, String>> getReferentielTables(Collection<Pair<String, String>> tables) {
|
|
| 213 |
+ Set<TopiaEntityEnum> types = new HashSet<>(Arrays.asList(Entities.REFERENCE_ENTITIES));
|
|
| 216 | 214 |
|
| 217 |
- List<Pair<String, String>> result = getTables(tables, types, EXTRA_TABLES);
|
|
| 215 |
+ List<Pair<String, String>> result = getTables(tables, types);
|
|
| 218 | 216 |
if (log.isInfoEnabled()) {
|
| 219 | 217 |
StringBuilder sb = new StringBuilder();
|
| 220 | 218 |
sb.append("Detected ").append(result.size()).append(" referentiel tables :");
|
| 221 | 219 |
for (Pair<String, String> s : result) {
|
| 222 | 220 |
sb.append("\n - ").append(s);
|
| 223 | 221 |
}
|
| 224 |
- log.info(sb.toString());
|
|
| 225 |
- }
|
|
| 226 |
- return result;
|
|
| 227 |
- }
|
|
| 228 |
- |
|
| 229 |
- protected List<Pair<String, String>> getDataTables(Collection<Pair<String, String>> tables,
|
|
| 230 |
- Collection<Pair<String, String>> referentielTables) {
|
|
| 231 |
- List<Pair<String, String>> result = new ArrayList<>(tables);
|
|
| 232 |
- result.removeAll(referentielTables);
|
|
| 222 |
+ List<Pair<String, String>> dataTables = new ArrayList<>(tables);
|
|
| 223 |
+ dataTables.removeAll(result);
|
|
| 233 | 224 |
|
| 234 |
- if (log.isInfoEnabled()) {
|
|
| 235 |
- StringBuilder sb = new StringBuilder();
|
|
| 236 |
- sb.append("Detected ").append(result.size()).append(" data tables :");
|
|
| 237 |
- for (Pair<String, String> s : result) {
|
|
| 225 |
+ sb.append("Detected ").append(dataTables.size()).append(" data tables :");
|
|
| 226 |
+ for (Pair<String, String> s : dataTables) {
|
|
| 238 | 227 |
sb.append("\n - ").append(s);
|
| 239 | 228 |
}
|
| 240 | 229 |
log.info(sb.toString());
|
| ... | ... | @@ -242,9 +231,7 @@ public class ObserveSecurityHelper { |
| 242 | 231 |
return result;
|
| 243 | 232 |
}
|
| 244 | 233 |
|
| 245 |
- protected List<Pair<String, String>> getTables(Iterable<Pair<String, String>> tables,
|
|
| 246 |
- Set<TopiaEntityEnum> types,
|
|
| 247 |
- Set<String> extraTypes) {
|
|
| 234 |
+ private List<Pair<String, String>> getTables(Iterable<Pair<String, String>> tables, Set<TopiaEntityEnum> types) {
|
|
| 248 | 235 |
List<Pair<String, String>> result = new ArrayList<>();
|
| 249 | 236 |
for (Pair<String, String> t : tables) {
|
| 250 | 237 |
String table = t.getRight();
|
| ... | ... | @@ -257,7 +244,7 @@ public class ObserveSecurityHelper { |
| 257 | 244 |
}
|
| 258 | 245 |
}
|
| 259 | 246 |
if (detectedType == null) {
|
| 260 |
- for (String extraType : extraTypes) {
|
|
| 247 |
+ for (String extraType : EXTRA_TABLES) {
|
|
| 261 | 248 |
if (table.equalsIgnoreCase(extraType)) {
|
| 262 | 249 |
detectedType = extraType;
|
| 263 | 250 |
break;
|
| ... | ... | @@ -272,35 +259,22 @@ public class ObserveSecurityHelper { |
| 272 | 259 |
return result;
|
| 273 | 260 |
}
|
| 274 | 261 |
|
| 275 |
- protected void addOnTablesForRole(String pattern,
|
|
| 276 |
- StringBuilder builder,
|
|
| 277 |
- Iterable<Pair<String, String>> tables,
|
|
| 278 |
- String role) {
|
|
| 279 |
- |
|
| 262 |
+ private void addOnTablesForRole(String pattern, SqlScriptWriter builder, Iterable<Pair<String, String>> tables, String role) {
|
|
| 280 | 263 |
for (Pair<String, String> t : tables) {
|
| 281 |
- builder.append(String.format(pattern, t.getLeft(), t.getRight(), role));
|
|
| 264 |
+ builder.writeSql(String.format(pattern, t.getLeft(), t.getRight(), role));
|
|
| 282 | 265 |
}
|
| 283 | 266 |
}
|
| 284 | 267 |
|
| 285 |
- protected void addOnSchemaForRole(String pattern,
|
|
| 286 |
- StringBuilder builder,
|
|
| 287 |
- Set<String> schemas,
|
|
| 288 |
- String role) {
|
|
| 289 |
- |
|
| 268 |
+ private void addOnSchemaForRole(String pattern, SqlScriptWriter builder, Set<String> schemas, String role) {
|
|
| 290 | 269 |
for (String t : schemas) {
|
| 291 |
- builder.append(String.format(pattern, t, role));
|
|
| 270 |
+ builder.writeSql(String.format(pattern, t, role));
|
|
| 292 | 271 |
}
|
| 293 | 272 |
}
|
| 294 | 273 |
|
| 295 |
- protected void addOnFunctionForRole(String pattern,
|
|
| 296 |
- StringBuilder builder,
|
|
| 297 |
- Set<String> functions,
|
|
| 298 |
- String role) {
|
|
| 299 |
- |
|
| 274 |
+ private void addOnFunctionForRole(String pattern, SqlScriptWriter builder, Set<String> functions, String role) {
|
|
| 300 | 275 |
for (String t : functions) {
|
| 301 |
- builder.append(String.format(pattern, t, role));
|
|
| 276 |
+ builder.writeSql(String.format(pattern, t, role));
|
|
| 302 | 277 |
}
|
| 303 | 278 |
}
|
| 304 | 279 |
|
| 305 |
- |
|
| 306 | 280 |
}
|
| ... | ... | @@ -10,22 +10,21 @@ package fr.ird.observe.services.local.service; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import com.google.common.base.Joiner;
|
|
| 26 | 25 |
import com.google.common.base.Preconditions;
|
| 27 | 26 |
import com.google.common.collect.ImmutableSet;
|
| 28 |
-import com.google.common.collect.Sets;
|
|
| 27 |
+import fr.ird.observe.dto.ObserveDbRole;
|
|
| 29 | 28 |
import fr.ird.observe.dto.db.ObserveDbUserDto;
|
| 30 | 29 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 31 | 30 |
import fr.ird.observe.entities.referentiel.ObserveReferentialEntity;
|
| ... | ... | @@ -33,7 +32,7 @@ import fr.ird.observe.persistence.ObserveEntityEnum; |
| 33 | 32 |
import fr.ird.observe.persistence.ObserveTopiaApplicationContext;
|
| 34 | 33 |
import fr.ird.observe.persistence.ObserveTopiaConfiguration;
|
| 35 | 34 |
import fr.ird.observe.persistence.ObserveTopiaConfigurationFactory;
|
| 36 |
-import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
|
|
| 35 |
+import fr.ird.observe.persistence.migration.ObserveTopiaMigrationServiceAskUserToMigrate;
|
|
| 37 | 36 |
import fr.ird.observe.services.configuration.DataSourceCreateConfigurationDto;
|
| 38 | 37 |
import fr.ird.observe.services.configuration.DataSourceCreateWithNoReferentialImportException;
|
| 39 | 38 |
import fr.ird.observe.services.configuration.IncompatibleDataSourceCreateConfigurationException;
|
| ... | ... | @@ -44,7 +43,6 @@ import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfiguratio |
| 44 | 43 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG;
|
| 45 | 44 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaSupport;
|
| 46 | 45 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConnectionTopia;
|
| 47 |
-import fr.ird.observe.services.local.ObserveJdbcHelper;
|
|
| 48 | 46 |
import fr.ird.observe.services.local.ObserveSecurityHelper;
|
| 49 | 47 |
import fr.ird.observe.services.local.ObserveTopiaApplicationContextFactory;
|
| 50 | 48 |
import fr.ird.observe.services.service.BabModelVersionException;
|
| ... | ... | @@ -61,16 +59,21 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper; |
| 61 | 59 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
| 62 | 60 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| 63 | 61 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModelVisitor;
|
| 62 |
+import org.nuiton.topia.persistence.sql.PostgresJdbcHelper;
|
|
| 63 |
+import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
|
|
| 64 |
+import org.nuiton.topia.service.migration.version.TMSVersion;
|
|
| 65 |
+import org.nuiton.topia.service.migration.version.TMSVersionHibernateDao;
|
|
| 64 | 66 |
import org.nuiton.version.Version;
|
| 65 | 67 |
import org.nuiton.version.Versions;
|
| 66 | 68 |
|
| 67 | 69 |
import java.io.File;
|
| 68 | 70 |
import java.io.IOException;
|
| 69 | 71 |
import java.nio.file.Files;
|
| 72 |
+import java.util.LinkedHashSet;
|
|
| 73 |
+import java.util.List;
|
|
| 70 | 74 |
import java.util.Optional;
|
| 71 | 75 |
import java.util.Set;
|
| 72 | 76 |
import java.util.UUID;
|
| 73 |
-import java.util.stream.Collectors;
|
|
| 74 | 77 |
|
| 75 | 78 |
import static org.nuiton.i18n.I18n.l;
|
| 76 | 79 |
|
| ... | ... | @@ -100,9 +103,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 100 | 103 |
|
| 101 | 104 |
@Override
|
| 102 | 105 |
public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 103 |
- if (log.isTraceEnabled()) {
|
|
| 104 |
- log.trace("checkCanConnect(" + dataSourceConfiguration + ")");
|
|
| 105 |
- }
|
|
| 106 | 106 |
|
| 107 | 107 |
Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
|
| 108 | 108 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
| ... | ... | @@ -137,11 +137,11 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 137 | 137 |
|
| 138 | 138 |
// On tente une connection à la base
|
| 139 | 139 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(h2DataSourceConfiguration.getDirectory(),
|
| 140 |
- h2DataSourceConfiguration.getDbName(),
|
|
| 141 |
- h2DataSourceConfiguration.getUsername(),
|
|
| 142 |
- new String(h2DataSourceConfiguration.getPassword()),
|
|
| 143 |
- false,
|
|
| 144 |
- false);
|
|
| 140 |
+ h2DataSourceConfiguration.getDbName(),
|
|
| 141 |
+ h2DataSourceConfiguration.getUsername(),
|
|
| 142 |
+ new String(h2DataSourceConfiguration.getPassword()),
|
|
| 143 |
+ false,
|
|
| 144 |
+ false);
|
|
| 145 | 145 |
|
| 146 | 146 |
|
| 147 | 147 |
try {
|
| ... | ... | @@ -162,9 +162,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 162 | 162 |
ObserveDataSourceConfigurationTopiaPG pgDataSourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfigurationTopiaSupport;
|
| 163 | 163 |
// On tente une connexion au serveur
|
| 164 | 164 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 165 |
- pgDataSourceConfiguration.getUsername(),
|
|
| 166 |
- new String(pgDataSourceConfiguration.getPassword()),
|
|
| 167 |
- false,
|
|
| 165 |
+ pgDataSourceConfiguration.getUsername(),
|
|
| 166 |
+ new String(pgDataSourceConfiguration.getPassword()),
|
|
| 167 |
+ false,
|
|
| 168 | 168 |
false);
|
| 169 | 169 |
|
| 170 | 170 |
try {
|
| ... | ... | @@ -187,9 +187,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 187 | 187 |
public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration)
|
| 188 | 188 |
throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException,
|
| 189 | 189 |
BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
| 190 |
- if (log.isTraceEnabled()) {
|
|
| 191 |
- log.trace("create(" + dataSourceConfiguration + ", " + dataSourceCreateConfiguration + ")");
|
|
| 192 |
- }
|
|
| 193 | 190 |
|
| 194 | 191 |
dataSourceCreateConfiguration.validateConfiguration();
|
| 195 | 192 |
|
| ... | ... | @@ -274,9 +271,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 274 | 271 |
|
| 275 | 272 |
if (importStandaloneReferantial) {
|
| 276 | 273 |
|
| 277 |
- if (log.isInfoEnabled()) {
|
|
| 278 |
- log.info("Import referential.");
|
|
| 279 |
- }
|
|
| 274 |
+ log.info("Import referential.");
|
|
| 280 | 275 |
|
| 281 | 276 |
ObserveDataSourceConfiguration importDataSourceConfiguration = dataSourceCreateConfiguration.getImportReferentialDataSourceConfiguration();
|
| 282 | 277 |
|
| ... | ... | @@ -336,9 +331,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 336 | 331 |
// Récupération du dump qui contient les données
|
| 337 | 332 |
ImmutableSet<String> importDataIds = dataSourceCreateConfiguration.getImportDataIds();
|
| 338 | 333 |
|
| 339 |
- if (log.isInfoEnabled()) {
|
|
| 340 |
- log.info("Get data: " + importDataIds);
|
|
| 341 |
- }
|
|
| 334 |
+ log.info("Get data: " + importDataIds);
|
|
| 342 | 335 |
|
| 343 | 336 |
request.dataIdsToAdd(importDataIds);
|
| 344 | 337 |
|
| ... | ... | @@ -394,9 +387,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 394 | 387 |
|
| 395 | 388 |
@Override
|
| 396 | 389 |
public ObserveDataSourceConnectionTopia open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
|
| 397 |
- if (log.isTraceEnabled()) {
|
|
| 398 |
- log.trace("open(" + dataSourceConfiguration + ")");
|
|
| 399 |
- }
|
|
| 400 | 390 |
|
| 401 | 391 |
ObserveDataSourceInformation dataSourceInformation = checkCanConnect(dataSourceConfiguration);
|
| 402 | 392 |
|
| ... | ... | @@ -418,9 +408,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 418 | 408 |
|
| 419 | 409 |
@Override
|
| 420 | 410 |
public void close() {
|
| 421 |
- if (log.isTraceEnabled()) {
|
|
| 422 |
- log.trace("close()");
|
|
| 423 |
- }
|
|
| 424 | 411 |
|
| 425 | 412 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration = serviceContext.getDataSourceConfiguration().orElseThrow(IllegalStateException::new);
|
| 426 | 413 |
Optional<ObserveTopiaApplicationContext> optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getTopiaApplicationContextIfPresent(dataSourceConfiguration);
|
| ... | ... | @@ -431,9 +418,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 431 | 418 |
|
| 432 | 419 |
@Override
|
| 433 | 420 |
public void destroy() throws DatabaseDestroyNotAuthorizedException {
|
| 434 |
- if (log.isTraceEnabled()) {
|
|
| 435 |
- log.trace("destroy()");
|
|
| 436 |
- }
|
|
| 437 | 421 |
|
| 438 | 422 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration = serviceContext.getDataSourceConfiguration().orElseThrow(IllegalStateException::new);
|
| 439 | 423 |
|
| ... | ... | @@ -461,7 +445,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 461 | 445 |
public void backup(File backupFile) {
|
| 462 | 446 |
|
| 463 | 447 |
if (!serviceContext.getTopiaApplicationContext().getConfiguration().isH2Configuration()) {
|
| 464 |
- |
|
| 465 | 448 |
throw new IllegalStateException("Cant backup a none H2 database.");
|
| 466 | 449 |
}
|
| 467 | 450 |
|
| ... | ... | @@ -471,26 +454,32 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 471 | 454 |
|
| 472 | 455 |
@Override
|
| 473 | 456 |
public Set<ObserveDbUserDto> getUsers(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
| 474 |
- if (log.isTraceEnabled()) {
|
|
| 475 |
- log.trace("getUsers(" + dataSourceConfiguration + ")");
|
|
| 476 |
- }
|
|
| 477 | 457 |
|
| 478 |
- Set<ObserveDbUserDto> users = Sets.newHashSet();
|
|
| 458 |
+ Set<ObserveDbUserDto> users = new LinkedHashSet<>();
|
|
| 479 | 459 |
|
| 480 | 460 |
// pas d'user pour les bases autres que postgresql
|
| 481 | 461 |
if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
|
| 482 | 462 |
|
| 483 | 463 |
ObserveDataSourceConfigurationTopiaPG sourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfiguration;
|
| 484 | 464 |
|
| 485 |
- ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration);
|
|
| 486 |
- |
|
| 487 |
- ObserveTopiaConfiguration topiaConfiguration = topiaApplicationContext.getConfiguration();
|
|
| 465 |
+ try (ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration)) {
|
|
| 488 | 466 |
|
| 489 |
- ObserveJdbcHelper observeJdbcHelper = new ObserveJdbcHelper(topiaConfiguration);
|
|
| 467 |
+ ObserveTopiaConfiguration topiaConfiguration = topiaApplicationContext.getConfiguration();
|
|
| 490 | 468 |
|
| 491 |
- users.addAll(observeJdbcHelper.getUsers());
|
|
| 469 |
+ PostgresJdbcHelper observeJdbcHelper = new PostgresJdbcHelper(topiaConfiguration);
|
|
| 492 | 470 |
|
| 493 |
- topiaApplicationContext.close();
|
|
| 471 |
+ Set<String> userNames = observeJdbcHelper.getRoles();
|
|
| 472 |
+ for (String userName : userNames) {
|
|
| 473 |
+ ObserveDbUserDto user = new ObserveDbUserDto();
|
|
| 474 |
+ user.setName(userName);
|
|
| 475 |
+ if (topiaConfiguration.getJdbcConnectionUser().equals(userName)) {
|
|
| 476 |
+ user.setRole(ObserveDbRole.ADMINISTRATOR);
|
|
| 477 |
+ } else {
|
|
| 478 |
+ user.setRole(ObserveDbRole.UNUSED);
|
|
| 479 |
+ }
|
|
| 480 |
+ users.add(user);
|
|
| 481 |
+ }
|
|
| 482 |
+ }
|
|
| 494 | 483 |
|
| 495 | 484 |
}
|
| 496 | 485 |
|
| ... | ... | @@ -499,22 +488,18 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 499 | 488 |
|
| 500 | 489 |
@Override
|
| 501 | 490 |
public void applySecurity(ObserveDataSourceConfiguration dataSourceConfiguration, ImmutableSet<ObserveDbUserDto> users) {
|
| 502 |
- if (log.isTraceEnabled()) {
|
|
| 503 |
- log.trace("applySecurity(" + dataSourceConfiguration + ", [" + Joiner.on(", ").join(users.stream().map(ObserveDbUserDto::getName).collect(Collectors.toList())) + "])");
|
|
| 504 |
- }
|
|
| 505 | 491 |
|
| 506 | 492 |
// pas de securité pour les bases autres que postgresql
|
| 507 | 493 |
if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
|
| 508 | 494 |
|
| 509 | 495 |
ObserveDataSourceConfigurationTopiaPG sourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfiguration;
|
| 510 | 496 |
|
| 511 |
- ObserveTopiaApplicationContext optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration);
|
|
| 512 |
- |
|
| 513 |
- ObserveTopiaConfiguration topiaConfiguration = optionalTopiaApplicationContext.getConfiguration();
|
|
| 514 |
- |
|
| 515 |
- ObserveSecurityHelper securityHelper = new ObserveSecurityHelper(topiaConfiguration);
|
|
| 497 |
+ ObserveTopiaConfiguration topiaConfiguration;
|
|
| 498 |
+ try (ObserveTopiaApplicationContext optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration)) {
|
|
| 516 | 499 |
|
| 517 |
- securityHelper.applySecurity(users, sourceConfiguration.isShowMigrationSql());
|
|
| 500 |
+ topiaConfiguration = optionalTopiaApplicationContext.getConfiguration();
|
|
| 501 |
+ new ObserveSecurityHelper(topiaConfiguration).applySecurity(users);
|
|
| 502 |
+ }
|
|
| 518 | 503 |
|
| 519 | 504 |
}
|
| 520 | 505 |
|
| ... | ... | @@ -522,14 +507,8 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 522 | 507 |
|
| 523 | 508 |
@Override
|
| 524 | 509 |
public void migrateData(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
| 525 |
- if (log.isTraceEnabled()) {
|
|
| 526 |
- log.trace("migrateData(" + dataSourceConfiguration + ")");
|
|
| 527 |
- }
|
|
| 528 |
- |
|
| 529 | 510 |
ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration);
|
| 530 |
- |
|
| 531 | 511 |
topiaApplicationContext.getMigrationService().runSchemaMigration();
|
| 532 |
- |
|
| 533 | 512 |
}
|
| 534 | 513 |
|
| 535 | 514 |
@Override
|
| ... | ... | @@ -561,9 +540,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 561 | 540 |
|
| 562 | 541 |
Version version;
|
| 563 | 542 |
|
| 564 |
- ObserveJdbcHelper observeJdbcHelper = new ObserveJdbcHelper(topiaConfiguration);
|
|
| 543 |
+ PostgresJdbcHelper jdbcHelper = new PostgresJdbcHelper(topiaConfiguration);
|
|
| 565 | 544 |
|
| 566 |
- version = observeJdbcHelper.getVersion();
|
|
| 545 |
+ version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
|
|
| 567 | 546 |
|
| 568 | 547 |
if (dataSourceConfiguration.isH2Database()) {
|
| 569 | 548 |
|
| ... | ... | @@ -594,45 +573,36 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 594 | 573 |
// stockées dans pg canWriteData, canWrite pour etre sur du resultat
|
| 595 | 574 |
|
| 596 | 575 |
// recherche des droits sur les données observers
|
| 597 |
- Set<String> dataPrivileges = observeJdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_SEINE_SCHEMA_NAME, "trip");
|
|
| 576 |
+ Set<String> dataPrivileges = jdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_SEINE_SCHEMA_NAME, "trip");
|
|
| 598 | 577 |
|
| 599 | 578 |
readData = canRead(dataPrivileges);
|
| 600 | 579 |
writeData = canWrite(dataPrivileges);
|
| 601 | 580 |
|
| 602 | 581 |
|
| 603 | 582 |
// recherche des droits sur le referentiel
|
| 604 |
- Set<String> referentielPrivileges = observeJdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_COMMON_SCHEMA_NAME, "vessel");
|
|
| 583 |
+ Set<String> referentielPrivileges = jdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_COMMON_SCHEMA_NAME, "vessel");
|
|
| 605 | 584 |
|
| 606 | 585 |
// Sur une base PG, on regarde en base ce que l'utilisateur peut lire/écrire
|
| 607 | 586 |
writeReferential = canWrite(referentielPrivileges);
|
| 608 |
- |
|
| 609 | 587 |
}
|
| 610 | 588 |
|
| 611 |
- if (log.isDebugEnabled()) {
|
|
| 612 |
- log.debug("User can write referential : " + writeReferential + ", " +
|
|
| 613 |
- "read data : " + readData + ", " +
|
|
| 614 |
- "write data : " + writeData + ".");
|
|
| 615 |
- }
|
|
| 589 |
+ log.debug(String.format("User can write referential : %s, read data : %s, write data : %s.", writeReferential, readData, writeData));
|
|
| 616 | 590 |
|
| 617 |
- ObserveMigrationConfigurationProvider observeMigrationConfigurationProvider = ObserveMigrationConfigurationProvider.get();
|
|
| 591 |
+ MigrationVersionResourceProvider observeMigrationConfigurationProvider = MigrationVersionResourceProvider.get();
|
|
| 618 | 592 |
return new ObserveDataSourceInformation(
|
| 619 | 593 |
true,
|
| 620 | 594 |
writeReferential,
|
| 621 | 595 |
readData,
|
| 622 | 596 |
writeData,
|
| 623 |
- observeMigrationConfigurationProvider.getMinimumVersion(),
|
|
| 597 |
+ ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
|
|
| 624 | 598 |
version,
|
| 625 | 599 |
observeMigrationConfigurationProvider.getVersionsAfter(version));
|
| 626 | 600 |
}
|
| 627 | 601 |
|
| 628 | 602 |
private void close(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaApplicationContext topiaApplicationContext) {
|
| 629 | 603 |
if (topiaApplicationContext != null) {
|
| 630 |
- |
|
| 631 |
- if (log.isInfoEnabled()) {
|
|
| 632 |
- log.info("Closing topia application context: " + dataSourceConfiguration);
|
|
| 633 |
- }
|
|
| 604 |
+ log.info("Closing topia application context: " + dataSourceConfiguration);
|
|
| 634 | 605 |
topiaApplicationContext.close();
|
| 635 |
- |
|
| 636 | 606 |
}
|
| 637 | 607 |
}
|
| 638 | 608 |
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service.sql; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -24,7 +24,6 @@ package fr.ird.observe.services.local.service.sql; |
| 24 | 24 |
|
| 25 | 25 |
import com.google.common.collect.ImmutableSet;
|
| 26 | 26 |
import com.google.common.collect.ListMultimap;
|
| 27 |
-import org.nuiton.topia.persistence.util.TopiaBlobsContainer;
|
|
| 28 | 27 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 29 | 28 |
import fr.ird.observe.persistence.Entities;
|
| 30 | 29 |
import fr.ird.observe.persistence.ObserveEntityEnum;
|
| ... | ... | @@ -36,24 +35,18 @@ import fr.ird.observe.services.service.sql.DeleteSqlScriptProducerRequest; |
| 36 | 35 |
import fr.ird.observe.services.service.sql.SqlScriptProducerService;
|
| 37 | 36 |
import fr.ird.observe.spi.DbModelHelper;
|
| 38 | 37 |
import org.apache.commons.collections4.CollectionUtils;
|
| 39 |
-import org.apache.commons.logging.Log;
|
|
| 40 |
-import org.apache.commons.logging.LogFactory;
|
|
| 41 | 38 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
| 42 |
-import org.nuiton.topia.service.sql.batch.SqlRequests;
|
|
| 43 |
-import org.nuiton.topia.service.sql.batch.SqlResult;
|
|
| 44 |
-import org.nuiton.topia.service.sql.batch.TopiaSqlBatchService;
|
|
| 45 |
-import org.nuiton.topia.service.sql.batch.actions.BlobsContainer;
|
|
| 46 |
-import org.nuiton.topia.service.sql.batch.actions.TopiaSqlTableSelectArgument;
|
|
| 47 |
- |
|
| 48 |
-import java.io.ByteArrayOutputStream;
|
|
| 49 |
-import java.io.IOException;
|
|
| 50 |
-import java.io.OutputStreamWriter;
|
|
| 51 |
-import java.io.Writer;
|
|
| 52 |
-import java.nio.charset.StandardCharsets;
|
|
| 39 |
+import org.nuiton.topia.persistence.util.TopiaBlobsContainer;
|
|
| 40 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorRequest;
|
|
| 41 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorResult;
|
|
| 42 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorService;
|
|
| 43 |
+import org.nuiton.topia.service.script.request.TopiaSqlTableSelectArgument;
|
|
| 44 |
+ |
|
| 45 |
+import java.nio.file.Files;
|
|
| 46 |
+import java.nio.file.Path;
|
|
| 53 | 47 |
import java.util.List;
|
| 54 | 48 |
import java.util.Set;
|
| 55 | 49 |
import java.util.stream.Collectors;
|
| 56 |
-import java.util.zip.GZIPOutputStream;
|
|
| 57 | 50 |
|
| 58 | 51 |
import static fr.ird.observe.persistence.Entities.IS_LONGLINE_ID;
|
| 59 | 52 |
import static fr.ird.observe.persistence.Entities.IS_SEINE_ID;
|
| ... | ... | @@ -66,35 +59,29 @@ import static fr.ird.observe.persistence.Entities.REFERENCE_ENTITIES_LIST; |
| 66 | 59 |
*/
|
| 67 | 60 |
public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implements SqlScriptProducerService {
|
| 68 | 61 |
|
| 69 |
- private static final Log log = LogFactory.getLog(SqlScriptProducerServiceLocal.class);
|
|
| 70 |
- |
|
| 71 | 62 |
@Override
|
| 72 | 63 |
public AddSqlScriptProducerResult produceAddSqlScript(AddSqlScriptProducerRequest request) {
|
| 73 |
- if (log.isTraceEnabled()) {
|
|
| 74 |
- log.trace("produceAddSqlScript(" + request + ")");
|
|
| 75 |
- }
|
|
| 76 |
- try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
| 64 |
+ |
|
| 65 |
+ Path targetPath = serviceContext.getTemporaryDirectoryRoot().toPath().resolve("addSqlScript-" + System.nanoTime() + ".sql");
|
|
| 66 |
+ |
|
| 67 |
+ try {
|
|
| 77 | 68 |
|
| 78 | 69 |
ImmutableSet.Builder<TopiaBlobsContainer> observeBlobContainers = ImmutableSet.builder();
|
| 79 |
- try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(out), StandardCharsets.UTF_8)) {
|
|
| 80 |
- |
|
| 81 |
- TopiaSqlBatchService sqlBatchService = serviceContext.getTopiaApplicationContext().getSqlBatchService();
|
|
| 82 |
- SqlRequests.Builder builder = sqlBatchService.requestBuilder().to(writer);
|
|
| 83 |
- |
|
| 84 |
- SqlRequests sqlRequests = sqlRequests(request, builder);
|
|
| 85 |
- SqlResult sqlResult = sqlBatchService.execute(sqlRequests);
|
|
| 86 |
- ImmutableSet<BlobsContainer> blobsContainers = sqlResult.getBlobsContainers();
|
|
| 87 |
- for (BlobsContainer blobsContainer : blobsContainers) {
|
|
| 88 |
- observeBlobContainers.add(new TopiaBlobsContainer(blobsContainer.getTableName(),
|
|
| 89 |
- blobsContainer.getColumnName(),
|
|
| 90 |
- blobsContainer.getBlobsById()));
|
|
| 91 |
- }
|
|
| 92 | 70 |
|
| 93 |
- }
|
|
| 71 |
+ TopiaSqlScriptGeneratorService sqlBatchService = serviceContext.getTopiaApplicationContext().getSqlScriptGeneratorService();
|
|
| 72 |
+ TopiaSqlScriptGeneratorRequest builder = sqlBatchService.newRequest(targetPath);
|
|
| 94 | 73 |
|
| 95 |
- return new AddSqlScriptProducerResult(out.toByteArray(), observeBlobContainers.build());
|
|
| 74 |
+ sqlRequests(request, builder);
|
|
| 75 |
+ TopiaSqlScriptGeneratorResult sqlResult = sqlBatchService.generate(builder);
|
|
| 76 |
+ ImmutableSet<TopiaBlobsContainer> blobsContainers = sqlResult.getBlobsContainers();
|
|
| 77 |
+ for (TopiaBlobsContainer blobsContainer : blobsContainers) {
|
|
| 78 |
+ observeBlobContainers.add(new TopiaBlobsContainer(blobsContainer.getTableName(),
|
|
| 79 |
+ blobsContainer.getColumnName(),
|
|
| 80 |
+ blobsContainer.getBlobsById()));
|
|
| 81 |
+ }
|
|
| 82 |
+ return new AddSqlScriptProducerResult(Files.readAllBytes(targetPath), observeBlobContainers.build());
|
|
| 96 | 83 |
|
| 97 |
- } catch (IOException e) {
|
|
| 84 |
+ } catch (Exception e) {
|
|
| 98 | 85 |
throw new RuntimeException("Could not produce sql script", e);
|
| 99 | 86 |
}
|
| 100 | 87 |
|
| ... | ... | @@ -102,57 +89,40 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement |
| 102 | 89 |
|
| 103 | 90 |
@Override
|
| 104 | 91 |
public byte[] produceDeleteSqlScript(DeleteSqlScriptProducerRequest request) {
|
| 105 |
- if (log.isTraceEnabled()) {
|
|
| 106 |
- log.trace("produceDeleteSqlScript(" + request + ")");
|
|
| 107 |
- }
|
|
| 108 |
- try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
|
| 109 | 92 |
|
| 110 |
- try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(out), StandardCharsets.UTF_8)) {
|
|
| 93 |
+ Path targetPath = serviceContext.getTemporaryDirectoryRoot().toPath().resolve("deleteSqlScript-" + System.nanoTime() + ".sql");
|
|
| 111 | 94 |
|
| 112 |
- TopiaSqlBatchService sqlBatchService = serviceContext.getTopiaApplicationContext().getSqlBatchService();
|
|
| 113 |
- SqlRequests.Builder builder = sqlBatchService.requestBuilder().to(writer);
|
|
| 95 |
+ try {
|
|
| 114 | 96 |
|
| 115 |
- SqlRequests sqlRequests = sqlRequests(request, builder);
|
|
| 116 |
- sqlBatchService.execute(sqlRequests);
|
|
| 117 |
- |
|
| 118 |
- }
|
|
| 119 |
- |
|
| 120 |
- return out.toByteArray();
|
|
| 121 |
- |
|
| 122 |
- } catch (IOException e) {
|
|
| 123 |
- throw new RuntimeException("Could not produce delete sql script", e);
|
|
| 97 |
+ TopiaSqlScriptGeneratorService sqlBatchService = serviceContext.getTopiaApplicationContext().getSqlScriptGeneratorService();
|
|
| 98 |
+ TopiaSqlScriptGeneratorRequest builder = sqlBatchService.newRequest(targetPath);
|
|
| 99 |
+ sqlRequests(request, builder);
|
|
| 100 |
+ sqlBatchService.generate(builder);
|
|
| 101 |
+ return Files.readAllBytes(targetPath);
|
|
| 102 |
+ } catch (Exception e) {
|
|
| 103 |
+ throw new RuntimeException("Could not produce sql script", e);
|
|
| 124 | 104 |
}
|
| 105 |
+ |
|
| 125 | 106 |
}
|
| 126 | 107 |
|
| 127 | 108 |
@SuppressWarnings("unchecked")
|
| 128 |
- private SqlRequests sqlRequests(AddSqlScriptProducerRequest request, SqlRequests.Builder builder) {
|
|
| 109 |
+ private void sqlRequests(AddSqlScriptProducerRequest request, TopiaSqlScriptGeneratorRequest builder) {
|
|
| 129 | 110 |
|
| 130 |
- if (serviceContext.getTopiaApplicationContext().getConfiguration().isShowSql()) {
|
|
| 131 |
- builder.showSql();
|
|
| 111 |
+ if (request.isH2()) {
|
|
| 112 |
+ builder.forH2();
|
|
| 113 |
+ } else {
|
|
| 114 |
+ builder.forPostgresql();
|
|
| 132 | 115 |
}
|
| 133 | 116 |
|
| 134 | 117 |
if (request.isAddSchema()) {
|
| 135 |
- |
|
| 136 |
- SqlRequests.CreateSchemaRequestBuilder createSchemaRequestBuilder = builder
|
|
| 137 |
- .createSchemaBuilder()
|
|
| 138 |
- .setTemporaryPath(serviceContext.getTemporaryDirectoryRoot().toPath());
|
|
| 139 |
- if (request.isH2()) {
|
|
| 140 |
- createSchemaRequestBuilder.forH2();
|
|
| 141 |
- } else {
|
|
| 142 |
- createSchemaRequestBuilder.forPostgres();
|
|
| 143 |
- }
|
|
| 144 |
- createSchemaRequestBuilder.flush();
|
|
| 145 |
- |
|
| 118 |
+ builder.addCreateSchemaRequest(true, true);
|
|
| 146 | 119 |
}
|
| 147 | 120 |
|
| 148 | 121 |
ObserveTopiaApplicationContext topiaApplicationContext = serviceContext.getTopiaApplicationContext();
|
| 149 | 122 |
TopiaMetadataModel metadataModel = topiaApplicationContext.getMetadataModel();
|
| 150 | 123 |
|
| 151 | 124 |
if (request.isAddReferential()) {
|
| 152 |
- builder.replicateTablesBuilder(metadataModel)
|
|
| 153 |
- .setTables(topiaApplicationContext.getReferentialTables())
|
|
| 154 |
- .flush();
|
|
| 155 |
- |
|
| 125 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getReferentialTables(), null, metadataModel);
|
|
| 156 | 126 |
}
|
| 157 | 127 |
|
| 158 | 128 |
if (request.isAddSomeReferential()) {
|
| ... | ... | @@ -167,12 +137,7 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement |
| 167 | 137 |
Class referenceType = DbModelHelper.fromReferentialEntity(entityType).toReferenceType();
|
| 168 | 138 |
List<String> ids = referentialIds.get(referenceType);
|
| 169 | 139 |
if (CollectionUtils.isNotEmpty(ids)) {
|
| 170 |
- |
|
| 171 |
- builder.replicateTablesBuilder(metadataModel)
|
|
| 172 |
- .setTables(topiaApplicationContext.getReferentialTable(entityType))
|
|
| 173 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(ids))
|
|
| 174 |
- .flush();
|
|
| 175 |
- |
|
| 140 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getReferentialTable(entityType), TopiaSqlTableSelectArgument.of(ids), metadataModel);
|
|
| 176 | 141 |
}
|
| 177 | 142 |
}
|
| 178 | 143 |
|
| ... | ... | @@ -183,27 +148,16 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement |
| 183 | 148 |
ImmutableSet<String> tripIds = request.getDataIds();
|
| 184 | 149 |
if (tripIds == null) {
|
| 185 | 150 |
|
| 186 |
- builder.replicateTablesBuilder(metadataModel)
|
|
| 187 |
- .setTables(topiaApplicationContext.getTripSeineTables())
|
|
| 188 |
- .replicateTablesBuilder(metadataModel)
|
|
| 189 |
- .setTables(topiaApplicationContext.getTripLonglineTables())
|
|
| 190 |
- .flush();
|
|
| 151 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getTripSeineTables(), null, metadataModel);
|
|
| 152 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getTripLonglineTables(), null, metadataModel);
|
|
| 191 | 153 |
|
| 192 | 154 |
} else {
|
| 193 | 155 |
|
| 194 | 156 |
{
|
| 195 |
- |
|
| 196 | 157 |
Set<String> tripIds1 = tripIds.stream().filter(IS_SEINE_ID).collect(Collectors.toSet());
|
| 197 |
- |
|
| 198 | 158 |
if (!tripIds1.isEmpty()) {
|
| 199 |
- |
|
| 200 |
- builder.replicateTablesBuilder(metadataModel)
|
|
| 201 |
- .setTables(topiaApplicationContext.getTripSeineTables())
|
|
| 202 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds1))
|
|
| 203 |
- .flush();
|
|
| 204 |
- |
|
| 159 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getTripSeineTables(), TopiaSqlTableSelectArgument.of(tripIds1), metadataModel);
|
|
| 205 | 160 |
}
|
| 206 |
- |
|
| 207 | 161 |
}
|
| 208 | 162 |
|
| 209 | 163 |
{
|
| ... | ... | @@ -211,28 +165,14 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement |
| 211 | 165 |
Set<String> tripIds1 = tripIds.stream().filter(IS_LONGLINE_ID).collect(Collectors.toSet());
|
| 212 | 166 |
|
| 213 | 167 |
if (!tripIds1.isEmpty()) {
|
| 214 |
- |
|
| 215 |
- builder.replicateTablesBuilder(metadataModel)
|
|
| 216 |
- .setTables(topiaApplicationContext.getTripLonglineTables())
|
|
| 217 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds1))
|
|
| 218 |
- .flush();
|
|
| 219 |
- |
|
| 168 |
+ builder.addReplicateTablesRequest(topiaApplicationContext.getTripLonglineTables(), TopiaSqlTableSelectArgument.of(tripIds1), metadataModel);
|
|
| 220 | 169 |
}
|
| 221 |
- |
|
| 222 | 170 |
}
|
| 223 |
- |
|
| 224 | 171 |
}
|
| 225 |
- |
|
| 226 | 172 |
}
|
| 227 |
- |
|
| 228 |
- return builder.build();
|
|
| 229 | 173 |
}
|
| 230 | 174 |
|
| 231 |
- private SqlRequests sqlRequests(DeleteSqlScriptProducerRequest request, SqlRequests.Builder builder) {
|
|
| 232 |
- |
|
| 233 |
- if (serviceContext.getTopiaApplicationContext().getConfiguration().isShowSql()) {
|
|
| 234 |
- builder.showSql();
|
|
| 235 |
- }
|
|
| 175 |
+ private void sqlRequests(DeleteSqlScriptProducerRequest request, TopiaSqlScriptGeneratorRequest builder) {
|
|
| 236 | 176 |
|
| 237 | 177 |
ObserveTopiaApplicationContext topiaApplicationContext = serviceContext.getTopiaApplicationContext();
|
| 238 | 178 |
|
| ... | ... | @@ -241,49 +181,26 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement |
| 241 | 181 |
ImmutableSet<String> tripIds = request.getDataIds();
|
| 242 | 182 |
if (tripIds == null) {
|
| 243 | 183 |
|
| 244 |
- builder.deleteTablesBuilder()
|
|
| 245 |
- .setTables(topiaApplicationContext.getTripSeineTables())
|
|
| 246 |
- .replicateTablesBuilder(topiaApplicationContext.getMetadataModel())
|
|
| 247 |
- .setTables(topiaApplicationContext.getTripLonglineTables())
|
|
| 248 |
- .flush();
|
|
| 184 |
+ builder.addDeleteTablesRequest(topiaApplicationContext.getTripSeineTables(), null);
|
|
| 185 |
+ builder.addDeleteTablesRequest(topiaApplicationContext.getTripLonglineTables(), null);
|
|
| 249 | 186 |
|
| 250 | 187 |
} else {
|
| 251 | 188 |
|
| 252 | 189 |
{
|
| 253 |
- |
|
| 254 | 190 |
Set<String> tripIds1 = tripIds.stream().filter(Entities.IS_SEINE_ID).collect(Collectors.toSet());
|
| 255 |
- |
|
| 256 | 191 |
if (!tripIds1.isEmpty()) {
|
| 257 |
- |
|
| 258 |
- builder.deleteTablesBuilder()
|
|
| 259 |
- .setTables(topiaApplicationContext.getTripSeineTables())
|
|
| 260 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds1))
|
|
| 261 |
- .flush();
|
|
| 262 |
- |
|
| 192 |
+ builder.addDeleteTablesRequest(topiaApplicationContext.getTripSeineTables(), TopiaSqlTableSelectArgument.of(tripIds1));
|
|
| 263 | 193 |
}
|
| 264 |
- |
|
| 265 | 194 |
}
|
| 266 | 195 |
|
| 267 | 196 |
{
|
| 268 |
- |
|
| 269 | 197 |
Set<String> tripIds1 = tripIds.stream().filter(Entities.IS_LONGLINE_ID).collect(Collectors.toSet());
|
| 270 |
- |
|
| 271 | 198 |
if (!tripIds1.isEmpty()) {
|
| 272 |
- |
|
| 273 |
- builder.deleteTablesBuilder()
|
|
| 274 |
- .setTables(topiaApplicationContext.getTripLonglineTables())
|
|
| 275 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds1))
|
|
| 276 |
- .flush();
|
|
| 277 |
- |
|
| 199 |
+ builder.addDeleteTablesRequest(topiaApplicationContext.getTripLonglineTables(), TopiaSqlTableSelectArgument.of(tripIds1));
|
|
| 278 | 200 |
}
|
| 279 |
- |
|
| 280 | 201 |
}
|
| 281 |
- |
|
| 282 | 202 |
}
|
| 283 |
- |
|
| 284 | 203 |
}
|
| 285 |
- |
|
| 286 |
- return builder.build();
|
|
| 287 | 204 |
}
|
| 288 | 205 |
|
| 289 | 206 |
}
|
| ... | ... | @@ -10,23 +10,23 @@ package fr.ird.observe.services.local; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
|
|
| 26 | 25 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
|
| 27 | 26 |
import fr.ird.observe.test.TestHelper;
|
| 28 | 27 |
import org.apache.commons.logging.Log;
|
| 29 | 28 |
import org.apache.commons.logging.LogFactory;
|
| 29 |
+import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
|
|
| 30 | 30 |
import org.nuiton.version.Version;
|
| 31 | 31 |
|
| 32 | 32 |
import java.io.File;
|
| ... | ... | @@ -100,7 +100,7 @@ public class DataSourcesForTestManager { |
| 100 | 100 |
configurationTopiaH2.setDirectory(localDbFile);
|
| 101 | 101 |
configurationTopiaH2.setDbName("obstuna");
|
| 102 | 102 |
configurationTopiaH2.setAutoMigrate(true);
|
| 103 |
- configurationTopiaH2.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
|
|
| 103 |
+ configurationTopiaH2.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
|
|
| 104 | 104 |
return configurationTopiaH2;
|
| 105 | 105 |
|
| 106 | 106 |
}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.entity; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -26,8 +26,8 @@ import fr.ird.observe.test.DatabaseName; |
| 26 | 26 |
import fr.ird.observe.test.ObserveFixtures;
|
| 27 | 27 |
import fr.ird.observe.test.spi.DatabaseNameConfiguration;
|
| 28 | 28 |
import org.junit.Test;
|
| 29 |
-import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest;
|
|
| 30 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables;
|
|
| 29 |
+import org.nuiton.topia.service.script.request.ReplicateTablesRequest;
|
|
| 30 |
+import org.nuiton.topia.service.script.table.TopiaSqlTables;
|
|
| 31 | 31 |
|
| 32 | 32 |
/**
|
| 33 | 33 |
* Created on 29/12/15.
|
| ... | ... | @@ -42,11 +42,7 @@ public class ReplicateReferentialsTest extends ReplicateTestSupport { |
| 42 | 42 |
|
| 43 | 43 |
TopiaSqlTables tables = localTestMethodResource.getTopiaApplicationContext().getReferentialTables();
|
| 44 | 44 |
|
| 45 |
- ReplicateTablesRequest request
|
|
| 46 |
- = createReplicateTablesRequest(DatabaseName.empty_h2)
|
|
| 47 |
- .setTables(tables)
|
|
| 48 |
- .build();
|
|
| 49 |
- |
|
| 45 |
+ ReplicateTablesRequest request = createReplicateTablesRequest(DatabaseName.empty_h2, tables, null);
|
|
| 50 | 46 |
testReplicate0(request, ObserveFixtures.REFERENTIAL_TABLES_COUNT);
|
| 51 | 47 |
|
| 52 | 48 |
}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.entity; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -23,7 +23,6 @@ package fr.ird.observe.services.local.entity; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import com.google.common.collect.ImmutableMap;
|
| 26 |
-import com.google.common.io.Files;
|
|
| 27 | 26 |
import fr.ird.observe.persistence.ObserveTopiaApplicationContext;
|
| 28 | 27 |
import fr.ird.observe.persistence.ObserveTopiaPersistenceContext;
|
| 29 | 28 |
import fr.ird.observe.services.configuration.DataSourceCreateWithNoReferentialImportException;
|
| ... | ... | @@ -38,15 +37,16 @@ import fr.ird.observe.test.DatabaseName; |
| 38 | 37 |
import org.apache.commons.logging.Log;
|
| 39 | 38 |
import org.apache.commons.logging.LogFactory;
|
| 40 | 39 |
import org.junit.Assert;
|
| 41 |
-import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest;
|
|
| 42 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable;
|
|
| 43 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables;
|
|
| 40 |
+import org.nuiton.topia.persistence.util.SqlScriptConsumer;
|
|
| 41 |
+import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorRequest;
|
|
| 42 |
+import org.nuiton.topia.service.script.request.ReplicateTablesRequest;
|
|
| 43 |
+import org.nuiton.topia.service.script.request.TopiaSqlTableSelectArgument;
|
|
| 44 |
+import org.nuiton.topia.service.script.table.TopiaSqlTable;
|
|
| 45 |
+import org.nuiton.topia.service.script.table.TopiaSqlTables;
|
|
| 44 | 46 |
import org.nuiton.util.StringUtil;
|
| 45 | 47 |
|
| 46 | 48 |
import java.io.File;
|
| 47 | 49 |
import java.io.IOException;
|
| 48 |
-import java.io.Writer;
|
|
| 49 |
-import java.nio.charset.StandardCharsets;
|
|
| 50 | 50 |
import java.util.Map;
|
| 51 | 51 |
|
| 52 | 52 |
/**
|
| ... | ... | @@ -62,29 +62,15 @@ class ReplicateTestSupport extends ServiceLocalTestSupport { |
| 62 | 62 |
private static final Log log = LogFactory.getLog(ReplicateTestSupport.class);
|
| 63 | 63 |
|
| 64 | 64 |
private File scriptFile;
|
| 65 |
+ private ObserveTopiaApplicationContext targetTopiaApplicationContext;
|
|
| 65 | 66 |
|
| 66 |
- ReplicateTablesRequest.Builder createReplicateTablesRequest(DatabaseName databaseName) throws DataSourceCreateWithNoReferentialImportException, IOException, IncompatibleDataSourceCreateConfigurationException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 67 |
- |
|
| 68 |
- File targetDatabaseDirectory = new File(localTestMethodResource.getTestDirectory(), "targetReplication");
|
|
| 69 |
- ObserveDataSourceConfigurationTopiaH2 targetTopiaConfiguration = TOPIA_TEST_CLASS_RESOURCE.createDataSourceConfiguration(localTestMethodResource.getDbVersion(), databaseName.name(), targetDatabaseDirectory, localTestMethodResource.getLogin(), localTestMethodResource.getPassword());
|
|
| 70 |
- ObserveTopiaApplicationContext targetTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(targetTopiaConfiguration);
|
|
| 71 |
- |
|
| 72 |
- scriptFile = new File(localTestMethodResource.getTestDirectory(), "script.sql");
|
|
| 73 |
- |
|
| 74 |
- Writer writer = Files.newWriter(scriptFile, StandardCharsets.UTF_8);
|
|
| 75 |
- |
|
| 76 |
- return localTestMethodResource.getTopiaApplicationContext()
|
|
| 77 |
- .getSqlBatchService()
|
|
| 78 |
- .replicateTablesRequestBuilder()
|
|
| 79 |
- .to(targetTopiaApplicationContext)
|
|
| 80 |
- .to(writer);
|
|
| 81 |
- }
|
|
| 82 |
- |
|
| 83 |
- private static void assertReplicateTripResults(ReplicateTablesRequest replicationRequest, ImmutableMap<String, Long> expectedResults) {
|
|
| 67 |
+ private static void assertReplicateTripResults(ObserveTopiaApplicationContext targetTopiaApplicationContext, File scriptFile, ReplicateTablesRequest replicationRequest, ImmutableMap<String, Long> expectedResults) {
|
|
| 84 | 68 |
|
| 85 | 69 |
TopiaSqlTables tables = replicationRequest.getTables();
|
| 86 |
- try (ObserveTopiaPersistenceContext persistenceContext = (ObserveTopiaPersistenceContext) replicationRequest.getTargetTopiaApplicationContext().newPersistenceContext()) {
|
|
| 87 | 70 |
|
| 71 |
+ try (ObserveTopiaPersistenceContext persistenceContext = targetTopiaApplicationContext.newPersistenceContext()) {
|
|
| 72 |
+ |
|
| 73 |
+ persistenceContext.getSqlSupport().doSqlWork(SqlScriptConsumer.of(scriptFile.toPath()));
|
|
| 88 | 74 |
for (TopiaSqlTable table : tables) {
|
| 89 | 75 |
|
| 90 | 76 |
String fullyTableName = table.getFullyTableName();
|
| ... | ... | @@ -112,17 +98,33 @@ class ReplicateTestSupport extends ServiceLocalTestSupport { |
| 112 | 98 |
|
| 113 | 99 |
}
|
| 114 | 100 |
|
| 101 |
+ ReplicateTablesRequest createReplicateTablesRequest(DatabaseName databaseName, TopiaSqlTables tables, TopiaSqlTableSelectArgument selectedArgument) throws DataSourceCreateWithNoReferentialImportException, IOException, IncompatibleDataSourceCreateConfigurationException, BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 102 |
+ |
|
| 103 |
+ File targetDatabaseDirectory = new File(localTestMethodResource.getTestDirectory(), "targetReplication");
|
|
| 104 |
+ ObserveDataSourceConfigurationTopiaH2 targetTopiaConfiguration = TOPIA_TEST_CLASS_RESOURCE.createDataSourceConfiguration(localTestMethodResource.getDbVersion(), databaseName.name(), targetDatabaseDirectory, localTestMethodResource.getLogin(), localTestMethodResource.getPassword());
|
|
| 105 |
+ targetTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(targetTopiaConfiguration);
|
|
| 106 |
+ |
|
| 107 |
+ scriptFile = new File(localTestMethodResource.getTestDirectory(), "script.sql");
|
|
| 108 |
+ |
|
| 109 |
+ return new ReplicateTablesRequest(tables, selectedArgument, targetTopiaApplicationContext.getMetadataModel());
|
|
| 110 |
+ }
|
|
| 111 |
+ |
|
| 115 | 112 |
void testReplicate0(ReplicateTablesRequest request, ImmutableMap<String, Long> expectedTablesCount) {
|
| 116 | 113 |
|
| 117 | 114 |
TopiaSqlTables tables = request.getTables();
|
| 118 | 115 |
log.info(String.format("Will replicate using %d tables.", tables.size()));
|
| 119 | 116 |
|
| 117 |
+ TopiaSqlScriptGeneratorRequest generatorRequest = localTestMethodResource.getTopiaApplicationContext()
|
|
| 118 |
+ .getSqlScriptGeneratorService()
|
|
| 119 |
+ .newRequest(scriptFile.toPath())
|
|
| 120 |
+ .gzip(false)
|
|
| 121 |
+ .addRequest(request);
|
|
| 120 | 122 |
localTestMethodResource.getTopiaApplicationContext()
|
| 121 |
- .getSqlBatchService()
|
|
| 122 |
- .execute(request);
|
|
| 123 |
+ .getSqlScriptGeneratorService()
|
|
| 124 |
+ .generate(generatorRequest);
|
|
| 123 | 125 |
|
| 124 | 126 |
|
| 125 |
- assertReplicateTripResults(request, expectedTablesCount);
|
|
| 127 |
+ assertReplicateTripResults(targetTopiaApplicationContext, scriptFile, request, expectedTablesCount);
|
|
| 126 | 128 |
|
| 127 | 129 |
log.debug(String.format("Replicate to script (length: %s) :\n%s", StringUtil.convertMemory(scriptFile.length()), scriptFile));
|
| 128 | 130 |
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.entity; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -33,9 +33,9 @@ import fr.ird.observe.test.ObserveFixtures; |
| 33 | 33 |
import fr.ird.observe.test.spi.DatabaseNameConfiguration;
|
| 34 | 34 |
import org.junit.Ignore;
|
| 35 | 35 |
import org.junit.Test;
|
| 36 |
-import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest;
|
|
| 37 |
-import org.nuiton.topia.service.sql.batch.actions.TopiaSqlTableSelectArgument;
|
|
| 38 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables;
|
|
| 36 |
+import org.nuiton.topia.service.script.request.ReplicateTablesRequest;
|
|
| 37 |
+import org.nuiton.topia.service.script.request.TopiaSqlTableSelectArgument;
|
|
| 38 |
+import org.nuiton.topia.service.script.table.TopiaSqlTables;
|
|
| 39 | 39 |
|
| 40 | 40 |
import java.io.IOException;
|
| 41 | 41 |
|
| ... | ... | @@ -57,9 +57,9 @@ public class ReplicateTripLonglineTest extends ReplicateTestSupport { |
| 57 | 57 |
@Test
|
| 58 | 58 |
public void testReplicateAllTripLongline2() throws Exception {
|
| 59 | 59 |
testReplicate(ObserveFixtures.ALL_TRIP_LONGLINE_COUNT,
|
| 60 |
- ObserveFixtures.TRIP_LONGLINE_ID_1,
|
|
| 61 |
- ObserveFixtures.TRIP_LONGLINE_ID_2,
|
|
| 62 |
- ObserveFixtures.TRIP_LONGLINE_ID_3);
|
|
| 60 |
+ ObserveFixtures.TRIP_LONGLINE_ID_1,
|
|
| 61 |
+ ObserveFixtures.TRIP_LONGLINE_ID_2,
|
|
| 62 |
+ ObserveFixtures.TRIP_LONGLINE_ID_3);
|
|
| 63 | 63 |
}
|
| 64 | 64 |
|
| 65 | 65 |
@Test
|
| ... | ... | @@ -80,12 +80,7 @@ public class ReplicateTripLonglineTest extends ReplicateTestSupport { |
| 80 | 80 |
protected void testReplicate(ImmutableMap<String, Long> expectedTablesCount, String... tripIds) throws DataSourceCreateWithNoReferentialImportException, IOException, IncompatibleDataSourceCreateConfigurationException, DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
|
| 81 | 81 |
|
| 82 | 82 |
TopiaSqlTables tables = localTestMethodResource.getTopiaApplicationContext().getTripLonglineTables();
|
| 83 |
- ReplicateTablesRequest request
|
|
| 84 |
- = createReplicateTablesRequest(DatabaseName.referentiel)
|
|
| 85 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds))
|
|
| 86 |
- .setTables(tables)
|
|
| 87 |
- .build();
|
|
| 88 |
- |
|
| 83 |
+ ReplicateTablesRequest request = createReplicateTablesRequest(DatabaseName.referentiel, tables, TopiaSqlTableSelectArgument.of(tripIds));
|
|
| 89 | 84 |
testReplicate0(request, expectedTablesCount);
|
| 90 | 85 |
|
| 91 | 86 |
}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.entity; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -27,9 +27,9 @@ import fr.ird.observe.test.DatabaseName; |
| 27 | 27 |
import fr.ird.observe.test.ObserveFixtures;
|
| 28 | 28 |
import fr.ird.observe.test.spi.DatabaseNameConfiguration;
|
| 29 | 29 |
import org.junit.Test;
|
| 30 |
-import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest;
|
|
| 31 |
-import org.nuiton.topia.service.sql.batch.actions.TopiaSqlTableSelectArgument;
|
|
| 32 |
-import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables;
|
|
| 30 |
+import org.nuiton.topia.service.script.request.ReplicateTablesRequest;
|
|
| 31 |
+import org.nuiton.topia.service.script.request.TopiaSqlTableSelectArgument;
|
|
| 32 |
+import org.nuiton.topia.service.script.table.TopiaSqlTables;
|
|
| 33 | 33 |
|
| 34 | 34 |
/**
|
| 35 | 35 |
* Created on 29/12/15.
|
| ... | ... | @@ -52,9 +52,9 @@ public class ReplicateTripSeineTest extends ReplicateTestSupport { |
| 52 | 52 |
@Test
|
| 53 | 53 |
public void testReplicateAllTripSeine2() throws Exception {
|
| 54 | 54 |
testReplicate(ObserveFixtures.ALL_TRIP_SEINE_COUNT,
|
| 55 |
- ObserveFixtures.TRIP_SEINE_ID_1,
|
|
| 56 |
- ObserveFixtures.TRIP_SEINE_ID_2,
|
|
| 57 |
- ObserveFixtures.TRIP_SEINE_ID_3);
|
|
| 55 |
+ ObserveFixtures.TRIP_SEINE_ID_1,
|
|
| 56 |
+ ObserveFixtures.TRIP_SEINE_ID_2,
|
|
| 57 |
+ ObserveFixtures.TRIP_SEINE_ID_3);
|
|
| 58 | 58 |
}
|
| 59 | 59 |
|
| 60 | 60 |
@Test
|
| ... | ... | @@ -68,15 +68,8 @@ public class ReplicateTripSeineTest extends ReplicateTestSupport { |
| 68 | 68 |
}
|
| 69 | 69 |
|
| 70 | 70 |
protected void testReplicate(ImmutableMap<String, Long> expectedTablesCount, String... tripIds) throws Exception {
|
| 71 |
- |
|
| 72 | 71 |
TopiaSqlTables tables = localTestMethodResource.getTopiaApplicationContext().getTripSeineTables();
|
| 73 |
- |
|
| 74 |
- ReplicateTablesRequest request
|
|
| 75 |
- = createReplicateTablesRequest(DatabaseName.referentiel)
|
|
| 76 |
- .setSelectArgument(TopiaSqlTableSelectArgument.of(tripIds))
|
|
| 77 |
- .setTables(tables)
|
|
| 78 |
- .build();
|
|
| 79 |
- |
|
| 72 |
+ ReplicateTablesRequest request = createReplicateTablesRequest(DatabaseName.referentiel, tables, TopiaSqlTableSelectArgument.of(tripIds));
|
|
| 80 | 73 |
testReplicate0(request, expectedTablesCount);
|
| 81 | 74 |
|
| 82 | 75 |
}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service; |
| 10 | 10 |
* it under the terms of the GNU General Public License as
|
| 11 | 11 |
* published by the Free Software Foundation, either version 3 of the
|
| 12 | 12 |
* License, or (at your option) any later version.
|
| 13 |
- *
|
|
| 13 |
+ *
|
|
| 14 | 14 |
* This program is distributed in the hope that it will be useful,
|
| 15 | 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 | 17 |
* GNU General Public License for more details.
|
| 18 |
- *
|
|
| 18 |
+ *
|
|
| 19 | 19 |
* You should have received a copy of the GNU General Public
|
| 20 | 20 |
* License along with this program. If not, see
|
| 21 | 21 |
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... | ... | @@ -25,7 +25,6 @@ package fr.ird.observe.services.local.service; |
| 25 | 25 |
import fr.ird.observe.dto.data.seine.TripSeineDto;
|
| 26 | 26 |
import fr.ird.observe.dto.form.Form;
|
| 27 | 27 |
import fr.ird.observe.dto.referential.ProgramDto;
|
| 28 |
-import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
|
|
| 29 | 28 |
import fr.ird.observe.services.configuration.ObserveDataSourceConnection;
|
| 30 | 29 |
import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG;
|
| 31 | 30 |
import fr.ird.observe.services.security.UnauthorizedException;
|
| ... | ... | @@ -42,6 +41,7 @@ import fr.ird.observe.test.spi.DatabasePasswordConfiguration; |
| 42 | 41 |
import org.junit.Assert;
|
| 43 | 42 |
import org.junit.Ignore;
|
| 44 | 43 |
import org.junit.Test;
|
| 44 |
+import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
|
|
| 45 | 45 |
|
| 46 | 46 |
/**
|
| 47 | 47 |
* FIXME Ca sert à quoi ? et je comprends pas le mot rigth ?
|
| ... | ... | @@ -102,13 +102,12 @@ public class RigthTest extends ServiceLocalTestSupport { |
| 102 | 102 |
configurationTopiaPG.setUsername(login);
|
| 103 | 103 |
configurationTopiaPG.setPassword('a');
|
| 104 | 104 |
configurationTopiaPG.setAutoMigrate(true);
|
| 105 |
- configurationTopiaPG.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
|
|
| 105 |
+ configurationTopiaPG.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
|
|
| 106 | 106 |
|
| 107 | 107 |
return configurationTopiaPG;
|
| 108 | 108 |
|
| 109 | 109 |
}
|
| 110 | 110 |
|
| 111 |
- |
|
| 112 | 111 |
public void testReadData(String login) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException, BabModelVersionException {
|
| 113 | 112 |
|
| 114 | 113 |
TripSeineService service = localTestMethodResource.newService(TripSeineService.class);
|