Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3

Commits:

10 changed files:

Changes:

  • pom.xml
    ... ... @@ -102,6 +102,7 @@
    102 102
         <applicationName>t3</applicationName>
    
    103 103
         <t3-data.version>1.9</t3-data.version>
    
    104 104
         <lib.version.java4all.i18n>4.0-alpha-11</lib.version.java4all.i18n>
    
    105
    +    <lib.version.java4all.config>1.0.2-SNAPSHOT</lib.version.java4all.config>
    
    105 106
     
    
    106 107
         <env>dev</env>
    
    107 108
         <skipITs>true</skipITs>
    

  • src/site/markdown/installer.md.vm
    ... ... @@ -27,13 +27,14 @@ Après téléchargement, on dézippe l'archive et on obtient l'arborescence suiv
    27 27
       t3-installer-${project.version}
    
    28 28
       ├── create-db.bat                        (1)
    
    29 29
       ├── create-db.sh                         (1)
    
    30
    +  ├── help.bat                             (1)
    
    31
    +  ├── help.sh                              (1)
    
    30 32
       ├── fill-db.bat                          (1)
    
    31 33
       ├── fill-db.sh                           (1)
    
    32
    -  ├── db.properties                        (2)
    
    33
    -  ├── translate.sh
    
    34
    -  ├── translate.bat
    
    34
    +  ├── translate.sh                         (1)
    
    35
    +  ├── translate.bat                        (1)
    
    35 36
       ├── README.md
    
    36
    -  ├── scripts                              (3)
    
    37
    +  ├── scripts                              (2)
    
    37 38
       │   ├── ddl
    
    38 39
       │   ├── h2
    
    39 40
       │   ├── referential
    
    ... ... @@ -41,25 +42,8 @@ Après téléchargement, on dézippe l'archive et on obtient l'arborescence suiv
    41 42
       └── t3-installer-${project.version}.jar
    
    42 43
     ```
    
    43 44
     
    
    44
    -1. les scripts de lancements
    
    45
    -2. le fichier où enregister la configuration de la base postgres
    
    46
    -3. Répertoire des scripts offert par l'installeur
    
    47
    -
    
    48
    -### Configuration de la base à remplir
    
    49
    -
    
    50
    -Le fichier *db.properties* contient la configuration de connection aux bases.
    
    51
    -
    
    52
    -L'utilisateur doit avoir les droits de création de bases et être super-utilisateur, il sera le propriétaire de toutes les bases créées.
    
    53
    -
    
    54
    -Par défaut, il contient la configuration suivante:
    
    55
    -```
    
    56
    -# Super user login that can create and should be also owner of all t3 databases
    
    57
    -login=t3-admin
    
    58
    -# Super user password that can create and should be also owner of all t3 databases
    
    59
    -password=a
    
    60
    -# Url pattern used to connect to any base
    
    61
    -url=jdbc:postgresql:%s
    
    62
    -```
    
    45
    +1. les scripts
    
    46
    +2. Répertoire des scripts offert par l'installeur
    
    63 47
     
    
    64 48
     # Créer une nouvelle base
    
    65 49
     
    
    ... ... @@ -73,6 +57,14 @@ Sous windows
    73 57
       create-db.bat dbName
    
    74 58
     ```
    
    75 59
     
    
    60
    +Trois questions vous seront posées (login, password, url).
    
    61
    +
    
    62
    +Si les réponses vont conviennent, vous n'avez qu'à presser la touche **Entrée**.
    
    63
    +
    
    64
    +Les réponses sont sauvegardée dans un fichier nommé **t3-installer.conf** dans le répertoire où vous lancer la commande.
    
    65
    +
    
    66
    +Son contenu est relu à chaque nouveau lancement.
    
    67
    +
    
    76 68
     # Remplir une nouvelle base
    
    77 69
     
    
    78 70
     **Il faut que la base soit créée (mais sans schéma) et que l'extension postgis soit installée**.
    
    ... ... @@ -87,6 +79,8 @@ Sous windows
    87 79
       fill-db.bat dbName
    
    88 80
     ```
    
    89 81
     
    
    82
    +Comme pour la commande Créer une nouvelle base, trois questions vous seront posées...
    
    83
    +
    
    90 84
     # Traduire l'application
    
    91 85
     
    
    92 86
     Sous Linux, Mac
    
    ... ... @@ -98,3 +92,15 @@ Sous windows
    98 92
     ```
    
    99 93
       translate.bat
    
    100 94
     ```
    
    95
    +
    
    96
    +# Aide
    
    97
    +
    
    98
    +Sous Linux, Mac
    
    99
    +```
    
    100
    +  sh help.sh
    
    101
    +```
    
    102
    +
    
    103
    +Sous windows
    
    104
    +```
    
    105
    +  help.bat
    
    106
    +```

  • t3-installer/pom.xml
    ... ... @@ -64,10 +64,29 @@
    64 64
     
    
    65 65
         <dependency>
    
    66 66
           <groupId>io.ultreia.java4all.i18n</groupId>
    
    67
    +      <artifactId>i18n-api</artifactId>
    
    68
    +    </dependency>
    
    69
    +    <dependency>
    
    70
    +      <groupId>io.ultreia.java4all.i18n</groupId>
    
    67 71
           <artifactId>i18n-editor</artifactId>
    
    68 72
         </dependency>
    
    69 73
     
    
    70 74
         <dependency>
    
    75
    +      <groupId>org.nuiton</groupId>
    
    76
    +      <artifactId>nuiton-utils</artifactId>
    
    77
    +    </dependency>
    
    78
    +
    
    79
    +    <dependency>
    
    80
    +      <groupId>commons-logging</groupId>
    
    81
    +      <artifactId>commons-logging</artifactId>
    
    82
    +    </dependency>
    
    83
    +
    
    84
    +    <dependency>
    
    85
    +      <groupId>com.google.guava</groupId>
    
    86
    +      <artifactId>guava</artifactId>
    
    87
    +    </dependency>
    
    88
    +
    
    89
    +    <dependency>
    
    71 90
           <groupId>com.h2database</groupId>
    
    72 91
           <artifactId>h2</artifactId>
    
    73 92
           <scope>runtime</scope>
    

  • t3-installer/src/main/assembly/dist/db.properties deleted
    1
    -###
    
    2
    -# #%L
    
    3
    -# T3 :: Installer
    
    4
    -# %%
    
    5
    -# Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
    
    6
    -# %%
    
    7
    -# This program is free software: you can redistribute it and/or modify
    
    8
    -# it under the terms of the GNU Affero General Public License as published by
    
    9
    -# the Free Software Foundation, either version 3 of the License, or
    
    10
    -# (at your option) any later version.
    
    11
    -# 
    
    12
    -# This program is distributed in the hope that it will be useful,
    
    13
    -# but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    -# GNU General Public License for more details.
    
    16
    -# 
    
    17
    -# You should have received a copy of the GNU Affero General Public License
    
    18
    -# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19
    -# #L%
    
    20
    -###
    
    21
    -
    
    22
    -# Super user login that can create and should be also owner of all t3 databases
    
    23
    -login=t3-admin
    
    24
    -# Super user password that can create and should be also owner of all t3 databases
    
    25
    -password=a
    
    26
    -# Url pattern used to connect to any base (if you need to change it, please keep the %s, it will be replaced by db name)
    
    27
    -url=jdbc:postgresql:%s
    \ No newline at end of file

  • t3-installer/src/main/assembly/dist/help.bat
    1
    +java  -Xmx2048M -Xms512M -jar ${project.build.finalName}.jar --help
    \ No newline at end of file

  • t3-installer/src/main/assembly/dist/help.sh
    1
    +#!/bin/sh
    
    2
    +
    
    3
    +java  -Xmx2048M -Xms512M -jar ${project.build.finalName}.jar --help

  • t3-installer/src/main/config/T3Installer.ini
    1
    +description = T3 Installer Config
    
    2
    +
    
    3
    +[option filename]
    
    4
    +description = Config filename
    
    5
    +key = config.file
    
    6
    +type = string
    
    7
    +defaultValue = t3-installer.conf
    
    8
    +
    
    9
    +
    
    10
    +[option login]
    
    11
    +description = Login
    
    12
    +key = login
    
    13
    +type = string
    
    14
    +
    
    15
    +[option password]
    
    16
    +description = Password
    
    17
    +key = password
    
    18
    +type = string
    
    19
    +
    
    20
    +[option dbName]
    
    21
    +description = Database's name
    
    22
    +key = dbName
    
    23
    +type = string
    
    24
    +
    
    25
    +[option url]
    
    26
    +description = Jdbc connection url
    
    27
    +key = url
    
    28
    +type = string
    
    29
    +defaultValue = jdbc:postgresql:${dbName}
    
    30
    +
    
    1 31
     [action createDb]
    
    32
    +description = To create a new database (requires one argument: dbName)
    
    2 33
     action = fr.ird.t3.console.T3DatabaseTool#create
    
    3 34
     aliases = --create-db
    
    4 35
     
    
    5 36
     [action fillDb]
    
    37
    +description = To fill a database (requires one argument: dbName)
    
    6 38
     action = fr.ird.t3.console.T3DatabaseTool#fill
    
    7 39
     aliases = --fill-db
    
    8 40
     
    
    9 41
     [action translate]
    
    42
    +description = Launch T3 Translate tool
    
    10 43
     action = fr.ird.t3.console.T3I18nTool#start
    
    11
    -aliases = --translate
    44
    +aliases = --translate, -t
    
    45
    +
    
    46
    +[action help]
    
    47
    +description = Display help
    
    48
    +action = fr.ird.t3.console.T3Console#help
    
    49
    +aliases = --help, -h

  • t3-installer/src/main/java/fr/ird/t3/console/T3Console.java
    ... ... @@ -21,13 +21,15 @@ package fr.ird.t3.console;
    21 21
      * #L%
    
    22 22
      */
    
    23 23
     
    
    24
    -import fr.ird.t3.T3Config;
    
    25 24
     import fr.ird.t3.installer.T3InstallerConfig;
    
    26
    -import io.ultreia.java4all.config.ApplicationConfig;
    
    25
    +import io.ultreia.java4all.config.ApplicationConfigInit;
    
    26
    +import io.ultreia.java4all.config.ApplicationConfigScope;
    
    27
    +import io.ultreia.java4all.config.ArgumentsParserException;
    
    27 28
     
    
    28
    -import java.io.File;
    
    29
    +import java.io.Console;
    
    29 30
     import java.util.Arrays;
    
    30 31
     import java.util.Date;
    
    32
    +import java.util.Objects;
    
    31 33
     
    
    32 34
     /**
    
    33 35
      * Created by tchemit on 13/03/2018.
    
    ... ... @@ -39,13 +41,70 @@ public class T3Console {
    39 41
         public static void main(String... args) throws Exception {
    
    40 42
             System.out.printf("Starting T3 Console with arguments: %s at %s %n", Arrays.toString(args), new Date());
    
    41 43
     
    
    42
    -        T3Config config = new T3Config();
    
    43
    -        config.parse();
    
    44
    -        config.setScriptsDirectory(new File("scripts"));
    
    45
    -        T3Config.set(config);
    
    44
    +        if (args.length == 0) {
    
    45
    +            throw new IllegalArgumentException("Need at least one argument. Try with --help to get details.");
    
    46
    +        }
    
    46 47
     
    
    47
    -        ApplicationConfig installerConfig = new T3InstallerConfig().get();
    
    48
    -        installerConfig.parse(args);
    
    49
    -        installerConfig.doAllAction();
    
    48
    +        T3InstallerConfig installerConfig;
    
    49
    +
    
    50
    +        String action = args[0];
    
    51
    +
    
    52
    +        if (action.contains("db")) {
    
    53
    +
    
    54
    +            if (args.length != 2) {
    
    55
    +                throw new IllegalArgumentException(String.format("Need one arguments for command %s. Try with --help to get details.", action));
    
    56
    +            }
    
    57
    +
    
    58
    +            installerConfig = new T3InstallerConfig(ApplicationConfigInit.forAllScopesWithout(ApplicationConfigScope.HOME, ApplicationConfigScope.SYSTEM).setConfigFileName(args[1]));
    
    59
    +            installerConfig.get().parse(args);
    
    60
    +
    
    61
    +            Console console = System.console();
    
    62
    +
    
    63
    +            String login = readValue(console, "Login", installerConfig.getLogin());
    
    64
    +            if (login != null) {
    
    65
    +                installerConfig.setLogin(login);
    
    66
    +            }
    
    67
    +            String password = readValue(console, "Password", installerConfig.getPassword());
    
    68
    +            if (password != null) {
    
    69
    +                installerConfig.setPassword(password);
    
    70
    +            }
    
    71
    +            String url = readValue(console, "Url", installerConfig.getUrl());
    
    72
    +            if (url != null) {
    
    73
    +                installerConfig.setUrl(url);
    
    74
    +            }
    
    75
    +            installerConfig.get().saveForCurrent();
    
    76
    +        } else {
    
    77
    +
    
    78
    +            installerConfig = new T3InstallerConfig();
    
    79
    +            installerConfig.get().parse(args);
    
    80
    +
    
    81
    +        }
    
    82
    +        installerConfig.get().doAllAction();
    
    83
    +    }
    
    84
    +
    
    85
    +    private static String readValue(Console console, String fieldName, String fieldValue) {
    
    86
    +        String result = null;
    
    87
    +        while (result == null) {
    
    88
    +            console.printf("%s [%s]: ", fieldName, fieldValue == null ? "Not defined" : fieldValue);
    
    89
    +            result = console.readLine().trim();
    
    90
    +            if (fieldValue == null) {
    
    91
    +                if (result.isEmpty()) {
    
    92
    +                    result = null;
    
    93
    +                }
    
    94
    +            } else {
    
    95
    +                if (result.isEmpty()) {
    
    96
    +                    result = fieldValue;
    
    97
    +                }
    
    98
    +            }
    
    99
    +        }
    
    100
    +
    
    101
    +        return Objects.equals(fieldValue, result) ? null : result;
    
    102
    +    }
    
    103
    +
    
    104
    +    public void help() throws ArgumentsParserException {
    
    105
    +        T3InstallerConfig config = new T3InstallerConfig();
    
    106
    +
    
    107
    +        config.get().parse();
    
    108
    +        System.out.println(config.getConfigurationDescription());
    
    50 109
         }
    
    51 110
     }

  • t3-domain/src/main/java/fr/ird/t3/console/T3DatabaseTool.javat3-installer/src/main/java/fr/ird/t3/console/T3DatabaseTool.java
    ... ... @@ -2,7 +2,7 @@ package fr.ird.t3.console;
    2 2
     
    
    3 3
     /*-
    
    4 4
      * #%L
    
    5
    - * T3 :: Domain
    
    5
    + * T3 :: Installer
    
    6 6
      * %%
    
    7 7
      * Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
    
    8 8
      * %%
    
    ... ... @@ -10,25 +10,26 @@ package fr.ird.t3.console;
    10 10
      * it under the terms of the GNU Affero General Public License as published by
    
    11 11
      * the Free Software Foundation, either version 3 of the License, or
    
    12 12
      * (at your option) any later version.
    
    13
    - *
    
    13
    + * 
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - *
    
    18
    + * 
    
    19 19
      * You should have received a copy of the GNU Affero General Public License
    
    20 20
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    21 21
      * #L%
    
    22 22
      */
    
    23 23
     
    
    24 24
     import com.google.common.base.Preconditions;
    
    25
    -import fr.ird.t3.T3Config;
    
    26 25
     import fr.ird.t3.T3SqlScriptsImporter;
    
    27 26
     import fr.ird.t3.entities.T3EntityHelper;
    
    28 27
     import fr.ird.t3.entities.T3JdbcHelper;
    
    29 28
     import fr.ird.t3.entities.T3TopiaApplicationContext;
    
    30 29
     import fr.ird.t3.entities.T3TopiaApplicationContextBuilder;
    
    31 30
     import fr.ird.t3.entities.user.JdbcConfiguration;
    
    31
    +import fr.ird.t3.installer.T3InstallerConfigOption;
    
    32
    +import io.ultreia.java4all.config.ApplicationConfig;
    
    32 33
     import org.apache.commons.logging.Log;
    
    33 34
     import org.apache.commons.logging.LogFactory;
    
    34 35
     import org.nuiton.i18n.I18n;
    
    ... ... @@ -37,7 +38,6 @@ import org.nuiton.util.FileUtil;
    37 38
     import org.nuiton.util.ZipUtil;
    
    38 39
     
    
    39 40
     import java.io.File;
    
    40
    -import java.io.FileInputStream;
    
    41 41
     import java.io.IOException;
    
    42 42
     import java.sql.Connection;
    
    43 43
     import java.sql.DriverManager;
    
    ... ... @@ -47,7 +47,6 @@ import java.sql.SQLException;
    47 47
     import java.util.List;
    
    48 48
     import java.util.Locale;
    
    49 49
     import java.util.Objects;
    
    50
    -import java.util.Properties;
    
    51 50
     
    
    52 51
     /**
    
    53 52
      * Tool around T3 database.
    
    ... ... @@ -60,25 +59,27 @@ public class T3DatabaseTool {
    60 59
     
    
    61 60
         private static final Log log = LogFactory.getLog(T3DatabaseTool.class);
    
    62 61
     
    
    62
    +    private final ApplicationConfig config;
    
    63
    +
    
    64
    +    public T3DatabaseTool(ApplicationConfig config) {
    
    65
    +        this.config = config;
    
    66
    +    }
    
    67
    +
    
    63 68
         @SuppressWarnings("unused")
    
    64
    -    public void create(File connectionFile, String databaseName) throws IOException, SQLException {
    
    65
    -        createOrFill(connectionFile, databaseName, true);
    
    69
    +    public void create(String databaseName) throws IOException, SQLException {
    
    70
    +        createOrFill(databaseName, true);
    
    66 71
         }
    
    67 72
     
    
    68 73
         @SuppressWarnings("unused")
    
    69
    -    public void fill(File connectionFile, String databaseName) throws IOException, SQLException {
    
    70
    -        createOrFill(connectionFile, databaseName, false);
    
    74
    +    public void fill(String databaseName) throws IOException, SQLException {
    
    75
    +        createOrFill(databaseName, false);
    
    71 76
         }
    
    72 77
     
    
    73
    -    private void createOrFill(File connectionFile, String databaseName, boolean create) throws IOException, SQLException {
    
    78
    +    private void createOrFill(String databaseName, boolean create) throws IOException, SQLException {
    
    74 79
     
    
    75
    -        Objects.requireNonNull(connectionFile);
    
    76
    -        Preconditions.checkArgument(connectionFile.exists(), String.format("%s was not found!", connectionFile));
    
    77 80
             Objects.requireNonNull(databaseName);
    
    78 81
     
    
    79
    -        T3Config config = Objects.requireNonNull(T3Config.instance());
    
    80
    -
    
    81
    -        File scriptsDirectory = config.getScriptsDirectory();
    
    82
    +        File scriptsDirectory = new File(new File("scripts").getAbsolutePath());
    
    82 83
             Preconditions.checkArgument(scriptsDirectory.exists(), String.format("%s was not found!", scriptsDirectory));
    
    83 84
     
    
    84 85
             File ddlDirectory = new File(scriptsDirectory, "ddl");
    
    ... ... @@ -93,7 +94,7 @@ public class T3DatabaseTool {
    93 94
             File[] postgisDataFiles = Objects.requireNonNull(postgisDataScript.listFiles((dir, name) -> name.endsWith(".zip")));
    
    94 95
             log.info("1/5 - Setup and connect to database...");
    
    95 96
     
    
    96
    -        T3TopiaApplicationContext applicationContext = setup(connectionFile, databaseName, create);
    
    97
    +        T3TopiaApplicationContext applicationContext = setup(databaseName, create);
    
    97 98
     
    
    98 99
             try {
    
    99 100
                 log.info("2/5 - Create database schema...");
    
    ... ... @@ -121,19 +122,14 @@ public class T3DatabaseTool {
    121 122
             }
    
    122 123
         }
    
    123 124
     
    
    124
    -    private T3TopiaApplicationContext setup(File connectionFile, String databaseName, boolean create) throws IOException, SQLException {
    
    125
    +    private T3TopiaApplicationContext setup(String databaseName, boolean create) throws SQLException {
    
    125 126
             DefaultI18nInitializer i18nInitializer = new DefaultI18nInitializer("t3-i18n");
    
    126 127
             i18nInitializer.setMissingKeyReturnNull(true);
    
    127 128
             I18n.init(i18nInitializer, Locale.getDefault());
    
    128 129
     
    
    129
    -        Properties p = new Properties();
    
    130
    -        try (FileInputStream inputStream = new FileInputStream(connectionFile)) {
    
    131
    -            p.load(inputStream);
    
    132
    -        }
    
    133
    -
    
    134
    -        String login = Objects.requireNonNull(p.getProperty("login"), String.format("login property not found in file %s", connectionFile));
    
    135
    -        String password = Objects.requireNonNull(p.getProperty("password"), String.format("password property not found in file %s", connectionFile));
    
    136
    -        String urlPattern = Objects.requireNonNull(p.getProperty("url"), String.format("url property not found in file %s", connectionFile));
    
    130
    +        String login = Objects.requireNonNull(config.getOption(T3InstallerConfigOption.LOGIN.getKey()));
    
    131
    +        String password = Objects.requireNonNull(config.getOption(T3InstallerConfigOption.PASSWORD.getKey()));
    
    132
    +        String urlPattern = Objects.requireNonNull(config.getOption(T3InstallerConfigOption.URL.getKey()));
    
    137 133
     
    
    138 134
             String adminUrl = String.format(urlPattern, "postgres");
    
    139 135
             try (Connection connection = DriverManager.getConnection(adminUrl, login, password)) {
    

  • t3-installer/src/test/resources/log4j.properties
    1 1
     ###
    
    2 2
     # #%L
    
    3
    -# T3 :: Test
    
    3
    +# T3 :: Installer
    
    4 4
     # %%
    
    5 5
     # Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
    
    6 6
     # %%