branch feature/8124-VerifAdmin updated (163d742 -> 3919be7)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8124-VerifAdmin in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git from 163d742 correction de création de base PG vide (see #8124). new 562c622 Ajout d'un script de migration pour supprimer les doublons dans la table OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM (see #8124). new 3919be7 correction pour la création d'une base distante (see #8124). The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 3919be71727117e827939b45db9daaaf14f5d8b1 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Mar 30 10:20:37 2016 +0200 correction pour la création d'une base distante (see #8124). commit 562c622515a1e6906e56540bc0eab00935eb95a5 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Mar 29 10:58:23 2016 +0200 Ajout d'un script de migration pour supprimer les doublons dans la table OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM (see #8124). Summary of changes: .../fr/ird/observe/db/ObserveSwingDataSource.java | 4 +- .../ird/observe/ui/storage/ObstunaAdminAction.java | 20 +- .../ird/observe/ui/storage/RemoteUILauncher.java | 1 - .../ird/observe/ui/storage/StorageUIHandler.java | 240 +-------------------- .../ird/observe/ui/storage/StorageUILauncher.java | 47 +++- .../fr/ird/observe/ui/storage/StorageUIModel.java | 111 +++++++--- .../ird/observe/ui/storage/tabs/ConfigDataUI.jaxx | 34 +++ .../ird/observe/ui/storage/tabs/ConfigDataUI.jcss | 34 ++- .../ui/storage/tabs/ConfigReferentielUI.jaxx | 36 ++++ .../ui/storage/tabs/ConfigReferentielUI.jcss | 34 ++- .../ui/storage/tabs/StorageTabUIHandler.java | 44 ++-- .../ftl/dataSourceConnectionReport_fr.ftl | 20 +- .../observe-application-swing_en_GB.properties | 9 + .../observe-application-swing_es_ES.properties | 9 + .../observe-application-swing_fr_FR.properties | 9 + .../controller/v1/DataSourceServiceController.java | 4 +- .../observe/ObserveTopiaApplicationContext.java | 40 ++-- .../DataSourceMigrationForVersion_4_903.java | 2 +- .../V4_903_03_remove_duplicate_rows-H2.sql | 21 ++ .../V4_903_03_remove_duplicate_rows-PG.sql | 21 ++ .../services/service/DataSourceService.java | 4 +- .../services/service/DataSourceServiceTopia.java | 139 ++++++++++-- 22 files changed, 530 insertions(+), 353 deletions(-) create mode 100644 observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-H2.sql create mode 100644 observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-PG.sql -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8124-VerifAdmin in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 562c622515a1e6906e56540bc0eab00935eb95a5 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Tue Mar 29 10:58:23 2016 +0200 Ajout d'un script de migration pour supprimer les doublons dans la table OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM (see #8124). --- .../DataSourceMigrationForVersion_4_903.java | 2 +- .../V4_903_03_remove_duplicate_rows-H2.sql | 21 +++++++++++++++++++++ .../V4_903_03_remove_duplicate_rows-PG.sql | 21 +++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/migration/versions/DataSourceMigrationForVersion_4_903.java b/observe-entities/src/main/java/fr/ird/observe/entities/migration/versions/DataSourceMigrationForVersion_4_903.java index 37450d0..afc4088 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/migration/versions/DataSourceMigrationForVersion_4_903.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/migration/versions/DataSourceMigrationForVersion_4_903.java @@ -51,7 +51,7 @@ public class DataSourceMigrationForVersion_4_903 extends AbstractObserveMigratio // See https://forge.codelutin.com/issues/7470 addScript("01", "remove_unit_field", queries); addScript("02", "remove_gender_field", queries); - + addScript("03", "remove_duplicate_rows", queries); } public static class H2DataSourceMigrationForVersion extends DataSourceMigrationForVersion_4_903 { diff --git a/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-H2.sql b/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-H2.sql new file mode 100644 index 0000000..d6d65b3 --- /dev/null +++ b/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-H2.sql @@ -0,0 +1,21 @@ +-- suppression des doublons dans la table observe_seine.activity_observedsystem +------------------------------------------------------------------------------- + + +-- creation d'un table temporaire +CREATE TABLE ACTIVITY_OBSERVEDSYSTEM_TMP(ACTIVITY VARCHAR(255) NOT NULL, OBSERVEDSYSTEM VARCHAR(255) NOT NULL); + +-- copie les données de la table vers la table temporaire +INSERT INTO ACTIVITY_OBSERVEDSYSTEM_TMP (ACTIVITY, OBSERVEDSYSTEM) SELECT DISTINCT ACTIVITY, OBSERVEDSYSTEM FROM OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM; + +-- suppession des enregistrements de la table +DELETE FROM OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM; + +-- Ajout de la contrainte +ALTER TABLE OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM ADD CONSTRAINT PK_ACTIVITY_OBSERVEDSYSTEM PRIMARY KEY (ACTIVITY, OBSERVEDSYSTEM); + +-- on remet les enregistrement dans la table +INSERT INTO OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM (ACTIVITY, OBSERVEDSYSTEM) SELECT ACTIVITY, OBSERVEDSYSTEM FROM ACTIVITY_OBSERVEDSYSTEM_TMP; + +-- suppression de la table temporaire +DROP TABLE ACTIVITY_OBSERVEDSYSTEM_TMP; diff --git a/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-PG.sql b/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-PG.sql new file mode 100644 index 0000000..5ce44ed --- /dev/null +++ b/observe-entities/src/main/resources/db/migration/V4_903_03_remove_duplicate_rows-PG.sql @@ -0,0 +1,21 @@ +-- suppression des doublons dans la table observe_seine.activity_observedsystem +------------------------------------------------------------------------------- + + +-- creation d'un table temporaire +CREATE TABLE OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM_TMP(ACTIVITY VARCHAR(255) NOT NULL, OBSERVEDSYSTEM VARCHAR(255) NOT NULL); + +-- copie les données de la table vers la table temporaire +INSERT INTO OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM_TMP (ACTIVITY, OBSERVEDSYSTEM) SELECT DISTINCT ACTIVITY, OBSERVEDSYSTEM FROM OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM; + +-- suppession des enregistrements de la table +DELETE FROM OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM; + +-- Ajout de la contrainte +ALTER TABLE OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM ADD CONSTRAINT PK_ACTIVITY_OBSERVEDSYSTEM PRIMARY KEY (ACTIVITY, OBSERVEDSYSTEM); + +-- on remet les enregistrement dans la table +INSERT INTO OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM (ACTIVITY, OBSERVEDSYSTEM) SELECT ACTIVITY, OBSERVEDSYSTEM FROM OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM_TMP; + +-- suppression de la table temporaire +DROP TABLE OBSERVE_SEINE.ACTIVITY_OBSERVEDSYSTEM_TMP; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8124-VerifAdmin in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 3919be71727117e827939b45db9daaaf14f5d8b1 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Mar 30 10:20:37 2016 +0200 correction pour la création d'une base distante (see #8124). --- .../fr/ird/observe/db/ObserveSwingDataSource.java | 4 +- .../ird/observe/ui/storage/ObstunaAdminAction.java | 20 +- .../ird/observe/ui/storage/RemoteUILauncher.java | 1 - .../ird/observe/ui/storage/StorageUIHandler.java | 240 +-------------------- .../ird/observe/ui/storage/StorageUILauncher.java | 47 +++- .../fr/ird/observe/ui/storage/StorageUIModel.java | 111 +++++++--- .../ird/observe/ui/storage/tabs/ConfigDataUI.jaxx | 34 +++ .../ird/observe/ui/storage/tabs/ConfigDataUI.jcss | 34 ++- .../ui/storage/tabs/ConfigReferentielUI.jaxx | 36 ++++ .../ui/storage/tabs/ConfigReferentielUI.jcss | 34 ++- .../ui/storage/tabs/StorageTabUIHandler.java | 44 ++-- .../ftl/dataSourceConnectionReport_fr.ftl | 20 +- .../observe-application-swing_en_GB.properties | 9 + .../observe-application-swing_es_ES.properties | 9 + .../observe-application-swing_fr_FR.properties | 9 + .../controller/v1/DataSourceServiceController.java | 4 +- .../observe/ObserveTopiaApplicationContext.java | 40 ++-- .../services/service/DataSourceService.java | 4 +- .../services/service/DataSourceServiceTopia.java | 139 ++++++++++-- 19 files changed, 487 insertions(+), 352 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java index e9695df..7c23a14 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/db/ObserveSwingDataSource.java @@ -152,7 +152,9 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements fireOpened(); } - public void create(DataSourceCreateConfigurationDto createDto) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException { + public void create(DataSourceCreateConfigurationDto createDto) + throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, + DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException { checkIsNotAlreadyOpen(); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java index 53d5340..964f01f 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/ObstunaAdminAction.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.storage; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import fr.ird.observe.ObserveSwingApplicationContext; import fr.ird.observe.db.ObserveSwingDataSource; import fr.ird.observe.db.constants.DbMode; @@ -46,6 +45,7 @@ import org.nuiton.version.Versions; import java.awt.Window; import java.util.Set; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -119,9 +119,6 @@ public enum ObstunaAdminAction { dataSource = ObserveSwingApplicationContext.get().newDataSource(restConfig); } - // references import - model.setCreationMode(model.getReferentielImportMode()); - createConfigurationDto = model.toImportReferentielSourceConfig(); ObserveDataSourceConfiguration importReferentialConfig = createConfigurationDto.getImportReferentialDataSourceConfiguration(); @@ -141,9 +138,6 @@ public enum ObstunaAdminAction { ObserveSwingDataSource importDataConfig = model.toImportDataSourceConfig(); - - ImmutableSet<String> importDataIds = null; - if (importDataConfig != null) { if (log.isInfoEnabled()) { @@ -154,13 +148,11 @@ public enum ObstunaAdminAction { DataSelectionModel dataModel = model.getSelectDataModel(); - if (!dataModel.isDataFull()) { - // on renseigne les marees a importer uniquement si - // on en a selectionner, de plus si on a selectionne - // toutes les marees, on le les passe pas : car c un dump - // complet de la base. - importDataIds = ImmutableSet.copyOf(Iterables.transform(dataModel.getSelectedData(), DataReference.getIdFunction())); - } + ImmutableSet<String> importDataIds = ImmutableSet.copyOf( + dataModel.getSelectedData() + .stream() + .map(DataReference::getId) + .collect(Collectors.toSet())); createConfigurationDto.setImportDataConfiguration(importDataConfig.getConfiguration(), importDataIds); } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java index c35ee38..de1e08d 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/RemoteUILauncher.java @@ -67,7 +67,6 @@ public abstract class RemoteUILauncher extends StorageUILauncher { model.setAdminAction(action); List<StorageStep> steps = new ArrayList<>(); - steps.add(StorageStep.CHOOSE_DB_MODE); steps.add(StorageStep.CONFIG); if (action == ObstunaAdminAction.CREATE) { diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java index d55e847..7107f0f 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIHandler.java @@ -43,9 +43,6 @@ import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.dto.DataReference; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; import fr.ird.observe.services.dto.ObserveDbUserDto; -import fr.ird.observe.services.service.BabModelVersionException; -import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; -import fr.ird.observe.services.service.DatabaseNotFoundException; import fr.ird.observe.services.service.SqlScriptProducerRequest; import fr.ird.observe.services.service.SqlScriptProducerService; import fr.ird.observe.ui.DecoratorService; @@ -54,7 +51,6 @@ import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.tabs.DataSelectionModel; import fr.ird.observe.ui.storage.tabs.RolesTableModel; import fr.ird.observe.ui.storage.tabs.SecurityModel; -import fr.ird.observe.ui.storage.tabs.SelectDataUI; import fr.ird.observe.ui.storage.tabs.StorageTabUI; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.DefaultApplicationContext.AutoLoad; @@ -63,7 +59,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.version.Version; import javax.swing.JTabbedPane; import java.awt.Component; @@ -265,7 +260,7 @@ public class StorageUIHandler { if (StorageStep.SELECT_DATA == newStep && mustRecompute) { if (ObstunaAdminAction.CREATE == ui.getModel().getAdminAction() - && model.getSelectDataModel().isEmpty()) { + && (model.getSelectDataModel() == null || model.getSelectDataModel().isEmpty())) { // récupération des données possibles à importer initSelectData(ui); @@ -718,211 +713,6 @@ public class StorageUIHandler { return decoratorService; } - protected void computeBackupReport(SelectDataUI stepUI, StorageUIModel model, - StringBuilder sb) { - - if (model.isLocal()) { - addTag("h2", sb, t("observe.storage.report.action.backup.local")); - } - if (model.isRemote()) { - addTag("h2", sb, t("observe.storage.report.action.backup.remote")); - } - - addTag("hr", sb, ""); - - addTag("h3", sb, t("observe.storage.report.selected.backup.file")); - addOpenTag("ul", sb); - addTag("li", sb, model.getBackupFile().getAbsolutePath()); - addCloseTag("ul", sb); - - if (!model.isUseSelectData()) { //FIXME || model.getSelectDataModel() == null) { - return; - } - - //FIXME -// DataSelectionModel dataModel = model.getSelectDataModel(); -// Set<String> selectedData = dataModel.getSelectedData(); - - addTag("h3", sb, - t("observe.storage.report.selected.data.to.export") - ); - addOpenTag("ul", sb); - - //FIXME -// if (dataModel.isDataEmpty()) { -// addTag("li", sb, -// t("observe.storage.report.selected.no.data")); -// } else { -// if (dataModel.isDataFull()) { -// addTag("li", sb, -// t("observe.storage.report.selected.all.data", selectedData.size()) -// ); -// } else { -// addOpenTag("li", sb); -// sb.append(t("observe.storage.report.selected.data", selectedData.size())); -// addOpenTag("ul", sb); -// Decorator<Program> pDecorator = -// getDecoratorService().getDecoratorByType(Program.class); -// Decorator<TripSeine> mDecorator = -// getDecoratorService().getDecoratorByType(TripSeine.class); -// DataSelectionTreeCellRenderer renderer = -// (DataSelectionTreeCellRenderer) stepUI.getSelectTree().getCellRenderer(); -// DataSource source = renderer.getDataProvider().getDataSource(); -// Map<String, List<String>> dataByProgram = -// dataModel.getSelectedDataByProgram(); -// -// Preconditions.checkState(source != null && source.isOpen(), "La source de données doit être ouverte!"); -// -// for (Map.Entry<String, List<String>> entry : dataByProgram.entrySet()) { -// String pId = entry.getKey(); -// List<String> mareeIds = entry.getValue(); -// addOpenTag("li", sb); -// try { -// sb.append(source.decorateEntity(null, pId, pDecorator)); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not decorate entity " + pId, e); -// } -// addTag("li", sb, pId); -// } -// addOpenTag("ul", sb); -// for (String mareeId : mareeIds) { -// try { -// addTag("li", sb, source.decorateEntity(null, mareeId, mDecorator)); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not decorate entity " + mareeId, e); -// } -// addTag("li", sb, mareeId); -// } -// } -// addCloseTag("ul", sb); -// addCloseTag("li", sb); -// } -// -// addCloseTag("li", sb); -// addCloseTag("ul", sb); -// } -// } - - addTag("li", sb, - t("observe.storage.report.selected.data.referentiel") - ); - addCloseTag("ul", sb); - } - - protected void computeImportDataReport(StorageUIModel model, StringBuilder sb) { - - //FIXME -// DataSelectionModel dataModel = model.getSelectDataModel(); - - addTag("h3", sb, - t("observe.storage.report.selected.data.to.import") - ); - addOpenTag("ul", sb); - - //FIXME -// if (dataModel.isDataEmpty()) { -// addTag("li", sb, -// t("observe.storage.report.selected.no.data.to.import")); -// } else { -// -// Set<String> selectedData = dataModel.getSelectedData(); -// -// if (dataModel.isDataFull()) { -// addTag("li", sb, -// t("observe.storage.report.selected.all.data.to.import", selectedData.size()) -// ); -// } else { -// addOpenTag("li", sb); -// sb.append(t("observe.storage.report.selected.data.for.import", selectedData.size())); -// addOpenTag("ul", sb); -// -// DataSourceConfig dataSourceConfig = model.toImportDataSourceConfig(); -// -// DataSource source = DataSourceFactory.newService(dataSourceConfig); -// -// try { -// source.doOpen(); -// -// Decorator<Program> pDecorator = -// getDecoratorService().getDecoratorByType(Program.class); -// Decorator<TripSeine> mDecorator = -// getDecoratorService().getDecoratorByType(TripSeine.class); -// -// Map<String, List<String>> dataByProgram = dataModel.getSelectedDataByProgram(); -// -// for (Map.Entry<String, List<String>> entry : dataByProgram.entrySet()) { -// String pId = entry.getKey(); -// List<String> mareeIds = entry.getValue(); -// addOpenTag("li", sb); -// try { -// sb.append(source.decorateEntity(null, pId, pDecorator)); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not decorate entity " + pId, e); -// } -// addTag("li", sb, pId); -// } -// addOpenTag("ul", sb); -// for (String mareeId : mareeIds) { -// try { -// addTag("li", sb, source.decorateEntity(null, mareeId, mDecorator)); -// } catch (Exception e) { -// if (log.isErrorEnabled()) { -// log.error("Could not decorate entity " + mareeId, e); -// } -// addTag("li", sb, mareeId); -// } -// } -// addCloseTag("ul", sb); -// addCloseTag("li", sb); -// } -// -// } finally { -// source.doClose(false); -// } -// -// -// addCloseTag("li", sb); -// addCloseTag("ul", sb); -// } -// } - addCloseTag("ul", sb); - } - - protected void computeCanMigrateAction(StorageUIModel model, StringBuilder sb) { - addTag("h3", sb, t("observe.storage.report.action.migrate") + " :"); - addOpenTag("ul", sb); - if (model.isCanMigrate()) { - Version version = model.getModelVersion(); - addTag("li", sb, t("observe.storage.report.can.migrate", version)); - if (model.isShowMigrationProgression()) { - addTag("li", sb, t("observe.storage.showMigrationProgression")); - } - if (model.isShowMigrationSql()) { - addTag("li", sb, t("observe.storage.showMigrationSql")); - } - } else { - addTag("li", sb, t("observe.storage.report.can.not.migrate")); - } - addCloseTag("ul", sb); - } - - public static void addTag(String tag, StringBuilder sb, String message) { - sb.append('<').append(tag).append('>'); - sb.append(message); - sb.append("</").append(tag).append('>'); - } - - public static void addOpenTag(String tag, StringBuilder sb) { - sb.append('<').append(tag).append('>'); - } - - public static void addCloseTag(String tag, StringBuilder sb) { - sb.append("</").append(tag).append('>'); - } - public void initSelectData(StorageUI ui, ObserveSwingDataSource source, boolean selectAll) { StorageUIModel model = ui.getModel(); @@ -957,34 +747,6 @@ public class StorageUIHandler { } - protected void checkImportDbVersion(StorageUIModel model, ObserveSwingDataSource dataSource) { - try { - dataSource.open(); - - Version importServiceDbVersion = dataSource.getVersion(); - Version currentDbVersion = model.getModelVersion(); - if (importServiceDbVersion.before(currentDbVersion)) { - throw new IllegalStateException("Import db version (" + importServiceDbVersion + ") is not compatible with the current database version (" + currentDbVersion + ")"); - } - - } catch (DatabaseConnexionNotAuthorizedException e) { - if (log.isErrorEnabled()) { - log.error("", e); - } - } catch (BabModelVersionException e) { - if (log.isErrorEnabled()) { - log.error("", e); - } - } catch (DatabaseNotFoundException e) { - if (log.isErrorEnabled()) { - log.error("", e); - } - } finally { - dataSource.close(); - } - - } - protected void initSelectData(StorageUI ui) { StorageUIModel model = ui.getModel(); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUILauncher.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUILauncher.java index 4e13da8..438abb5 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUILauncher.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUILauncher.java @@ -211,6 +211,49 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod public static void obtainRemoteConnexion(final JAXXContext context, Window mainUI, final StorageUIModel model) { + obtainConnexion(context, mainUI, model, t("observe.title.connect.remoteDB"), DbMode.USE_REMOTE); + } + + /** + * Méthode pour lancer l'action de connexion à une base distante. + * + * Cette méthode doit être appelée avant toute action avec un server distant + * : + * + * synchronisation, récupération du référentiel distant... + * + * @param context le context applicatif + * @param mainUI la fenetre principale parent (peut etre null) + * @param model le modèle de source de données à utiliser + * @see StorageUI + */ + public static void obtainServerConnexion(final JAXXContext context, + Window mainUI, + final StorageUIModel model) { + obtainConnexion(context, mainUI, model, t("observe.title.connect.serverDB"), DbMode.USE_SERVER); + } + + /** + * Méthode pour lancer l'action de connexion à une source distante. + * + * Cette méthode doit être appelée avant toute action avec un source distante + * : + * + * synchronisation, récupération du référentiel distant... + * + * @param context le context applicatif + * @param mainUI la fenetre principale parent (peut etre null) + * @param model le modèle de source de données à utiliser + * @param title le titre de la fenêtre + * @param model le type deconnexion (base distante ou serveur distant) + * @see StorageUI + */ + public static void obtainConnexion(final JAXXContext context, + Window mainUI, + final StorageUIModel model, + String title, + DbMode dbMode) { + if (mainUI == null) { mainUI = ObserveSwingApplicationContext.get().getObserveMainUI(); @@ -220,7 +263,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod context, mainUI, model, - t("observe.title.connect.remoteDB")) { + title) { @Override protected void init(StorageUI ui) { @@ -243,7 +286,7 @@ public class StorageUILauncher extends WizardUILancher<StorageStep, StorageUIMod model.setSteps(StorageStep.CONFIG); model.updateUniverse(); - model.setDbMode(DbMode.USE_REMOTE); + model.setDbMode(dbMode); } @Override diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java index 6c7eb31..d9b07b3 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/StorageUIModel.java @@ -749,6 +749,10 @@ public class StorageUIModel extends WizardModel<StorageStep> { return adminAction; } + public String getAdminActionLabel() { + return t(getAdminAction().getLabel()); + } + public DataSelectionModel getSelectDataModel() { return selectDataModel; } @@ -779,15 +783,14 @@ public class StorageUIModel extends WizardModel<StorageStep> { @Override public String getLabel() { - String txt; - String params; - txt = t("observe.storage.label.import.referentiel"); + String txt = t("observe.storage.label.import.referentiel"); if (getDbMode() == DbMode.CREATE_LOCAL) { - params = getH2Config().getDirectory().getAbsolutePath(); - } else { - params = getRemoteUrl(); + txt = t("observe.storage.label.import.referentiel", getH2Config().getDirectory().getAbsolutePath()); + } else if (isRemote()){ + txt = t("observe.storage.label.import.referentiel.remote", getRemoteUrl()); + } else if (isServer()){ + txt = t("observe.storage.label.import.referentiel.server", getServerUrl()); } - txt = t(txt, params); return txt; } @@ -809,15 +812,14 @@ public class StorageUIModel extends WizardModel<StorageStep> { @Override public String getLabel() { - String txt; - String params; - txt = t("observe.storage.label.import.data"); + String txt = t("observe.storage.label.import.data"); if (getDbMode() == DbMode.CREATE_LOCAL) { - params = getH2Config().getDirectory().getAbsolutePath(); - } else { - params = getRemoteUrl(); + txt = t("observe.storage.label.import.data", getH2Config().getDirectory().getAbsolutePath()); + } else if (isRemote()){ + txt = t("observe.storage.label.import.data.remote", getRemoteUrl()); + } else if (isServer()){ + txt = t("observe.storage.label.import.data.server", getServerUrl()); } - txt = t(txt, params); return txt; } @@ -849,7 +851,11 @@ public class StorageUIModel extends WizardModel<StorageStep> { return; } List<StorageStep> universe = new ArrayList<>(); - universe.add(StorageStep.CHOOSE_DB_MODE); + if (adminAction == null) { + + // when doing an admin mode we do not choose db mode, we always work on remote + universe.add(StorageStep.CHOOSE_DB_MODE); + } boolean canBackup = localStorageExist; switch (dbMode) { @@ -1033,7 +1039,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { if (validate) { - validate = centralSourceModel.getDataSourceInformation().canReadData(); + validate = dataSourceModel.getDataSourceInformation().canReadData(); } @@ -1152,7 +1158,11 @@ public class StorageUIModel extends WizardModel<StorageStep> { if (dbMode == DbMode.CREATE_LOCAL) { txt = h2Config.getLabel(); } else { - txt = pgConfig.getLabel(); + if (isRemote()) { + txt = pgConfig.getLabel(); + } else { + txt = restConfig.getLabel(); + } } return txt; } @@ -1881,18 +1891,63 @@ public class StorageUIModel extends WizardModel<StorageStep> { case IMPORT_EXTERNAL_DUMP: - try (FileInputStream inputStream = new FileInputStream(dumpFile)) { + if (ObstunaAdminAction.CREATE.equals(getAdminAction())) { - byte[] bytes = IOUtils.toByteArray(inputStream); + // on import que le référentiel donc on créé un base temporaire pour cette import + ObserveSwingApplicationContext context = ObserveSwingApplicationContext.get(); - importReferenceConfig.setImportDatabase(bytes); + DataSourceCreateConfigurationDto createConfigurationDto = new DataSourceCreateConfigurationDto(); - } catch (IOException e) { + File dumpFile = getCentralSourceModel().getDumpFile(); - throw new RuntimeException("Could not read dump file", e); + try (FileInputStream inputStream = new FileInputStream(dumpFile)) { + + byte[] bytes = IOUtils.toByteArray(inputStream); + + createConfigurationDto.setImportDatabase(bytes); + + } catch (Exception e) { + + throw new RuntimeException("Could not read dump file", e); + + } + + try (ObserveSwingDataSource importDataSource = context.createDataSourceH2Temp(dbLabel)) { + + try { + importDataSource.create(createConfigurationDto); + } catch (IncompatibleDataSourceCreateConfigurationException + | DataSourceCreateWithNoReferentialImportException + | DatabaseNotFoundException + | DatabaseConnexionNotAuthorizedException + | BabModelVersionException e) { + throw new ObserveSwingTechnicalException("Could not create import data source", e); + } + + importReferenceConfig.setImportReferentialDataSourceConfiguration(importDataSource.getConfiguration()); + + } + + + } else { + + File dumpFile = getDumpFile(); + + try (FileInputStream inputStream = new FileInputStream(dumpFile)) { + + byte[] bytes = IOUtils.toByteArray(inputStream); + + importReferenceConfig.setImportDatabase(bytes); + + } catch (IOException e) { + + throw new RuntimeException("Could not read dump file", e); + + } } + break; case IMPORT_REMOTE_STORAGE: @@ -1942,6 +1997,8 @@ public class StorageUIModel extends WizardModel<StorageStep> { DataSourceCreateConfigurationDto createConfigurationDto = new DataSourceCreateConfigurationDto(); + File dumpFile = ObstunaAdminAction.CREATE.equals(getAdminAction()) ? getDataSourceModel().getDumpFile() : getDumpFile(); + try (FileInputStream inputStream = new FileInputStream(dumpFile)) { byte[] bytes = IOUtils.toByteArray(inputStream); @@ -1962,7 +2019,11 @@ public class StorageUIModel extends WizardModel<StorageStep> { try { importDataSource2.create(createConfigurationDto); - } catch (IncompatibleDataSourceCreateConfigurationException | DataSourceCreateWithNoReferentialImportException e) { + } catch (IncompatibleDataSourceCreateConfigurationException + | DataSourceCreateWithNoReferentialImportException + | DatabaseNotFoundException + | DatabaseConnexionNotAuthorizedException + | BabModelVersionException e) { throw new ObserveSwingTechnicalException("Could not create import data source", e); } @@ -1972,7 +2033,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { case IMPORT_REMOTE_STORAGE: { // import referentiel from a remote db - ObserveDataSourceConfigurationTopiaPG dataSourceConfig = getCentralSourceModel().toPGStorageConfig(dbLabel); + ObserveDataSourceConfigurationTopiaPG dataSourceConfig = getDataSourceModel().toPGStorageConfig(dbLabel); dataSourceConfig.setCanMigrate(false); @@ -1984,7 +2045,7 @@ public class StorageUIModel extends WizardModel<StorageStep> { case IMPORT_SERVER_STORAGE: { // import referentiel from a server db - ObserveDataSourceConfigurationRest dataSourceConfig = getCentralSourceModel().toRestStorageConfig(dbLabel); + ObserveDataSourceConfigurationRest dataSourceConfig = getDataSourceModel().toRestStorageConfig(dbLabel); importDataSource = ObserveSwingApplicationContext.get().newDataSource(dataSourceConfig); diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jaxx index c10cfae..fcfd9e6 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jaxx @@ -64,6 +64,7 @@ public void init() { <JRadioButton id="noImportData" styleClass='creationMode'/> <JRadioButton id="importDataFromBackup" styleClass='creationMode'/> <JRadioButton id="importDataFromRemote" styleClass='creationMode'/> + <JRadioButton id="importDataFromServer" styleClass='creationMode'/> </JPanel> </cell> </row> @@ -131,6 +132,39 @@ public void init() { </cell> </row> </Table> + + <!-- importer les données a partir d'une base distante --> + <Table id='IMPORT_SERVER_STORAGE' fill="both" + constraints='"IMPORT_SERVER_STORAGE"'> + <row> + <cell> + <JLabel + text='observe.storage.importServerStorageData.config'/> + </cell> + </row> + <row> + <cell weightx='1' fill='both'> + <JLabel id='centralSourceServerLabel'/> + </cell> + <cell> + <JButton id='configureCentralSourceServer' + onActionPerformed='getHandler().obtainServerConnexion(this)'/> + </cell> + <cell anchor='east'> + <JLabel id='centralSourceServerStatus'/> + </cell> + </row> + <row> + <cell fill='both' columns="2"> + <JLabel id='centralSourceServerPolicy'/> + </cell> + </row> + <row> + <cell fill='both' columns="2"> + <JLabel id='centralSourceServerInfoLabel'/> + </cell> + </row> + </Table> </JPanel> </cell> </row> diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jcss b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jcss index cfa946c..f89d8e5 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jcss +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigDataUI.jcss @@ -52,6 +52,12 @@ selected:{model.getDataImportMode() == CreationMode.IMPORT_REMOTE_STORAGE}; } +#importDataFromServer { + value:{CreationMode.IMPORT_SERVER_STORAGE}; + text:"observe.synchro.import.data.fromServerStorage"; + selected:{model.getDataImportMode() == CreationMode.IMPORT_SERVER_STORAGE}; +} + #noImportDataConfig { enabled: false; text:"observe.storage.noImportData.config"; @@ -59,7 +65,7 @@ #centralSourceLabel { _no:{n("observe.synchro.no.remote.storage")}; - text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel)}; + text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel, true)}; } #configureCentralSource { @@ -72,7 +78,7 @@ } #centralSourcePolicy { - text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid())} + text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid(), true)} } #centralSourceInfoLabel { @@ -80,6 +86,30 @@ text:"observe.synchro.config.export.required.read.data"; } +#centralSourceServerLabel { + _no:{n("observe.synchro.no.server.storage")}; + text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel, false)}; +} + +#configureCentralSourceServer { + text:"observe.action.configure"; + actionIcon:"config"; +} + +#centralSourceServerStatus { + icon:{(Icon) getClientProperty(centralSourceModel.isValid() ? "successIcon" : "failedIcon")}; +} + +#centralSourceServerPolicy { + text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid(), false)} +} + +#centralSourceServerInfoLabel { + actionIcon:"information"; + text:"observe.synchro.config.export.required.read.data"; +} + + #fileChooserAction { actionIcon:"fileChooser"; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jaxx b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jaxx index 15025e4..1348012 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jaxx +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jaxx @@ -67,6 +67,8 @@ public void init() { styleClass='creationMode'/> <JRadioButton id="importReferentielFromRemote" styleClass='creationMode'/> + <JRadioButton id="importReferentielFromServer" + styleClass='creationMode'/> </JPanel> </cell> </row> @@ -136,6 +138,40 @@ public void init() { </cell> </row> </Table> + + <!-- importer le référentiel a partir d'un serveur distant --> + <Table id='IMPORT_SERVER_STORAGE' fill="both" + constraints='"IMPORT_SERVER_STORAGE"'> + <row> + <cell> + <JLabel + text='observe.storage.importServerStorageReferentiel.config'/> + </cell> + </row> + <row> + <cell weightx='1' fill='both'> + <JLabel id='centralSourceServerLabel'/> + </cell> + <cell> + <JButton id='configureCentralSourceServer' + onActionPerformed='getHandler().obtainServerConnexion(this)'/> + </cell> + <cell anchor='east'> + <JLabel id='centralSourceServerStatus'/> + </cell> + </row> + <row> + <cell fill='both' columns="2"> + <JLabel id='centralSourceServerPolicy'/> + </cell> + </row> + <row> + <cell fill='both' columns="2"> + <JLabel id='centralSourceServerInfoLabel'/> + </cell> + </row> + </Table> + </JPanel> </cell> </row> diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jcss b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jcss index 715d1d8..09c7921 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jcss +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/ConfigReferentielUI.jcss @@ -52,6 +52,12 @@ selected:{model.getReferentielImportMode() == CreationMode.IMPORT_REMOTE_STORAGE}; } +#importReferentielFromServer { + value:{CreationMode.IMPORT_SERVER_STORAGE}; + text:{CreationMode.IMPORT_SERVER_STORAGE.getLabel()}; + selected:{model.getReferentielImportMode() == CreationMode.IMPORT_SERVER_STORAGE}; +} + #noImportReferentielConfig { enabled: false; text:"observe.storage.noImportReferentiel.config"; @@ -59,7 +65,7 @@ #centralSourceLabel { _no:{n("observe.synchro.no.remote.storage")}; - text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel)}; + text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel, true)}; } #configureCentralSource { @@ -72,7 +78,7 @@ } #centralSourcePolicy { - text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid())} + text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid(), true)} } #centralSourceInfoLabel { @@ -80,6 +86,30 @@ text:"observe.synchro.config.export.required.read.referentiel"; } +#centralSourceServerLabel { + _no:{n("observe.synchro.no.server.storage")}; + text:{getHandler().updateStorageLabel(centralSourceModel, centralSourceModel.isValid(), centralSourceLabel, false)}; +} + +#configureCentralSourceServer { + text:"observe.action.configure"; + actionIcon:"config"; +} + +#centralSourceServerStatus { + icon:{(Icon) getClientProperty(centralSourceModel.isValid() ? "successIcon" : "failedIcon")}; +} + +#centralSourceServerPolicy { + text:{getHandler().updateDataSourcePolicy(centralSourceModel, centralSourceModel.isValid(), false)} +} + +#centralSourceServerInfoLabel { + actionIcon:"information"; + text:"observe.synchro.config.export.required.read.referentiel"; +} + + #fileChooserAction { actionIcon:"fileChooser"; } diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java index dd6c769..275c4ec 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ui/storage/tabs/StorageTabUIHandler.java @@ -28,7 +28,6 @@ import fr.ird.observe.db.ObserveSwingDataSource; import fr.ird.observe.db.constants.ConnexionStatus; import fr.ird.observe.db.constants.CreationMode; import fr.ird.observe.db.constants.DbMode; -import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.storage.StorageStep; @@ -422,10 +421,18 @@ public class StorageTabUIHandler { sourceModel ); - // on recopie la configuration de la source d'import - ObserveDataSourceConfiguration config = sourceModel.toPGStorageConfig("Import référentiel"); - //Fixme - //ui.getModel().getCreationConfigurationDto().setImportReferentialDataSourceConfiguration(config); + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + + public void obtainServerConnexion(ConfigReferentielUI ui) { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainServerConnexion( + ui.getDelegateContext(), + ui.getParentContainer(Window.class), + sourceModel + ); sourceModel.validate(StorageStep.CONFIG); @@ -440,10 +447,19 @@ public class StorageTabUIHandler { sourceModel ); - // on recopie la configuration de la source d'import - ObserveDataSourceConfiguration config = sourceModel.toPGStorageConfig("Import référentiel"); - // Fixme - //ui.getModel().getCreationConfigurationDto().setImportDataConfiguration(config, ImmutableSet.<String>of()); + sourceModel.validate(StorageStep.CONFIG); + + ui.getModel().validate(); + } + + + public void obtainServerConnexion(ConfigDataUI ui) { + StorageUIModel sourceModel = ui.getCentralSourceModel(); + StorageUILauncher.obtainServerConnexion( + ui.getDelegateContext(), + ui.getParentContainer(Window.class), + sourceModel + ); sourceModel.validate(StorageStep.CONFIG); @@ -452,9 +468,10 @@ public class StorageTabUIHandler { public String updateStorageLabel(StorageUIModel service, boolean serviceValid, - JLabel label) { + JLabel label, + boolean remote) { String text; - if (serviceValid) { + if (serviceValid && remote == service.isRemote()) { // on recupere le label du service text = service.getLabel(); @@ -467,9 +484,10 @@ public class StorageTabUIHandler { } protected String updateDataSourcePolicy(StorageUIModel sourceModel, - boolean valid) { + boolean valid, + boolean remote) { String text = null; - if (valid) { + if (valid && remote == sourceModel.isRemote()) { ObserveDataSourceInformation dataSourceInformation = sourceModel.getDataSourceInformation(); if (dataSourceInformation != null) { diff --git a/observe-application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl b/observe-application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl index 6d5a383..26d3626 100644 --- a/observe-application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl +++ b/observe-application-swing/src/main/resources/ftl/dataSourceConnectionReport_fr.ftl @@ -158,7 +158,7 @@ <#else> - <h2>${adminAction.label}</h2> + <h2>${adminActionLabel}</h2> <hr/> <h3>Informations sur la connexion distance à utiliser :</h3> @@ -197,25 +197,25 @@ <#if importData> - <#if referentielImportMode.name() == "IMPORT_EXTERNAL_DUMP"> + <#if dataImportMode.name() == "IMPORT_EXTERNAL_DUMP"> - <h3>Import du référentiel depuis une sauvegarde :</h3> + <h3>Import de données depuis une sauvegarde :</h3> <ul> - <li>${centralSourceModel.dumpFile.absolutePath}</li> + <li>${dataSourceModel.dumpFile.absolutePath}</li> </ul> - <#elseif referentielImportMode.name() == "IMPORT_REMOTE_STORAGE"> + <#elseif dataImportMode.name() == "IMPORT_REMOTE_STORAGE"> - <h3>Import du référentiel depuis une base distante :</h3> + <h3>Import de données depuis une base distante :</h3> - <@storageInfo.storageModelDataSourceInformation storageModel=centralSourceModel /> + <@storageInfo.storageModelDataSourceInformation storageModel=dataSourceModel /> - <#elseif referentielImportMode.name() == "IMPORT_SERVER_STORAGE"> + <#elseif dataImportMode.name() == "IMPORT_SERVER_STORAGE"> - <h3>Import du référentiel depuis un serveur distant :</h3> + <h3>Import de données depuis un serveur distant :</h3> - <@storageInfo.storageModelDataSourceInformation storageModel=centralSourceModel /> + <@storageInfo.storageModelDataSourceInformation storageModel=dataSourceModel /> </#if> diff --git a/observe-application-swing/src/main/resources/i18n/observe-application-swing_en_GB.properties b/observe-application-swing/src/main/resources/i18n/observe-application-swing_en_GB.properties index e500afe..20cd6a9 100644 --- a/observe-application-swing/src/main/resources/i18n/observe-application-swing_en_GB.properties +++ b/observe-application-swing/src/main/resources/i18n/observe-application-swing_en_GB.properties @@ -1864,6 +1864,8 @@ observe.storage.importRemoteStorageData.config= observe.storage.importRemoteStorageReferentiel.config= observe.storage.importServerStorage.config= observe.storage.importServerStorage.description= +observe.storage.importServerStorageData.config= +observe.storage.importServerStorageReferentiel.config= observe.storage.internalDump.last.modified= observe.storage.internalDump.not.exist= observe.storage.label.backup= @@ -1873,8 +1875,12 @@ observe.storage.label.db.to.drop= observe.storage.label.db.to.update= observe.storage.label.db.to.update.security= observe.storage.label.import.data= +observe.storage.label.import.data.remote= +observe.storage.label.import.data.server= observe.storage.label.import.local= observe.storage.label.import.referentiel= +observe.storage.label.import.referentiel.remote= +observe.storage.label.import.referentiel.server= observe.storage.label.import.remote= observe.storage.label.local=Local database observe.storage.label.reference.import.db= @@ -2010,6 +2016,7 @@ observe.synchro.configuration= observe.synchro.continue.with.no.save.report= observe.synchro.import.data.fromBackup= observe.synchro.import.data.fromRemoteStorage= +observe.synchro.import.data.fromServerStorage= observe.synchro.importGPS.invalidIntervals.list= observe.synchro.message.all.obsolete.entities.fixed= observe.synchro.message.need.save.for.synchro.operation= @@ -2022,6 +2029,7 @@ observe.synchro.no.data.import= observe.synchro.no.local.storage= observe.synchro.no.referentiel.import= observe.synchro.no.remote.storage= +observe.synchro.no.server.storage= observe.synchro.obsolete.entities.list= observe.synchro.obsolete.entity.fix= observe.synchro.obsolete.entity.label= @@ -2218,6 +2226,7 @@ observe.title.config.migrate= observe.title.connect.existingDB= observe.title.connect.localDB= observe.title.connect.remoteDB= +observe.title.connect.serverDB= observe.title.consolidate= observe.title.consolidate.tip= observe.title.content.HookSizes= diff --git a/observe-application-swing/src/main/resources/i18n/observe-application-swing_es_ES.properties b/observe-application-swing/src/main/resources/i18n/observe-application-swing_es_ES.properties index f66dd5a..91d030e 100644 --- a/observe-application-swing/src/main/resources/i18n/observe-application-swing_es_ES.properties +++ b/observe-application-swing/src/main/resources/i18n/observe-application-swing_es_ES.properties @@ -1866,6 +1866,8 @@ observe.storage.importRemoteStorageData.config= observe.storage.importRemoteStorageReferentiel.config=Escoja la base remota que contenga el referencial a importar observe.storage.importServerStorage.config= observe.storage.importServerStorage.description= +observe.storage.importServerStorageData.config= +observe.storage.importServerStorageReferentiel.config= observe.storage.internalDump.last.modified=(última importación \: %1$td/%1$tm/%1$tY à %1$tH\:%1$tM) observe.storage.internalDump.not.exist=No hay base de embarque. observe.storage.label.backup=Base temporal para backup @@ -1875,8 +1877,12 @@ observe.storage.label.db.to.drop= observe.storage.label.db.to.update= observe.storage.label.db.to.update.security= observe.storage.label.import.data= +observe.storage.label.import.data.remote= +observe.storage.label.import.data.server= observe.storage.label.import.local=Base local de importación observe.storage.label.import.referentiel=Base remota de importación +observe.storage.label.import.referentiel.remote= +observe.storage.label.import.referentiel.server= observe.storage.label.import.remote=Base remota de importación observe.storage.label.local=Base local observe.storage.label.reference.import.db= @@ -2012,6 +2018,7 @@ observe.synchro.configuration=Configuración de las operaciones observe.synchro.continue.with.no.save.report=Continuar sin guardar el informe observe.synchro.import.data.fromBackup= observe.synchro.import.data.fromRemoteStorage= +observe.synchro.import.data.fromServerStorage= observe.synchro.importGPS.invalidIntervals.list=Lista de los intervalos de puntos gps no usables observe.synchro.message.all.obsolete.entities.fixed=No hay mas referencias a los objetos obsoletos. observe.synchro.message.need.save.for.synchro.operation=La operación de sincronización de referenciales ha generado cambios @@ -2024,6 +2031,7 @@ observe.synchro.no.data.import= observe.synchro.no.local.storage=No hay base origen definida observe.synchro.no.referentiel.import=No importar el referencial observe.synchro.no.remote.storage=No hay base de referencia definida +observe.synchro.no.server.storage= observe.synchro.obsolete.entities.list=La lista de entidades de referenciales está obsoleta observe.synchro.obsolete.entity.fix=Cambiar las referencias del objeto seleccionado observe.synchro.obsolete.entity.label=%1$s \: "%2$s" @@ -2220,6 +2228,7 @@ observe.title.config.migrate= observe.title.connect.existingDB= observe.title.connect.localDB= observe.title.connect.remoteDB= +observe.title.connect.serverDB= observe.title.consolidate= observe.title.consolidate.tip= observe.title.content.HookSizes= diff --git a/observe-application-swing/src/main/resources/i18n/observe-application-swing_fr_FR.properties b/observe-application-swing/src/main/resources/i18n/observe-application-swing_fr_FR.properties index e845ca4..a4e4ff4 100644 --- a/observe-application-swing/src/main/resources/i18n/observe-application-swing_fr_FR.properties +++ b/observe-application-swing/src/main/resources/i18n/observe-application-swing_fr_FR.properties @@ -1857,6 +1857,8 @@ observe.storage.importRemoteStorageData.config=Choisir la base distante contenan observe.storage.importRemoteStorageReferentiel.config=Choisir la base distante contenant le référentiel à importer observe.storage.importServerStorage.config=Sélection du serveur distant à importer observe.storage.importServerStorage.description=Veuillez configurer la connexion vers un serveur distant.\nAvant de pouvoir poursuivre, vous devez valider la connexion. +observe.storage.importServerStorageData.config=Choisir le serveur distant contenant les données à importer +observe.storage.importServerStorageReferentiel.config=Choisir le serveur distant contenant le référentiel à importer observe.storage.internalDump.last.modified=(dernier import \: %1$td/%1$tm/%1$tY à %1$tH\:%1$tM) observe.storage.internalDump.not.exist=Pas de base embarquée. observe.storage.label.backup=Base temporaire pour backup @@ -1866,8 +1868,12 @@ observe.storage.label.db.to.drop=Base à vider observe.storage.label.db.to.update=Base à mettre à jour observe.storage.label.db.to.update.security=Base à mettre à jour (sécurité) observe.storage.label.import.data=Base distante d'import de données +observe.storage.label.import.data.remote=Base distante d'import de données +observe.storage.label.import.data.server=Serveur distant d'import de données observe.storage.label.import.local=Base locale d'import observe.storage.label.import.referentiel=Base distante d'import +observe.storage.label.import.referentiel.remote=Base distante d'import +observe.storage.label.import.referentiel.server=Serveur distant d'import observe.storage.label.import.remote=Base distante d'import observe.storage.label.local=Base locale observe.storage.label.reference.import.db=Base d'import de référentiels @@ -2002,6 +2008,7 @@ observe.synchro.configuration=Configuration des opérations observe.synchro.continue.with.no.save.report=Continuer sans sauver de rapport observe.synchro.import.data.fromBackup=Importer les données depuis une sauvegarde de base locale (*.sql.gz) observe.synchro.import.data.fromRemoteStorage=Importer les données depuis une base distante +observe.synchro.import.data.fromServerStorage=Importer les données depuis un serveur distant observe.synchro.importGPS.invalidIntervals.list=Liste des intervalles de points gps non utilisables observe.synchro.message.all.obsolete.entities.fixed=Il n'y a plus de références sur des objets obsolètes. observe.synchro.message.need.save.for.synchro.operation=L'opération de synchronisation du référentiel a engendrée des modifications. @@ -2014,6 +2021,7 @@ observe.synchro.no.data.import=Ne pas importer de données observe.synchro.no.local.storage=Aucune base source définie observe.synchro.no.referentiel.import=Ne pas importer de référentiel observe.synchro.no.remote.storage=Aucune base de référence définie +observe.synchro.no.server.storage=Aucun serveur de référence défini observe.synchro.obsolete.entities.list=Liste des entités du référentiel obsolètes observe.synchro.obsolete.entity.fix=Changer les références sur l'objet sélectionné observe.synchro.obsolete.entity.label=%1$s \: "%2$s" @@ -2210,6 +2218,7 @@ observe.title.config.migrate=Déplacement du fichier de configuration observe.title.connect.existingDB=Connexion à une source de données existante observe.title.connect.localDB=Connexion à une source de données locale observe.title.connect.remoteDB=Connexion à une source de données distante +observe.title.connect.serverDB=Connexion à un serveur de données distant observe.title.consolidate=Consolider les données observateur observe.title.consolidate.tip=Consolider les données observateur observe.title.content.HookSizes= diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DataSourceServiceController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DataSourceServiceController.java index 89d5df7..65d40ac 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DataSourceServiceController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DataSourceServiceController.java @@ -72,7 +72,9 @@ public class DataSourceServiceController extends ObserveServiceControllerSupport } @Override - public ObserveDataSourceConnectionRest create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException { + public ObserveDataSourceConnectionRest create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) + throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, + DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException { ObserveDataSourceConfiguration dataSourceConfigurationTopia = getTopiaDataSourceConfiguration(dataSourceConfiguration); diff --git a/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaApplicationContext.java b/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaApplicationContext.java index c424661..1e27b2b 100644 --- a/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaApplicationContext.java +++ b/observe-entities/src/main/java/fr/ird/observe/ObserveTopiaApplicationContext.java @@ -23,7 +23,6 @@ package fr.ird.observe; */ import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.migration.ObserveMigrationEngine; import org.apache.commons.logging.Log; @@ -44,10 +43,11 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.LinkedHashSet; -import java.util.List; import java.util.Objects; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicationContext { @@ -67,7 +67,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat + "CREATE SCHEMA OBSERVE_LONGLINE;\n" + "CREATE SCHEMA OBSERVE_SEINE;\n"; - private static final String INSERT_LAST_UPDATE_PATTERN = "INSERT INTO OBSERVE_COMMON.LASTUPDATEDATE (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, TYPE, LASTUPDATEDATE) VALUES ('fr.ird.observe.entities.LastUpdateDate#1236861982132#0.%02d', 0, CURRENT_TIMESTAMP, '%s', CURRENT_TIMESTAMP);\n"; + private static final String INSERT_LAST_UPDATE_PATTERN = "INSERT INTO OBSERVE_COMMON.LASTUPDATEDATE (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, TYPE, LASTUPDATEDATE) VALUES ('fr.ird.observe.entities.LastUpdateDate#1236861982132#0.%03d', 0, CURRENT_TIMESTAMP, '%s', CURRENT_TIMESTAMP);"; /** @@ -129,34 +129,34 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat Configuration hibernateConfiguration = getHibernateProvider().getHibernateConfiguration(); new SchemaExport(hibernateConfiguration).execute(showSchema, true, false, true); - // alimentation de la table lastUpdate - try (ObserveTopiaPersistenceContext topiaPersistenceContext = newPersistenceContext()) { - StringBuilder sql = new StringBuilder(); + topiaFiresSupport.firePostCreateSchema(this); + } catch (HibernateException eee) { + throw new TopiaException(String.format("Could not create schema for reason: %s", eee.getMessage()), eee); + } + } - int entitiesIndex = 0; + public void insertLastUpdateDate() { + try { - List<ObserveEntityEnum> entities = Lists.newLinkedList(Entities.REFERENCE_ENTITIES_LIST); - entities.addAll(Entities.DATA_ENTITIES_LIST); + // alimentation de la table lastUpdate + try (ObserveTopiaPersistenceContext topiaPersistenceContext = newPersistenceContext()) { - for (ObserveEntityEnum entity : entities) { - entitiesIndex++; - sql.append(String.format( - INSERT_LAST_UPDATE_PATTERN, - entitiesIndex, - entity.getContract().getCanonicalName() - )); - } + String sql = Stream.concat(Entities.REFERENCE_ENTITIES_LIST.stream(), Entities.DATA_ENTITIES_LIST.stream()) + .map(entity -> String.format(INSERT_LAST_UPDATE_PATTERN, entity.ordinal(), entity.getContract().getCanonicalName())) + .collect(Collectors.joining("\n")); - topiaPersistenceContext.getSqlSupport().executeSql(sql.toString()); + topiaPersistenceContext.getSqlSupport().executeSql(sql); topiaPersistenceContext.commit(); } - topiaFiresSupport.firePostCreateSchema(this); + } catch (HibernateException eee) { - throw new TopiaException(String.format("Could not create schema for reason: %s", eee.getMessage()), eee); + throw new TopiaException(String.format("Could insert lastupdateDate for reason: %s", eee.getMessage()), eee); } + } + public void executeSqlStatements(byte... content) { try { diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java index d4e88d5..1d66a31 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java @@ -50,7 +50,9 @@ public interface DataSourceService extends ObserveService, Closeable { ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException; @NoDataAccess - ObserveDataSourceConnection create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException; + ObserveDataSourceConnection create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) + throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, + BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException; @NoDataAccess ObserveDataSourceConnection open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException; diff --git a/observe-services-topia/src/main/java/fr/ird/observe/services/service/DataSourceServiceTopia.java b/observe-services-topia/src/main/java/fr/ird/observe/services/service/DataSourceServiceTopia.java index 919eb5f..4024e43 100644 --- a/observe-services-topia/src/main/java/fr/ird/observe/services/service/DataSourceServiceTopia.java +++ b/observe-services-topia/src/main/java/fr/ird/observe/services/service/DataSourceServiceTopia.java @@ -40,6 +40,7 @@ import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.configuration.ObserveDataSourceConfigurationTopiaH2; import fr.ird.observe.services.configuration.ObserveDataSourceConfigurationTopiaPG; import fr.ird.observe.services.configuration.ObserveDataSourceConfigurationTopiaSupport; +import fr.ird.observe.services.configuration.ObserveDataSourceConnection; import fr.ird.observe.services.configuration.ObserveDataSourceConnectionTopia; import fr.ird.observe.services.configuration.ObserveDataSourceInformation; import fr.ird.observe.services.dto.DataSourceCreateConfigurationDto; @@ -54,7 +55,10 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper; import org.nuiton.version.Version; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.Set; +import java.util.UUID; import static org.nuiton.i18n.I18n.l; @@ -154,7 +158,9 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS } @Override - public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException { + public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration) + throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException, + BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException { if (log.isTraceEnabled()) { log.trace("create(" + dataSourceConfiguration + ", " + dataSourceCreateConfiguration + ")"); } @@ -176,15 +182,56 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS } byte[] importDatabase = dataSourceCreateConfiguration.getImportDatabase(); - topiaApplicationContext.executeSqlStatements(importDatabase); - topiaApplicationContext.getMigrationService().createSchemaIfNotExit(); - topiaApplicationContext.getMigrationService().runSchemaMigration(); + if (((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration).isH2Database()) { + topiaApplicationContext.executeSqlStatements(importDatabase); + topiaApplicationContext.getMigrationService().createSchemaIfNotExit(); + topiaApplicationContext.getMigrationService().runSchemaMigration(); + } else { // base postgre + + // on realise les import dans un base H2 temporaire + // FIXME il faut obtenir le repertoit temporaire d'observe plutot que celui du système + File tmpDir; + try { + tmpDir = Files.createTempDirectory("obstuna").toFile(); + } catch (IOException e) { + throw new IllegalStateException("could not create temporary directory ", e); + } + + ObserveDataSourceConfigurationTopiaH2 temporaryConfiguration = createTemporaryConfiguration(tmpDir, dataSourceConfiguration.getModelVersion()); + + ObserveTopiaApplicationContext temporaryTopiaApplicationContext = ObserveTopiaApplicationContextFactory.createTopiaApplicationContext(temporaryConfiguration, false); + temporaryTopiaApplicationContext.executeSqlStatements(importDatabase); + temporaryTopiaApplicationContext.getMigrationService().createSchemaIfNotExit(); + temporaryTopiaApplicationContext.getMigrationService().runSchemaMigration(); + + SqlScriptProducerService dumpProducerService = serviceContext.newService(temporaryConfiguration, SqlScriptProducerService.class); + SqlScriptProducerRequest request = SqlScriptProducerRequest.forPostgres().addSchema().addReferential().addAllData(); + byte[] dump = dumpProducerService.produceSqlScript(request); + topiaApplicationContext.executeSqlStatements(dump); + topiaApplicationContext.getMigrationService().createSchemaIfNotExit(); + topiaApplicationContext.getMigrationService().runSchemaMigration(); + + temporaryTopiaApplicationContext.close(); + File databaseFile = temporaryConfiguration.getDatabaseFile(); + + if (!databaseFile.delete()) { + throw new IllegalStateException("could not delete " + databaseFile); + } + + + } } else { boolean importReferential = dataSourceCreateConfiguration.isImportReferential(); boolean importData = dataSourceCreateConfiguration.isImportData(); + // si le referentiel n'est pas importé on aliment la table lasteUpdateDate + if (!importReferential) { + topiaApplicationContext.insertLastUpdateDate(); + } + + boolean importStandaloneReferantial = importReferential; if (importReferential && importData) { @@ -206,9 +253,30 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS } ObserveDataSourceConfiguration importDataSourceConfiguration = dataSourceCreateConfiguration.getImportReferentialDataSourceConfiguration(); - SqlScriptProducerService dumpProducerService = serviceContext.newService(importDataSourceConfiguration, SqlScriptProducerService.class); - SqlScriptProducerRequest request = SqlScriptProducerRequest.forH2().addReferential(); - byte[] referentialDump = dumpProducerService.produceSqlScript(request); + + SqlScriptProducerRequest request; + if (((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration).isH2Database()) { + request = SqlScriptProducerRequest.forH2(); + } else { + request = SqlScriptProducerRequest.forPostgres(); + } + request.addReferential(); + + + DataSourceService dataSourceService = serviceContext.newService(importDataSourceConfiguration, DataSourceService.class); + + byte[] referentialDump; + + try { + ObserveDataSourceConnection importDataSourceConnection = dataSourceService.open(importDataSourceConfiguration); + + SqlScriptProducerService dumpProducerService = serviceContext.newService(importDataSourceConnection, SqlScriptProducerService.class); + referentialDump = dumpProducerService.produceSqlScript(request); + + } finally { + dataSourceService.close(); + } + topiaApplicationContext.executeSqlStatements(referentialDump); referantialImported = true; @@ -219,23 +287,21 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS if (importData) { ObserveDataSourceConfiguration importDataSourceConfiguration = dataSourceCreateConfiguration.getImportDataDataSourceConfiguration(); - SqlScriptProducerService dumpProducerService = serviceContext.newService(importDataSourceConfiguration, SqlScriptProducerService.class); - - if (!referantialImported) { - if (log.isInfoEnabled()) { - log.info("Get referential."); - } - // Réplication du référentiel - SqlScriptProducerRequest request = SqlScriptProducerRequest.forH2().addReferential(); - byte[] referentialDump = dumpProducerService.produceSqlScript(request); + SqlScriptProducerRequest request; + if (((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration).isH2Database()) { + request = SqlScriptProducerRequest.forH2(); + } else { + request = SqlScriptProducerRequest.forPostgres(); + } + if (!referantialImported) { if (log.isInfoEnabled()) { - log.info("Import referential."); + log.info("Get referential."); } - topiaApplicationContext.executeSqlStatements(referentialDump); + request.addReferential(); } // Récupération du dump qui contient les données @@ -245,12 +311,26 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS log.info("Get data: " + importDataIds); } - SqlScriptProducerRequest request = SqlScriptProducerRequest.forH2().addDataIds(importDataIds); - byte[] dataDump = dumpProducerService.produceSqlScript(request); + request.addDataIds(importDataIds); + + DataSourceService dataSourceService = serviceContext.newService(importDataSourceConfiguration, DataSourceService.class); + + byte[] dataDump; + + try { + ObserveDataSourceConnection importDataSourceConnection = dataSourceService.open(importDataSourceConfiguration); + + SqlScriptProducerService dumpProducerService = serviceContext.newService(importDataSourceConnection, SqlScriptProducerService.class); + dataDump = dumpProducerService.produceSqlScript(request); + + } finally { + dataSourceService.close(); + } if (log.isInfoEnabled()) { - log.info("Import data."); + log.info("Import data" + (request.isAddReferential() ? " and referential." : ".")); } + topiaApplicationContext.executeSqlStatements(dataDump); } @@ -263,6 +343,23 @@ public class DataSourceServiceTopia extends ObserveServiceTopia implements DataS } + protected ObserveDataSourceConfigurationTopiaH2 createTemporaryConfiguration(File tmpDirectory, Version version) { + + File dbDirectory = new File(tmpDirectory, "obstuna" + UUID.randomUUID().toString()); + + ObserveDataSourceConfigurationTopiaH2 configuration = new ObserveDataSourceConfigurationTopiaH2(); + configuration.setLabel("obtunaTmp"); + configuration.setDbName("obstuna"); + configuration.setUsername("sa"); + configuration.setPassword("sa".toCharArray()); + configuration.setDirectory(dbDirectory); + configuration.setShowMigrationProgression(true); + configuration.setShowMigrationSql(true); + configuration.setModelVersion(version); + + return configuration; + } + @Override public ObserveDataSourceConnectionTopia open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException { if (log.isTraceEnabled()) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm