Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
31be83c4
by tchemit at 2020-04-14T00:49:37+02:00
26 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/ClientUIContext.java
- client-core/src/main/java/fr/ird/observe/client/ObserveSwingApplicationContext.java
- client-core/src/main/java/fr/ird/observe/client/datasource/api/ObserveDataSourcesManager.java
- client-core/src/main/java/fr/ird/observe/client/datasource/api/ObserveSwingDataSource.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/entities/AbstractObserveTopiaDao.java
- − persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaConfiguration.java
- − persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaConfigurationFactory.java
- persistence/src/test/java/fr/ird/observe/persistence/ObserveTopiaApplicationContextTest.java → persistence/src/test/java/fr/ird/observe/entities/ObserveTopiaApplicationContextTest.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
- persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaIdFactory.java → services/src/main/java/fr/ird/observe/services/service/CleanTemporaryFilesTaskConfiguration.java
Changes:
| ... | ... | @@ -146,8 +146,16 @@ defaultValue = ${dcp.presets.directory}/ps/logbook |
| 146 | 146 |
transient = true
|
| 147 | 147 |
final = true
|
| 148 | 148 |
|
| 149 |
+[option temporaryDirectory]
|
|
| 150 |
+description = observe.config.temporaryDirectory.description
|
|
| 151 |
+key = temporary.directory
|
|
| 152 |
+type = file
|
|
| 153 |
+defaultValue = ${data.directory}/tmp
|
|
| 154 |
+transient = true
|
|
| 155 |
+final = true
|
|
| 156 |
+ |
|
| 149 | 157 |
[option tmpDirectory]
|
| 150 |
-description = observe.config.defaultTmpDirectory.description
|
|
| 158 |
+description = observe.config.temporaryDirectory.description
|
|
| 151 | 159 |
key = tmp.directory
|
| 152 | 160 |
type = file
|
| 153 | 161 |
defaultValue = ${data.directory}/tmp
|
| ... | ... | @@ -717,6 +725,12 @@ key = ui.seineBycatchObservedSystem |
| 717 | 725 |
type = fr.ird.observe.validation.SeineBycatchObservedSystemConfig
|
| 718 | 726 |
defaultValue = {\"fr.ird.referential.common.Species#1239832684290#0.04680507324710936\": [\"fr.ird.referential.ps.observation.ObservedSystem#0#1.0\",\"fr.ird.referential.ps.observation.ObservedSystem#0#1.1\"]}
|
| 719 | 727 |
|
| 728 |
+[option temporaryFilesTimeout]
|
|
| 729 |
+description = observe.config.temporaryFilesTimeout.description
|
|
| 730 |
+key = observe.config.temporaryFilesTimeout
|
|
| 731 |
+type = int
|
|
| 732 |
+defaultValue = 120
|
|
| 733 |
+ |
|
| 720 | 734 |
[action help]
|
| 721 | 735 |
description = observe.action.commandline.help
|
| 722 | 736 |
action = "fr.ird.observe.client.ObserveCLAction#help"
|
| ... | ... | @@ -33,7 +33,6 @@ observe.config.defaultLocalDbDirectory.description |
| 33 | 33 |
observe.config.defaultMapDirectory.description
|
| 34 | 34 |
observe.config.defaultReportDirectory.description
|
| 35 | 35 |
observe.config.defaultResourcesDirectory.description
|
| 36 |
-observe.config.defaultTmpDirectory.description
|
|
| 37 | 36 |
observe.config.defaultValidationReportDirectory.description
|
| 38 | 37 |
observe.config.h2.can.editReferential.description
|
| 39 | 38 |
observe.config.h2.can.migrate.description
|
| ... | ... | @@ -91,6 +90,8 @@ observe.config.speciesList.seine.observation.schoolEstimate |
| 91 | 90 |
observe.config.speciesList.seine.observation.targetCatch
|
| 92 | 91 |
observe.config.swingSessionFile.description
|
| 93 | 92 |
observe.config.temperature.format
|
| 93 |
+observe.config.temporaryDirectory.description
|
|
| 94 |
+observe.config.temporaryFilesTimeout.description
|
|
| 94 | 95 |
observe.config.ui.autoPopupNumberEditor
|
| 95 | 96 |
observe.config.ui.blockStateColor
|
| 96 | 97 |
observe.config.ui.busyStateColor
|
| ... | ... | @@ -35,6 +35,7 @@ import fr.ird.observe.dto.referential.ReferentialLocale; |
| 35 | 35 |
import fr.ird.observe.gson.ObserveDtoGsonSupplier;
|
| 36 | 36 |
import fr.ird.observe.navigation.model.edit.ObserveEditModel;
|
| 37 | 37 |
import fr.ird.observe.navigation.model.select.ObserveSelectModel;
|
| 38 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTaskConfiguration;
|
|
| 38 | 39 |
import io.ultreia.java4all.application.context.spi.ApplicationComponentInstantiateStrategy;
|
| 39 | 40 |
import io.ultreia.java4all.application.context.spi.GenerateApplicationComponent;
|
| 40 | 41 |
import io.ultreia.java4all.application.template.TemplateGeneratorConfig;
|
| ... | ... | @@ -92,12 +93,13 @@ import static io.ultreia.java4all.i18n.I18n.t; |
| 92 | 93 |
hints = {
|
| 93 | 94 |
TemplateGeneratorConfig.class,
|
| 94 | 95 |
ObServeSwingSessionConfig.class,
|
| 95 |
- ReferentialLocaleConfig.class},
|
|
| 96 |
+ ReferentialLocaleConfig.class,
|
|
| 97 |
+ CleanTemporaryFilesTaskConfiguration.class},
|
|
| 96 | 98 |
instantiateStrategy = ApplicationComponentInstantiateStrategy.SUPPLIER,
|
| 97 | 99 |
instantiateSupplier = ClientConfigFinder.class
|
| 98 | 100 |
)
|
| 99 | 101 |
@GenerateTemplate(template = "about.ftl")
|
| 100 |
-public class ClientConfig extends GeneratedClientConfig implements TemplateGeneratorConfig, ObServeSwingSessionConfig, ReferentialLocaleConfig, NavigationTreeConfig {
|
|
| 102 |
+public class ClientConfig extends GeneratedClientConfig implements TemplateGeneratorConfig, ObServeSwingSessionConfig, ReferentialLocaleConfig, NavigationTreeConfig, CleanTemporaryFilesTaskConfiguration {
|
|
| 101 | 103 |
|
| 102 | 104 |
public static final String DB_NAME = "obstuna";
|
| 103 | 105 |
public static final List<ClientConfigOption> MAP_LAYERS = ImmutableList.of(
|
| ... | ... | @@ -266,7 +268,7 @@ public class ClientConfig extends GeneratedClientConfig implements TemplateGener |
| 266 | 268 |
resourceManager.createDirectory(this, ClientConfigOption.TMP_DIRECTORY);
|
| 267 | 269 |
|
| 268 | 270 |
// suppression du contenu du répertoire temporaire
|
| 269 |
- FileUtils.cleanDirectory(this.getTmpDirectory());
|
|
| 271 |
+ FileUtils.cleanDirectory(this.getTemporaryDirectory());
|
|
| 270 | 272 |
|
| 271 | 273 |
// 3 - backup directory
|
| 272 | 274 |
|
| ... | ... | @@ -34,6 +34,7 @@ import fr.ird.observe.dto.IdDto; |
| 34 | 34 |
import fr.ird.observe.dto.decoration.DecoratorService;
|
| 35 | 35 |
import fr.ird.observe.dto.decoration.DecoratorServiceApplicationComponent;
|
| 36 | 36 |
import fr.ird.observe.dto.decoration.ObserveI18nDecoratorHelper;
|
| 37 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTask;
|
|
| 37 | 38 |
import io.ultreia.java4all.application.context.ApplicationContext;
|
| 38 | 39 |
import io.ultreia.java4all.application.context.spi.GenerateApplicationComponent;
|
| 39 | 40 |
import io.ultreia.java4all.i18n.I18n;
|
| ... | ... | @@ -57,9 +58,11 @@ import java.awt.event.ComponentEvent; |
| 57 | 58 |
import java.awt.event.WindowAdapter;
|
| 58 | 59 |
import java.awt.event.WindowEvent;
|
| 59 | 60 |
import java.beans.PropertyChangeListener;
|
| 61 |
+import java.io.Closeable;
|
|
| 60 | 62 |
import java.util.List;
|
| 61 | 63 |
import java.util.Locale;
|
| 62 | 64 |
import java.util.Objects;
|
| 65 |
+import java.util.Timer;
|
|
| 63 | 66 |
|
| 64 | 67 |
import static io.ultreia.java4all.i18n.I18n.t;
|
| 65 | 68 |
import static javax.swing.JOptionPane.CLOSED_OPTION;
|
| ... | ... | @@ -71,7 +74,7 @@ import static javax.swing.JOptionPane.VALUE_PROPERTY; |
| 71 | 74 |
ObserveSwingSessionHelper.class,
|
| 72 | 75 |
ActionExecutor.class
|
| 73 | 76 |
})
|
| 74 |
-public class ClientUIContext {
|
|
| 77 |
+public class ClientUIContext implements Closeable {
|
|
| 75 | 78 |
|
| 76 | 79 |
private static final Logger log = LogManager.getLogger(ClientUIContext.class);
|
| 77 | 80 |
|
| ... | ... | @@ -81,7 +84,9 @@ public class ClientUIContext { |
| 81 | 84 |
private final ActionExecutor actionExecutor;
|
| 82 | 85 |
private ObserveMainUI mainUI;
|
| 83 | 86 |
private ObserveUICallbackManager uiCallbackManager;
|
| 87 |
+ private Timer deleteTemporaryFilesTimer;
|
|
| 84 | 88 |
private final BusyModel busyModel;
|
| 89 |
+ |
|
| 85 | 90 |
public ClientUIContext(DecoratorService decoratorService, ClientConfig clientConfig, ObserveSwingSessionHelper observeSwingSessionHelper, ActionExecutor actionExecutor) {
|
| 86 | 91 |
this.decoratorService = decoratorService;
|
| 87 | 92 |
this.clientConfig = clientConfig;
|
| ... | ... | @@ -90,6 +95,13 @@ public class ClientUIContext { |
| 90 | 95 |
this.busyModel = new BusyModel();
|
| 91 | 96 |
}
|
| 92 | 97 |
|
| 98 |
+ public void initDeleteTemporaryFilesTimer() {
|
|
| 99 |
+ if (deleteTemporaryFilesTimer != null) {
|
|
| 100 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 101 |
+ }
|
|
| 102 |
+ deleteTemporaryFilesTimer = CleanTemporaryFilesTask.create(getClientConfig());
|
|
| 103 |
+ }
|
|
| 104 |
+ |
|
| 93 | 105 |
public static void displayInfo(String text) {
|
| 94 | 106 |
JFrame ui = ClientUIContextApplicationComponent.value().getMainUI();
|
| 95 | 107 |
if (ui == null) {
|
| ... | ... | @@ -365,7 +377,9 @@ public class ClientUIContext { |
| 365 | 377 |
return observeSwingSessionHelper;
|
| 366 | 378 |
}
|
| 367 | 379 |
|
| 380 |
+ @Override
|
|
| 368 | 381 |
public void close() {
|
| 382 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 369 | 383 |
mainUI = null;
|
| 370 | 384 |
}
|
| 371 | 385 |
|
| ... | ... | @@ -464,4 +478,16 @@ public class ClientUIContext { |
| 464 | 478 |
public BusyModel getBusyModel() {
|
| 465 | 479 |
return busyModel;
|
| 466 | 480 |
}
|
| 481 |
+ |
|
| 482 |
+ |
|
| 483 |
+ void closeDeleteTemporaryFilesTimer() {
|
|
| 484 |
+ if (deleteTemporaryFilesTimer != null) {
|
|
| 485 |
+ try {
|
|
| 486 |
+ deleteTemporaryFilesTimer.cancel();
|
|
| 487 |
+ } catch (Exception e) {
|
|
| 488 |
+ log.error("Could not terminates delete temporary files timer...", e);
|
|
| 489 |
+ }
|
|
| 490 |
+ }
|
|
| 491 |
+ }
|
|
| 492 |
+ |
|
| 467 | 493 |
}
|
| ... | ... | @@ -22,6 +22,7 @@ |
| 22 | 22 |
package fr.ird.observe.client;
|
| 23 | 23 |
|
| 24 | 24 |
import fr.ird.observe.client.configuration.ClientConfig;
|
| 25 |
+import fr.ird.observe.client.configuration.ClientConfigApplicationComponent;
|
|
| 25 | 26 |
import fr.ird.observe.services.ObserveServiceMainFactory;
|
| 26 | 27 |
import fr.ird.observe.services.ObserveServiceMainFactoryApplicationComponent;
|
| 27 | 28 |
import fr.ird.observe.spi.DtoModelHelper;
|
| ... | ... | @@ -53,9 +54,12 @@ public class ObserveSwingApplicationContext extends ApplicationContext { |
| 53 | 54 |
//FIXME Je ne comprends pas pourquoi cela ne fonctionne plus.
|
| 54 | 55 |
// config.get().setOption("user.home", SystemUtils.USER_HOME);
|
| 55 | 56 |
|
| 56 |
- log.debug("Init model helper: " + DtoModelHelper.class);
|
|
| 57 |
+ log.debug(String.format("Init model helper: %s", DtoModelHelper.class));
|
|
| 57 | 58 |
ObserveServiceMainFactory serviceMainFactory = ObserveServiceMainFactoryApplicationComponent.value();
|
| 58 |
- log.info("Initialize services factory: " + serviceMainFactory);
|
|
| 59 |
+ log.info(String.format("Initialize services factory: %s", serviceMainFactory));
|
|
| 60 |
+ ClientUIContext clientUIContext = ClientUIContextApplicationComponent.value();
|
|
| 61 |
+ log.info("Initialize delete temporary files task.");
|
|
| 62 |
+ clientUIContext.initDeleteTemporaryFilesTimer();
|
|
| 59 | 63 |
}
|
| 60 | 64 |
|
| 61 | 65 |
// We put here the i18n keys from the client-runner module, otherwise we need yet another module before observe-i18n
|
| ... | ... | @@ -126,7 +126,7 @@ public class ObserveDataSourcesManager implements Closeable { |
| 126 | 126 |
|
| 127 | 127 |
public ObserveSwingDataSource newTemporaryH2DataSource(String label) {
|
| 128 | 128 |
|
| 129 |
- File tmpDirectory = config.getTmpDirectory();
|
|
| 129 |
+ File tmpDirectory = config.getTemporaryDirectory();
|
|
| 130 | 130 |
|
| 131 | 131 |
File dbDirectory = new File(tmpDirectory, ClientConfig.DB_NAME + UUID.randomUUID().toString());
|
| 132 | 132 |
|
| ... | ... | @@ -482,7 +482,7 @@ public class ObserveSwingDataSource extends ObserveServicesProviderSupport { |
| 482 | 482 |
|
| 483 | 483 |
Locale locale = config.getLocale();
|
| 484 | 484 |
|
| 485 |
- File tmpDirectory = config.getTmpDirectory();
|
|
| 485 |
+ File tmpDirectory = config.getTemporaryDirectory();
|
|
| 486 | 486 |
|
| 487 | 487 |
ReferentialLocale referentialLocale = ReferentialLocale.valueOf(locale);
|
| 488 | 488 |
|
| ... | ... | @@ -482,7 +482,6 @@ observe.config.defaultLocalDbDirectory.description=Default directory where to st |
| 482 | 482 |
observe.config.defaultMapDirectory.description=Default directory where to store map layers
|
| 483 | 483 |
observe.config.defaultReportDirectory.description=Default directory where to store report definition files
|
| 484 | 484 |
observe.config.defaultResourcesDirectory.description=Default user resources directory
|
| 485 |
-observe.config.defaultTmpDirectory.description=Default temporary directory used by application and clean at each launch.
|
|
| 486 | 485 |
observe.config.defaultValidationReportDirectory.description=Default validation report directory
|
| 487 | 486 |
observe.config.devMode=Dev mode
|
| 488 | 487 |
observe.config.floatingObjectPresets.description=Floating Objects references
|
| ... | ... | @@ -542,6 +541,8 @@ observe.config.speciesList.seine.observation.schoolEstimate=Species for school e |
| 542 | 541 |
observe.config.speciesList.seine.observation.targetCatch=Species for target catches
|
| 543 | 542 |
observe.config.swingSessionFile.description=Swing session file.
|
| 544 | 543 |
observe.config.temperature.format=Default temperature format
|
| 544 |
+observe.config.temporaryDirectory.description=Default temporary directory used by application and clean at each launch.
|
|
| 545 |
+observe.config.temporaryFilesTimeout.description=Temporary files delete (in hours)
|
|
| 545 | 546 |
observe.config.ui.autoPopupNumberEditor=Flag sets to true when number editor show automaticly popup
|
| 546 | 547 |
observe.config.ui.blockStateColor=Color of block state
|
| 547 | 548 |
observe.config.ui.busyStateColor=Color of busy state
|
| ... | ... | @@ -3519,7 +3520,7 @@ observeweb.devMode.description=Dev mode |
| 3519 | 3520 |
observeweb.host.description=Application host
|
| 3520 | 3521 |
observeweb.httpTimeout.description=Http timeout in milli seconds
|
| 3521 | 3522 |
observeweb.log4jConfigurationFile.description=Path to log configuration file
|
| 3522 |
-observeweb.sessionExpirationDelay.description=Session expiration deplay (in minutes)
|
|
| 3523 |
+observeweb.sessionExpirationDelay.description=Session expiration delay (in minutes)
|
|
| 3523 | 3524 |
observeweb.sessionMaximumSize.description=Session maximum size
|
| 3524 | 3525 |
observeweb.temporaryDirectory.description=Path to temporary directory
|
| 3525 | 3526 |
observeweb.usersConfigurationFile.description=Path to users configuration file
|
| ... | ... | @@ -482,7 +482,6 @@ observe.config.defaultLocalDbDirectory.description=Directorio de almacenamiento |
| 482 | 482 |
observe.config.defaultMapDirectory.description=El directorio donde se ubican los mapas.
|
| 483 | 483 |
observe.config.defaultReportDirectory.description=Directorio por defecto de los informes de la aplicación
|
| 484 | 484 |
observe.config.defaultResourcesDirectory.description=Directorio de almacenamiento de los recursos de usuario como las traducciones o la consultas de informes
|
| 485 |
-observe.config.defaultTmpDirectory.description=Directorio temporal por defecto
|
|
| 486 | 485 |
observe.config.defaultValidationReportDirectory.description=Directorio por defecto de almacenamiento de los informes de validación
|
| 487 | 486 |
observe.config.devMode=Modo desarrollador
|
| 488 | 487 |
observe.config.floatingObjectPresets.description=Objetos flotantes de referencia
|
| ... | ... | @@ -542,6 +541,8 @@ observe.config.speciesList.seine.observation.schoolEstimate=Especies para las es |
| 542 | 541 |
observe.config.speciesList.seine.observation.targetCatch=Especies par las capturas objetivo
|
| 543 | 542 |
observe.config.swingSessionFile.description=Copia de seguridad del estado del UI.
|
| 544 | 543 |
observe.config.temperature.format=Unidad de temperatura
|
| 544 |
+observe.config.temporaryDirectory.description=Directorio temporal por defecto
|
|
| 545 |
+observe.config.temporaryFilesTimeout.description=Temporary files delete (in hours) \#TODO
|
|
| 545 | 546 |
observe.config.ui.autoPopupNumberEditor=Para mostrar automáticamente el editor numérico durante la edición de un número
|
| 546 | 547 |
observe.config.ui.blockStateColor=Color of block state \#TODO
|
| 547 | 548 |
observe.config.ui.busyStateColor=Color of busy state \#TODO
|
| ... | ... | @@ -482,7 +482,6 @@ observe.config.defaultLocalDbDirectory.description=Le répertoire où est stock |
| 482 | 482 |
observe.config.defaultMapDirectory.description=Le répertoire où sont stockées les cartes.
|
| 483 | 483 |
observe.config.defaultReportDirectory.description=Répertoire par défaut des rapports de l'application
|
| 484 | 484 |
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.
|
| 485 |
-observe.config.defaultTmpDirectory.description=Le répertoire temporaire par défaut
|
|
| 486 | 485 |
observe.config.defaultValidationReportDirectory.description=Le répertoire par défaut où sont stockés les rapports de validation
|
| 487 | 486 |
observe.config.devMode=Mode développeur
|
| 488 | 487 |
observe.config.floatingObjectPresets.description=Objets flottants de référence
|
| ... | ... | @@ -542,6 +541,8 @@ observe.config.speciesList.seine.observation.schoolEstimate=Espèces pour les es |
| 542 | 541 |
observe.config.speciesList.seine.observation.targetCatch=Espèces pour les captures cible
|
| 543 | 542 |
observe.config.swingSessionFile.description=Fichier de sauvegarde des états des UI.
|
| 544 | 543 |
observe.config.temperature.format=Unité de température
|
| 544 |
+observe.config.temporaryDirectory.description=Le répertoire temporaire par défaut
|
|
| 545 |
+observe.config.temporaryFilesTimeout.description=Nettoyage des fichiers temporaires (en heures)
|
|
| 545 | 546 |
observe.config.ui.autoPopupNumberEditor=Pour afficher automatiquement l'éditeur numérique lors de l'édition d'un nombre
|
| 546 | 547 |
observe.config.ui.blockStateColor=Couleur lorsque l'on bloque une partie de l'application
|
| 547 | 548 |
observe.config.ui.busyStateColor=Couleur lorsque l'application est occupée
|
| 1 |
-package fr.ird.observe.entities;
|
|
| 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.internal.AbstractTopiaDao;
|
|
| 26 |
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
|
|
| 27 |
- |
|
| 28 |
-import java.sql.Connection;
|
|
| 29 |
-import java.sql.PreparedStatement;
|
|
| 30 |
-import java.sql.ResultSet;
|
|
| 31 |
-import java.sql.SQLException;
|
|
| 32 |
-import java.sql.Timestamp;
|
|
| 33 |
-import java.util.Date;
|
|
| 34 |
-import java.util.List;
|
|
| 35 |
-import java.util.Map;
|
|
| 36 |
- |
|
| 37 |
-public abstract class AbstractObserveTopiaDao<E extends Entity> extends AbstractTopiaDao<E> {
|
|
| 38 |
- |
|
| 39 |
- private final GetLastUpdateDateSqlQuery getLastUpdateDateSqlQuery;
|
|
| 40 |
- |
|
| 41 |
- protected AbstractObserveTopiaDao() {
|
|
| 42 |
- String schemaName = getTopiaEntityEnum().dbSchemaName();
|
|
| 43 |
- String tableName = getTopiaEntityEnum().dbTableName();
|
|
| 44 |
- getLastUpdateDateSqlQuery = new GetLastUpdateDateSqlQuery(schemaName, tableName);
|
|
| 45 |
- }
|
|
| 46 |
- |
|
| 47 |
- public Date getLastUpdateDate() {
|
|
| 48 |
- return topiaSqlSupport.findSingleResult(getLastUpdateDateSqlQuery);
|
|
| 49 |
- }
|
|
| 50 |
- |
|
| 51 |
- public <O> List<O> findAllFromHql(String hql, Map<String, Object> hqlParameters) {
|
|
| 52 |
- return findAll(hql, hqlParameters);
|
|
| 53 |
- }
|
|
| 54 |
- |
|
| 55 |
- private static class GetLastUpdateDateSqlQuery extends TopiaSqlQuery<Timestamp> {
|
|
| 56 |
- |
|
| 57 |
- protected final String sql;
|
|
| 58 |
- |
|
| 59 |
- private GetLastUpdateDateSqlQuery(String schemaName, String tableName) {
|
|
| 60 |
- this.sql = "SELECT max(" + Entity.PROPERTY_LAST_UPDATE_DATE + ") FROM " + schemaName + "." + tableName;
|
|
| 61 |
- }
|
|
| 62 |
- |
|
| 63 |
- @Override
|
|
| 64 |
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
|
|
| 65 |
- return connection.prepareStatement(sql);
|
|
| 66 |
- }
|
|
| 67 |
- |
|
| 68 |
- @Override
|
|
| 69 |
- public Timestamp prepareResult(ResultSet set) throws SQLException {
|
|
| 70 |
- return set.getTimestamp(1);
|
|
| 71 |
- }
|
|
| 72 |
- |
|
| 73 |
- }
|
|
| 74 |
- |
|
| 75 |
- |
|
| 76 |
-}
|
| 1 |
-package fr.ird.observe.entities;
|
|
| 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.entities;
|
|
| 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;
|
|
| 1 |
+package fr.ird.observe.entities;
|
|
| 2 | 2 |
|
| 3 | 3 |
/*-
|
| 4 | 4 |
* #%L
|
| ... | ... | @@ -22,9 +22,6 @@ package fr.ird.observe.persistence; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
-import fr.ird.observe.entities.ObserveTopiaApplicationContext;
|
|
| 26 |
-import fr.ird.observe.entities.ObserveTopiaConfiguration;
|
|
| 27 |
-import fr.ird.observe.entities.ObserveTopiaConfigurationFactory;
|
|
| 28 | 25 |
import fr.ird.observe.test.TestHelper;
|
| 29 | 26 |
import fr.ird.observe.test.TestSupportWithConfig;
|
| 30 | 27 |
import org.junit.Assert;
|
| ... | ... | @@ -46,7 +43,7 @@ public class ObserveTopiaApplicationContextTest extends TestSupportWithConfig { |
| 46 | 43 |
|
| 47 | 44 |
File testBasedir = TestHelper.getTestBasedir(getClass());
|
| 48 | 45 |
|
| 49 |
- ObserveTopiaConfiguration observeTopiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(testBasedir, "testReplicateModel", "sa", "sa", true, false);
|
|
| 46 |
+ ObserveTopiaConfiguration observeTopiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(testBasedir, "testReplicateModel", "sa", "sa", testBasedir.toPath().resolve("temporary"), true, false);
|
|
| 50 | 47 |
try (ObserveTopiaApplicationContext applicationContext = new ObserveTopiaApplicationContext(observeTopiaConfiguration)) {
|
| 51 | 48 |
TopiaSqlTables tripLonglineTables = applicationContext.getTripLonglineTables();
|
| 52 | 49 |
Assert.assertNotNull(tripLonglineTables);
|
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 |
<parent>
|
| 25 | 25 |
<groupId>io.ultreia.maven</groupId>
|
| 26 | 26 |
<artifactId>pom</artifactId>
|
| 27 |
- <version>2020.15</version>
|
|
| 27 |
+ <version>2020.17</version>
|
|
| 28 | 28 |
</parent>
|
| 29 | 29 |
|
| 30 | 30 |
<groupId>fr.ird.observe</groupId>
|
| ... | ... | @@ -162,7 +162,7 @@ |
| 162 | 162 |
<maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
|
| 163 | 163 |
<buildDate>${maven.build.timestamp}</buildDate>
|
| 164 | 164 |
|
| 165 |
- <lib.version.toolkit>4.27</lib.version.toolkit>
|
|
| 165 |
+ <lib.version.toolkit>4.28</lib.version.toolkit>
|
|
| 166 | 166 |
<lib.version.nuiton.validation>3.1</lib.version.nuiton.validation>
|
| 167 | 167 |
<!--can't use 1.4.197 (date has changed + blob also)-->
|
| 168 | 168 |
<lib.version.h2>1.4.196</lib.version.h2>
|
| ... | ... | @@ -176,7 +176,7 @@ |
| 176 | 176 |
<!--<lib.version.java4all.i18n>4.0-beta-3-SNAPSHOT</lib.version.java4all.i18n>-->
|
| 177 | 177 |
<!--<lib.version.java4all.config>1.0.8-SNAPSHOT</lib.version.java4all.config>-->
|
| 178 | 178 |
<!--<lib.version.nuiton.topia>3.4.2-SNAPSHOT</lib.version.nuiton.topia>-->
|
| 179 |
- <!--<lib.version.java4all.topia>1.14</lib.version.java4all.topia>-->
|
|
| 179 |
+<!-- <lib.version.java4all.topia>1.19-SNAPSHOT</lib.version.java4all.topia>-->
|
|
| 180 | 180 |
<!--<lib.version.java4all.http>1.0.17-SNAPSHOT</lib.version.java4all.http>-->
|
| 181 | 181 |
|
| 182 | 182 |
<!-- license header configuration -->
|
| ... | ... | @@ -48,7 +48,11 @@ |
| 48 | 48 |
<version>${project.version}</version>
|
| 49 | 49 |
<scope>provided</scope>
|
| 50 | 50 |
</dependency>
|
| 51 |
- |
|
| 51 |
+ <dependency>
|
|
| 52 |
+ <groupId>${project.groupId}</groupId>
|
|
| 53 |
+ <artifactId>services</artifactId>
|
|
| 54 |
+ <version>${project.version}</version>
|
|
| 55 |
+ </dependency>
|
|
| 52 | 56 |
<dependency>
|
| 53 | 57 |
<groupId>io.ultreia.java4all</groupId>
|
| 54 | 58 |
<artifactId>application-context</artifactId>
|
| ... | ... | @@ -103,3 +103,9 @@ key = observeweb.httpTimeout |
| 103 | 103 |
type = int
|
| 104 | 104 |
defaultValue = 30000
|
| 105 | 105 |
|
| 106 |
+[option temporaryFilesTimeout]
|
|
| 107 |
+description = observe.config.temporaryFilesTimeout.description
|
|
| 108 |
+key = observeweb.temporaryFilesTimeout
|
|
| 109 |
+type = int
|
|
| 110 |
+defaultValue = 120
|
|
| 111 |
+ |
| 1 | 1 |
ObserveWebApplicationConfig.description
|
| 2 |
+observe.config.temporaryFilesTimeout.description
|
|
| 2 | 3 |
observe.model.version
|
| 3 | 4 |
observeweb.adminApiKey.description
|
| 4 | 5 |
observeweb.baseDirectory.description
|
| ... | ... | @@ -24,6 +24,7 @@ package fr.ird.observe.server.configuration; |
| 24 | 24 |
|
| 25 | 25 |
import fr.ird.observe.dto.ObserveUtil;
|
| 26 | 26 |
import fr.ird.observe.dto.decoration.ReferentialLocaleConfig;
|
| 27 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTaskConfiguration;
|
|
| 27 | 28 |
import io.ultreia.java4all.application.context.spi.GenerateApplicationComponent;
|
| 28 | 29 |
import io.ultreia.java4all.application.template.TemplateGeneratorConfig;
|
| 29 | 30 |
import io.ultreia.java4all.config.ApplicationConfig;
|
| ... | ... | @@ -46,8 +47,8 @@ import java.nio.file.Paths; |
| 46 | 47 |
* @author Tony Chemit - dev@tchemit.fr
|
| 47 | 48 |
*/
|
| 48 | 49 |
@GenerateApplicationComponent(name = "ObServe Web configuration",
|
| 49 |
- hints = {TemplateGeneratorConfig.class, ReferentialLocaleConfig.class})
|
|
| 50 |
-public class ServerConfig extends GeneratedServerConfig {
|
|
| 50 |
+ hints = {TemplateGeneratorConfig.class, ReferentialLocaleConfig.class, CleanTemporaryFilesTaskConfiguration.class})
|
|
| 51 |
+public class ServerConfig extends GeneratedServerConfig implements CleanTemporaryFilesTaskConfiguration {
|
|
| 51 | 52 |
|
| 52 | 53 |
private static Logger log = LogManager.getLogger(ServerConfig.class);
|
| 53 | 54 |
|
| ... | ... | @@ -43,6 +43,7 @@ import fr.ird.observe.server.configuration.user.ObserveWebUsersHelperApplication |
| 43 | 43 |
import fr.ird.observe.server.configuration.user.impl.ObserveWebUsersImmutable;
|
| 44 | 44 |
import fr.ird.observe.server.security.ObserveWebSecurityApplicationContext;
|
| 45 | 45 |
import fr.ird.observe.server.security.ObserveWebSecurityApplicationContextApplicationComponent;
|
| 46 |
+import fr.ird.observe.services.service.CleanTemporaryFilesTask;
|
|
| 46 | 47 |
import fr.ird.observe.services.ObserveServiceFactory;
|
| 47 | 48 |
import fr.ird.observe.services.ObserveServiceInitializer;
|
| 48 | 49 |
import fr.ird.observe.services.ObserveServiceMainFactoryApplicationComponent;
|
| ... | ... | @@ -51,11 +52,14 @@ import fr.ird.observe.services.service.ObserveService; |
| 51 | 52 |
import fr.ird.observe.services.service.actions.consolidate.dcp.FloatingObjectModification;
|
| 52 | 53 |
import io.ultreia.java4all.application.context.ApplicationComponent;
|
| 53 | 54 |
import io.ultreia.java4all.application.context.ApplicationContext;
|
| 55 |
+import org.apache.logging.log4j.LogManager;
|
|
| 56 |
+import org.apache.logging.log4j.Logger;
|
|
| 54 | 57 |
import org.debux.webmotion.server.call.HttpContext;
|
| 55 | 58 |
import org.nuiton.version.Version;
|
| 56 | 59 |
|
| 57 | 60 |
import javax.servlet.ServletContext;
|
| 58 | 61 |
import java.util.Map;
|
| 62 |
+import java.util.Timer;
|
|
| 59 | 63 |
|
| 60 | 64 |
/**
|
| 61 | 65 |
* @author Tony Chemit - dev@tchemit.fr
|
| ... | ... | @@ -67,6 +71,8 @@ public class ObserveWebApplicationContext extends ApplicationContext { |
| 67 | 71 |
private static final String MISSING_APPLICATION_CONTEXT =
|
| 68 | 72 |
String.format("%s not found. You probably forgot to register %s in your web.xml", ObserveWebApplicationContext.class.getSimpleName(), ObserveWebApplicationListener.class.getName());
|
| 69 | 73 |
|
| 74 |
+ private static final Logger log = LogManager.getLogger(ObserveWebApplicationContext.class);
|
|
| 75 |
+ |
|
| 70 | 76 |
private ObserveDtoGsonSupplier gsonSupplier;
|
| 71 | 77 |
private ServerConfig applicationConfiguration;
|
| 72 | 78 |
private ObserveServiceFactory mainServiceFactory;
|
| ... | ... | @@ -75,6 +81,7 @@ public class ObserveWebApplicationContext extends ApplicationContext { |
| 75 | 81 |
|
| 76 | 82 |
private ObserveWebSecurityApplicationContext securityApplicationContext;
|
| 77 | 83 |
private static ServerConfig applicationConfiguration1;
|
| 84 |
+ private Timer deleteTemporaryFilesTimer;
|
|
| 78 | 85 |
|
| 79 | 86 |
static ObserveWebApplicationContext getApplicationContext(HttpContext context) {
|
| 80 | 87 |
|
| ... | ... | @@ -153,18 +160,26 @@ public class ObserveWebApplicationContext extends ApplicationContext { |
| 153 | 160 |
}
|
| 154 | 161 |
};
|
| 155 | 162 |
}
|
| 163 |
+ if (deleteTemporaryFilesTimer != null) {
|
|
| 164 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 165 |
+ }
|
|
| 166 |
+ deleteTemporaryFilesTimer = CleanTemporaryFilesTask.create(getApplicationConfiguration());
|
|
| 167 |
+ }
|
|
| 168 |
+ |
|
| 169 |
+ @Override
|
|
| 170 |
+ public void close() {
|
|
| 171 |
+ |
|
| 172 |
+ closeDeleteTemporaryFilesTimer();
|
|
| 173 |
+ super.close();
|
|
| 156 | 174 |
}
|
| 157 | 175 |
|
| 158 |
-// @Override
|
|
| 159 |
-// public void close() {
|
|
| 160 |
-//
|
|
| 161 |
-// // Supprimer le cache des sessions
|
|
| 162 |
-// securityApplicationContext.close();
|
|
| 163 |
-//
|
|
| 164 |
-// // Fermer l'usine de services
|
|
| 165 |
-// mainServiceFactory.close();
|
|
| 166 |
-//
|
|
| 167 |
-// }
|
|
| 176 |
+ void closeDeleteTemporaryFilesTimer() {
|
|
| 177 |
+ try {
|
|
| 178 |
+ deleteTemporaryFilesTimer.cancel();
|
|
| 179 |
+ } catch (Exception e) {
|
|
| 180 |
+ log.error("Could not terminates delete temporary files timer...", e);
|
|
| 181 |
+ }
|
|
| 182 |
+ }
|
|
| 168 | 183 |
|
| 169 | 184 |
public ObserveDtoGsonSupplier getGsonSupplier() {
|
| 170 | 185 |
return gsonSupplier;
|
| ... | ... | @@ -27,13 +27,13 @@ import fr.ird.observe.dto.ObserveDbRole; |
| 27 | 27 |
import fr.ird.observe.dto.db.ObserveDbUserDto;
|
| 28 | 28 |
import fr.ird.observe.entities.Entities;
|
| 29 | 29 |
import fr.ird.observe.entities.ObserveTopiaApplicationContext;
|
| 30 |
+import fr.ird.observe.entities.ObserveTopiaConfiguration;
|
|
| 30 | 31 |
import org.apache.commons.lang3.tuple.Pair;
|
| 31 | 32 |
import org.apache.logging.log4j.LogManager;
|
| 32 | 33 |
import org.apache.logging.log4j.Logger;
|
| 33 | 34 |
import org.nuiton.topia.migration.mappings.TMSVersionHibernateDao;
|
| 34 | 35 |
import org.nuiton.topia.persistence.TopiaEntityEnum;
|
| 35 | 36 |
import org.nuiton.topia.persistence.TopiaException;
|
| 36 |
-import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
|
| 37 | 37 |
import org.nuiton.topia.persistence.jdbc.JdbcPostgresHelper;
|
| 38 | 38 |
import org.nuiton.topia.persistence.script.SqlScriptConsumer;
|
| 39 | 39 |
import org.nuiton.topia.persistence.script.SqlScriptWriter;
|
| ... | ... | @@ -81,10 +81,12 @@ public class ObserveSecurityHelper { |
| 81 | 81 |
private static final String SCHEMA_PUBLIC = "public";
|
| 82 | 82 |
private static final Logger log = LogManager.getLogger(ObserveSecurityHelper.class);
|
| 83 | 83 |
private final JdbcPostgresHelper jdbcHelper;
|
| 84 |
+ private final Path temporaryDirectory;
|
|
| 84 | 85 |
|
| 85 | 86 |
|
| 86 |
- public ObserveSecurityHelper(JdbcConfiguration jdbcConfiguration) {
|
|
| 87 |
+ public ObserveSecurityHelper(ObserveTopiaConfiguration jdbcConfiguration) {
|
|
| 87 | 88 |
this.jdbcHelper = new JdbcPostgresHelper(jdbcConfiguration);
|
| 89 |
+ this.temporaryDirectory = jdbcConfiguration.getTemporaryDirectory();
|
|
| 88 | 90 |
}
|
| 89 | 91 |
|
| 90 | 92 |
public void applySecurity(Set<ObserveDbUserDto> users) {
|
| ... | ... | @@ -93,7 +95,7 @@ public class ObserveSecurityHelper { |
| 93 | 95 |
}
|
| 94 | 96 |
Path scriptPath;
|
| 95 | 97 |
try {
|
| 96 |
- scriptPath = Files.createTempFile("topia-sql-script-", ".sql");
|
|
| 98 |
+ scriptPath = Files.createTempFile(temporaryDirectory, "topia-sql-script-", ".sql");
|
|
| 97 | 99 |
} catch (IOException e) {
|
| 98 | 100 |
throw new IllegalStateException("Can't create temporary path", e);
|
| 99 | 101 |
}
|
| ... | ... | @@ -150,6 +150,7 @@ public class ObserveTopiaApplicationContextFactory { |
| 150 | 150 |
configuration.getJdbcUrl(),
|
| 151 | 151 |
configuration.getUsername(),
|
| 152 | 152 |
String.valueOf(configuration.getPassword()),
|
| 153 |
+ configuration.getTemporaryDirectory(),
|
|
| 153 | 154 |
initSchema,
|
| 154 | 155 |
configuration.isTraceSql()
|
| 155 | 156 |
);
|
| ... | ... | @@ -175,6 +176,7 @@ public class ObserveTopiaApplicationContextFactory { |
| 175 | 176 |
configuration.getDbName(),
|
| 176 | 177 |
configuration.getUsername(),
|
| 177 | 178 |
String.valueOf(configuration.getPassword()),
|
| 179 |
+ configuration.getTemporaryDirectory(),
|
|
| 178 | 180 |
initSchema,
|
| 179 | 181 |
configuration.isTraceSql()
|
| 180 | 182 |
);
|
| ... | ... | @@ -69,6 +69,7 @@ import org.nuiton.version.Versions; |
| 69 | 69 |
import java.io.File;
|
| 70 | 70 |
import java.io.IOException;
|
| 71 | 71 |
import java.nio.file.Files;
|
| 72 |
+import java.nio.file.Path;
|
|
| 72 | 73 |
import java.util.LinkedHashSet;
|
| 73 | 74 |
import java.util.Optional;
|
| 74 | 75 |
import java.util.Set;
|
| ... | ... | @@ -108,6 +109,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 108 | 109 |
public ObserveDataSourceInformation checkCanConnectOrBeEmpty(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 109 | 110 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
| 110 | 111 |
|
| 112 |
+ Path temporaryDirectory = serviceContext.getTemporaryDirectoryRoot().toPath();
|
|
| 111 | 113 |
ObserveDataSourceInformation dataSourceInformation;
|
| 112 | 114 |
|
| 113 | 115 |
if (dataSourceConfigurationTopiaSupport.isH2Database()) {
|
| ... | ... | @@ -141,7 +143,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 141 | 143 |
h2DataSourceConfiguration.getDbName(),
|
| 142 | 144 |
h2DataSourceConfiguration.getUsername(),
|
| 143 | 145 |
new String(h2DataSourceConfiguration.getPassword()),
|
| 144 |
- false,
|
|
| 146 |
+ temporaryDirectory, false,
|
|
| 145 | 147 |
false);
|
| 146 | 148 |
|
| 147 | 149 |
|
| ... | ... | @@ -165,7 +167,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 165 | 167 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 166 | 168 |
pgDataSourceConfiguration.getUsername(),
|
| 167 | 169 |
new String(pgDataSourceConfiguration.getPassword()),
|
| 168 |
- false,
|
|
| 170 |
+ temporaryDirectory, false,
|
|
| 169 | 171 |
false);
|
| 170 | 172 |
|
| 171 | 173 |
try {
|
| ... | ... | @@ -188,6 +190,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 188 | 190 |
@Override
|
| 189 | 191 |
public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
|
| 190 | 192 |
|
| 193 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 191 | 194 |
ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
|
| 192 | 195 |
|
| 193 | 196 |
ObserveDataSourceInformation dataSourceInformation;
|
| ... | ... | @@ -223,6 +226,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 223 | 226 |
h2DataSourceConfiguration.getDbName(),
|
| 224 | 227 |
h2DataSourceConfiguration.getUsername(),
|
| 225 | 228 |
new String(h2DataSourceConfiguration.getPassword()),
|
| 229 |
+ temporaryDirectory,
|
|
| 226 | 230 |
false,
|
| 227 | 231 |
false);
|
| 228 | 232 |
|
| ... | ... | @@ -247,6 +251,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 247 | 251 |
ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
|
| 248 | 252 |
pgDataSourceConfiguration.getUsername(),
|
| 249 | 253 |
new String(pgDataSourceConfiguration.getPassword()),
|
| 254 |
+ temporaryDirectory,
|
|
| 250 | 255 |
false,
|
| 251 | 256 |
false);
|
| 252 | 257 |
|
| ... | ... | @@ -266,13 +271,22 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 266 | 271 |
|
| 267 | 272 |
}
|
| 268 | 273 |
|
| 274 |
+ Path getTemporaryDirectory(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
|
| 275 |
+ Path temporaryDirectory = dataSourceConfiguration.getTemporaryDirectory();
|
|
| 276 |
+ if (temporaryDirectory == null) {
|
|
| 277 |
+ temporaryDirectory = serviceContext.getTemporaryDirectoryRoot().toPath();
|
|
| 278 |
+ dataSourceConfiguration.setTemporaryDirectory(temporaryDirectory);
|
|
| 279 |
+ }
|
|
| 280 |
+ return temporaryDirectory;
|
|
| 281 |
+ }
|
|
| 282 |
+ |
|
| 269 | 283 |
@Override
|
| 270 | 284 |
public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration)
|
| 271 | 285 |
throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException,
|
| 272 | 286 |
BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
|
| 273 | 287 |
|
| 274 | 288 |
dataSourceCreateConfiguration.validateConfiguration();
|
| 275 |
- |
|
| 289 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 276 | 290 |
boolean initSchema = !dataSourceCreateConfiguration.isImportDatabase();
|
| 277 | 291 |
|
| 278 | 292 |
ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.createTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration, initSchema);
|
| ... | ... | @@ -291,10 +305,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 291 | 305 |
} else { // base postgres
|
| 292 | 306 |
|
| 293 | 307 |
// on realise les import dans un base H2 temporaire
|
| 294 |
- // FIXME il faut obtenir le repertoit temporaire d'observe plutot que celui du système
|
|
| 295 | 308 |
File tmpDir;
|
| 296 | 309 |
try {
|
| 297 |
- tmpDir = Files.createTempDirectory("obstuna").toFile();
|
|
| 310 |
+ tmpDir = Files.createTempDirectory(temporaryDirectory, "obstuna").toFile();
|
|
| 298 | 311 |
} catch (IOException e) {
|
| 299 | 312 |
throw new IllegalStateException("could not create temporary directory ", e);
|
| 300 | 313 |
}
|
| ... | ... | @@ -455,7 +468,8 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 455 | 468 |
|
| 456 | 469 |
@Override
|
| 457 | 470 |
public ObserveDataSourceConnectionTopia open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
|
| 458 |
- |
|
| 471 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 472 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 459 | 473 |
ObserveDataSourceInformation dataSourceInformation = checkCanConnect(dataSourceConfiguration);
|
| 460 | 474 |
|
| 461 | 475 |
Version dbVersion = dataSourceInformation.getVersion();
|
| ... | ... | @@ -557,6 +571,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 557 | 571 |
@Override
|
| 558 | 572 |
public void applySecurity(ObserveDataSourceConfiguration dataSourceConfiguration, ImmutableSet<ObserveDbUserDto> users) {
|
| 559 | 573 |
|
| 574 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 575 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 576 |
+ |
|
| 560 | 577 |
// pas de securité pour les bases autres que postgresql
|
| 561 | 578 |
if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
|
| 562 | 579 |
|
| ... | ... | @@ -575,6 +592,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS |
| 575 | 592 |
|
| 576 | 593 |
@Override
|
| 577 | 594 |
public void migrateData(ObserveDataSourceConfiguration dataSourceConfiguration) {
|
| 595 |
+ Path temporaryDirectory = getTemporaryDirectory(dataSourceConfiguration);
|
|
| 596 |
+ log.debug("Will use temporary directory: " + temporaryDirectory);
|
|
| 597 |
+ |
|
| 578 | 598 |
ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration);
|
| 579 | 599 |
topiaApplicationContext.getMigrationService().runSchemaMigration();
|
| 580 | 600 |
}
|
| ... | ... | @@ -90,7 +90,6 @@ public class LocalTestClassResource extends TestClassResourceSupport { |
| 90 | 90 |
public ObserveDataSourceConfigurationTopiaH2 createDataSourceConfiguration(Version dbVersion, String dbName, File targetPath, String login, char[] password) throws DataSourceCreateWithNoReferentialImportException, IOException, IncompatibleDataSourceCreateConfigurationException, DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
|
| 91 | 91 |
|
| 92 | 92 |
ObserveDataSourceConfigurationTopiaH2 sharedDatabaseConfiguration = dataSourcesForTestManager.createSharedDataSourceConfigurationH2(dbVersion, dbName, login, password);
|
| 93 |
- |
|
| 94 | 93 |
File sharedDatabaseFile = sharedDatabaseConfiguration.getDatabaseFile();
|
| 95 | 94 |
|
| 96 | 95 |
ObserveDataSourceConfigurationTopiaH2 dataSourceConfiguration;
|
| ... | ... | @@ -101,6 +100,7 @@ public class LocalTestClassResource extends TestClassResourceSupport { |
| 101 | 100 |
if (log.isInfoEnabled()) {
|
| 102 | 101 |
log.info("Create shared database: " + dbVersion.toString() + "/" + dbName + " to " + sharedDatabaseFile);
|
| 103 | 102 |
}
|
| 103 |
+ sharedDatabaseConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 104 | 104 |
|
| 105 | 105 |
try (DataSourceService dataSourceService = newService(sharedDatabaseConfiguration, DataSourceService.class)) {
|
| 106 | 106 |
DataSourceCreateConfigurationDto createConfiguration = new DataSourceCreateConfigurationDto();
|
| ... | ... | @@ -135,12 +135,14 @@ public class LocalTestClassResource extends TestClassResourceSupport { |
| 135 | 135 |
}
|
| 136 | 136 |
|
| 137 | 137 |
dataSourceConfiguration.setModelVersion(ObserveTestConfiguration.getModelVersion());
|
| 138 |
+ dataSourceConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 138 | 139 |
|
| 139 | 140 |
return dataSourceConfiguration;
|
| 140 | 141 |
|
| 141 | 142 |
}
|
| 142 | 143 |
|
| 143 | 144 |
public <S extends ObserveService> S newService(ObserveDataSourceConfiguration dataSourceConfiguration, Class<S> serviceType) {
|
| 145 |
+ dataSourceConfiguration.setTemporaryDirectory(getTemporaryDirectoryRoot());
|
|
| 144 | 146 |
ObserveServiceInitializer observeServiceInitializer = ObserveServiceInitializer.create(
|
| 145 | 147 |
Locale.FRANCE,
|
| 146 | 148 |
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 io.ultreia.java4all.util.Dates;
|
|
| 26 |
+import org.apache.logging.log4j.LogManager;
|
|
| 27 |
+import org.apache.logging.log4j.Logger;
|
|
| 28 |
+ |
|
| 29 |
+import java.io.IOException;
|
|
| 30 |
+import java.nio.file.DirectoryStream;
|
|
| 31 |
+import java.nio.file.Files;
|
|
| 32 |
+import java.nio.file.Path;
|
|
| 33 |
+import java.util.Calendar;
|
|
| 34 |
+import java.util.Date;
|
|
| 35 |
+import java.util.Objects;
|
|
| 36 |
+import java.util.Timer;
|
|
| 37 |
+import java.util.TimerTask;
|
|
| 38 |
+import java.util.concurrent.TimeUnit;
|
|
| 39 |
+ |
|
| 40 |
+/**
|
|
| 41 |
+ * To clean temporaries files.
|
|
| 42 |
+ *
|
|
| 43 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 44 |
+ * @since 8.0
|
|
| 45 |
+ */
|
|
| 46 |
+ |
|
| 47 |
+public class CleanTemporaryFilesTask extends TimerTask {
|
|
| 48 |
+ |
|
| 49 |
+ private static final Logger log = LogManager.getLogger(CleanTemporaryFilesTask.class);
|
|
| 50 |
+ |
|
| 51 |
+ private final CleanTemporaryFilesTaskConfiguration configuration;
|
|
| 52 |
+ |
|
| 53 |
+ public static Timer create(CleanTemporaryFilesTaskConfiguration configuration) {
|
|
| 54 |
+ Timer result = new Timer("Delete temporary files daemon", true);
|
|
| 55 |
+ result.scheduleAtFixedRate(new CleanTemporaryFilesTask(configuration), new Date(), TimeUnit.HOURS.toMillis(1));
|
|
| 56 |
+ return result;
|
|
| 57 |
+ }
|
|
| 58 |
+ |
|
| 59 |
+ public CleanTemporaryFilesTask(CleanTemporaryFilesTaskConfiguration configuration) {
|
|
| 60 |
+ this.configuration = configuration;
|
|
| 61 |
+ }
|
|
| 62 |
+ |
|
| 63 |
+ @Override
|
|
| 64 |
+ public void run() {
|
|
| 65 |
+ |
|
| 66 |
+ Path temporaryDirectory = configuration.getTemporaryDirectory().toPath();
|
|
| 67 |
+ Calendar calendar = Calendar.getInstance();
|
|
| 68 |
+ calendar.setTime(new Date());
|
|
| 69 |
+ calendar.add(Calendar.HOUR_OF_DAY, -configuration.getTemporaryFilesTimeout());
|
|
| 70 |
+ Date deleteBefore = calendar.getTime();
|
|
| 71 |
+ long deleteBeforeTime = deleteBefore.getTime();
|
|
| 72 |
+ |
|
| 73 |
+ log.info(String.format("Delete temporary files in directory %s before %s", temporaryDirectory, deleteBefore));
|
|
| 74 |
+ delete(temporaryDirectory, deleteBeforeTime);
|
|
| 75 |
+ }
|
|
| 76 |
+ |
|
| 77 |
+ private boolean delete(Path path, long deleteBeforeTime) {
|
|
| 78 |
+ try {
|
|
| 79 |
+ Files.walk(path).forEach(p -> {
|
|
| 80 |
+ if (Objects.equals(path, p)) {
|
|
| 81 |
+ return;
|
|
| 82 |
+ }
|
|
| 83 |
+ if (Files.isDirectory(p)) {
|
|
| 84 |
+ boolean deleted = delete(p, deleteBeforeTime);
|
|
| 85 |
+ if (deleted) {
|
|
| 86 |
+ delete0(p, deleteBeforeTime);
|
|
| 87 |
+ }
|
|
| 88 |
+ }
|
|
| 89 |
+ if (Files.isRegularFile(p)) {
|
|
| 90 |
+ delete0(p, deleteBeforeTime);
|
|
| 91 |
+ }
|
|
| 92 |
+ });
|
|
| 93 |
+ if (Files.isRegularFile(path)) {
|
|
| 94 |
+ return Files.notExists(path);
|
|
| 95 |
+ }
|
|
| 96 |
+ if (Files.isDirectory(path)) {
|
|
| 97 |
+ return isDirEmpty(path);
|
|
| 98 |
+ }
|
|
| 99 |
+ return false;
|
|
| 100 |
+ } catch (IOException e) {
|
|
| 101 |
+ throw new RuntimeException(String.format("Could not walk through temporary directory: %s", path), e);
|
|
| 102 |
+ }
|
|
| 103 |
+ }
|
|
| 104 |
+ |
|
| 105 |
+ private static boolean isDirEmpty(final Path directory) throws IOException {
|
|
| 106 |
+ try(DirectoryStream<Path> dirStream = Files.newDirectoryStream(directory)) {
|
|
| 107 |
+ return !dirStream.iterator().hasNext();
|
|
| 108 |
+ }
|
|
| 109 |
+ }
|
|
| 110 |
+ private void delete0(Path p, long deleteBeforeTime) {
|
|
| 111 |
+ try {
|
|
| 112 |
+ if (Files.getLastModifiedTime(p).toMillis() < deleteBeforeTime) {
|
|
| 113 |
+ log.info("Delete temporary file: " + p);
|
|
| 114 |
+ Files.delete(p);
|
|
| 115 |
+ }
|
|
| 116 |
+ } catch (IOException e) {
|
|
| 117 |
+ log.error("Something wrong while process file: " + p, e);
|
|
| 118 |
+ }
|
|
| 119 |
+ }
|
|
| 120 |
+}
|
| 1 |
-package fr.ird.observe.entities;
|
|
| 1 |
+package fr.ird.observe.services.service;
|
|
| 2 | 2 |
|
| 3 |
-/*
|
|
| 3 |
+/*-
|
|
| 4 | 4 |
* #%L
|
| 5 |
- * ObServe :: Persistence
|
|
| 5 |
+ * ObServe :: Services API
|
|
| 6 | 6 |
* %%
|
| 7 | 7 |
* Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
| 8 | 8 |
* %%
|
| ... | ... | @@ -22,17 +22,19 @@ package fr.ird.observe.entities; |
| 22 | 22 |
* #L%
|
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 |
+import java.io.File;
|
|
| 26 |
+ |
|
| 25 | 27 |
/**
|
| 26 |
- * Created on 21/08/15.
|
|
| 27 |
- *
|
|
| 28 | 28 |
* @author Tony Chemit - dev@tchemit.fr
|
| 29 |
+ * @since 8.0
|
|
| 29 | 30 |
*/
|
| 30 |
-public class ObserveTopiaIdFactory extends ObserveTopiaIdFactorySupport {
|
|
| 31 |
+public interface CleanTemporaryFilesTaskConfiguration {
|
|
| 32 |
+ |
|
| 33 |
+ File getTemporaryDirectory();
|
|
| 31 | 34 |
|
| 32 |
- private static final long serialVersionUID = 1L;
|
|
| 35 |
+ void setTemporaryDirectory(File temporaryDirectory);
|
|
| 33 | 36 |
|
| 34 |
- public ObserveTopiaIdFactory() {
|
|
| 35 |
- super("fr.ird.observe.entities.");
|
|
| 36 |
- }
|
|
| 37 |
+ int getTemporaryFilesTimeout();
|
|
| 37 | 38 |
|
| 39 |
+ void setTemporaryFilesTimeout(int temporaryFilesTimeout);
|
|
| 38 | 40 |
}
|