Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe
Commits:
-
ae6dc319
by tchemit at 2020-04-14T00:44:33+02:00
27 changed files:
- client-configuration/src/main/config/Client.ini
- client-configuration/src/main/i18n/getters/config.getter
- client-configuration/src/main/java/fr/ird/observe/client/configuration/ClientConfig.java
- client-core/src/main/java/fr/ird/observe/client/ObserveRunner.java
- client-core/src/main/java/fr/ird/observe/client/ObserveSwingApplicationContext.java
- 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/main/menu/config/ShowConfigAction.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
- − persistence/src/main/java/fr/ird/observe/persistence/AbstractObserveTopiaDao.java
- − persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaConfiguration.java
- − persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaConfigurationFactory.java
- − persistence/src/main/java/fr/ird/observe/persistence/ObserveTopiaIdFactory.java
- pom.xml
- server-configuration/pom.xml
- server-configuration/src/main/config/Server.ini
- server-configuration/src/main/i18n/getters/config.getter
- server-configuration/src/main/java/fr/ird/observe/server/configuration/ServerConfig.java
- server-core/src/main/java/fr/ird/observe/server/ObserveWebApplicationContext.java
- services-local/src/main/java/fr/ird/observe/services/local/ObserveSecurityHelper.java
- services-local/src/main/java/fr/ird/observe/services/local/ObserveTopiaApplicationContextFactory.java
- services-local/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java
- services-local/src/test/java/fr/ird/observe/services/local/LocalTestClassResource.java
- + services/src/main/java/fr/ird/observe/services/service/CleanTemporaryFilesTask.java
- + services/src/main/java/fr/ird/observe/services/service/CleanTemporaryFilesTaskConfiguration.java
Changes:
| ... | ... | @@ -130,8 +130,8 @@ defaultValue = ${data.directory}/validation-report |
| 130 | 130 |
transient = true
|
| 131 | 131 |
final = true
|
| 132 | 132 |
|
| 133 |
-[option tmpDirectory]
|
|
| 134 |
-description = observe.config.defaultTmpDirectory.description
|
|
| 133 |
+[option temporaryDirectory]
|
|
| 134 |
+description = observe.config.temporaryDirectory.description
|
|
| 135 | 135 |
key = tmp.directory
|
| 136 | 136 |
type = file
|
| 137 | 137 |
defaultValue = ${data.directory}/tmp
|
| ... | ... | @@ -599,6 +599,12 @@ key = ui.seineBycatchObservedSystem |
| 599 | 599 |
type = fr.ird.observe.validation.SeineBycatchObservedSystemConfig
|
| 600 | 600 |
defaultValue = {\"fr.ird.observe.entities.referentiel.Species#1239832684290#0.04680507324710936\": [\"fr.ird.observe.entities.referentiel.seine.ObservedSystem#0#1.0\",\"fr.ird.observe.entities.referentiel.seine.ObservedSystem#0#1.1\"]}
|
| 601 | 601 |
|
| 602 |
+[option temporaryFilesTimeout]
|
|
| 603 |
+description = observe.config.temporaryFilesTimeout.description
|
|
| 604 |
+key = observe.config.temporaryFilesTimeout
|
|
| 605 |
+type = int
|
|
| 606 |
+defaultValue = 120
|
|
| 607 |
+ |
|
| 602 | 608 |
[action help]
|
| 603 | 609 |
description = observe.action.commandline.help
|
| 604 | 610 |
action = "fr.ird.observe.client.ObserveCLAction#help"
|
| ... | ... | @@ -30,7 +30,6 @@ observe.config.defaultLocalDbDirectory.description |
| 30 | 30 |
observe.config.defaultMapDirectory.description
|
| 31 | 31 |
observe.config.defaultReportDirectory.description
|
| 32 | 32 |
observe.config.defaultResourcesDirectory.description
|
| 33 |
-observe.config.defaultTmpDirectory.description
|
|
| 34 | 33 |
observe.config.defaultValidationReportDirectory.description
|
| 35 | 34 |
observe.config.devMode
|
| 36 | 35 |
observe.config.floatingObjectPresets.description
|
| ... | ... | @@ -78,6 +77,8 @@ observe.config.speciesList.seine.schoolEstimate |
| 78 | 77 |
observe.config.speciesList.seine.targetCatch
|
| 79 | 78 |
observe.config.swingSessionFile.description
|
| 80 | 79 |
observe.config.temperature.format
|
| 80 |
+observe.config.temporaryDirectory.description
|
|
| 81 |
+observe.config.temporaryFilesTimeout.description
|
|
| 81 | 82 |
observe.config.ui.autoPopupNumberEditor
|
| 82 | 83 |
observe.config.ui.changeSynchroSrc
|
| 83 | 84 |
observe.config.ui.dcp.error.color
|
| ... | ... | @@ -30,6 +30,7 @@ import fr.ird.observe.client.constants.DbMode; |
| 30 | 30 |
import fr.ird.observe.dto.FloatingObjectPreset;
|
| 31 | 31 |
import fr.ird.observe.dto.presets.RemoteDataSourceConfiguration;
|
| 32 | 32 |
import fr.ird.observe.dto.presets.ServerDataSourceConfiguration;
|
| 33 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTaskConfiguration;
|
|
| 33 | 34 |
import io.ultreia.java4all.config.ApplicationConfig;
|
| 34 | 35 |
import io.ultreia.java4all.config.ApplicationConfigInit;
|
| 35 | 36 |
import io.ultreia.java4all.config.ApplicationConfigScope;
|
| ... | ... | @@ -66,7 +67,7 @@ import static io.ultreia.java4all.i18n.I18n.t; |
| 66 | 67 |
* @author Tony Chemit - dev@tchemit.fr
|
| 67 | 68 |
* @since 1.0
|
| 68 | 69 |
*/
|
| 69 |
-public class ClientConfig extends GeneratedClientConfig implements NavigationTreeConfig {
|
|
| 70 |
+public class ClientConfig extends GeneratedClientConfig implements NavigationTreeConfig, CleanTemporaryFilesTaskConfiguration {
|
|
| 70 | 71 |
|
| 71 | 72 |
public static final String DB_NAME = "obstuna";
|
| 72 | 73 |
public static final List<ClientConfigOption> MAP_LAYERS = ImmutableList.of(
|
| ... | ... | @@ -37,7 +37,6 @@ import io.ultreia.java4all.i18n.runtime.boot.UserI18nBootLoader; |
| 37 | 37 |
import org.apache.commons.beanutils.ConvertUtils;
|
| 38 | 38 |
import org.apache.commons.beanutils.Converter;
|
| 39 | 39 |
import org.apache.commons.beanutils.converters.DateConverter;
|
| 40 |
-import org.apache.commons.io.FileUtils;
|
|
| 41 | 40 |
import org.apache.commons.lang3.BooleanUtils;
|
| 42 | 41 |
import org.apache.logging.log4j.LogManager;
|
| 43 | 42 |
import org.apache.logging.log4j.Logger;
|
| ... | ... | @@ -71,7 +70,7 @@ import static fr.ird.observe.client.configuration.ClientConfigOption.INITIAL_DB_ |
| 71 | 70 |
import static fr.ird.observe.client.configuration.ClientConfigOption.MAP_DIRECTORY;
|
| 72 | 71 |
import static fr.ird.observe.client.configuration.ClientConfigOption.REPORT_DIRECTORY;
|
| 73 | 72 |
import static fr.ird.observe.client.configuration.ClientConfigOption.RESOURCES_DIRECTORY;
|
| 74 |
-import static fr.ird.observe.client.configuration.ClientConfigOption.TMP_DIRECTORY;
|
|
| 73 |
+import static fr.ird.observe.client.configuration.ClientConfigOption.TEMPORARY_DIRECTORY;
|
|
| 75 | 74 |
import static fr.ird.observe.client.configuration.ClientConfigOption.VALIDATION_REPORT_DIRECTORY;
|
| 76 | 75 |
import static io.ultreia.java4all.i18n.I18n.t;
|
| 77 | 76 |
|
| ... | ... | @@ -402,10 +401,7 @@ public abstract class ObserveRunner extends ApplicationRunner { |
| 402 | 401 |
|
| 403 | 402 |
// 2 - tmp directory
|
| 404 | 403 |
|
| 405 |
- resourceManager.createDirectory(config, TMP_DIRECTORY);
|
|
| 406 |
- |
|
| 407 |
- // suppression du contenu du répertoire temporaire
|
|
| 408 |
- FileUtils.cleanDirectory(config.getTmpDirectory());
|
|
| 404 |
+ resourceManager.createDirectory(config, TEMPORARY_DIRECTORY);
|
|
| 409 | 405 |
|
| 410 | 406 |
// 3 - backup directory
|
| 411 | 407 |
|
| ... | ... | @@ -36,6 +36,7 @@ import fr.ird.observe.dto.decoration.DecoratorService; |
| 36 | 36 |
import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 37 | 37 |
import fr.ird.observe.services.ObserveDataSourceConfigurationMainFactory;
|
| 38 | 38 |
import fr.ird.observe.services.ObserveServiceMainFactory;
|
| 39 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTask;
|
|
| 39 | 40 |
import fr.ird.observe.spi.DtoModelHelper;
|
| 40 | 41 |
import fr.ird.observe.validation.ValidatorDto;
|
| 41 | 42 |
import fr.ird.observe.validation.ValidatorsManager;
|
| ... | ... | @@ -53,6 +54,7 @@ import java.util.Collection; |
| 53 | 54 |
import java.util.LinkedList;
|
| 54 | 55 |
import java.util.List;
|
| 55 | 56 |
import java.util.Objects;
|
| 57 |
+import java.util.Timer;
|
|
| 56 | 58 |
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
| 57 | 59 |
import java.util.concurrent.TimeUnit;
|
| 58 | 60 |
|
| ... | ... | @@ -65,6 +67,7 @@ import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.DATA_ |
| 65 | 67 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.DATA_SOURCES_MANAGER;
|
| 66 | 68 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.DATA_SOURCE_CONFIGURATION_FACTORY;
|
| 67 | 69 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.DECORATOR_SERVICE;
|
| 70 |
+import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.DELETE_TEMPORARY_FILES_TASK;
|
|
| 68 | 71 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.FLOATING_OBJECT_REFERENCES_MANAGER;
|
| 69 | 72 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.H2_SERVER;
|
| 70 | 73 |
import static fr.ird.observe.client.ObserveSwingApplicationContext.Entries.H2_SERVER_MODE;
|
| ... | ... | @@ -130,7 +133,7 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 130 | 133 |
BACKUP_MANAGER.set(new BackupsManager(config.getBackupDirectory().toPath(), config.getBackupsFile().toPath()));
|
| 131 | 134 |
LOCAL_DATABASE_BACKUP_TIMER.set(new ScheduledThreadPoolExecutor(1));
|
| 132 | 135 |
OBSERVE_SWING_SESSION_HELPER.set(new ObserveSwingSessionHelper(config.getSwingSessionFile()));
|
| 133 |
- |
|
| 136 |
+ DELETE_TEMPORARY_FILES_TASK.set(CleanTemporaryFilesTask.create(config));
|
|
| 134 | 137 |
lock = new Object();
|
| 135 | 138 |
}
|
| 136 | 139 |
|
| ... | ... | @@ -174,6 +177,10 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 174 | 177 |
return DATA_SOURCES_MANAGER.get();
|
| 175 | 178 |
}
|
| 176 | 179 |
|
| 180 |
+ public Timer getCleanTemporaryFilesTask() {
|
|
| 181 |
+ return DELETE_TEMPORARY_FILES_TASK.get();
|
|
| 182 |
+ }
|
|
| 183 |
+ |
|
| 177 | 184 |
public DecoratorService getDecoratorService() {
|
| 178 | 185 |
return DECORATOR_SERVICE.get();
|
| 179 | 186 |
}
|
| ... | ... | @@ -319,7 +326,6 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 319 | 326 |
toClose.add(OBSERVE_SWING_SESSION_HELPER);
|
| 320 | 327 |
toClose.add(BACKUP_MANAGER);
|
| 321 | 328 |
toClose.add(DATA_SOURCES_MANAGER);
|
| 322 |
- |
|
| 323 | 329 |
for (Entries closeable : toClose) {
|
| 324 | 330 |
try {
|
| 325 | 331 |
log.info("Closing " + closeable.objectName);
|
| ... | ... | @@ -329,7 +335,7 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 329 | 335 |
}
|
| 330 | 336 |
}
|
| 331 | 337 |
ObserveServiceMainFactory.get().close();
|
| 332 |
- |
|
| 338 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 333 | 339 |
// fermeture du context principal
|
| 334 | 340 |
clear();
|
| 335 | 341 |
|
| ... | ... | @@ -347,6 +353,13 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 347 | 353 |
super.finalize();
|
| 348 | 354 |
}
|
| 349 | 355 |
|
| 356 |
+ void closeDeleteTemporaryFilesTimer() {
|
|
| 357 |
+ try {
|
|
| 358 |
+ getCleanTemporaryFilesTask().cancel();
|
|
| 359 |
+ } catch (Exception e) {
|
|
| 360 |
+ log.error("Could not terminates delete temporary files timer...", e);
|
|
| 361 |
+ }
|
|
| 362 |
+ }
|
|
| 350 | 363 |
enum Entries {
|
| 351 | 364 |
|
| 352 | 365 |
CONFIG("Config", ClientConfig.class),
|
| ... | ... | @@ -359,6 +372,7 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext im |
| 359 | 372 |
DATA_SOURCES_MANAGER("Data sources manager", ObserveDataSourcesManager.class),
|
| 360 | 373 |
FLOATING_OBJECT_REFERENCES_MANAGER("Floating object referenfences manager", FloatingObjectPresetsManager.class),
|
| 361 | 374 |
OBSERVE_SWING_SESSION_HELPER("Swing session Helper", ObserveSwingSessionHelper.class),
|
| 375 |
+ DELETE_TEMPORARY_FILES_TASK(" Delete temporary files task", Timer.class),
|
|
| 362 | 376 |
VALIDATION_CONTEXT("Validation context", ClientValidationContext.class),
|
| 363 | 377 |
MAIN_UI("Main UI", ObserveMainUI.class),
|
| 364 | 378 |
ACTIONS("Command line Actions", ObserveCLAction.class),
|
| ... | ... | @@ -171,7 +171,7 @@ public class ObserveDataSourcesManager implements Closeable { |
| 171 | 171 |
ClientConfig config = applicationContext.getConfig();
|
| 172 | 172 |
ObserveDataSourceConfigurationMainFactory configurationMainFactory = applicationContext.getObserveDataSourceConfigurationMainFactory();
|
| 173 | 173 |
|
| 174 |
- File tmpDirectory = config.getTmpDirectory();
|
|
| 174 |
+ File tmpDirectory = config.getTemporaryDirectory();
|
|
| 175 | 175 |
|
| 176 | 176 |
File dbDirectory = new File(tmpDirectory, ClientConfig.DB_NAME + UUID.randomUUID().toString());
|
| 177 | 177 |
|
| ... | ... | @@ -477,7 +477,7 @@ public class ObserveSwingDataSource extends AbstractSerializableBean implements |
| 477 | 477 |
|
| 478 | 478 |
Locale locale = config.getLocale();
|
| 479 | 479 |
|
| 480 |
- File tmpDirectory = config.getTmpDirectory();
|
|
| 480 |
+ File tmpDirectory = config.getTemporaryDirectory();
|
|
| 481 | 481 |
|
| 482 | 482 |
ReferentialLocale referentialLocale = ReferentialLocale.valueOf(locale);
|
| 483 | 483 |
|
| ... | ... | @@ -291,7 +291,7 @@ public class ShowConfigAction extends MenuActionSupport { |
| 291 | 291 |
helper.addOption(ClientConfigOption.DB_DIRECTORY);
|
| 292 | 292 |
helper.addOption(ClientConfigOption.BACKUP_DIRECTORY);
|
| 293 | 293 |
helper.addOption(ClientConfigOption.IMPORT_DIRECTORY);
|
| 294 |
- helper.addOption(ClientConfigOption.TMP_DIRECTORY);
|
|
| 294 |
+ helper.addOption(ClientConfigOption.TEMPORARY_DIRECTORY);
|
|
| 295 | 295 |
helper.addOption(ClientConfigOption.VALIDATION_REPORT_DIRECTORY);
|
| 296 | 296 |
helper.addOption(ClientConfigOption.RESOURCES_DIRECTORY);
|
| 297 | 297 |
helper.addOption(ClientConfigOption.SWING_SESSION_FILE);
|
| ... | ... | @@ -1738,7 +1738,6 @@ observe.config.defaultLocalDbDirectory.description=Default directory where to st |
| 1738 | 1738 |
observe.config.defaultMapDirectory.description=Default directory where to store map layers
|
| 1739 | 1739 |
observe.config.defaultReportDirectory.description=Default directory where to store report definition files
|
| 1740 | 1740 |
observe.config.defaultResourcesDirectory.description=Default user resources directory
|
| 1741 |
-observe.config.defaultTmpDirectory.description=Default temporary directory used by application and clean at each launch.
|
|
| 1742 | 1741 |
observe.config.defaultValidationReportDirectory.description=Default validation report directory
|
| 1743 | 1742 |
observe.config.devMode=Dev mode
|
| 1744 | 1743 |
observe.config.floatingObjectPresets.description=Floating Objects references
|
| ... | ... | @@ -1786,6 +1785,8 @@ observe.config.speciesList.seine.schoolEstimate=Species for school esitmates |
| 1786 | 1785 |
observe.config.speciesList.seine.targetCatch=Species for target catches
|
| 1787 | 1786 |
observe.config.swingSessionFile.description=Swing session file.
|
| 1788 | 1787 |
observe.config.temperature.format=Default temperature format
|
| 1788 |
+observe.config.temporaryDirectory.description=Default temporary directory used by application and clean at each launch.
|
|
| 1789 |
+observe.config.temporaryFilesTimeout.description=Temporary files delete (in hours)
|
|
| 1789 | 1790 |
observe.config.ui.autoPopupNumberEditor=Flag sets to true when number editor show automaticly popup
|
| 1790 | 1791 |
observe.config.ui.changeSynchroSrc=Flag sets to true if you can change local source in admin tasks
|
| 1791 | 1792 |
observe.config.ui.dcp.error.color=Color to notify errors while validating floating object materials.
|
| ... | ... | @@ -1738,7 +1738,6 @@ observe.config.defaultLocalDbDirectory.description=Directorio de almacenamiento |
| 1738 | 1738 |
observe.config.defaultMapDirectory.description=El directorio donde se ubican los mapas.
|
| 1739 | 1739 |
observe.config.defaultReportDirectory.description=Directorio por defecto de los informes de la aplicación
|
| 1740 | 1740 |
observe.config.defaultResourcesDirectory.description=Directorio de almacenamiento de los recursos de usuario como las traducciones o la consultas de informes
|
| 1741 |
-observe.config.defaultTmpDirectory.description=Directorio temporal por defecto
|
|
| 1742 | 1741 |
observe.config.defaultValidationReportDirectory.description=Directorio por defecto de almacenamiento de los informes de validación
|
| 1743 | 1742 |
observe.config.devMode=Modo desarrollador
|
| 1744 | 1743 |
observe.config.floatingObjectPresets.description=Objetos flotantes de referencia
|
| ... | ... | @@ -1786,6 +1785,8 @@ observe.config.speciesList.seine.schoolEstimate=Especies para las estimaciones |
| 1786 | 1785 |
observe.config.speciesList.seine.targetCatch=Especies par las capturas objetivo
|
| 1787 | 1786 |
observe.config.swingSessionFile.description=Copia de seguridad del estado del UI.
|
| 1788 | 1787 |
observe.config.temperature.format=Unidad de temperatura
|
| 1788 |
+observe.config.temporaryDirectory.description=Directorio temporal por defecto
|
|
| 1789 |
+observe.config.temporaryFilesTimeout.description=Temporary files delete (in hours) \#TODO
|
|
| 1789 | 1790 |
observe.config.ui.autoPopupNumberEditor=Para mostrar automáticamente el editor numérico durante la edición de un número
|
| 1790 | 1791 |
observe.config.ui.changeSynchroSrc=Para autorizar la seleción de la base fuente durante las operaciones sobre la base
|
| 1791 | 1792 |
observe.config.ui.dcp.error.color=Color para notificar los errores sobre la composición de dcps
|
| ... | ... | @@ -1738,7 +1738,6 @@ observe.config.defaultLocalDbDirectory.description=Le répertoire où est stock |
| 1738 | 1738 |
observe.config.defaultMapDirectory.description=Le répertoire où sont stockées les cartes.
|
| 1739 | 1739 |
observe.config.defaultReportDirectory.description=Répertoire par défaut des rapports de l'application
|
| 1740 | 1740 |
observe.config.defaultResourcesDirectory.description=Le répertoire où sont stockées les ressources de l'utilisateur comme les traductions ou les requêtes de rapports.
|
| 1741 |
-observe.config.defaultTmpDirectory.description=Le répertoire temporaire par défaut
|
|
| 1742 | 1741 |
observe.config.defaultValidationReportDirectory.description=Le répertoire par défaut où sont stockés les rapports de validation
|
| 1743 | 1742 |
observe.config.devMode=Mode développeur
|
| 1744 | 1743 |
observe.config.floatingObjectPresets.description=Objets flottants de référence
|
| ... | ... | @@ -1786,6 +1785,8 @@ observe.config.speciesList.seine.schoolEstimate=Espèces pour les estimations |
| 1786 | 1785 |
observe.config.speciesList.seine.targetCatch=Espèces pour les captures cible
|
| 1787 | 1786 |
observe.config.swingSessionFile.description=Fichier de sauvegarde des états des UI.
|
| 1788 | 1787 |
observe.config.temperature.format=Unité de température
|
| 1788 |
+observe.config.temporaryDirectory.description=Le répertoire temporaire par défaut
|
|
| 1789 |
+observe.config.temporaryFilesTimeout.description=Nettoyage des fichiers temporaires (en heures)
|
|
| 1789 | 1790 |
observe.config.ui.autoPopupNumberEditor=Pour afficher automatiquement l'éditeur numérique lors de l'édition d'un nombre
|
| 1790 | 1791 |
observe.config.ui.changeSynchroSrc=Pour autoriser la sélection de la base source dans les opérations sur base
|
| 1791 | 1792 |
observe.config.ui.dcp.error.color=Couleur pour notifier les erreurs sur la composition des dcps
|
| 1 |
-package fr.ird.observe.persistence;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import fr.ird.observe.entities.ObserveEntity;
|
|
| 26 |
-import org.nuiton.topia.persistence.internal.AbstractTopiaDao;
|
|
| 27 |
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
|
|
| 28 |
- |
|
| 29 |
-import java.sql.Connection;
|
|
| 30 |
-import java.sql.PreparedStatement;
|
|
| 31 |
-import java.sql.ResultSet;
|
|
| 32 |
-import java.sql.SQLException;
|
|
| 33 |
-import java.sql.Timestamp;
|
|
| 34 |
-import java.util.Date;
|
|
| 35 |
-import java.util.List;
|
|
| 36 |
-import java.util.Map;
|
|
| 37 |
- |
|
| 38 |
-public abstract class AbstractObserveTopiaDao<E extends ObserveEntity> extends AbstractTopiaDao<E> {
|
|
| 39 |
- |
|
| 40 |
- private final GetLastupdateDateSqlQuery getLastUpdateDateSqlQuery;
|
|
| 41 |
- |
|
| 42 |
- protected AbstractObserveTopiaDao() {
|
|
| 43 |
- String schemaName = getTopiaEntityEnum().dbSchemaName();
|
|
| 44 |
- String tableName = getTopiaEntityEnum().dbTableName();
|
|
| 45 |
- getLastUpdateDateSqlQuery = new GetLastupdateDateSqlQuery(schemaName, tableName);
|
|
| 46 |
- }
|
|
| 47 |
- |
|
| 48 |
- public Date getLastUpdateDate() {
|
|
| 49 |
- return topiaSqlSupport.findSingleResult(getLastUpdateDateSqlQuery);
|
|
| 50 |
- }
|
|
| 51 |
- |
|
| 52 |
- public <O> List<O> findAllFromHql(String hql, Map<String, Object> hqlParameters) {
|
|
| 53 |
- return findAll(hql, hqlParameters);
|
|
| 54 |
- }
|
|
| 55 |
- |
|
| 56 |
- private static class GetLastupdateDateSqlQuery extends TopiaSqlQuery<Timestamp> {
|
|
| 57 |
- |
|
| 58 |
- protected final String sql;
|
|
| 59 |
- |
|
| 60 |
- private GetLastupdateDateSqlQuery(String schemaName, String tableName) {
|
|
| 61 |
- this.sql = "SELECT max(" + ObserveEntity.PROPERTY_LAST_UPDATE_DATE + ") FROM " + schemaName + "." + tableName;
|
|
| 62 |
- }
|
|
| 63 |
- |
|
| 64 |
- @Override
|
|
| 65 |
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 66 |
- return connection.prepareStatement(sql);
|
|
| 67 |
- }
|
|
| 68 |
- |
|
| 69 |
- @Override
|
|
| 70 |
- public Timestamp prepareResult(ResultSet set) throws SQLException {
|
|
| 71 |
- return set.getTimestamp(1);
|
|
| 72 |
- }
|
|
| 73 |
- |
|
| 74 |
- }
|
|
| 75 |
- |
|
| 76 |
- |
|
| 77 |
-}
|
| 1 |
-package fr.ird.observe.persistence;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import org.nuiton.topia.persistence.BeanTopiaConfiguration;
|
|
| 26 |
-import org.nuiton.topia.persistence.HibernateAvailableSettings;
|
|
| 27 |
-import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
|
| 28 |
- |
|
| 29 |
-import java.io.IOException;
|
|
| 30 |
-import java.io.InputStream;
|
|
| 31 |
-import java.util.Map;
|
|
| 32 |
-import java.util.Properties;
|
|
| 33 |
-import java.util.TreeMap;
|
|
| 34 |
- |
|
| 35 |
-/**
|
|
| 36 |
- * Created on 23/08/15.
|
|
| 37 |
- *
|
|
| 38 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 39 |
- */
|
|
| 40 |
-public class ObserveTopiaConfiguration extends BeanTopiaConfiguration {
|
|
| 41 |
- |
|
| 42 |
- private static final long serialVersionUID = 1L;
|
|
| 43 |
- |
|
| 44 |
- private final boolean h2Configuration;
|
|
| 45 |
- protected final boolean showSql;
|
|
| 46 |
- private static final Map<String, String> HIBERNATE_GLOBAL_PROPERTIES;
|
|
| 47 |
- |
|
| 48 |
- static {
|
|
| 49 |
- |
|
| 50 |
- Properties p = new Properties();
|
|
| 51 |
- try (InputStream stream = ObserveTopiaPersistenceContext.class.getResourceAsStream("/hibernate.properties")) {
|
|
| 52 |
- try {
|
|
| 53 |
- p.load(stream);
|
|
| 54 |
- } catch (IOException e) {
|
|
| 55 |
- throw new IllegalStateException(e);
|
|
| 56 |
- }
|
|
| 57 |
- } catch (IOException e) {
|
|
| 58 |
- throw new IllegalStateException(e);
|
|
| 59 |
- }
|
|
| 60 |
- HIBERNATE_GLOBAL_PROPERTIES = new TreeMap<>();
|
|
| 61 |
- for (String s : p.stringPropertyNames()) {
|
|
| 62 |
- HIBERNATE_GLOBAL_PROPERTIES.put(s, p.getProperty(s));
|
|
| 63 |
- }
|
|
| 64 |
- |
|
| 65 |
- }
|
|
| 66 |
- |
|
| 67 |
- public ObserveTopiaConfiguration(JdbcConfiguration jdbcConfiguration, boolean h2Configuration, boolean showSql) {
|
|
| 68 |
- super(jdbcConfiguration);
|
|
| 69 |
- this.h2Configuration = h2Configuration;
|
|
| 70 |
- this.showSql = showSql;
|
|
| 71 |
- if (showSql) {
|
|
| 72 |
- hibernateExtraConfiguration.put(HibernateAvailableSettings.SHOW_SQL, Boolean.TRUE.toString());
|
|
| 73 |
- }
|
|
| 74 |
- hibernateExtraConfiguration.putAll(HIBERNATE_GLOBAL_PROPERTIES);
|
|
| 75 |
- }
|
|
| 76 |
- |
|
| 77 |
- public boolean isH2Configuration() {
|
|
| 78 |
- return h2Configuration;
|
|
| 79 |
- }
|
|
| 80 |
- |
|
| 81 |
- public boolean isShowSql() {
|
|
| 82 |
- return showSql;
|
|
| 83 |
- }
|
|
| 84 |
-}
|
| 1 |
-package fr.ird.observe.persistence;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import org.apache.logging.log4j.Logger;
|
|
| 26 |
-import org.apache.logging.log4j.LogManager;
|
|
| 27 |
-import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
|
| 28 |
-import org.nuiton.topia.persistence.jdbc.JdbcConfigurationBuilder;
|
|
| 29 |
-import org.nuiton.topia.service.migration.TopiaMigrationService;
|
|
| 30 |
-import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorServiceImpl;
|
|
| 31 |
- |
|
| 32 |
-import java.io.File;
|
|
| 33 |
- |
|
| 34 |
-/**
|
|
| 35 |
- * Created on 23/08/15.
|
|
| 36 |
- *
|
|
| 37 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 38 |
- */
|
|
| 39 |
-public class ObserveTopiaConfigurationFactory {
|
|
| 40 |
- |
|
| 41 |
- /** l'url d'acces a la base locale */
|
|
| 42 |
- private static final String H2_LOCAL_URL =
|
|
| 43 |
- "jdbc:h2:file:%s;" +
|
|
| 44 |
- // on peut aussi utiliser file, socket
|
|
| 45 |
- "FILE_LOCK=file;" +
|
|
| 46 |
- //1 or 2 is needed to restore avec crash
|
|
| 47 |
- // 0: logging is disabled (faster),
|
|
| 48 |
- // 1: logging of the data is enabled, but logging of the index
|
|
| 49 |
- // changes is disabled (default), 2: logging of both data and index
|
|
| 50 |
- // changes are enabled
|
|
| 51 |
- "LOG=0;" +
|
|
| 52 |
- // on peut aussi utiliser hsqldb, mysql ou postgresql
|
|
| 53 |
- "MODE=postgresql;" +
|
|
| 54 |
- //"MODE=hsqldb;" +
|
|
| 55 |
- // Sets the default lock timeout (in milliseconds) in this
|
|
| 56 |
- // database that is used for the new sessions.
|
|
| 57 |
- "DEFAULT_LOCK_TIMEOUT=100;" +
|
|
| 58 |
- // -1: the database is never closed until the close delay is set to
|
|
| 59 |
- // some other rev or SHUTDOWN is called., 0: no delay (default; the
|
|
| 60 |
- // database is closed if the last connection to it is closed)., n:
|
|
| 61 |
- // the database is left open for n second after the last connection
|
|
| 62 |
- // is closed.
|
|
| 63 |
- "DB_CLOSE_DELAY=0;" +
|
|
| 64 |
- // 0: no locking (should only be used for testing),
|
|
| 65 |
- // 1: table level locking (default),
|
|
| 66 |
- // 2: table level locking with garbage collection (if the
|
|
| 67 |
- // application does not close all connections).
|
|
| 68 |
- // LOCK_MODE 3 (READ_COMMITTED). Table level locking, but only when
|
|
| 69 |
- // writing (no read locks).
|
|
| 70 |
- "LOCK_MODE=3;" +
|
|
| 71 |
- // Levels: 0=off, 1=error, 2=info, 3=debug.
|
|
| 72 |
- "TRACE_LEVEL_FILE=0;" +
|
|
| 73 |
- // on system.out: 0=off, 1=error, 2=info, 3=debug.
|
|
| 74 |
- "TRACE_LEVEL_SYSTEM_OUT=0;" +
|
|
| 75 |
- // maximumn cache to improve performance...
|
|
| 76 |
- "CACHE_SIZE=65536;" +
|
|
| 77 |
- // avoid timeout on reading tables (see http://stackoverflow.com/questions/4162557/timeout-error-trying-to-lock-table-in-h2)
|
|
| 78 |
- "MVCC=true";
|
|
| 79 |
- |
|
| 80 |
- private static final JdbcConfigurationBuilder JDBC_CONFIGURATION_BUILDER = new JdbcConfigurationBuilder();
|
|
| 81 |
- private static final Logger log = LogManager.getLogger(ObserveTopiaConfigurationFactory.class);
|
|
| 82 |
- |
|
| 83 |
- public static ObserveTopiaConfiguration forPostgresqlDatabase(String jdbcUrl,
|
|
| 84 |
- String username,
|
|
| 85 |
- String password,
|
|
| 86 |
- boolean initSchema,
|
|
| 87 |
- boolean traceSql) {
|
|
| 88 |
- |
|
| 89 |
- JdbcConfiguration jdbcConfiguration = JDBC_CONFIGURATION_BUILDER.forPostgresqlDatabase(jdbcUrl, username, password);
|
|
| 90 |
- |
|
| 91 |
- ObserveTopiaConfiguration topiaConfiguration = createTopiaConfiguration(jdbcConfiguration,
|
|
| 92 |
- initSchema,
|
|
| 93 |
- false,
|
|
| 94 |
- traceSql);
|
|
| 95 |
- |
|
| 96 |
- log.debug("PG topia configuration: " + topiaConfiguration);
|
|
| 97 |
- return topiaConfiguration;
|
|
| 98 |
- |
|
| 99 |
- }
|
|
| 100 |
- |
|
| 101 |
- public static ObserveTopiaConfiguration forH2Database(File dbDirectory,
|
|
| 102 |
- String dbName,
|
|
| 103 |
- String username,
|
|
| 104 |
- String password,
|
|
| 105 |
- boolean initSchema,
|
|
| 106 |
- boolean traceSql) {
|
|
| 107 |
- |
|
| 108 |
- String dbPath = new File(dbDirectory, dbName).getPath();
|
|
| 109 |
- String jdbcUrl = String.format(H2_LOCAL_URL, dbPath);
|
|
| 110 |
- |
|
| 111 |
- JdbcConfiguration jdbcConfiguration = JDBC_CONFIGURATION_BUILDER.forH2Database(jdbcUrl, username, password);
|
|
| 112 |
- |
|
| 113 |
- ObserveTopiaConfiguration topiaConfiguration = createTopiaConfiguration(jdbcConfiguration,
|
|
| 114 |
- initSchema,
|
|
| 115 |
- true,
|
|
| 116 |
- traceSql);
|
|
| 117 |
- |
|
| 118 |
- log.debug("H2 topia configuration: " + topiaConfiguration);
|
|
| 119 |
- return topiaConfiguration;
|
|
| 120 |
- |
|
| 121 |
- }
|
|
| 122 |
- |
|
| 123 |
- private static ObserveTopiaConfiguration createTopiaConfiguration(JdbcConfiguration jdbcConfiguration,
|
|
| 124 |
- boolean initSchema,
|
|
| 125 |
- boolean h2Configuration,
|
|
| 126 |
- boolean traceSql) {
|
|
| 127 |
- |
|
| 128 |
- ObserveTopiaConfiguration topiaConfiguration = new ObserveTopiaConfiguration(jdbcConfiguration, h2Configuration, traceSql);
|
|
| 129 |
- topiaConfiguration.setTopiaIdFactoryClass(ObserveTopiaIdFactory.class);
|
|
| 130 |
- topiaConfiguration.setInitSchema(initSchema);
|
|
| 131 |
- topiaConfiguration.setValidateSchema(false);
|
|
| 132 |
- topiaConfiguration.setUseHikariForJdbcConnectionPooling(true);
|
|
| 133 |
- |
|
| 134 |
- log.debug("jdbcUrl: " + topiaConfiguration.getJdbcConnectionUrl());
|
|
| 135 |
- |
|
| 136 |
- topiaConfiguration.addDeclaredService(ObserveTopiaApplicationContext.MIGRATION_SERVICE_NAME, TopiaMigrationService.class);
|
|
| 137 |
- topiaConfiguration.addDeclaredService(ObserveTopiaApplicationContext.SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME, TopiaSqlScriptGeneratorServiceImpl.class);
|
|
| 138 |
- |
|
| 139 |
- return topiaConfiguration;
|
|
| 140 |
- |
|
| 141 |
- }
|
|
| 142 |
- |
|
| 143 |
-}
|
| 1 |
-package fr.ird.observe.persistence;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
-import org.apache.commons.lang3.StringUtils;
|
|
| 26 |
-import org.apache.logging.log4j.LogManager;
|
|
| 27 |
-import org.apache.logging.log4j.Logger;
|
|
| 28 |
-import org.nuiton.topia.persistence.TopiaEntity;
|
|
| 29 |
-import org.nuiton.topia.persistence.internal.LegacyTopiaIdFactory;
|
|
| 30 |
- |
|
| 31 |
-/**
|
|
| 32 |
- * Created on 21/08/15.
|
|
| 33 |
- *
|
|
| 34 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 35 |
- */
|
|
| 36 |
-public class ObserveTopiaIdFactory extends LegacyTopiaIdFactory {
|
|
| 37 |
- |
|
| 38 |
- private static final Logger log = LogManager.getLogger(ObserveTopiaIdFactory.class);
|
|
| 39 |
- |
|
| 40 |
- private static final long serialVersionUID = 1L;
|
|
| 41 |
- |
|
| 42 |
- public <E extends TopiaEntity> String newTopiaId(Class<E> entityType) {
|
|
| 43 |
- |
|
| 44 |
- double random = Math.random();
|
|
| 45 |
- while (Double.toString(random).contains("E-")) {
|
|
| 46 |
- random = Math.random();
|
|
| 47 |
- }
|
|
| 48 |
- return newTopiaId(entityType, random + "");
|
|
| 49 |
- }
|
|
| 50 |
- |
|
| 51 |
- public <E extends TopiaEntity> boolean isTopiaId(Class<E> entityClass, String str) {
|
|
| 52 |
- boolean isTopiaId = false;
|
|
| 53 |
- if (str != null && !str.endsWith(getSeparator())) {
|
|
| 54 |
- String[] split = str.split(getSeparator());
|
|
| 55 |
- if (split.length == 3) {
|
|
| 56 |
- String className = split[0];
|
|
| 57 |
- isTopiaId = entityClass.getName().equals(className);
|
|
| 58 |
- for (int index = 1; index < split.length; index++) {
|
|
| 59 |
- isTopiaId &= StringUtils.isNumeric(split[index]);
|
|
| 60 |
- }
|
|
| 61 |
- }
|
|
| 62 |
- }
|
|
| 63 |
- return isTopiaId;
|
|
| 64 |
- }
|
|
| 65 |
- |
|
| 66 |
- @Override
|
|
| 67 |
- public boolean isTopiaId(String str) {
|
|
| 68 |
- boolean isTopiaId = false;
|
|
| 69 |
- if (str != null && !str.endsWith(getSeparator())) {
|
|
| 70 |
- String[] split = str.split(getSeparator());
|
|
| 71 |
- if (split.length == 3) {
|
|
| 72 |
- String className = split[0];
|
|
| 73 |
- try {
|
|
| 74 |
- Class.forName(className);
|
|
| 75 |
- isTopiaId = true;
|
|
| 76 |
- for (int index = 1; index < split.length; index++) {
|
|
| 77 |
- isTopiaId &= StringUtils.isNumeric(split[index]);
|
|
| 78 |
- }
|
|
| 79 |
- } catch (ClassNotFoundException eee) {
|
|
| 80 |
- // nothing to do, just return false
|
|
| 81 |
- if (log.isDebugEnabled()) {
|
|
| 82 |
- log.debug(eee);
|
|
| 83 |
- }
|
|
| 84 |
- }
|
|
| 85 |
- }
|
|
| 86 |
- }
|
|
| 87 |
- return isTopiaId;
|
|
| 88 |
- }
|
|
| 89 |
- |
|
| 90 |
-}
|
| ... | ... | @@ -26,7 +26,7 @@ |
| 26 | 26 |
<parent>
|
| 27 | 27 |
<groupId>io.ultreia.maven</groupId>
|
| 28 | 28 |
<artifactId>pom</artifactId>
|
| 29 |
- <version>2020.15</version>
|
|
| 29 |
+ <version>2020.17</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.27</observeToolkitVersion>
|
|
| 158 |
+ <observeToolkitVersion>3.7.28</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-56</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.16</lib.version.java4all.topia>
|
|
| 168 |
+ <lib.version.java4all.topia>1.1.17</lib.version.java4all.topia>
|
|
| 169 | 169 |
<lib.version.nuiton.utils>3.0</lib.version.nuiton.utils>
|
| 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>-->
|
| ... | ... | @@ -112,6 +112,12 @@ |
| 112 | 112 |
<groupId>junit</groupId>
|
| 113 | 113 |
<artifactId>junit</artifactId>
|
| 114 | 114 |
</dependency>
|
| 115 |
+ <dependency>
|
|
| 116 |
+ <groupId>fr.ird.observe</groupId>
|
|
| 117 |
+ <artifactId>services</artifactId>
|
|
| 118 |
+ <version>7.5.1-SNAPSHOT</version>
|
|
| 119 |
+ <scope>compile</scope>
|
|
| 120 |
+ </dependency>
|
|
| 115 | 121 |
|
| 116 | 122 |
|
| 117 | 123 |
</dependencies>
|
| ... | ... | @@ -117,3 +117,9 @@ key = observeweb.httpTimeout |
| 117 | 117 |
type = int
|
| 118 | 118 |
defaultValue = 30000
|
| 119 | 119 |
|
| 120 |
+[option temporaryFilesTimeout]
|
|
| 121 |
+description = observe.config.temporaryFilesTimeout.description
|
|
| 122 |
+key = observeweb.temporaryFilesTimeout
|
|
| 123 |
+type = int
|
|
| 124 |
+defaultValue = 120
|
|
| 125 |
+ |
| 1 | 1 |
ObserveWebApplicationConfig.description
|
| 2 |
+observe.config.temporaryFilesTimeout.description
|
|
| 2 | 3 |
observe.model.version
|
| 3 | 4 |
observeweb.adminApiKey.description
|
| 4 | 5 |
observeweb.apiUrl.description
|
| ... | ... | @@ -25,6 +25,7 @@ package fr.ird.observe.server.configuration; |
| 25 | 25 |
import com.google.common.io.CharSource;
|
| 26 | 26 |
import com.google.common.io.Resources;
|
| 27 | 27 |
import fr.ird.observe.dto.ObserveUtil;
|
| 28 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTaskConfiguration;
|
|
| 28 | 29 |
import io.ultreia.java4all.config.ApplicationConfig;
|
| 29 | 30 |
import io.ultreia.java4all.config.ArgumentsParserException;
|
| 30 | 31 |
import org.apache.logging.log4j.LogManager;
|
| ... | ... | @@ -44,7 +45,7 @@ import java.nio.file.Paths; |
| 44 | 45 |
*
|
| 45 | 46 |
* @author Tony Chemit - dev@tchemit.fr
|
| 46 | 47 |
*/
|
| 47 |
-public class ServerConfig extends GeneratedServerConfig {
|
|
| 48 |
+public class ServerConfig extends GeneratedServerConfig implements CleanTemporaryFilesTaskConfiguration {
|
|
| 48 | 49 |
|
| 49 | 50 |
private static final String DEFAULT_OBSERVE_WEB_CONFIGURATION_FILENAME = "observe-server.conf";
|
| 50 | 51 |
/** Logger. */
|
| ... | ... | @@ -42,20 +42,26 @@ import fr.ird.observe.services.ObserveServiceFactory; |
| 42 | 42 |
import fr.ird.observe.services.ObserveServiceInitializer;
|
| 43 | 43 |
import fr.ird.observe.services.ObserveServiceMainFactory;
|
| 44 | 44 |
import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration;
|
| 45 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTask;
|
|
| 45 | 46 |
import fr.ird.observe.services.service.ObserveService;
|
| 46 | 47 |
import fr.ird.observe.services.service.actions.consolidate.dcp.FloatingObjectModification;
|
| 48 |
+import org.apache.logging.log4j.LogManager;
|
|
| 49 |
+import org.apache.logging.log4j.Logger;
|
|
| 47 | 50 |
import org.debux.webmotion.server.call.HttpContext;
|
| 48 | 51 |
import org.nuiton.version.Version;
|
| 49 | 52 |
|
| 50 | 53 |
import javax.servlet.ServletContext;
|
| 51 | 54 |
import java.io.Closeable;
|
| 52 | 55 |
import java.io.IOException;
|
| 56 |
+import java.util.Timer;
|
|
| 53 | 57 |
|
| 54 | 58 |
/**
|
| 55 | 59 |
* @author Tony Chemit - dev@tchemit.fr
|
| 56 | 60 |
*/
|
| 57 | 61 |
public class ObserveWebApplicationContext implements Closeable {
|
| 58 | 62 |
|
| 63 |
+ private static final Logger log = LogManager.getLogger(ObserveWebApplicationContext.class);
|
|
| 64 |
+ |
|
| 59 | 65 |
public static final String APPLICATION_CONTEXT_PARAMETER = ObserveWebApplicationContext.class.getName();
|
| 60 | 66 |
|
| 61 | 67 |
public static final String MISSING_APPLICATION_CONTEXT =
|
| ... | ... | @@ -74,6 +80,8 @@ public class ObserveWebApplicationContext implements Closeable { |
| 74 | 80 |
|
| 75 | 81 |
protected ObserveWebSecurityApplicationContext securityApplicationContext;
|
| 76 | 82 |
|
| 83 |
+ private Timer deleteTemporaryFilesTimer;
|
|
| 84 |
+ |
|
| 77 | 85 |
public static ObserveWebApplicationContext getApplicationContext(HttpContext context) {
|
| 78 | 86 |
|
| 79 | 87 |
ServletContext servletContext = context.getServletContext();
|
| ... | ... | @@ -125,6 +133,10 @@ public class ObserveWebApplicationContext implements Closeable { |
| 125 | 133 |
|
| 126 | 134 |
}
|
| 127 | 135 |
};
|
| 136 |
+ if (deleteTemporaryFilesTimer != null) {
|
|
| 137 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 138 |
+ }
|
|
| 139 |
+ deleteTemporaryFilesTimer = CleanTemporaryFilesTask.create(getApplicationConfiguration());
|
|
| 128 | 140 |
|
| 129 | 141 |
}
|
| 130 | 142 |
|
| ... | ... | @@ -147,6 +159,8 @@ public class ObserveWebApplicationContext implements Closeable { |
| 147 | 159 |
@Override
|
| 148 | 160 |
public void close() throws IOException {
|
| 149 | 161 |
|
| 162 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 163 |
+ |
|
| 150 | 164 |
// Supprimer le cache des sessions
|
| 151 | 165 |
securityApplicationContext.close();
|
| 152 | 166 |
|
| ... | ... | @@ -154,6 +168,13 @@ public class ObserveWebApplicationContext implements Closeable { |
| 154 | 168 |
mainServiceFactory.close();
|
| 155 | 169 |
|
| 156 | 170 |
}
|
| 171 |
+ void closeDeleteTemporaryFilesTimer() {
|
|
| 172 |
+ try {
|
|
| 173 |
+ deleteTemporaryFilesTimer.cancel();
|
|
| 174 |
+ } catch (Exception e) {
|
|
| 175 |
+ log.error("Could not terminates delete temporary files timer...", e);
|
|
| 176 |
+ }
|
|
| 177 |
+ }
|
|
| 157 | 178 |
|
| 158 | 179 |
public ObserveDtoGsonSupplier getGsonSupplier() {
|
| 159 | 180 |
return gsonSupplier;
|
| ... | ... | @@ -27,6 +27,7 @@ import com.google.common.collect.Sets; |
| 27 | 27 |
import fr.ird.observe.dto.ObserveDbRole;
|
| 28 | 28 |
import fr.ird.observe.dto.db.ObserveDbUserDto;
|
| 29 | 29 |
import fr.ird.observe.persistence.Entities;
|
| 30 |
+import fr.ird.observe.persistence.ObserveTopiaConfiguration;
|
|
| 30 | 31 |
import org.apache.commons.lang3.tuple.Pair;
|
| 31 | 32 |
import org.apache.logging.log4j.Logger;
|
| 32 | 33 |
import org.apache.logging.log4j.LogManager;
|
| ... | ... | @@ -86,20 +87,21 @@ public class ObserveSecurityHelper { |
| 86 | 87 |
OBSERVE_LONGLINE_SCHEMA_NAME);
|
| 87 | 88 |
private static final Logger log = LogManager.getLogger(ObserveSecurityHelper.class);
|
| 88 | 89 |
private final JdbcPostgresHelper jdbcHelper;
|
| 90 |
+ private final Path temporaryDirectory;
|
|
| 89 | 91 |
|
| 90 | 92 |
|
| 91 |
- public ObserveSecurityHelper(JdbcConfiguration jdbcConfiguration) {
|
|
| 93 |
+ public ObserveSecurityHelper(ObserveTopiaConfiguration jdbcConfiguration) {
|
|
| 92 | 94 |
this.jdbcHelper = new JdbcPostgresHelper(jdbcConfiguration);
|
| 95 |
+ this.temporaryDirectory = jdbcConfiguration.getTemporaryDirectory();
|
|
| 93 | 96 |
}
|
| 94 | 97 |
|
| 95 | 98 |
public void applySecurity(Set<ObserveDbUserDto> users) {
|
| 96 | 99 |
if (users == null) {
|
| 97 | 100 |
throw new NullPointerException("users can not be null");
|
| 98 | 101 |
}
|
| 99 |
- |
|
| 100 | 102 |
Path scriptPath;
|
| 101 | 103 |
try {
|
| 102 |
- scriptPath = Files.createTempFile("topia-sql-script-", ".sql");
|
|
| 104 |
+ scriptPath = Files.createTempFile(temporaryDirectory, "topia-sql-script-", ".sql");
|
|
| 103 | 105 |
} catch (IOException e) {
|
| 104 | 106 |
throw new IllegalStateException("Can't create temporary path", e);
|
| 105 | 107 |
}
|
| ... | ... | @@ -149,6 +149,7 @@ public class ObserveTopiaApplicationContextFactory { |
| 149 | 149 |
configuration.getJdbcUrl(),
|
| 150 | 150 |
configuration.getUsername(),
|
| 151 | 151 |
String.valueOf(configuration.getPassword()),
|
| 152 |
+ configuration.getTemporaryDirectory(),
|
|
| 152 | 153 |
initSchema,
|
| 153 | 154 |
configuration.isTraceSql()
|
| 154 | 155 |
);
|
| ... | ... | @@ -174,6 +175,7 @@ public class ObserveTopiaApplicationContextFactory { |
| 174 | 175 |
configuration.getDbName(),
|
| 175 | 176 |
configuration.getUsername(),
|
| 176 | 177 |
String.valueOf(configuration.getPassword()),
|
| 178 |
+ configuration.getTemporaryDirectory(),
|
|
| 177 | 179 |
initSchema,
|
| 178 | 180 |
configuration.isTraceSql()
|
| 179 | 181 |
);
|
| ... | ... | @@ -70,6 +70,7 @@ import org.nuiton.version.Versions; |
| 70 | 70 |
import java.io.File;
|
| 71 | 71 |
import java.io.IOException;
|
| 72 | 72 |
import java.nio.file.Files;
|
| 73 |
+import java.nio.file.Path;
|
|
| 73 | 74 |
import java.util.LinkedHashSet;
|
| 74 | 75 |
import java.util.Optional;
|
| 75 | 76 |
import java.util.Set;
|
| ... | ... | @@ -110,6 +111,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 110 | 111 |
Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
|
| 111 | 112 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
| 112 | 113 |
|
| 114 |
+ Path temporaryDirectory = serviceContext.getTemporaryDirectoryRoot().toPath();
|
|
| 113 | 115 |
ObserveDataSourceInformation dataSourceInformation;
|
| 114 | 116 |
|
| 115 | 117 |
if (dataSourceConfigurationTopiaSupport.isH2Database()) {
|
| ... | ... | @@ -143,7 +145,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 143 | 145 |
h2DataSourceConfiguration.getDbName(),
|
| 144 | 146 |
h2DataSourceConfiguration.getUsername(),
|
| 145 | 147 |
new String(h2DataSourceConfiguration.getPassword()),
|
| 146 |
- false,
|
|
| 148 |
+ temporaryDirectory, false,
|
|
| 147 | 149 |
false);
|
| 148 | 150 |
|
| 149 | 151 |
|
| ... | ... | @@ -167,7 +169,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 167 | 169 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 168 | 170 |
pgDataSourceConfiguration.getUsername(),
|
| 169 | 171 |
new String(pgDataSourceConfiguration.getPassword()),
|
| 170 |
- false,
|
|
| 172 |
+ temporaryDirectory, false,
|
|
| 171 | 173 |
false);
|
| 172 | 174 |
|
| 173 | 175 |
try {
|
| ... | ... | @@ -190,6 +192,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 190 | 192 |
@Override
|
| 191 | 193 |
public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 192 | 194 |
|
| 195 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 193 | 196 |
Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
|
| 194 | 197 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
| 195 | 198 |
|
| ... | ... | @@ -226,6 +229,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 226 | 229 |
h2DataSourceConfiguration.getDbName(),
|
| 227 | 230 |
h2DataSourceConfiguration.getUsername(),
|
| 228 | 231 |
new String(h2DataSourceConfiguration.getPassword()),
|
| 232 |
+ temporaryDirectory,
|
|
| 229 | 233 |
false,
|
| 230 | 234 |
false);
|
| 231 | 235 |
|
| ... | ... | @@ -250,6 +254,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 250 | 254 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 251 | 255 |
pgDataSourceConfiguration.getUsername(),
|
| 252 | 256 |
new String(pgDataSourceConfiguration.getPassword()),
|
| 257 |
+ temporaryDirectory,
|
|
| 253 | 258 |
false,
|
| 254 | 259 |
false);
|
| 255 | 260 |
|
| ... | ... | @@ -269,13 +274,22 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 269 | 274 |
|
| 270 | 275 |
}
|
| 271 | 276 |
|
| 277 |
+ Path getTemporaryDirectory(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
|
| 278 |
+ Path temporaryDirectory = dataSourceConfiguration.getTemporaryDirectory();
|
|
| 279 |
+ if (temporaryDirectory == null) {
|
|
| 280 |
+ temporaryDirectory = serviceContext.getTemporaryDirectoryRoot().toPath();
|
|
| 281 |
+ dataSourceConfiguration.setTemporaryDirectory(temporaryDirectory);
|
|
| 282 |
+ }
|
|
| 283 |
+ return temporaryDirectory;
|
|
| 284 |
+ }
|
|
| 285 |
+ |
|
| 272 | 286 |
@Override
|
| 273 | 287 |
public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration)
|
| 274 | 288 |
throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException,
|
| 275 | 289 |
BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
| 276 | 290 |
|
| 277 | 291 |
dataSourceCreateConfiguration.validateConfiguration();
|
| 278 |
- |
|
| 292 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 279 | 293 |
boolean initSchema = !dataSourceCreateConfiguration.isImportDatabase();
|
| 280 | 294 |
|
| 281 | 295 |
ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.createTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, initSchema);
|
| ... | ... | @@ -294,10 +308,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 294 | 308 |
} else { // base postgres
|
| 295 | 309 |
|
| 296 | 310 |
// on realise les import dans un base H2 temporaire
|
| 297 |
- // FIXME il faut obtenir le repertoit temporaire d'observe plutot que celui du système
|
|
| 298 | 311 |
File tmpDir;
|
| 299 | 312 |
try {
|
| 300 |
- tmpDir = Files.createTempDirectory("obstuna").toFile();
|
|
| 313 |
+ tmpDir = Files.createTempDirectory(temporaryDirectory, "obstuna").toFile();
|
|
| 301 | 314 |
} catch (IOException e) {
|
| 302 | 315 |
throw new IllegalStateException("could not create temporary directory ", e);
|
| 303 | 316 |
}
|
| ... | ... | @@ -322,8 +335,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 322 | 335 |
if (!databaseFile.delete()) {
|
| 323 | 336 |
throw new IllegalStateException("could not delete " + databaseFile);
|
| 324 | 337 |
}
|
| 325 |
- |
|
| 326 |
- |
|
| 327 | 338 |
}
|
| 328 | 339 |
|
| 329 | 340 |
} else {
|
| ... | ... | @@ -429,7 +440,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 429 | 440 |
dataSourceService.close();
|
| 430 | 441 |
}
|
| 431 | 442 |
}
|
| 432 |
- log.info(String.format("Import data%s", request.isAddReferential() ? " and referential." : "."));
|
|
| 443 |
+ log.info("Import data" + (request.isAddReferential() ? " and referential." : "."));
|
|
| 433 | 444 |
topiaApplicationContext.executeSqlStatements(dataDump);
|
| 434 | 445 |
}
|
| 435 | 446 |
|
| ... | ... | @@ -460,7 +471,8 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 460 | 471 |
|
| 461 | 472 |
@Override
|
| 462 | 473 |
public ObserveDataSourceConnectionTopia open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
|
| 463 |
- |
|
| 474 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 475 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 464 | 476 |
ObserveDataSourceInformation dataSourceInformation = checkCanConnect(dataSourceConfiguration);
|
| 465 | 477 |
|
| 466 | 478 |
Version dbVersion = dataSourceInformation.getVersion();
|
| ... | ... | @@ -562,6 +574,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 562 | 574 |
@Override
|
| 563 | 575 |
public void applySecurity(ObserveDataSourceConfiguration dataSourceConfiguration, ImmutableSet<ObserveDbUserDto> users) {
|
| 564 | 576 |
|
| 577 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 578 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 579 |
+ |
|
| 565 | 580 |
// pas de securité pour les bases autres que postgresql
|
| 566 | 581 |
if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
|
| 567 | 582 |
|
| ... | ... | @@ -580,6 +595,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 580 | 595 |
|
| 581 | 596 |
@Override
|
| 582 | 597 |
public void migrateData(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
| 598 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 599 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 600 |
+ |
|
| 583 | 601 |
ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration);
|
| 584 | 602 |
topiaApplicationContext.getMigrationService().runSchemaMigration();
|
| 585 | 603 |
}
|
| ... | ... | @@ -105,6 +105,7 @@ public class LocalTestClassResource extends TestClassResourceSupport { |
| 105 | 105 |
if (log.isInfoEnabled()) {
|
| 106 | 106 |
log.info("Create shared database: " + dbVersion.toString() + "/" + dbName + " to " + sharedDatabaseFile);
|
| 107 | 107 |
}
|
| 108 |
+ sharedDatabaseConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 108 | 109 |
|
| 109 | 110 |
try (DataSourceService dataSourceService = newService(sharedDatabaseConfiguration, DataSourceService.class)) {
|
| 110 | 111 |
DataSourceCreateConfigurationDto createConfiguration = new DataSourceCreateConfigurationDto();
|
| ... | ... | @@ -139,12 +140,14 @@ public class LocalTestClassResource extends TestClassResourceSupport { |
| 139 | 140 |
}
|
| 140 | 141 |
|
| 141 | 142 |
dataSourceConfiguration.setModelVersion(ObserveTestConfiguration.getModelVersion());
|
| 143 |
+ dataSourceConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 142 | 144 |
|
| 143 | 145 |
return dataSourceConfiguration;
|
| 144 | 146 |
|
| 145 | 147 |
}
|
| 146 | 148 |
|
| 147 | 149 |
public <S extends ObserveService> S newService(ObserveDataSourceConfiguration dataSourceConfiguration, Class<S> serviceType) {
|
| 150 |
+ dataSourceConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 148 | 151 |
ObserveServiceInitializer observeServiceInitializer = ObserveServiceInitializer.create(
|
| 149 | 152 |
Locale.FRANCE,
|
| 150 | 153 |
ReferentialLocale.FR,
|
| 1 |
+package fr.ird.observe.services.service;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Services API
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import org.apache.logging.log4j.LogManager;
|
|
| 26 |
+import org.apache.logging.log4j.Logger;
|
|
| 27 |
+ |
|
| 28 |
+import java.io.IOException;
|
|
| 29 |
+import java.nio.file.DirectoryStream;
|
|
| 30 |
+import java.nio.file.Files;
|
|
| 31 |
+import java.nio.file.Path;
|
|
| 32 |
+import java.util.Calendar;
|
|
| 33 |
+import java.util.Date;
|
|
| 34 |
+import java.util.Objects;
|
|
| 35 |
+import java.util.Timer;
|
|
| 36 |
+import java.util.TimerTask;
|
|
| 37 |
+import java.util.concurrent.TimeUnit;
|
|
| 38 |
+ |
|
| 39 |
+/**
|
|
| 40 |
+ * To clean temporaries files.
|
|
| 41 |
+ *
|
|
| 42 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 43 |
+ * @since 8.0
|
|
| 44 |
+ */
|
|
| 45 |
+ |
|
| 46 |
+public class CleanTemporaryFilesTask extends TimerTask {
|
|
| 47 |
+ |
|
| 48 |
+ private static final Logger log = LogManager.getLogger(CleanTemporaryFilesTask.class);
|
|
| 49 |
+ |
|
| 50 |
+ private final CleanTemporaryFilesTaskConfiguration configuration;
|
|
| 51 |
+ |
|
| 52 |
+ public static Timer create(CleanTemporaryFilesTaskConfiguration configuration) {
|
|
| 53 |
+ Timer result = new Timer("Delete temporary files daemon", true);
|
|
| 54 |
+ result.scheduleAtFixedRate(new CleanTemporaryFilesTask(configuration), new Date(), TimeUnit.HOURS.toMillis(1));
|
|
| 55 |
+ return result;
|
|
| 56 |
+ }
|
|
| 57 |
+ |
|
| 58 |
+ public CleanTemporaryFilesTask(CleanTemporaryFilesTaskConfiguration configuration) {
|
|
| 59 |
+ this.configuration = configuration;
|
|
| 60 |
+ }
|
|
| 61 |
+ |
|
| 62 |
+ @Override
|
|
| 63 |
+ public void run() {
|
|
| 64 |
+ |
|
| 65 |
+ Path temporaryDirectory = configuration.getTemporaryDirectory().toPath();
|
|
| 66 |
+ Calendar calendar = Calendar.getInstance();
|
|
| 67 |
+ calendar.setTime(new Date());
|
|
| 68 |
+ calendar.add(Calendar.HOUR_OF_DAY, -configuration.getTemporaryFilesTimeout());
|
|
| 69 |
+ Date deleteBefore = calendar.getTime();
|
|
| 70 |
+ long deleteBeforeTime = deleteBefore.getTime();
|
|
| 71 |
+ |
|
| 72 |
+ log.info(String.format("Delete temporary files in directory %s before %s", temporaryDirectory, deleteBefore));
|
|
| 73 |
+ delete(temporaryDirectory, deleteBeforeTime);
|
|
| 74 |
+ }
|
|
| 75 |
+ |
|
| 76 |
+ private boolean delete(Path path, long deleteBeforeTime) {
|
|
| 77 |
+ try {
|
|
| 78 |
+ Files.walk(path).forEach(p -> {
|
|
| 79 |
+ if (Objects.equals(path, p)) {
|
|
| 80 |
+ return;
|
|
| 81 |
+ }
|
|
| 82 |
+ if (Files.isDirectory(p)) {
|
|
| 83 |
+ boolean deleted = delete(p, deleteBeforeTime);
|
|
| 84 |
+ if (deleted) {
|
|
| 85 |
+ delete0(p, deleteBeforeTime);
|
|
| 86 |
+ }
|
|
| 87 |
+ }
|
|
| 88 |
+ if (Files.isRegularFile(p)) {
|
|
| 89 |
+ delete0(p, deleteBeforeTime);
|
|
| 90 |
+ }
|
|
| 91 |
+ });
|
|
| 92 |
+ if (Files.isRegularFile(path)) {
|
|
| 93 |
+ return Files.notExists(path);
|
|
| 94 |
+ }
|
|
| 95 |
+ if (Files.isDirectory(path)) {
|
|
| 96 |
+ return isDirEmpty(path);
|
|
| 97 |
+ }
|
|
| 98 |
+ return false;
|
|
| 99 |
+ } catch (IOException e) {
|
|
| 100 |
+ throw new RuntimeException(String.format("Could not walk through temporary directory: %s", path), e);
|
|
| 101 |
+ }
|
|
| 102 |
+ }
|
|
| 103 |
+ |
|
| 104 |
+ private static boolean isDirEmpty(final Path directory) throws IOException {
|
|
| 105 |
+ try(DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory)) {
|
|
| 106 |
+ return !dirStream.iterator().hasNext();
|
|
| 107 |
+ }
|
|
| 108 |
+ }
|
|
| 109 |
+ private void delete0(Path p, long deleteBeforeTime) {
|
|
| 110 |
+ try {
|
|
| 111 |
+ if (Files.getLastModifiedTime(p).toMillis() < deleteBeforeTime) {
|
|
| 112 |
+ log.info("Delete temporary file: " + p);
|
|
| 113 |
+ Files.delete(p);
|
|
| 114 |
+ }
|
|
| 115 |
+ } catch (IOException e) {
|
|
| 116 |
+ log.error("Something wrong while process file: " + p, e);
|
|
| 117 |
+ }
|
|
| 118 |
+ }
|
|
| 119 |
+}
|
| 1 |
+package fr.ird.observe.services.service;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Services API
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
+ * %%
|
|
| 9 |
+ * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
+ * it under the terms of the GNU General Public License as
|
|
| 11 |
+ * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
+ * License, or (at your option) any later version.
|
|
| 13 |
+ *
|
|
| 14 |
+ * This program is distributed in the hope that it will be useful,
|
|
| 15 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
+ * GNU General Public License for more details.
|
|
| 18 |
+ *
|
|
| 19 |
+ * You should have received a copy of the GNU General Public
|
|
| 20 |
+ * License along with this program. If not, see
|
|
| 21 |
+ * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
+ * #L%
|
|
| 23 |
+ */
|
|
| 24 |
+ |
|
| 25 |
+import java.io.File;
|
|
| 26 |
+ |
|
| 27 |
+/**
|
|
| 28 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 29 |
+ * @since 7.5.1
|
|
| 30 |
+ */
|
|
| 31 |
+public interface CleanTemporaryFilesTaskConfiguration {
|
|
| 32 |
+ |
|
| 33 |
+ File getTemporaryDirectory();
|
|
| 34 |
+ |
|
| 35 |
+ void setTemporaryDirectory(File temporaryDirectory);
|
|
| 36 |
+ |
|
| 37 |
+ int getTemporaryFilesTimeout();
|
|
| 38 |
+ |
|
| 39 |
+ void setTemporaryFilesTimeout(int temporaryFilesTimeout);
|
|
| 40 |
+}
|