Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
175475b0
by tchemit at 2019-06-28T15:50:09Z
15 changed files:
- client-core/src/main/i18n/getters/java.getter
- client-core/src/main/java/fr/ird/observe/client/db/ObserveDataSourcesManager.java
- client-core/src/main/java/fr/ird/observe/client/db/ObserveSwingDataSource.java
- client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/TestRemoteUIAction.java
- client-core/src/main/java/fr/ird/observe/client/ui/actions/storage/presets/TestServerUIAction.java
- client-core/src/main/java/fr/ird/observe/client/ui/admin/config/ConfigModel.java
- client-core/src/main/java/fr/ird/observe/client/ui/storage/StorageUIHandler.java
- client-core/src/main/java/fr/ird/observe/client/ui/storage/StorageUIModel.java
- observe-i18n/src/main/i18n/translations/observe_en_GB.properties
- observe-i18n/src/main/i18n/translations/observe_es_ES.properties
- observe-i18n/src/main/i18n/translations/observe_fr_FR.properties
- pom.xml
- server-core/src/main/filtered-resources/mapping
- services-local/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java
- services/src/main/java/fr/ird/observe/services/service/DataSourceService.java
Changes:
| ... | ... | @@ -910,6 +910,7 @@ observe.storage.error.rest.user.required |
| 910 | 910 |
observe.storage.error.rest.user.unknown
|
| 911 | 911 |
observe.storage.error.serverVersionMismatch
|
| 912 | 912 |
observe.storage.error.serverVersionModelMismatch
|
| 913 |
+observe.storage.error.user.not.owner
|
|
| 913 | 914 |
observe.storage.internalDump.last.modified
|
| 914 | 915 |
observe.storage.internalDump.not.exist
|
| 915 | 916 |
observe.storage.label.data.import.db
|
| ... | ... | @@ -125,7 +125,9 @@ public class ObserveDataSourcesManager implements Closeable { |
| 125 | 125 |
dataSource = newDataSource(configuration);
|
| 126 | 126 |
break;
|
| 127 | 127 |
}
|
| 128 |
- |
|
| 128 |
+ if (model.getDataSourceInformation() != null) {
|
|
| 129 |
+ dataSource.setOwner(model.getDataSourceInformation().isOwner());
|
|
| 130 |
+ }
|
|
| 129 | 131 |
return dataSource;
|
| 130 | 132 |
}
|
| 131 | 133 |
|
| ... | ... | @@ -293,8 +295,8 @@ public class ObserveDataSourcesManager implements Closeable { |
| 293 | 295 |
|
| 294 | 296 |
try {
|
| 295 | 297 |
|
| 296 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 297 |
- |
|
| 298 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 299 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 298 | 300 |
dataSource.migrateDataIfPossible(dataSourceInformation, config.getModelVersion());
|
| 299 | 301 |
|
| 300 | 302 |
// la source sera utilisée dans les ui
|
| ... | ... | @@ -360,7 +362,8 @@ public class ObserveDataSourcesManager implements Closeable { |
| 360 | 362 |
|
| 361 | 363 |
try {
|
| 362 | 364 |
|
| 363 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 365 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 366 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 364 | 367 |
|
| 365 | 368 |
dataSource.migrateData(dataSourceInformation, config.getModelVersion());
|
| 366 | 369 |
|
| ... | ... | @@ -151,6 +151,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 151 | 151 |
|
| 152 | 152 |
// indique si une modification a été effectuéé sur la base depuis son ouverture
|
| 153 | 153 |
private boolean modified;
|
| 154 |
+ private boolean owner;
|
|
| 154 | 155 |
|
| 155 | 156 |
public ObserveSwingDataSource(ObserveDataSourceConfiguration configuration) {
|
| 156 | 157 |
this.configuration = configuration;
|
| ... | ... | @@ -223,7 +224,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 223 | 224 |
canWriteReferential(),
|
| 224 | 225 |
canReadData(),
|
| 225 | 226 |
canWriteData(),
|
| 226 |
- getVersion(),
|
|
| 227 |
+ isOwner(), getVersion(),
|
|
| 227 | 228 |
getVersion(),
|
| 228 | 229 |
ImmutableList.of());
|
| 229 | 230 |
}
|
| ... | ... | @@ -395,6 +396,10 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 395 | 396 |
|
| 396 | 397 |
}
|
| 397 | 398 |
|
| 399 |
+ public boolean isOwner() {
|
|
| 400 |
+ return owner;
|
|
| 401 |
+ }
|
|
| 402 |
+ |
|
| 398 | 403 |
void migrateDataIfPossible(ObserveDataSourceInformation dataSourceInformation, Version targetVersion) {
|
| 399 | 404 |
|
| 400 | 405 |
checkIsNotOpen();
|
| ... | ... | @@ -445,10 +450,10 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 445 | 450 |
return connection != null;
|
| 446 | 451 |
}
|
| 447 | 452 |
|
| 448 |
- public ObserveDataSourceInformation checkCanConnect() throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 453 |
+ public ObserveDataSourceInformation checkCanConnect(boolean canBeEmpty) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 449 | 454 |
checkIsNotAlreadyOpen();
|
| 450 | 455 |
DataSourceService dataSourceService = servicesProvider.getDataSourceService();
|
| 451 |
- return dataSourceService.checkCanConnect(configuration);
|
|
| 456 |
+ return canBeEmpty ? dataSourceService.checkCanConnectOrBeEmpty(configuration) : dataSourceService.checkCanConnect(configuration);
|
|
| 452 | 457 |
}
|
| 453 | 458 |
|
| 454 | 459 |
public boolean isLocal() {
|
| ... | ... | @@ -828,4 +833,12 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 828 | 833 |
public void setProgressModel(ProgressModel progressModel) {
|
| 829 | 834 |
this.progressModel = progressModel;
|
| 830 | 835 |
}
|
| 836 |
+ |
|
| 837 |
+ public void setOwner(boolean owner) {
|
|
| 838 |
+ this.owner = owner;
|
|
| 839 |
+ }
|
|
| 840 |
+ |
|
| 841 |
+ public boolean getOwner() {
|
|
| 842 |
+ return owner;
|
|
| 843 |
+ }
|
|
| 831 | 844 |
}
|
| ... | ... | @@ -67,7 +67,8 @@ public class TestRemoteUIAction extends PresetsUIActionSupport { |
| 67 | 67 |
ObserveSwingDataSource dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(config);
|
| 68 | 68 |
try {
|
| 69 | 69 |
|
| 70 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 70 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 71 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 71 | 72 |
|
| 72 | 73 |
Version versionDataSource = dataSourceInformation.getVersion();
|
| 73 | 74 |
|
| ... | ... | @@ -102,7 +102,7 @@ public class TestServerUIAction extends PresetsUIActionSupport { |
| 102 | 102 |
}
|
| 103 | 103 |
if (connexionStatusError == null) {
|
| 104 | 104 |
|
| 105 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 105 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 106 | 106 |
|
| 107 | 107 |
Version versionDataSource = dataSourceInformation.getVersion();
|
| 108 | 108 |
|
| ... | ... | @@ -651,7 +651,7 @@ public class ConfigModel extends AdminActionModel { |
| 651 | 651 |
|
| 652 | 652 |
try {
|
| 653 | 653 |
|
| 654 |
- localSourceInformation = localSource.checkCanConnect();
|
|
| 654 |
+ localSourceInformation = localSource.checkCanConnect(false);
|
|
| 655 | 655 |
|
| 656 | 656 |
} catch (Exception e) {
|
| 657 | 657 |
//FIXME ! il faut faire quelque chose dans ce cas précis, au moins avertir l'utilisateur
|
| ... | ... | @@ -554,8 +554,8 @@ public class StorageUIHandler implements UIHandler<StorageUI> { |
| 554 | 554 |
// si on utilise la base local on lance une migration de la base si necessaire
|
| 555 | 555 |
if (DbMode.USE_LOCAL.equals((model.getDbMode()))) {
|
| 556 | 556 |
|
| 557 |
- ObserveDataSourceInformation dataSourceInformation = currentDataSource.checkCanConnect();
|
|
| 558 |
- |
|
| 557 |
+ ObserveDataSourceInformation dataSourceInformation = currentDataSource.checkCanConnect(false);
|
|
| 558 |
+ currentDataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 559 | 559 |
progressModel.incrementsCurrentStep();
|
| 560 | 560 |
|
| 561 | 561 |
currentDataSource.migrateData(dataSourceInformation, config.getModelVersion());
|
| ... | ... | @@ -1665,12 +1665,14 @@ public class StorageUIModel extends WizardModel<StorageStep> { |
| 1665 | 1665 |
|
| 1666 | 1666 |
if (!error) {
|
| 1667 | 1667 |
|
| 1668 |
- dataSourceInformation = dataSource.checkCanConnect();
|
|
| 1668 |
+ boolean createAction = ObstunaAdminAction.CREATE.equals(adminAction);
|
|
| 1669 | 1669 |
|
| 1670 |
+ dataSourceInformation = dataSource.checkCanConnect(createAction);
|
|
| 1671 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 1670 | 1672 |
Version versionDataSource = dataSourceInformation.getVersion();
|
| 1671 | 1673 |
|
| 1672 | 1674 |
// en mise a jour de la base on ne test pas la version
|
| 1673 |
- if (getModelVersion().equals(versionDataSource) || isCanMigrate() || ObstunaAdminAction.CREATE.equals(adminAction)) {
|
|
| 1675 |
+ if (isCanMigrate() || createAction || getModelVersion().equals(versionDataSource)) {
|
|
| 1674 | 1676 |
|
| 1675 | 1677 |
setConnexionStatus(ConnexionStatus.SUCCESS);
|
| 1676 | 1678 |
|
| ... | ... | @@ -1738,6 +1740,16 @@ public class StorageUIModel extends WizardModel<StorageStep> { |
| 1738 | 1740 |
setBusy(false);
|
| 1739 | 1741 |
}
|
| 1740 | 1742 |
|
| 1743 |
+ if (result && dataSourceInformation != null && adminAction != null) {
|
|
| 1744 |
+ |
|
| 1745 |
+ // must be owner of database to perform a such action
|
|
| 1746 |
+ if (!dataSourceInformation.isOwner()) {
|
|
| 1747 |
+ connexionStatusError = t("observe.storage.error.user.not.owner");
|
|
| 1748 |
+ log.error(connexionStatusError);
|
|
| 1749 |
+ setConnexionStatus(ConnexionStatus.FAILED);
|
|
| 1750 |
+ result = false;
|
|
| 1751 |
+ }
|
|
| 1752 |
+ }
|
|
| 1741 | 1753 |
return result;
|
| 1742 | 1754 |
}
|
| 1743 | 1755 |
|
| ... | ... | @@ -1949,7 +1961,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { |
| 1949 | 1961 |
if (h2DataSourceInformation == null && localStorageExist) {
|
| 1950 | 1962 |
ObserveSwingDataSource dataSource = ObserveSwingApplicationContext.get().getDataSourcesManager().newDataSource(h2Config);
|
| 1951 | 1963 |
try {
|
| 1952 |
- h2DataSourceInformation = dataSource.checkCanConnect();
|
|
| 1964 |
+ h2DataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 1953 | 1965 |
} catch (Exception e) {
|
| 1954 | 1966 |
if (log.isDebugEnabled()) {
|
| 1955 | 1967 |
log.debug("error on load data source information for local storage", e);
|
| ... | ... | @@ -3049,6 +3049,7 @@ observe.storage.error.rest.user.required=User login is mandatory |
| 3049 | 3049 |
observe.storage.error.rest.user.unknown=User "%s" is not defined on server
|
| 3050 | 3050 |
observe.storage.error.serverVersionMismatch=Remote server version (%s) is not compliant with the client version (%s)
|
| 3051 | 3051 |
observe.storage.error.serverVersionModelMismatch=Remote server model version (%s) is not compliant with the client model version (%s)
|
| 3052 |
+observe.storage.error.user.not.owner=User must be owner of database to perform this action\!
|
|
| 3052 | 3053 |
observe.storage.import.data.fromBackup=Import data from a backup of a local database (*.sql.gz)
|
| 3053 | 3054 |
observe.storage.import.data.fromRemoteStorage=Import data from a remote database
|
| 3054 | 3055 |
observe.storage.import.data.fromServerStorage=Import data from a remove server
|
| ... | ... | @@ -3049,6 +3049,7 @@ observe.storage.error.rest.user.required=El usuario es obligatorio |
| 3049 | 3049 |
observe.storage.error.rest.user.unknown=El usuario "%s" no es conocido del servidor
|
| 3050 | 3050 |
observe.storage.error.serverVersionMismatch=La versión del servidor remoto (%s) no es compatible con la versión del modelo (%s)
|
| 3051 | 3051 |
observe.storage.error.serverVersionModelMismatch=La version du modèle du serveur distant (%s) n'est pas compatible avec la version du modèle du client (%s) \#TODO
|
| 3052 |
+observe.storage.error.user.not.owner=User must be owner of database to perform this action\! \#TODO
|
|
| 3052 | 3053 |
observe.storage.import.data.fromBackup=Importar los datos de una copia de seguridad de una base local (*.sql.gz)
|
| 3053 | 3054 |
observe.storage.import.data.fromRemoteStorage=Importar los datos de una base remota
|
| 3054 | 3055 |
observe.storage.import.data.fromServerStorage=Importar los datos de un servidor remoto
|
| ... | ... | @@ -3049,6 +3049,7 @@ observe.storage.error.rest.user.required=L'utilisateur est obligatoire |
| 3049 | 3049 |
observe.storage.error.rest.user.unknown=L'utilisateur "%s" est inconnu sur le serveur
|
| 3050 | 3050 |
observe.storage.error.serverVersionMismatch=La version du serveur distant (%s) n'est pas compatible avec la version du client (%s)
|
| 3051 | 3051 |
observe.storage.error.serverVersionModelMismatch=La version du modèle du serveur distant (%s) n'est pas compatible avec la version du modèle du client (%s)
|
| 3052 |
+observe.storage.error.user.not.owner=L'utilisateur doit être le propriétaire de la base pour effectuer cette opération \!
|
|
| 3052 | 3053 |
observe.storage.import.data.fromBackup=Importer les données depuis une sauvegarde de base locale (*.sql.gz)
|
| 3053 | 3054 |
observe.storage.import.data.fromRemoteStorage=Importer les données depuis une base distante
|
| 3054 | 3055 |
observe.storage.import.data.fromServerStorage=Importer les données depuis un serveur distant
|
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 |
<parent>
|
| 27 | 27 |
<groupId>io.ultreia.maven</groupId>
|
| 28 | 28 |
<artifactId>pom</artifactId>
|
| 29 |
- <version>2019.8.22</version>
|
|
| 29 |
+ <version>2019.8.23</version>
|
|
| 30 | 30 |
</parent>
|
| 31 | 31 |
|
| 32 | 32 |
<groupId>fr.ird.observe</groupId>
|
| ... | ... | @@ -156,7 +156,7 @@ |
| 156 | 156 |
<maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
|
| 157 | 157 |
<buildDate>${maven.build.timestamp}</buildDate>
|
| 158 | 158 |
|
| 159 |
- <observeToolkitVersion>4.13</observeToolkitVersion>
|
|
| 159 |
+ <observeToolkitVersion>4.14-SNAPSHOT</observeToolkitVersion>
|
|
| 160 | 160 |
<lib.version.nuiton.validation>3.1</lib.version.nuiton.validation>
|
| 161 | 161 |
<!--can't use 1.4.197 (date has changed + blob also)-->
|
| 162 | 162 |
<lib.version.h2>1.4.196</lib.version.h2>
|
| ... | ... | @@ -56,6 +56,7 @@ GET /admin/configuration/resetAuthenticationTokens ConfigurationCo |
| 56 | 56 |
GET /api/v1/DataSourceService/applySecurity v1.DataSourceServiceRestApi.applySecurity
|
| 57 | 57 |
GET /api/v1/DataSourceService/backup v1.DataSourceServiceRestApi.backup
|
| 58 | 58 |
GET /api/v1/DataSourceService/checkCanConnect v1.DataSourceServiceRestApi.checkCanConnect
|
| 59 |
+GET /api/v1/DataSourceService/checkCanConnectOrBeEmpty v1.DataSourceServiceRestApi.checkCanConnectOrBeEmpty
|
|
| 59 | 60 |
GET /api/v1/DataSourceService/close v1.DataSourceServiceRestApi.close
|
| 60 | 61 |
GET /api/v1/DataSourceService/create v1.DataSourceServiceRestApi.create
|
| 61 | 62 |
GET /api/v1/DataSourceService/destroy v1.DataSourceServiceRestApi.destroy
|
| ... | ... | @@ -27,12 +27,12 @@ import com.google.common.collect.ImmutableSet; |
| 27 | 27 |
import fr.ird.observe.dto.ObserveDbRole;
|
| 28 | 28 |
import fr.ird.observe.dto.db.ObserveDbUserDto;
|
| 29 | 29 |
import fr.ird.observe.dto.reference.ReferentialDtoReference;
|
| 30 |
-import fr.ird.observe.entities.referential.ObserveReferentialEntity;
|
|
| 31 | 30 |
import fr.ird.observe.entities.ObserveEntityEnum;
|
| 32 | 31 |
import fr.ird.observe.entities.ObserveTopiaApplicationContext;
|
| 33 | 32 |
import fr.ird.observe.entities.ObserveTopiaConfiguration;
|
| 34 | 33 |
import fr.ird.observe.entities.ObserveTopiaConfigurationFactory;
|
| 35 | 34 |
import fr.ird.observe.entities.migration.ObserveTopiaMigrationServiceAskUserToMigrate;
|
| 35 |
+import fr.ird.observe.entities.referential.ObserveReferentialEntity;
|
|
| 36 | 36 |
import fr.ird.observe.services.configuration.DataSourceCreateConfigurationDto;
|
| 37 | 37 |
import fr.ird.observe.services.configuration.DataSourceCreateWithNoReferentialImportException;
|
| 38 | 38 |
import fr.ird.observe.services.configuration.IncompatibleDataSourceCreateConfigurationException;
|
| ... | ... | @@ -53,8 +53,8 @@ import fr.ird.observe.services.service.DatabaseNotFoundException; |
| 53 | 53 |
import fr.ird.observe.services.service.sql.AddSqlScriptProducerRequest;
|
| 54 | 54 |
import fr.ird.observe.services.service.sql.SqlScriptProducerService;
|
| 55 | 55 |
import fr.ird.observe.spi.DbModelHelper;
|
| 56 |
-import org.apache.logging.log4j.Logger;
|
|
| 57 | 56 |
import org.apache.logging.log4j.LogManager;
|
| 57 |
+import org.apache.logging.log4j.Logger;
|
|
| 58 | 58 |
import org.nuiton.topia.persistence.jdbc.JdbcHelper;
|
| 59 | 59 |
import org.nuiton.topia.persistence.jdbc.JdbcPostgresHelper;
|
| 60 | 60 |
import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
|
| ... | ... | @@ -71,6 +71,7 @@ import java.io.File; |
| 71 | 71 |
import java.io.IOException;
|
| 72 | 72 |
import java.nio.file.Files;
|
| 73 | 73 |
import java.util.LinkedHashSet;
|
| 74 |
+import java.util.Objects;
|
|
| 74 | 75 |
import java.util.Optional;
|
| 75 | 76 |
import java.util.Set;
|
| 76 | 77 |
import java.util.UUID;
|
| ... | ... | @@ -98,6 +99,96 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 98 | 99 |
return privileges != null && !privileges.isEmpty();
|
| 99 | 100 |
}
|
| 100 | 101 |
|
| 102 |
+ private static boolean isOwner(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, JdbcPostgresHelper jdbcHelper) {
|
|
| 103 |
+ if (dataSourceConfiguration.isH2Database()) {
|
|
| 104 |
+ return true;
|
|
| 105 |
+ }
|
|
| 106 |
+ String ownerName = jdbcHelper.runSelectOnString("SELECT pg_catalog.pg_get_userbyid(d.datdba) FROM pg_catalog.pg_database d WHERE d.datname = (SELECT current_database())\n");
|
|
| 107 |
+ return Objects.equals(dataSourceConfiguration.getUsername(), ownerName);
|
|
| 108 |
+ }
|
|
| 109 |
+ |
|
| 110 |
+ @Override
|
|
| 111 |
+ public ObserveDataSourceInformation checkCanConnectOrBeEmpty(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
|
| 112 |
+ Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
|
|
| 113 |
+ ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
|
| 114 |
+ |
|
| 115 |
+ ObserveDataSourceInformation dataSourceInformation;
|
|
| 116 |
+ |
|
| 117 |
+ if (dataSourceConfigurationTopiaSupport.isH2Database()) {
|
|
| 118 |
+ |
|
| 119 |
+ ObserveDataSourceConfigurationTopiaH2 h2DataSourceConfiguration = (ObserveDataSourceConfigurationTopiaH2) dataSourceConfigurationTopiaSupport;
|
|
| 120 |
+ |
|
| 121 |
+ // On vérifie que le fichier de la base existe
|
|
| 122 |
+ File databaseFile = h2DataSourceConfiguration.getDatabaseFile();
|
|
| 123 |
+ |
|
| 124 |
+ if (!databaseFile.exists()) {
|
|
| 125 |
+ |
|
| 126 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.notFound");
|
|
| 127 |
+ throw new DatabaseNotFoundException(message, dataSourceConfiguration);
|
|
| 128 |
+ |
|
| 129 |
+ }
|
|
| 130 |
+ |
|
| 131 |
+ // On vérifier que la base n'est pas déjà en cours d'utilisation
|
|
| 132 |
+ File databaseLockFile = h2DataSourceConfiguration.getLockFile();
|
|
| 133 |
+ if (databaseLockFile.exists()) {
|
|
| 134 |
+ |
|
| 135 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.locked");
|
|
| 136 |
+ if (log.isWarnEnabled()) {
|
|
| 137 |
+ log.warn(message);
|
|
| 138 |
+ }
|
|
| 139 |
+ // FIXME even if file is lock we still authorize to connect,
|
|
| 140 |
+ //throw new DatabaseConnexionNotAuthorizedException(message, dataSourceConfiguration);
|
|
| 141 |
+ }
|
|
| 142 |
+ |
|
| 143 |
+ // On tente une connection à la base
|
|
| 144 |
+ ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(h2DataSourceConfiguration.getDirectory(),
|
|
| 145 |
+ h2DataSourceConfiguration.getDbName(),
|
|
| 146 |
+ h2DataSourceConfiguration.getUsername(),
|
|
| 147 |
+ new String(h2DataSourceConfiguration.getPassword()),
|
|
| 148 |
+ false,
|
|
| 149 |
+ false);
|
|
| 150 |
+ |
|
| 151 |
+ |
|
| 152 |
+ try {
|
|
| 153 |
+ new JdbcHelper(topiaConfiguration).runSelectOnString("SELECT 1;");
|
|
| 154 |
+ } catch (Exception e) {
|
|
| 155 |
+ |
|
| 156 |
+ // Authentification refusée
|
|
| 157 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.badAuthentication");
|
|
| 158 |
+ throw new DatabaseConnexionNotAuthorizedException(message, e, dataSourceConfiguration);
|
|
| 159 |
+ |
|
| 160 |
+ }
|
|
| 161 |
+ |
|
| 162 |
+ dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration, false);
|
|
| 163 |
+ |
|
| 164 |
+ |
|
| 165 |
+ } else {
|
|
| 166 |
+ |
|
| 167 |
+ ObserveDataSourceConfigurationTopiaPG pgDataSourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfigurationTopiaSupport;
|
|
| 168 |
+ // On tente une connexion au serveur
|
|
| 169 |
+ ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
|
| 170 |
+ pgDataSourceConfiguration.getUsername(),
|
|
| 171 |
+ new String(pgDataSourceConfiguration.getPassword()),
|
|
| 172 |
+ false,
|
|
| 173 |
+ false);
|
|
| 174 |
+ |
|
| 175 |
+ try {
|
|
| 176 |
+ new JdbcHelper(topiaConfiguration).runSelectOnString("SELECT 1;");
|
|
| 177 |
+ } catch (Exception e) {
|
|
| 178 |
+ |
|
| 179 |
+ throw new DatabaseConnexionNotAuthorizedException(e.getMessage(), e, dataSourceConfiguration);
|
|
| 180 |
+ |
|
| 181 |
+ }
|
|
| 182 |
+ |
|
| 183 |
+ dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration, true);
|
|
| 184 |
+ |
|
| 185 |
+ }
|
|
| 186 |
+ |
|
| 187 |
+ return dataSourceInformation;
|
|
| 188 |
+ |
|
| 189 |
+ }
|
|
| 190 |
+ |
|
| 191 |
+ |
|
| 101 | 192 |
@Override
|
| 102 | 193 |
public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 103 | 194 |
|
| ... | ... | @@ -151,7 +242,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 151 | 242 |
|
| 152 | 243 |
}
|
| 153 | 244 |
|
| 154 |
- dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration);
|
|
| 245 |
+ dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration, false);
|
|
| 155 | 246 |
|
| 156 | 247 |
|
| 157 | 248 |
} else {
|
| ... | ... | @@ -172,7 +263,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 172 | 263 |
|
| 173 | 264 |
}
|
| 174 | 265 |
|
| 175 |
- dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration);
|
|
| 266 |
+ dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration, false);
|
|
| 176 | 267 |
|
| 177 | 268 |
}
|
| 178 | 269 |
|
| ... | ... | @@ -359,7 +450,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 359 | 450 |
|
| 360 | 451 |
}
|
| 361 | 452 |
|
| 362 |
- ObserveDataSourceInformation dataSourceInformation = getDataSourceInformation((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, topiaApplicationContext.getConfiguration());
|
|
| 453 |
+ ObserveDataSourceInformation dataSourceInformation = getDataSourceInformation((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, topiaApplicationContext.getConfiguration(), false);
|
|
| 363 | 454 |
|
| 364 | 455 |
return createDataSourceConnection(dataSourceInformation, topiaApplicationContext.getAuthenticationToken());
|
| 365 | 456 |
|
| ... | ... | @@ -529,7 +620,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 529 | 620 |
dataSourceInformation.getVersion());
|
| 530 | 621 |
}
|
| 531 | 622 |
|
| 532 |
- private ObserveDataSourceInformation getDataSourceInformation(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaConfiguration topiaConfiguration) {
|
|
| 623 |
+ private ObserveDataSourceInformation getDataSourceInformation(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaConfiguration topiaConfiguration, boolean canBeEmpty) {
|
|
| 533 | 624 |
|
| 534 | 625 |
boolean writeReferential;
|
| 535 | 626 |
boolean readData;
|
| ... | ... | @@ -538,8 +629,37 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 538 | 629 |
Version version;
|
| 539 | 630 |
|
| 540 | 631 |
JdbcPostgresHelper jdbcHelper = new JdbcPostgresHelper(topiaConfiguration);
|
| 632 |
+ boolean owner = isOwner(dataSourceConfiguration, jdbcHelper);
|
|
| 541 | 633 |
|
| 542 |
- version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
|
|
| 634 |
+ try {
|
|
| 635 |
+ version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
|
|
| 636 |
+ } catch (Exception e) {
|
|
| 637 |
+ if (!canBeEmpty) {
|
|
| 638 |
+ throw e;
|
|
| 639 |
+ }
|
|
| 640 |
+ if (dataSourceConfiguration.isH2Database()) {
|
|
| 641 |
+ |
|
| 642 |
+ // Sur une base H2, on a le droit de tout lire, mais uniquement d'écrire les données
|
|
| 643 |
+ writeReferential = false;
|
|
| 644 |
+ readData = true;
|
|
| 645 |
+ writeData = true;
|
|
| 646 |
+ owner = true;
|
|
| 647 |
+ |
|
| 648 |
+ } else {
|
|
| 649 |
+ writeReferential = true;
|
|
| 650 |
+ readData = true;
|
|
| 651 |
+ writeData = true;
|
|
| 652 |
+ }
|
|
| 653 |
+ return new ObserveDataSourceInformation(
|
|
| 654 |
+ true,
|
|
| 655 |
+ writeReferential,
|
|
| 656 |
+ readData,
|
|
| 657 |
+ writeData,
|
|
| 658 |
+ owner,
|
|
| 659 |
+ ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
|
|
| 660 |
+ null,
|
|
| 661 |
+ null);
|
|
| 662 |
+ }
|
|
| 543 | 663 |
|
| 544 | 664 |
if (dataSourceConfiguration.isH2Database()) {
|
| 545 | 665 |
|
| ... | ... | @@ -591,6 +711,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 591 | 711 |
writeReferential,
|
| 592 | 712 |
readData,
|
| 593 | 713 |
writeData,
|
| 714 |
+ owner,
|
|
| 594 | 715 |
ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
|
| 595 | 716 |
version,
|
| 596 | 717 |
observeMigrationConfigurationProvider.getVersionsAfter(version));
|
| ... | ... | @@ -47,6 +47,9 @@ public interface DataSourceService extends ObserveService, Closeable { |
| 47 | 47 |
@Get(addAuthtoken = false)
|
| 48 | 48 |
ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException;
|
| 49 | 49 |
|
| 50 |
+ @Get(addAuthtoken = false)
|
|
| 51 |
+ ObserveDataSourceInformation checkCanConnectOrBeEmpty(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException;
|
|
| 52 |
+ |
|
| 50 | 53 |
@Get(addAuthtoken = false)
|
| 51 | 54 |
ObserveDataSourceConnection create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration)
|
| 52 | 55 |
throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException,
|