Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
603c4e88
by tchemit at 2019-07-03T12:56:02Z
-
4d449fa3
by tchemit at 2019-07-03T13:26:13Z
-
5f9d6431
by tchemit at 2019-07-03T14:02:14Z
16 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/SaveCurrentServerConfigurationUIAction.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:
| ... | ... | @@ -800,6 +800,7 @@ observe.storage.error.rest.user.required |
| 800 | 800 |
observe.storage.error.rest.user.unknown
|
| 801 | 801 |
observe.storage.error.serverVersionMismatch
|
| 802 | 802 |
observe.storage.error.serverVersionModelMismatch
|
| 803 |
+observe.storage.error.user.not.owner
|
|
| 803 | 804 |
observe.storage.internalDump.last.modified
|
| 804 | 805 |
observe.storage.internalDump.not.exist
|
| 805 | 806 |
observe.storage.label.data.import.db
|
| ... | ... | @@ -37,7 +37,6 @@ import fr.ird.observe.client.ui.ObserveUIMode; |
| 37 | 37 |
import fr.ird.observe.client.ui.actions.main.menu.storage.ChangeStorageAction;
|
| 38 | 38 |
import fr.ird.observe.client.ui.storage.StorageUIModel;
|
| 39 | 39 |
import fr.ird.observe.client.ui.util.ProgressModel;
|
| 40 |
-import org.nuiton.topia.persistence.script.TopiaSqlScript;
|
|
| 41 | 40 |
import fr.ird.observe.services.ObserveDataSourceConfigurationMainFactory;
|
| 42 | 41 |
import fr.ird.observe.services.configuration.DataSourceCreateConfigurationDto;
|
| 43 | 42 |
import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration;
|
| ... | ... | @@ -48,6 +47,7 @@ import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfiguratio |
| 48 | 47 |
import fr.ird.observe.services.service.BabModelVersionException;
|
| 49 | 48 |
import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException;
|
| 50 | 49 |
import fr.ird.observe.services.service.DatabaseNotFoundException;
|
| 50 |
+import org.nuiton.topia.persistence.script.TopiaSqlScript;
|
|
| 51 | 51 |
|
| 52 | 52 |
import javax.swing.JLabel;
|
| 53 | 53 |
import javax.swing.JOptionPane;
|
| ... | ... | @@ -123,7 +123,9 @@ public class ObserveDataSourcesManager implements Closeable { |
| 123 | 123 |
dataSource = newDataSource(configuration);
|
| 124 | 124 |
break;
|
| 125 | 125 |
}
|
| 126 |
- |
|
| 126 |
+ if (model.getDataSourceInformation() != null) {
|
|
| 127 |
+ dataSource.setOwner(model.getDataSourceInformation().isOwner());
|
|
| 128 |
+ }
|
|
| 127 | 129 |
return dataSource;
|
| 128 | 130 |
}
|
| 129 | 131 |
|
| ... | ... | @@ -291,8 +293,8 @@ public class ObserveDataSourcesManager implements Closeable { |
| 291 | 293 |
|
| 292 | 294 |
try {
|
| 293 | 295 |
|
| 294 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 295 |
- |
|
| 296 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 297 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 296 | 298 |
dataSource.migrateDataIfPossible(dataSourceInformation, config.getModelVersion());
|
| 297 | 299 |
|
| 298 | 300 |
// la source sera utilisée dans les ui
|
| ... | ... | @@ -358,7 +360,8 @@ public class ObserveDataSourcesManager implements Closeable { |
| 358 | 360 |
|
| 359 | 361 |
try {
|
| 360 | 362 |
|
| 361 |
- ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect();
|
|
| 363 |
+ ObserveDataSourceInformation dataSourceInformation = dataSource.checkCanConnect(false);
|
|
| 364 |
+ dataSource.setOwner(dataSourceInformation.isOwner());
|
|
| 362 | 365 |
|
| 363 | 366 |
dataSource.migrateData(dataSourceInformation, config.getModelVersion());
|
| 364 | 367 |
|
| ... | ... | @@ -704,6 +707,7 @@ public class ObserveDataSourcesManager implements Closeable { |
| 704 | 707 |
}
|
| 705 | 708 |
}
|
| 706 | 709 |
|
| 710 |
+ @SuppressWarnings({"unused", "WeakerAccess"})
|
|
| 707 | 711 |
public static class InitStorageModel {
|
| 708 | 712 |
private final File localDb;
|
| 709 | 713 |
private final BackupStorage lastAutomaticBackup;
|
| ... | ... | @@ -724,7 +728,7 @@ public class ObserveDataSourcesManager implements Closeable { |
| 724 | 728 |
return lastAutomaticBackup != null;
|
| 725 | 729 |
}
|
| 726 | 730 |
|
| 727 |
- String getBackupDate() {
|
|
| 731 |
+ public String getBackupDate() {
|
|
| 728 | 732 |
return Optional.ofNullable(lastAutomaticBackup).map(l -> simpleDateFormat.format(l.getDate())).orElse("");
|
| 729 | 733 |
}
|
| 730 | 734 |
}
|
| ... | ... | @@ -10,12 +10,12 @@ package fr.ird.observe.client.db; |
| 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>.
|
| ... | ... | @@ -120,12 +120,9 @@ import static io.ultreia.java4all.i18n.I18n.t; |
| 120 | 120 |
*/
|
| 121 | 121 |
public class ObserveSwingDataSource extends AbstractSerializableBean implements Closeable, ObserveServicesProvider {
|
| 122 | 122 |
|
| 123 |
+ public static final ObserveServicesProvider MAIN = new ObserveMainDataSourceServicesProvider();
|
|
| 123 | 124 |
private static final long serialVersionUID = 1L;
|
| 124 |
- |
|
| 125 | 125 |
private static final Logger log = LogManager.getLogger(ObserveSwingDataSource.class);
|
| 126 |
- |
|
| 127 |
- public static final ObserveServicesProvider MAIN = new ObserveMainDataSourceServicesProvider();
|
|
| 128 |
- |
|
| 129 | 126 |
private final EventListenerList listenerList;
|
| 130 | 127 |
|
| 131 | 128 |
private final ObserveDataSourceConfiguration configuration;
|
| ... | ... | @@ -143,6 +140,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 143 | 140 |
|
| 144 | 141 |
// indique si une modification a été effectuéé sur la base depuis son ouverture
|
| 145 | 142 |
private boolean modified;
|
| 143 |
+ private boolean owner;
|
|
| 146 | 144 |
|
| 147 | 145 |
public ObserveSwingDataSource(ObserveDataSourceConfiguration configuration) {
|
| 148 | 146 |
this.configuration = configuration;
|
| ... | ... | @@ -208,6 +206,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 208 | 206 |
canWriteReferential(),
|
| 209 | 207 |
canReadData(),
|
| 210 | 208 |
canWriteData(),
|
| 209 |
+ isOwner(),
|
|
| 211 | 210 |
getVersion(),
|
| 212 | 211 |
getVersion(),
|
| 213 | 212 |
ImmutableList.of());
|
| ... | ... | @@ -249,7 +248,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 249 | 248 |
@Override
|
| 250 | 249 |
public void close() {
|
| 251 | 250 |
|
| 252 |
- if (connection==null) {
|
|
| 251 |
+ if (connection == null) {
|
|
| 253 | 252 |
return;
|
| 254 | 253 |
}
|
| 255 | 254 |
checkIsOpen();
|
| ... | ... | @@ -368,6 +367,10 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 368 | 367 |
|
| 369 | 368 |
}
|
| 370 | 369 |
|
| 370 |
+ public boolean isOwner() {
|
|
| 371 |
+ return owner;
|
|
| 372 |
+ }
|
|
| 373 |
+ |
|
| 371 | 374 |
void migrateDataIfPossible(ObserveDataSourceInformation dataSourceInformation, Version targetVersion) {
|
| 372 | 375 |
|
| 373 | 376 |
checkIsNotOpen();
|
| ... | ... | @@ -398,39 +401,30 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 398 | 401 |
}
|
| 399 | 402 |
|
| 400 | 403 |
public <D extends IdDto> ImmutableDtoMap<ReferentialDtoReferenceSet<?>> updateReferentialReferenceSetsCache(Class<D> dtoType) {
|
| 401 |
- |
|
| 402 | 404 |
ReferentialService referentialService = servicesProvider.getReferentialService();
|
| 403 | 405 |
return referentialCache.loadReferenceSets(referentialService, dtoType);
|
| 404 |
- |
|
| 405 | 406 |
}
|
| 406 | 407 |
|
| 407 |
- private <R extends ReferentialDtoReference> ReferentialDtoReferenceSet<R> getReferentialReferenceSet(Class<R> type) {
|
|
| 408 |
- |
|
| 408 |
+ @SuppressWarnings("unchecked")
|
|
| 409 |
+ public <R extends ReferentialDtoReference> ReferentialDtoReferenceSet<R> getReferentialReferenceSet(Class<R> type) {
|
|
| 409 | 410 |
checkIsOpen();
|
| 410 |
- |
|
| 411 | 411 |
ReferentialService referentialService = servicesProvider.getReferentialService();
|
| 412 | 412 |
return referentialCache.getReferentialReferenceSet(referentialService, type);
|
| 413 | 413 |
}
|
| 414 | 414 |
|
| 415 | 415 |
public <R extends ReferentialDtoReference> Set<R> getReferentialReferences(Class<R> type) {
|
| 416 |
- |
|
| 417 | 416 |
ReferentialDtoReferenceSet<R> referentialReferenceSet = getReferentialReferenceSet(type);
|
| 418 | 417 |
return referentialReferenceSet.toSet();
|
| 419 |
- |
|
| 420 | 418 |
}
|
| 421 | 419 |
|
| 422 | 420 |
public boolean isOpen() {
|
| 423 | 421 |
return connection != null;
|
| 424 | 422 |
}
|
| 425 | 423 |
|
| 426 |
- public ObserveDataSourceInformation checkCanConnect() throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 427 |
- |
|
| 424 |
+ public ObserveDataSourceInformation checkCanConnect(boolean canBeEmpty) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
|
| 428 | 425 |
checkIsNotAlreadyOpen();
|
| 429 |
- |
|
| 430 | 426 |
DataSourceService dataSourceService = servicesProvider.getDataSourceService();
|
| 431 |
- |
|
| 432 |
- return dataSourceService.checkCanConnect(configuration);
|
|
| 433 |
- |
|
| 427 |
+ return canBeEmpty ? dataSourceService.checkCanConnectOrBeEmpty(configuration) : dataSourceService.checkCanConnect(configuration);
|
|
| 434 | 428 |
}
|
| 435 | 429 |
|
| 436 | 430 |
public boolean isLocal() {
|
| ... | ... | @@ -454,9 +448,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 454 | 448 |
}
|
| 455 | 449 |
|
| 456 | 450 |
public void removeObserveSwingDataSourceListener(ObserveSwingDataSourceListener listener) {
|
| 457 |
- if (log.isInfoEnabled()) {
|
|
| 458 |
- log.info("removing listener " + listener);
|
|
| 459 |
- }
|
|
| 451 |
+ log.info("removing listener " + listener);
|
|
| 460 | 452 |
listenerList.remove(ObserveSwingDataSourceListener.class, listener);
|
| 461 | 453 |
}
|
| 462 | 454 |
|
| ... | ... | @@ -782,4 +774,8 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 782 | 774 |
public void setProgressModel(ProgressModel progressModel) {
|
| 783 | 775 |
this.progressModel = progressModel;
|
| 784 | 776 |
}
|
| 777 |
+ |
|
| 778 |
+ public void setOwner(boolean owner) {
|
|
| 779 |
+ this.owner = owner;
|
|
| 780 |
+ }
|
|
| 785 | 781 |
}
|
| ... | ... | @@ -22,6 +22,7 @@ package fr.ird.observe.client.ui.actions.storage; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import fr.ird.observe.client.ObserveSwingApplicationContext;
|
|
| 25 | 26 |
import fr.ird.observe.client.ui.ObserveMainUI;
|
| 26 | 27 |
import fr.ird.observe.client.ui.actions.main.menu.MenuActionSupport;
|
| 27 | 28 |
import fr.ird.observe.client.ui.storage.StorageUIModel;
|
| ... | ... | @@ -116,8 +117,7 @@ public class SaveCurrentServerConfigurationUIAction extends MenuActionSupport { |
| 116 | 117 |
configuration.setLogin(model.getRemoteLogin());
|
| 117 | 118 |
configuration.setPassword(new String(model.getRemotePassword()));
|
| 118 | 119 |
configuration.setDatabaseName(model.getServerDatabase());
|
| 119 |
- getMainUI().getConfig().addServerDataSourceConfiguration(configuration);
|
|
| 120 |
- |
|
| 120 |
+ ObserveSwingApplicationContext.get().getConfig().addServerDataSourceConfiguration(configuration);
|
|
| 121 | 121 |
configUI.getHandler().addServerConfiguration(getMainUI(), configuration, configUI.getServerMenu().getComponentCount() - 2);
|
| 122 | 122 |
}
|
| 123 | 123 |
}
|
| ... | ... | @@ -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 |
|
| ... | ... | @@ -642,7 +642,7 @@ public class ConfigModel extends AdminActionModel { |
| 642 | 642 |
|
| 643 | 643 |
try {
|
| 644 | 644 |
|
| 645 |
- localSourceInformation = localSource.checkCanConnect();
|
|
| 645 |
+ localSourceInformation = localSource.checkCanConnect(false);
|
|
| 646 | 646 |
|
| 647 | 647 |
} catch (Exception e) {
|
| 648 | 648 |
//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);
|
| ... | ... | @@ -2043,6 +2043,7 @@ observe.storage.error.rest.user.required=User login is mandatory |
| 2043 | 2043 |
observe.storage.error.rest.user.unknown=User "%s" is not defined on server
|
| 2044 | 2044 |
observe.storage.error.serverVersionMismatch=Remote server version (%s) is not compliant with the client version (%s)
|
| 2045 | 2045 |
observe.storage.error.serverVersionModelMismatch=Remote server model version (%s) is not compliant with the client model version (%s)
|
| 2046 |
+observe.storage.error.user.not.owner=User must be owner of database to perform this action\!
|
|
| 2046 | 2047 |
observe.storage.import.data.fromBackup=Import data from a backup of a local database (*.sql.gz)
|
| 2047 | 2048 |
observe.storage.import.data.fromRemoteStorage=Import data from a remote database
|
| 2048 | 2049 |
observe.storage.import.data.fromServerStorage=Import data from a remove server
|
| ... | ... | @@ -2043,6 +2043,7 @@ observe.storage.error.rest.user.required=El usuario es obligatorio |
| 2043 | 2043 |
observe.storage.error.rest.user.unknown=El usuario "%s" no es conocido por el servidor
|
| 2044 | 2044 |
observe.storage.error.serverVersionMismatch=La versión del servidor remoto (%s) no es compatible con la versión del modelo (%s)
|
| 2045 | 2045 |
observe.storage.error.serverVersionModelMismatch=La versión del modelo del servidor remoto (%s) no es compatible con la versión del modelo (%s)
|
| 2046 |
+observe.storage.error.user.not.owner=User must be owner of database to perform this action\! \#TODO
|
|
| 2046 | 2047 |
observe.storage.import.data.fromBackup=Importar los datos de una copia de seguridad de la base local (*.sql.gz)
|
| 2047 | 2048 |
observe.storage.import.data.fromRemoteStorage=Importar los datos de una base remota
|
| 2048 | 2049 |
observe.storage.import.data.fromServerStorage=Importar los datos de un servidor remoto
|
| ... | ... | @@ -2043,6 +2043,7 @@ observe.storage.error.rest.user.required=L'utilisateur est obligatoire |
| 2043 | 2043 |
observe.storage.error.rest.user.unknown=L'utilisateur "%s" est inconnu sur le serveur
|
| 2044 | 2044 |
observe.storage.error.serverVersionMismatch=La version du serveur distant (%s) n'est pas compatible avec la version du client (%s)
|
| 2045 | 2045 |
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)
|
| 2046 |
+observe.storage.error.user.not.owner=L'utilisateur doit être le propriétaire de la base pour effectuer cette opération \!
|
|
| 2046 | 2047 |
observe.storage.import.data.fromBackup=Importer les données depuis une sauvegarde de base locale (*.sql.gz)
|
| 2047 | 2048 |
observe.storage.import.data.fromRemoteStorage=Importer les données depuis une base distante
|
| 2048 | 2049 |
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>
|
| ... | ... | @@ -155,7 +155,7 @@ |
| 155 | 155 |
<maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
|
| 156 | 156 |
<buildDate>${maven.build.timestamp}</buildDate>
|
| 157 | 157 |
|
| 158 |
- <observeToolkitVersion>3.7.17</observeToolkitVersion>
|
|
| 158 |
+ <observeToolkitVersion>3.7.19-SNAPSHOT</observeToolkitVersion>
|
|
| 159 | 159 |
<!--<lib.version.java4all.http>1.0.13</lib.version.java4all.http>-->
|
| 160 | 160 |
<lib.version.nuiton.validation>3.1</lib.version.nuiton.validation>
|
| 161 | 161 |
<!--<lib.version.java4all.config>1.0.3</lib.version.java4all.config>-->
|
| ... | ... | @@ -165,7 +165,7 @@ |
| 165 | 165 |
<lib.version.java4all.eugene>3.0-alpha-26</lib.version.java4all.eugene>
|
| 166 | 166 |
<!--lib.version.java4all.jaxx>3.0-alpha-50</lib.version.java4all.jaxx-->
|
| 167 | 167 |
<!--<lib.version.java4all.i18n>4.0-beta-8-SNAPSHOT</lib.version.java4all.i18n>-->
|
| 168 |
- <lib.version.java4all.topia>1.1.14</lib.version.java4all.topia>
|
|
| 168 |
+ <lib.version.java4all.topia>1.1.15-SNAPSHOT</lib.version.java4all.topia>
|
|
| 169 | 169 |
|
| 170 | 170 |
<!--<lib.version.nuiton.topia>3.6-SNAPSHOT</lib.version.nuiton.topia>-->
|
| 171 | 171 |
<!--<lib.version.java4all.eugene>3.0-alpha-21</lib.version.java4all.eugene>-->
|
| ... | ... | @@ -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
|
| ... | ... | @@ -98,6 +98,95 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 98 | 98 |
return privileges != null && !privileges.isEmpty();
|
| 99 | 99 |
}
|
| 100 | 100 |
|
| 101 |
+ private static boolean isOwner(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, JdbcPostgresHelper jdbcHelper) {
|
|
| 102 |
+ if (dataSourceConfiguration.isH2Database()) {
|
|
| 103 |
+ return true;
|
|
| 104 |
+ }
|
|
| 105 |
+ return jdbcHelper.isOwner();
|
|
| 106 |
+ }
|
|
| 107 |
+ |
|
| 108 |
+ @Override
|
|
| 109 |
+ public ObserveDataSourceInformation checkCanConnectOrBeEmpty(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
|
| 110 |
+ Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
|
|
| 111 |
+ ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
|
| 112 |
+ |
|
| 113 |
+ ObserveDataSourceInformation dataSourceInformation;
|
|
| 114 |
+ |
|
| 115 |
+ if (dataSourceConfigurationTopiaSupport.isH2Database()) {
|
|
| 116 |
+ |
|
| 117 |
+ ObserveDataSourceConfigurationTopiaH2 h2DataSourceConfiguration = (ObserveDataSourceConfigurationTopiaH2) dataSourceConfigurationTopiaSupport;
|
|
| 118 |
+ |
|
| 119 |
+ // On vérifie que le fichier de la base existe
|
|
| 120 |
+ File databaseFile = h2DataSourceConfiguration.getDatabaseFile();
|
|
| 121 |
+ |
|
| 122 |
+ if (!databaseFile.exists()) {
|
|
| 123 |
+ |
|
| 124 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.notFound");
|
|
| 125 |
+ throw new DatabaseNotFoundException(message, dataSourceConfiguration);
|
|
| 126 |
+ |
|
| 127 |
+ }
|
|
| 128 |
+ |
|
| 129 |
+ // On vérifier que la base n'est pas déjà en cours d'utilisation
|
|
| 130 |
+ File databaseLockFile = h2DataSourceConfiguration.getLockFile();
|
|
| 131 |
+ if (databaseLockFile.exists()) {
|
|
| 132 |
+ |
|
| 133 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.locked");
|
|
| 134 |
+ if (log.isWarnEnabled()) {
|
|
| 135 |
+ log.warn(message);
|
|
| 136 |
+ }
|
|
| 137 |
+ // FIXME even if file is lock we still authorize to connect,
|
|
| 138 |
+ //throw new DatabaseConnexionNotAuthorizedException(message, dataSourceConfiguration);
|
|
| 139 |
+ }
|
|
| 140 |
+ |
|
| 141 |
+ // On tente une connection à la base
|
|
| 142 |
+ ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(h2DataSourceConfiguration.getDirectory(),
|
|
| 143 |
+ h2DataSourceConfiguration.getDbName(),
|
|
| 144 |
+ h2DataSourceConfiguration.getUsername(),
|
|
| 145 |
+ new String(h2DataSourceConfiguration.getPassword()),
|
|
| 146 |
+ false,
|
|
| 147 |
+ false);
|
|
| 148 |
+ |
|
| 149 |
+ |
|
| 150 |
+ try {
|
|
| 151 |
+ new JdbcHelper(topiaConfiguration).runSelectOnString("SELECT 1;");
|
|
| 152 |
+ } catch (Exception e) {
|
|
| 153 |
+ |
|
| 154 |
+ // Authentification refusée
|
|
| 155 |
+ String message = l(getApplicationLocale(), "observe.services.topia.error.h2.database.badAuthentication");
|
|
| 156 |
+ throw new DatabaseConnexionNotAuthorizedException(message, e, dataSourceConfiguration);
|
|
| 157 |
+ |
|
| 158 |
+ }
|
|
| 159 |
+ |
|
| 160 |
+ dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration, false);
|
|
| 161 |
+ |
|
| 162 |
+ |
|
| 163 |
+ } else {
|
|
| 164 |
+ |
|
| 165 |
+ ObserveDataSourceConfigurationTopiaPG pgDataSourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfigurationTopiaSupport;
|
|
| 166 |
+ // On tente une connexion au serveur
|
|
| 167 |
+ ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
|
| 168 |
+ pgDataSourceConfiguration.getUsername(),
|
|
| 169 |
+ new String(pgDataSourceConfiguration.getPassword()),
|
|
| 170 |
+ false,
|
|
| 171 |
+ false);
|
|
| 172 |
+ |
|
| 173 |
+ try {
|
|
| 174 |
+ new JdbcHelper(topiaConfiguration).runSelectOnString("SELECT 1;");
|
|
| 175 |
+ } catch (Exception e) {
|
|
| 176 |
+ |
|
| 177 |
+ throw new DatabaseConnexionNotAuthorizedException(e.getMessage(), e, dataSourceConfiguration);
|
|
| 178 |
+ |
|
| 179 |
+ }
|
|
| 180 |
+ |
|
| 181 |
+ dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration, true);
|
|
| 182 |
+ |
|
| 183 |
+ }
|
|
| 184 |
+ |
|
| 185 |
+ return dataSourceInformation;
|
|
| 186 |
+ |
|
| 187 |
+ }
|
|
| 188 |
+ |
|
| 189 |
+ |
|
| 101 | 190 |
@Override
|
| 102 | 191 |
public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 103 | 192 |
|
| ... | ... | @@ -134,11 +223,11 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 134 | 223 |
|
| 135 | 224 |
// On tente une connection à la base
|
| 136 | 225 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(h2DataSourceConfiguration.getDirectory(),
|
| 137 |
- h2DataSourceConfiguration.getDbName(),
|
|
| 138 |
- h2DataSourceConfiguration.getUsername(),
|
|
| 139 |
- new String(h2DataSourceConfiguration.getPassword()),
|
|
| 140 |
- false,
|
|
| 141 |
- false);
|
|
| 226 |
+ h2DataSourceConfiguration.getDbName(),
|
|
| 227 |
+ h2DataSourceConfiguration.getUsername(),
|
|
| 228 |
+ new String(h2DataSourceConfiguration.getPassword()),
|
|
| 229 |
+ false,
|
|
| 230 |
+ false);
|
|
| 142 | 231 |
|
| 143 | 232 |
|
| 144 | 233 |
try {
|
| ... | ... | @@ -151,7 +240,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 151 | 240 |
|
| 152 | 241 |
}
|
| 153 | 242 |
|
| 154 |
- dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration);
|
|
| 243 |
+ dataSourceInformation = getDataSourceInformation(h2DataSourceConfiguration, topiaConfiguration, false);
|
|
| 155 | 244 |
|
| 156 | 245 |
|
| 157 | 246 |
} else {
|
| ... | ... | @@ -159,10 +248,10 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 159 | 248 |
ObserveDataSourceConfigurationTopiaPG pgDataSourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfigurationTopiaSupport;
|
| 160 | 249 |
// On tente une connexion au serveur
|
| 161 | 250 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 162 |
- pgDataSourceConfiguration.getUsername(),
|
|
| 163 |
- new String(pgDataSourceConfiguration.getPassword()),
|
|
| 164 |
- false,
|
|
| 165 |
- false);
|
|
| 251 |
+ pgDataSourceConfiguration.getUsername(),
|
|
| 252 |
+ new String(pgDataSourceConfiguration.getPassword()),
|
|
| 253 |
+ false,
|
|
| 254 |
+ false);
|
|
| 166 | 255 |
|
| 167 | 256 |
try {
|
| 168 | 257 |
new JdbcHelper(topiaConfiguration).runSelectOnString("SELECT 1;");
|
| ... | ... | @@ -172,7 +261,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 172 | 261 |
|
| 173 | 262 |
}
|
| 174 | 263 |
|
| 175 |
- dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration);
|
|
| 264 |
+ dataSourceInformation = getDataSourceInformation(pgDataSourceConfiguration, topiaConfiguration, false);
|
|
| 176 | 265 |
|
| 177 | 266 |
}
|
| 178 | 267 |
|
| ... | ... | @@ -359,7 +448,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 359 | 448 |
|
| 360 | 449 |
}
|
| 361 | 450 |
|
| 362 |
- ObserveDataSourceInformation dataSourceInformation = getDataSourceInformation((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, topiaApplicationContext.getConfiguration());
|
|
| 451 |
+ ObserveDataSourceInformation dataSourceInformation = getDataSourceInformation((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, topiaApplicationContext.getConfiguration(), false);
|
|
| 363 | 452 |
|
| 364 | 453 |
return createDataSourceConnection(dataSourceInformation, topiaApplicationContext.getAuthenticationToken());
|
| 365 | 454 |
|
| ... | ... | @@ -529,7 +618,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 529 | 618 |
dataSourceInformation.getVersion());
|
| 530 | 619 |
}
|
| 531 | 620 |
|
| 532 |
- private ObserveDataSourceInformation getDataSourceInformation(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaConfiguration topiaConfiguration) {
|
|
| 621 |
+ private ObserveDataSourceInformation getDataSourceInformation(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaConfiguration topiaConfiguration, boolean canBeEmpty) {
|
|
| 533 | 622 |
|
| 534 | 623 |
boolean writeReferential;
|
| 535 | 624 |
boolean readData;
|
| ... | ... | @@ -538,8 +627,37 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 538 | 627 |
Version version;
|
| 539 | 628 |
|
| 540 | 629 |
JdbcPostgresHelper jdbcHelper = new JdbcPostgresHelper(topiaConfiguration);
|
| 630 |
+ boolean owner = isOwner(dataSourceConfiguration, jdbcHelper);
|
|
| 541 | 631 |
|
| 542 |
- version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
|
|
| 632 |
+ try {
|
|
| 633 |
+ version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
|
|
| 634 |
+ } catch (Exception e) {
|
|
| 635 |
+ if (!canBeEmpty) {
|
|
| 636 |
+ throw e;
|
|
| 637 |
+ }
|
|
| 638 |
+ if (dataSourceConfiguration.isH2Database()) {
|
|
| 639 |
+ |
|
| 640 |
+ // Sur une base H2, on a le droit de tout lire, mais uniquement d'écrire les données
|
|
| 641 |
+ writeReferential = false;
|
|
| 642 |
+ readData = true;
|
|
| 643 |
+ writeData = true;
|
|
| 644 |
+ owner = true;
|
|
| 645 |
+ |
|
| 646 |
+ } else {
|
|
| 647 |
+ writeReferential = true;
|
|
| 648 |
+ readData = true;
|
|
| 649 |
+ writeData = true;
|
|
| 650 |
+ }
|
|
| 651 |
+ return new ObserveDataSourceInformation(
|
|
| 652 |
+ true,
|
|
| 653 |
+ writeReferential,
|
|
| 654 |
+ readData,
|
|
| 655 |
+ writeData,
|
|
| 656 |
+ owner,
|
|
| 657 |
+ ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
|
|
| 658 |
+ null,
|
|
| 659 |
+ null);
|
|
| 660 |
+ }
|
|
| 543 | 661 |
|
| 544 | 662 |
if (dataSourceConfiguration.isH2Database()) {
|
| 545 | 663 |
|
| ... | ... | @@ -591,6 +709,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 591 | 709 |
writeReferential,
|
| 592 | 710 |
readData,
|
| 593 | 711 |
writeData,
|
| 712 |
+ owner,
|
|
| 594 | 713 |
ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
|
| 595 | 714 |
version,
|
| 596 | 715 |
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,
|