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

Commits:

12 changed files:

Changes:

  • client/pom.xml
    ... ... @@ -375,6 +375,10 @@
    375 375
           <groupId>fr.ird.observe.toolkit</groupId>
    
    376 376
           <artifactId>common-service</artifactId>
    
    377 377
         </dependency>
    
    378
    +    <dependency>
    
    379
    +      <groupId>fr.ird.observe.toolkit</groupId>
    
    380
    +      <artifactId>topia-extension</artifactId>
    
    381
    +    </dependency>
    
    378 382
     
    
    379 383
         <dependency>
    
    380 384
           <groupId>io.ultreia.java4all</groupId>
    

  • client/src/test/java/fr/ird/observe/client/DataSourcesForTestManager.java
    ... ... @@ -10,23 +10,23 @@ package fr.ird.observe.client;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
    
    26 25
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    27 26
     import fr.ird.observe.test.TestHelper;
    
    28 27
     import org.apache.commons.logging.Log;
    
    29 28
     import org.apache.commons.logging.LogFactory;
    
    29
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    30 30
     import org.nuiton.version.Version;
    
    31 31
     
    
    32 32
     import java.io.File;
    
    ... ... @@ -100,7 +100,7 @@ public class DataSourcesForTestManager {
    100 100
             configurationTopiaH2.setDirectory(localDbFile);
    
    101 101
             configurationTopiaH2.setDbName("obstuna");
    
    102 102
             configurationTopiaH2.setAutoMigrate(true);
    
    103
    -        configurationTopiaH2.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
    
    103
    +        configurationTopiaH2.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
    
    104 104
             return configurationTopiaH2;
    
    105 105
     
    
    106 106
         }
    
    ... ... @@ -116,7 +116,7 @@ public class DataSourcesForTestManager {
    116 116
         private void deleteDirectory(Path directory) {
    
    117 117
             try {
    
    118 118
                 log.debug(String.format("Delete directory: %s", directory));
    
    119
    -            Files.walk(directory).filter(f->!f.equals(directory)).forEach(f -> {
    
    119
    +            Files.walk(directory).filter(f -> !f.equals(directory)).forEach(f -> {
    
    120 120
                     try {
    
    121 121
                         if (Files.isDirectory(f)) {
    
    122 122
                             deleteDirectory(f);
    

  • persistence/pom.xml
    ... ... @@ -52,7 +52,6 @@
    52 52
         <dependency>
    
    53 53
           <groupId>fr.ird.observe.toolkit</groupId>
    
    54 54
           <artifactId>topia-extension</artifactId>
    
    55
    -      <version>${observeToolkitVersion}</version>
    
    56 55
         </dependency>
    
    57 56
     
    
    58 57
         <dependency>
    

  • persistence/src/main/java/fr/ird/observe/persistence/migration/ObserveMigrationConfigurationProvider.java deleted
    1
    -package fr.ird.observe.persistence.migration;
    
    2
    -
    
    3
    -/*-
    
    4
    - * #%L
    
    5
    - * ObServe :: Persistence
    
    6
    - * %%
    
    7
    - * Copyright (C) 2008 - 2018 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 com.google.common.collect.ImmutableList;
    
    26
    -import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    27
    -import org.nuiton.version.Version;
    
    28
    -import org.nuiton.version.VersionBuilder;
    
    29
    -
    
    30
    -import java.util.List;
    
    31
    -
    
    32
    -/**
    
    33
    - * Created on 01/08/16.
    
    34
    - *
    
    35
    - * @author Tony Chemit - dev@tchemit.fr
    
    36
    - * @since 5.0
    
    37
    - */
    
    38
    -public final class ObserveMigrationConfigurationProvider {
    
    39
    -
    
    40
    -    private static ObserveMigrationConfigurationProvider INSTANCE;
    
    41
    -
    
    42
    -    private final MigrationVersionResourceProvider resourceProvider;
    
    43
    -
    
    44
    -    private ObserveMigrationConfigurationProvider() {
    
    45
    -        resourceProvider = new MigrationVersionResourceProvider();
    
    46
    -    }
    
    47
    -
    
    48
    -    public static ObserveMigrationConfigurationProvider get() {
    
    49
    -        if (INSTANCE == null) {
    
    50
    -            INSTANCE = new ObserveMigrationConfigurationProvider();
    
    51
    -        }
    
    52
    -        return INSTANCE;
    
    53
    -    }
    
    54
    -
    
    55
    -    public List<Version> getAvailableVersions() {
    
    56
    -        return resourceProvider.getAvailableVersions();
    
    57
    -    }
    
    58
    -
    
    59
    -    public Version getLastVersion() {
    
    60
    -        return resourceProvider.getLastVersion();
    
    61
    -    }
    
    62
    -
    
    63
    -    public ImmutableList<Version> getVersionsAfter(Version current) {
    
    64
    -        return resourceProvider.getVersionsAfter(current);
    
    65
    -    }
    
    66
    -
    
    67
    -    public Version getMinimumVersion() {
    
    68
    -        return VersionBuilder.create("3.0").build();
    
    69
    -    }
    
    70
    -
    
    71
    -}

  • persistence/src/main/java/fr/ird/observe/persistence/migration/ObserveTopiaMigrationServiceAskUserToMigrate.java
    ... ... @@ -35,12 +35,13 @@ import java.util.List;
    35 35
      * @author Tony Chemit - dev@tchemit.fr
    
    36 36
      */
    
    37 37
     @AutoService(TopiaMigrationServiceAskUserToMigrate.class)
    
    38
    +@SuppressWarnings("WeakerAccess")
    
    38 39
     public class ObserveTopiaMigrationServiceAskUserToMigrate implements TopiaMigrationServiceAskUserToMigrate {
    
    39 40
     
    
    40
    -    private final Version minimumVersion = VersionBuilder.create("3.0").build();
    
    41
    +    private static final Version MINIMUM_VERSION = VersionBuilder.create("3.0").build();
    
    41 42
     
    
    42
    -    public Version getMinimumVersion() {
    
    43
    -        return minimumVersion;
    
    43
    +    public static Version getMinimumVersion() {
    
    44
    +        return MINIMUM_VERSION;
    
    44 45
         }
    
    45 46
     
    
    46 47
         @Override
    

  • pom.xml
    ... ... @@ -152,7 +152,7 @@
    152 152
         <maven.build.timestamp.format>dd/MM/yyyy HH:mm z</maven.build.timestamp.format>
    
    153 153
         <buildDate>${maven.build.timestamp}</buildDate>
    
    154 154
     
    
    155
    -    <observeToolkitVersion>3.4-SNAPSHOT</observeToolkitVersion>
    
    155
    +    <observeToolkitVersion>3.5-SNAPSHOT</observeToolkitVersion>
    
    156 156
     
    
    157 157
         <!--<lib.version.java4all.jaxx>3.0-alpha-31</lib.version.java4all.jaxx>-->
    
    158 158
         <!--<lib.version.nuiton.topia>3.4.2-SNAPSHOT</lib.version.nuiton.topia>-->
    

  • services-local/src/main/java/fr/ird/observe/services/local/ObserveJdbcHelper.java deleted
    1
    -package fr.ird.observe.services.local;
    
    2
    -
    
    3
    -/*-
    
    4
    - * #%L
    
    5
    - * ObServe :: Services local implementation
    
    6
    - * %%
    
    7
    - * Copyright (C) 2008 - 2018 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 com.google.common.collect.Lists;
    
    26
    -import com.google.common.collect.Sets;
    
    27
    -import fr.ird.observe.dto.ObserveDbRole;
    
    28
    -import fr.ird.observe.dto.db.ObserveDbUserDto;
    
    29
    -import org.apache.commons.lang3.tuple.Pair;
    
    30
    -import org.apache.commons.logging.Log;
    
    31
    -import org.apache.commons.logging.LogFactory;
    
    32
    -import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
    
    33
    -import org.nuiton.topia.persistence.jdbc.JdbcHelper;
    
    34
    -import org.nuiton.version.Version;
    
    35
    -import org.nuiton.version.Versions;
    
    36
    -
    
    37
    -import java.sql.Connection;
    
    38
    -import java.sql.DatabaseMetaData;
    
    39
    -import java.sql.PreparedStatement;
    
    40
    -import java.sql.ResultSet;
    
    41
    -import java.sql.SQLException;
    
    42
    -import java.util.ArrayList;
    
    43
    -import java.util.Collections;
    
    44
    -import java.util.LinkedHashSet;
    
    45
    -import java.util.List;
    
    46
    -import java.util.Set;
    
    47
    -
    
    48
    -/**
    
    49
    - * @author Tony Chemit - dev@tchemit.fr
    
    50
    - */
    
    51
    -public class ObserveJdbcHelper extends JdbcHelper {
    
    52
    -
    
    53
    -    private static final Set<String> POSTGIS_TABLES = Sets.newHashSet("geometry_columns", "spatial_ref_sys");
    
    54
    -    private static final Log log = LogFactory.getLog(ObserveJdbcHelper.class);
    
    55
    -
    
    56
    -
    
    57
    -    public ObserveJdbcHelper(JdbcConfiguration jdbcConfiguration) {
    
    58
    -        super(jdbcConfiguration);
    
    59
    -    }
    
    60
    -
    
    61
    -    public Set<String> getTablePrivileges(String schema, String tableName) {
    
    62
    -        Connection connection = null;
    
    63
    -        try {
    
    64
    -            connection = openConnection();
    
    65
    -            DatabaseMetaData metaData = connection.getMetaData();
    
    66
    -            ResultSet observerDataPrivilege = metaData.getTablePrivileges(null, schema, tableName);
    
    67
    -
    
    68
    -            Set<String> tablePrivileges = Sets.newHashSet();
    
    69
    -
    
    70
    -            while (observerDataPrivilege.next()) {
    
    71
    -                String security = observerDataPrivilege.getString("PRIVILEGE");
    
    72
    -                String grantor = observerDataPrivilege.getString("GRANTOR");
    
    73
    -                String grantee = observerDataPrivilege.getString("GRANTEE");
    
    74
    -                // Il se peut que le login soit echappe sous la forme \"login\"
    
    75
    -                grantor= grantor.replaceAll("\\\\\"", "");
    
    76
    -                grantee = grantee.replaceAll("\\\\\"", "");
    
    77
    -                if (log.isDebugEnabled()) {
    
    78
    -                    log.debug(String.format("(security %s) - grantee (%s)", security, grantee));
    
    79
    -                }
    
    80
    -                if (grantor.equals(jdbcConfiguration.getJdbcConnectionUser())) {
    
    81
    -                    if (log.isDebugEnabled()) {
    
    82
    -                        log.debug("for " + tableName + " table " + grantor + '/' + security);
    
    83
    -                    }
    
    84
    -                    tablePrivileges.add(security);
    
    85
    -                } else if (grantee.equals(jdbcConfiguration.getJdbcConnectionUser())) {
    
    86
    -                    if (log.isDebugEnabled()) {
    
    87
    -                        log.debug("for " + tableName + " table " + grantee + '/' + security);
    
    88
    -                    }
    
    89
    -                    tablePrivileges.add(security);
    
    90
    -                }
    
    91
    -            }
    
    92
    -
    
    93
    -            return tablePrivileges;
    
    94
    -
    
    95
    -        } catch (SQLException e) {
    
    96
    -            throw new RuntimeException(e);
    
    97
    -        } finally {
    
    98
    -            closeQuietly(connection);
    
    99
    -        }
    
    100
    -
    
    101
    -    }
    
    102
    -
    
    103
    -    public Version getVersion() {
    
    104
    -        Version version = Version.VZERO;
    
    105
    -
    
    106
    -        Connection connection = null;
    
    107
    -        PreparedStatement preparedStatement = null;
    
    108
    -        try {
    
    109
    -            connection = openConnection();
    
    110
    -            // la connexion est reussie, on recherche les droits de
    
    111
    -            // récupération de la version de la base
    
    112
    -            preparedStatement = connection.prepareStatement("SELECT version FROM tms_version;");
    
    113
    -            ResultSet resultSet = preparedStatement.executeQuery();
    
    114
    -
    
    115
    -            if (resultSet.next()) {
    
    116
    -                String versionStr = resultSet.getString(1);
    
    117
    -                version = Versions.valueOf(versionStr);
    
    118
    -            }
    
    119
    -
    
    120
    -        } catch (SQLException e) {
    
    121
    -            if (log.isErrorEnabled()) {
    
    122
    -                log.error(e);
    
    123
    -            }
    
    124
    -        } finally {
    
    125
    -            closeQuietly(preparedStatement);
    
    126
    -            closeQuietly(connection);
    
    127
    -        }
    
    128
    -
    
    129
    -        return version;
    
    130
    -
    
    131
    -    }
    
    132
    -
    
    133
    -    public List<ObserveDbUserDto> getUsers() {
    
    134
    -        Connection connection = null;
    
    135
    -        PreparedStatement preparedStatement = null;
    
    136
    -        List<ObserveDbUserDto> users = Lists.newLinkedList();
    
    137
    -
    
    138
    -        try {
    
    139
    -            connection = openConnection();
    
    140
    -            // la connexion est reussie, on recherche les droits de
    
    141
    -            // récupération de la version de la base
    
    142
    -            preparedStatement = connection.prepareStatement("SELECT rolname FROM pg_catalog.pg_roles;");
    
    143
    -            ResultSet resultSet = preparedStatement.executeQuery();
    
    144
    -
    
    145
    -            while (resultSet.next()) {
    
    146
    -                String name = resultSet.getString(1);
    
    147
    -                ObserveDbUserDto user = new ObserveDbUserDto();
    
    148
    -                user.setName(name);
    
    149
    -                if (jdbcConfiguration.getJdbcConnectionUser().equals(name)) {
    
    150
    -                    user.setRole(ObserveDbRole.ADMINISTRATOR);
    
    151
    -                } else {
    
    152
    -                    user.setRole(ObserveDbRole.UNUSED);
    
    153
    -                }
    
    154
    -
    
    155
    -                users.add(user);
    
    156
    -            }
    
    157
    -
    
    158
    -            return users;
    
    159
    -
    
    160
    -        } catch (SQLException e) {
    
    161
    -            throw new RuntimeException(e);
    
    162
    -        } finally {
    
    163
    -            closeQuietly(preparedStatement);
    
    164
    -            closeQuietly(connection);
    
    165
    -        }
    
    166
    -    }
    
    167
    -
    
    168
    -    public List<Pair<String, String>> getTables(Set<String> schemas, Set<String> extraTables) {
    
    169
    -        List<Pair<String, String>> result = new ArrayList<>();
    
    170
    -
    
    171
    -        Connection connection = null;
    
    172
    -        ResultSet tables = null;
    
    173
    -
    
    174
    -        try {
    
    175
    -            // recuperation des tables sur la base
    
    176
    -            connection = openConnection();
    
    177
    -            DatabaseMetaData data = connection.getMetaData();
    
    178
    -            tables = data.getTables(null,
    
    179
    -                                    null,
    
    180
    -                                    null,
    
    181
    -                                    new String[]{"TABLE"}
    
    182
    -            );
    
    183
    -
    
    184
    -            int columnCount = tables.getMetaData().getColumnCount();
    
    185
    -
    
    186
    -            if (log.isDebugEnabled()) {
    
    187
    -                StringBuilder builder = new StringBuilder();
    
    188
    -                builder.append("\nheader");
    
    189
    -                for (int i = 1; i <= columnCount; i++) {
    
    190
    -                    String columnName = tables.getMetaData().getColumnName(i);
    
    191
    -                    builder.append("\n [").append(i).append("] :").append(columnName);
    
    192
    -                }
    
    193
    -                log.debug(builder.toString());
    
    194
    -                log.debug("fetchSize : " + tables.getFetchSize());
    
    195
    -            }
    
    196
    -            while (tables.next()) {
    
    197
    -                String schemaName = tables.getString(2);
    
    198
    -                String tableName = tables.getString(3);
    
    199
    -                if (log.isDebugEnabled()) {
    
    200
    -                    log.debug(String.format("Discover table named %s", tables));
    
    201
    -                }
    
    202
    -                if (!extraTables.contains(tableName)) {
    
    203
    -
    
    204
    -                    if (POSTGIS_TABLES.contains(tableName)) {
    
    205
    -                        continue;
    
    206
    -                    }
    
    207
    -
    
    208
    -                    if (schemaName == null || !schemas.contains(schemaName.toLowerCase())) {
    
    209
    -                        continue;
    
    210
    -                    }
    
    211
    -
    
    212
    -                }
    
    213
    -
    
    214
    -                if (log.isDebugEnabled()) {
    
    215
    -                    log.debug(String.format("Keep table: %s", tables));
    
    216
    -                }
    
    217
    -                result.add(Pair.of(schemaName, tableName));
    
    218
    -            }
    
    219
    -
    
    220
    -            Collections.sort(result);
    
    221
    -            return result;
    
    222
    -        } catch (SQLException e) {
    
    223
    -            throw new RuntimeException(e);
    
    224
    -        } finally {
    
    225
    -            closeQuietly(connection);
    
    226
    -            closeQuietly(tables);
    
    227
    -        }
    
    228
    -    }
    
    229
    -
    
    230
    -    public Set<String> getPostgisFunctions(String functionPattern) {
    
    231
    -
    
    232
    -        final Set<String> result = new LinkedHashSet<>();
    
    233
    -        Connection connection = null;
    
    234
    -        PreparedStatement preparedStatement = null;
    
    235
    -
    
    236
    -        String sql = String.format("SELECT ns.nspname::text || '.' ||  p.proname::text || '(' || oidvectortypes(p.proargtypes)::text || ')'" +
    
    237
    -                                           " FROM pg_proc p INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)" +
    
    238
    -                                           " WHERE ns.nspname = 'public' AND p.proname ILIKE '%s%%';", functionPattern);
    
    239
    -        try {
    
    240
    -            connection = openConnection();
    
    241
    -            preparedStatement = connection.prepareStatement(sql);
    
    242
    -            ResultSet set = preparedStatement.executeQuery();
    
    243
    -
    
    244
    -            while (set.next()) {
    
    245
    -                String functionPrototype = set.getString(1);
    
    246
    -                result.add(functionPrototype);
    
    247
    -            }
    
    248
    -
    
    249
    -        } catch (SQLException e) {
    
    250
    -            throw new RuntimeException(e);
    
    251
    -        } finally {
    
    252
    -            closeQuietly(connection);
    
    253
    -            closeQuietly(preparedStatement);
    
    254
    -        }
    
    255
    -        return result;
    
    256
    -
    
    257
    -    }
    
    258
    -
    
    259
    -    public void loadScript(String scriptContent) {
    
    260
    -        Connection connection = null;
    
    261
    -        PreparedStatement preparedStatement = null;
    
    262
    -
    
    263
    -        try {
    
    264
    -            connection = openConnection();
    
    265
    -
    
    266
    -            preparedStatement = connection.prepareStatement(scriptContent);
    
    267
    -
    
    268
    -            preparedStatement.executeUpdate();
    
    269
    -
    
    270
    -        } catch (SQLException e) {
    
    271
    -            throw new RuntimeException(e);
    
    272
    -        } finally {
    
    273
    -            closeQuietly(connection);
    
    274
    -            closeQuietly(preparedStatement);
    
    275
    -        }
    
    276
    -    }
    
    277
    -
    
    278
    -
    
    279
    -}

  • services-local/src/main/java/fr/ird/observe/services/local/ObserveSecurityHelper.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.observe.services.local;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -32,9 +32,16 @@ import org.apache.commons.logging.Log;
    32 32
     import org.apache.commons.logging.LogFactory;
    
    33 33
     import org.nuiton.topia.migration.mappings.TMSVersionHibernateDao;
    
    34 34
     import org.nuiton.topia.persistence.TopiaEntityEnum;
    
    35
    +import org.nuiton.topia.persistence.TopiaException;
    
    35 36
     import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
    
    37
    +import org.nuiton.topia.persistence.sql.PostgresJdbcHelper;
    
    38
    +import org.nuiton.topia.persistence.util.SqlScriptConsumer;
    
    39
    +import org.nuiton.topia.persistence.util.SqlScriptWriter;
    
    36 40
     import org.nuiton.util.StringUtil;
    
    37 41
     
    
    42
    +import java.io.IOException;
    
    43
    +import java.nio.file.Files;
    
    44
    +import java.nio.file.Path;
    
    38 45
     import java.util.ArrayList;
    
    39 46
     import java.util.Arrays;
    
    40 47
     import java.util.Collection;
    
    ... ... @@ -53,64 +60,68 @@ public class ObserveSecurityHelper {
    53 60
     
    
    54 61
         public static final String OBSERVE_COMMON_SCHEMA_NAME = "observe_common";
    
    55 62
         public static final String OBSERVE_SEINE_SCHEMA_NAME = "observe_seine";
    
    56
    -    public static final String OBSERVE_LONGLINE_SCHEMA_NAME = "observe_longline";
    
    57
    -    public static final Function<String, String> ESCAPE_STRING = input -> "\"" + input + "\"";
    
    58
    -    protected static final String DROP_TABLE_PATTERN = "DROP TABLE IF EXISTS %s.%s CASCADE;\n";
    
    59
    -    protected static final String DROP_SCHEMA_PATTERN = "DROP SCHEMA IF EXISTS %s CASCADE;\n";
    
    60
    -    protected static final String REVOKE_ON_TABLE_ALL_PATTERN = "REVOKE ALL ON %s.%s FROM %s CASCADE;\n";
    
    61
    -    protected static final String SET_ON_TABLE_OWNER_PATTERN = "ALTER TABLE %s.%s OWNER TO %s;\n";
    
    62
    -    protected static final String GRANT_ON_TABLE_READ_PATTERN = "GRANT SELECT ON %s.%s TO %s;\n";
    
    63
    -    protected static final String GRANT_ON_TABLE_ALL_PATTERN = "GRANT ALL ON %s.%s TO %s;\n";
    
    64
    -    protected static final String GRANT_ON_FUNCTION_PATTERN = "GRANT EXECUTE ON FUNCTION %s TO %s;\n";
    
    65
    -    protected static final String REVOKE_ON_SCHEMA_ALL_PATTERN = "REVOKE ALL ON SCHEMA %s FROM %s CASCADE;\n";
    
    66
    -    protected static final String REVOKE_ON_FUNCTIONS_PATTERN = "REVOKE EXECUTE ON FUNCTION %s FROM %s CASCADE;\n";
    
    67
    -    protected static final String GRANT_ON_SCHEMA_ALL_PATTERN = "GRANT USAGE ON SCHEMA %s TO %s;\n";
    
    68
    -    protected static final Set<String> EXTRA_TABLES = Sets.newHashSet(
    
    63
    +    private static final String OBSERVE_LONGLINE_SCHEMA_NAME = "observe_longline";
    
    64
    +    private static final Function<String, String> ESCAPE_STRING = input -> "\"" + input + "\"";
    
    65
    +    private static final String REVOKE_ON_TABLE_ALL_PATTERN = "REVOKE ALL ON %s.%s FROM %s CASCADE;";
    
    66
    +    private static final String SET_ON_TABLE_OWNER_PATTERN = "ALTER TABLE %s.%s OWNER TO %s;";
    
    67
    +    private static final String GRANT_ON_TABLE_READ_PATTERN = "GRANT SELECT ON %s.%s TO %s;";
    
    68
    +    private static final String GRANT_ON_TABLE_ALL_PATTERN = "GRANT ALL ON %s.%s TO %s;";
    
    69
    +    private static final String GRANT_ON_FUNCTION_PATTERN = "GRANT EXECUTE ON FUNCTION %s TO %s;";
    
    70
    +    private static final String REVOKE_ON_SCHEMA_ALL_PATTERN = "REVOKE ALL ON SCHEMA %s FROM %s CASCADE;";
    
    71
    +    private static final String REVOKE_ON_FUNCTIONS_PATTERN = "REVOKE EXECUTE ON FUNCTION %s FROM %s CASCADE;";
    
    72
    +    private static final String GRANT_ON_SCHEMA_ALL_PATTERN = "GRANT USAGE ON SCHEMA %s TO %s;";
    
    73
    +    private static final Set<String> EXTRA_TABLES = Sets.newHashSet(
    
    69 74
                 TMSVersionHibernateDao.TABLE_NAME,
    
    70 75
                 TMSVersionHibernateDao.LEGACY_TABLE_NAME);
    
    71
    -    protected static final Set<String> FUNCTION_NAMES_PREFIXS = Sets.newHashSet("ST_MakePoint",
    
    72
    -                                                                                "ST_SetSRID",
    
    73
    -                                                                                "sync_",
    
    74
    -                                                                                "tr_sync",
    
    75
    -                                                                                "ot_enhanced_school_type",
    
    76
    -                                                                                "observe_");
    
    77
    -    protected static final String SCHEMA_PUBLIC = "public";
    
    78
    -    protected static final Set<String> SCHEMAS = Sets.newHashSet(SCHEMA_PUBLIC,
    
    79
    -                                                                 OBSERVE_COMMON_SCHEMA_NAME,
    
    80
    -                                                                 OBSERVE_SEINE_SCHEMA_NAME,
    
    81
    -                                                                 OBSERVE_LONGLINE_SCHEMA_NAME);
    
    76
    +    private static final Set<String> FUNCTION_NAMES_PREFIXS = Sets.newHashSet("ST_MakePoint",
    
    77
    +            "ST_SetSRID",
    
    78
    +            "sync_",
    
    79
    +            "tr_sync",
    
    80
    +            "ot_enhanced_school_type",
    
    81
    +            "observe_");
    
    82
    +    private static final String SCHEMA_PUBLIC = "public";
    
    83
    +    private static final Set<String> SCHEMAS = Sets.newHashSet(SCHEMA_PUBLIC,
    
    84
    +            OBSERVE_COMMON_SCHEMA_NAME,
    
    85
    +            OBSERVE_SEINE_SCHEMA_NAME,
    
    86
    +            OBSERVE_LONGLINE_SCHEMA_NAME);
    
    82 87
         private static final Log log = LogFactory.getLog(ObserveSecurityHelper.class);
    
    83
    -    protected final ObserveJdbcHelper jdbcHelper;
    
    84
    -    protected final JdbcConfiguration jdbcConfiguration;
    
    88
    +    private final PostgresJdbcHelper jdbcHelper;
    
    85 89
     
    
    86 90
     
    
    87 91
         public ObserveSecurityHelper(JdbcConfiguration jdbcConfiguration) {
    
    88
    -        this.jdbcConfiguration = jdbcConfiguration;
    
    89
    -        this.jdbcHelper = new ObserveJdbcHelper(jdbcConfiguration);
    
    92
    +        this.jdbcHelper = new PostgresJdbcHelper(jdbcConfiguration);
    
    90 93
         }
    
    91 94
     
    
    92
    -    public void applySecurity(Set<ObserveDbUserDto> users, boolean showSql) {
    
    95
    +    public void applySecurity(Set<ObserveDbUserDto> users) {
    
    93 96
             if (users == null) {
    
    94 97
                 throw new NullPointerException("users can not be null");
    
    95 98
             }
    
    96 99
     
    
    97
    -        String script = createSecurityScript(users);
    
    98
    -
    
    99
    -        if (showSql && log.isInfoEnabled()) {
    
    100
    -            log.info("SQL to execute :\n" + script);
    
    100
    +        Path scriptPath;
    
    101
    +        try {
    
    102
    +            scriptPath = Files.createTempFile("topia-sql-script-", ".sql");
    
    103
    +        } catch (IOException e) {
    
    104
    +            throw new IllegalStateException("Can't create temporary path", e);
    
    101 105
             }
    
    102 106
     
    
    103
    -        jdbcHelper.loadScript(script);
    
    104
    -
    
    107
    +        try {
    
    108
    +            try (SqlScriptWriter sqlScriptWriter = SqlScriptWriter.of(scriptPath)) {
    
    109
    +                createSecurityScript(users, sqlScriptWriter);
    
    110
    +                log.info(String.format("Generate security script %d statements(s) at %s", sqlScriptWriter.getStatementCount(), scriptPath));
    
    111
    +            }
    
    112
    +            jdbcHelper.consume(SqlScriptConsumer.of(scriptPath));
    
    113
    +        } catch (IOException e) {
    
    114
    +            throw new TopiaException(String.format("Can't generate security script at %s", scriptPath), e);
    
    115
    +        }
    
    105 116
         }
    
    106 117
     
    
    107
    -    protected String createSecurityScript(Set<ObserveDbUserDto> users) {
    
    118
    +    private void createSecurityScript(Set<ObserveDbUserDto> users, SqlScriptWriter sqlScriptWriter) {
    
    108 119
     
    
    109 120
             List<Pair<String, String>> tables = jdbcHelper.getTables(SCHEMAS, EXTRA_TABLES);
    
    110 121
     
    
    111 122
             if (tables.isEmpty()) {
    
    112 123
                 // no tables
    
    113
    -            return "";
    
    124
    +            return;
    
    114 125
             }
    
    115 126
     
    
    116 127
             String administratorName = Iterables.get(getUserNamesByRole(users, ObserveDbRole.ADMINISTRATOR), 0);
    
    ... ... @@ -130,16 +141,12 @@ public class ObserveSecurityHelper {
    130 141
     
    
    131 142
             List<Pair<String, String>> referentielTables = getReferentielTables(tables);
    
    132 143
     
    
    133
    -        getDataTables(tables, referentielTables);
    
    134
    -
    
    135 144
             Set<String> allPostgisFunctions = new LinkedHashSet<>();
    
    136 145
             for (String postgisFunction : FUNCTION_NAMES_PREFIXS) {
    
    137 146
                 Set<String> postgisFunctions = jdbcHelper.getPostgisFunctions(postgisFunction);
    
    138 147
                 allPostgisFunctions.addAll(postgisFunctions);
    
    139 148
             }
    
    140 149
     
    
    141
    -        StringBuilder builder = new StringBuilder();
    
    142
    -
    
    143 150
             String administratorEscapedName = ESCAPE_STRING.apply(administratorName);
    
    144 151
             Set<String> technicalEscapedNames = escapedNames(technicalNames);
    
    145 152
             Set<String> usersEscapedNames = escapedNames(usersNames);
    
    ... ... @@ -157,84 +164,66 @@ public class ObserveSecurityHelper {
    157 164
     
    
    158 165
                 String roles = StringUtil.join(privateRoles, ",", true);
    
    159 166
     
    
    160
    -            addOnTablesForRole(REVOKE_ON_TABLE_ALL_PATTERN, builder, tables, roles);
    
    161
    -            addOnSchemaForRole(REVOKE_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
    
    162
    -            addOnFunctionForRole(REVOKE_ON_FUNCTIONS_PATTERN, builder, allPostgisFunctions, roles);
    
    167
    +            addOnTablesForRole(REVOKE_ON_TABLE_ALL_PATTERN, sqlScriptWriter, tables, roles);
    
    168
    +            addOnSchemaForRole(REVOKE_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
    
    169
    +            addOnFunctionForRole(REVOKE_ON_FUNCTIONS_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
    
    163 170
     
    
    164 171
             }
    
    165 172
     
    
    166 173
             // ajout propriétaire
    
    167
    -        addOnTablesForRole(SET_ON_TABLE_OWNER_PATTERN, builder, tables, administratorEscapedName);
    
    168
    -        addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, administratorEscapedName);
    
    169
    -        addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, administratorEscapedName);
    
    174
    +        addOnTablesForRole(SET_ON_TABLE_OWNER_PATTERN, sqlScriptWriter, tables, administratorEscapedName);
    
    175
    +        addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, administratorEscapedName);
    
    176
    +        addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, administratorEscapedName);
    
    170 177
     
    
    171 178
             // ajout administrateurs
    
    172 179
             if (!technicalEscapedNames.isEmpty()) {
    
    173 180
                 String roles = StringUtil.join(technicalEscapedNames, ",", true);
    
    174
    -            addOnTablesForRole(GRANT_ON_TABLE_ALL_PATTERN, builder, tables, roles);
    
    175
    -            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
    
    176
    -            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
    
    181
    +            addOnTablesForRole(GRANT_ON_TABLE_ALL_PATTERN, sqlScriptWriter, tables, roles);
    
    182
    +            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
    
    183
    +            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
    
    177 184
             }
    
    178 185
     
    
    179 186
             // ajout utilisateur
    
    180 187
             if (!usersEscapedNames.isEmpty()) {
    
    181 188
                 String roles = StringUtil.join(usersEscapedNames, ",", true);
    
    182
    -            addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, builder, tables, roles);
    
    183
    -            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
    
    184
    -            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
    
    189
    +            addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, sqlScriptWriter, tables, roles);
    
    190
    +            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
    
    191
    +            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
    
    185 192
             }
    
    186 193
     
    
    187 194
             // ajout referentiel
    
    188 195
             if (!referentialEscapedNames.isEmpty()) {
    
    189 196
                 String roles = StringUtil.join(referentialEscapedNames, ",", true);
    
    190
    -            addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, builder, referentielTables, roles);
    
    191
    -            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, builder, SCHEMAS, roles);
    
    192
    -            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, builder, allPostgisFunctions, roles);
    
    197
    +            addOnTablesForRole(GRANT_ON_TABLE_READ_PATTERN, sqlScriptWriter, referentielTables, roles);
    
    198
    +            addOnSchemaForRole(GRANT_ON_SCHEMA_ALL_PATTERN, sqlScriptWriter, SCHEMAS, roles);
    
    199
    +            addOnSchemaForRole(GRANT_ON_FUNCTION_PATTERN, sqlScriptWriter, allPostgisFunctions, roles);
    
    193 200
             }
    
    194 201
     
    
    195
    -        String result = builder.toString();
    
    196
    -
    
    197
    -        if (log.isInfoEnabled()) {
    
    198
    -            log.info("Security script :\n" + result);
    
    199
    -        }
    
    200
    -        return result;
    
    201
    -
    
    202
    -
    
    203 202
         }
    
    204 203
     
    
    205
    -    protected List<String> getUserNamesByRole(Set<ObserveDbUserDto> users, ObserveDbRole role) {
    
    204
    +    private List<String> getUserNamesByRole(Set<ObserveDbUserDto> users, ObserveDbRole role) {
    
    206 205
             return users.stream().filter(u -> u.getRole() == role).map(ObserveDbUserDto::getName).collect(Collectors.toList());
    
    207 206
         }
    
    208 207
     
    
    209
    -    protected Set<String> escapedNames(List<String> names) {
    
    208
    +    private Set<String> escapedNames(List<String> names) {
    
    210 209
             return names.stream().map(ESCAPE_STRING).collect(Collectors.toSet());
    
    211 210
         }
    
    212 211
     
    
    213
    -    protected List<Pair<String, String>> getReferentielTables(Iterable<Pair<String, String>> tables) {
    
    214
    -        Set<TopiaEntityEnum> types = new HashSet<>();
    
    215
    -        types.addAll(Arrays.asList(Entities.REFERENCE_ENTITIES));
    
    212
    +    private List<Pair<String, String>> getReferentielTables(Collection<Pair<String, String>> tables) {
    
    213
    +        Set<TopiaEntityEnum> types = new HashSet<>(Arrays.asList(Entities.REFERENCE_ENTITIES));
    
    216 214
     
    
    217
    -        List<Pair<String, String>> result = getTables(tables, types, EXTRA_TABLES);
    
    215
    +        List<Pair<String, String>> result = getTables(tables, types);
    
    218 216
             if (log.isInfoEnabled()) {
    
    219 217
                 StringBuilder sb = new StringBuilder();
    
    220 218
                 sb.append("Detected ").append(result.size()).append(" referentiel tables :");
    
    221 219
                 for (Pair<String, String> s : result) {
    
    222 220
                     sb.append("\n - ").append(s);
    
    223 221
                 }
    
    224
    -            log.info(sb.toString());
    
    225
    -        }
    
    226
    -        return result;
    
    227
    -    }
    
    228
    -
    
    229
    -    protected List<Pair<String, String>> getDataTables(Collection<Pair<String, String>> tables,
    
    230
    -                                                       Collection<Pair<String, String>> referentielTables) {
    
    231
    -        List<Pair<String, String>> result = new ArrayList<>(tables);
    
    232
    -        result.removeAll(referentielTables);
    
    222
    +            List<Pair<String, String>> dataTables = new ArrayList<>(tables);
    
    223
    +            dataTables.removeAll(result);
    
    233 224
     
    
    234
    -        if (log.isInfoEnabled()) {
    
    235
    -            StringBuilder sb = new StringBuilder();
    
    236
    -            sb.append("Detected ").append(result.size()).append(" data tables :");
    
    237
    -            for (Pair<String, String> s : result) {
    
    225
    +            sb.append("Detected ").append(dataTables.size()).append(" data tables :");
    
    226
    +            for (Pair<String, String> s : dataTables) {
    
    238 227
                     sb.append("\n - ").append(s);
    
    239 228
                 }
    
    240 229
                 log.info(sb.toString());
    
    ... ... @@ -242,9 +231,7 @@ public class ObserveSecurityHelper {
    242 231
             return result;
    
    243 232
         }
    
    244 233
     
    
    245
    -    protected List<Pair<String, String>> getTables(Iterable<Pair<String, String>> tables,
    
    246
    -                                                   Set<TopiaEntityEnum> types,
    
    247
    -                                                   Set<String> extraTypes) {
    
    234
    +    private List<Pair<String, String>> getTables(Iterable<Pair<String, String>> tables, Set<TopiaEntityEnum> types) {
    
    248 235
             List<Pair<String, String>> result = new ArrayList<>();
    
    249 236
             for (Pair<String, String> t : tables) {
    
    250 237
                 String table = t.getRight();
    
    ... ... @@ -257,7 +244,7 @@ public class ObserveSecurityHelper {
    257 244
                     }
    
    258 245
                 }
    
    259 246
                 if (detectedType == null) {
    
    260
    -                for (String extraType : extraTypes) {
    
    247
    +                for (String extraType : EXTRA_TABLES) {
    
    261 248
                         if (table.equalsIgnoreCase(extraType)) {
    
    262 249
                             detectedType = extraType;
    
    263 250
                             break;
    
    ... ... @@ -272,35 +259,22 @@ public class ObserveSecurityHelper {
    272 259
             return result;
    
    273 260
         }
    
    274 261
     
    
    275
    -    protected void addOnTablesForRole(String pattern,
    
    276
    -                                      StringBuilder builder,
    
    277
    -                                      Iterable<Pair<String, String>> tables,
    
    278
    -                                      String role) {
    
    279
    -
    
    262
    +    private void addOnTablesForRole(String pattern, SqlScriptWriter builder, Iterable<Pair<String, String>> tables, String role) {
    
    280 263
             for (Pair<String, String> t : tables) {
    
    281
    -            builder.append(String.format(pattern, t.getLeft(), t.getRight(), role));
    
    264
    +            builder.writeSql(String.format(pattern, t.getLeft(), t.getRight(), role));
    
    282 265
             }
    
    283 266
         }
    
    284 267
     
    
    285
    -    protected void addOnSchemaForRole(String pattern,
    
    286
    -                                      StringBuilder builder,
    
    287
    -                                      Set<String> schemas,
    
    288
    -                                      String role) {
    
    289
    -
    
    268
    +    private void addOnSchemaForRole(String pattern, SqlScriptWriter builder, Set<String> schemas, String role) {
    
    290 269
             for (String t : schemas) {
    
    291
    -            builder.append(String.format(pattern, t, role));
    
    270
    +            builder.writeSql(String.format(pattern, t, role));
    
    292 271
             }
    
    293 272
         }
    
    294 273
     
    
    295
    -    protected void addOnFunctionForRole(String pattern,
    
    296
    -                                        StringBuilder builder,
    
    297
    -                                        Set<String> functions,
    
    298
    -                                        String role) {
    
    299
    -
    
    274
    +    private void addOnFunctionForRole(String pattern, SqlScriptWriter builder, Set<String> functions, String role) {
    
    300 275
             for (String t : functions) {
    
    301
    -            builder.append(String.format(pattern, t, role));
    
    276
    +            builder.writeSql(String.format(pattern, t, role));
    
    302 277
             }
    
    303 278
         }
    
    304 279
     
    
    305
    -
    
    306 280
     }

  • services-local/src/main/java/fr/ird/observe/services/local/service/DataSourceServiceLocal.java
    ... ... @@ -10,22 +10,21 @@ package fr.ird.observe.services.local.service;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import com.google.common.base.Joiner;
    
    26 25
     import com.google.common.base.Preconditions;
    
    27 26
     import com.google.common.collect.ImmutableSet;
    
    28
    -import com.google.common.collect.Sets;
    
    27
    +import fr.ird.observe.dto.ObserveDbRole;
    
    29 28
     import fr.ird.observe.dto.db.ObserveDbUserDto;
    
    30 29
     import fr.ird.observe.dto.reference.ReferentialDtoReference;
    
    31 30
     import fr.ird.observe.entities.referentiel.ObserveReferentialEntity;
    
    ... ... @@ -33,7 +32,7 @@ import fr.ird.observe.persistence.ObserveEntityEnum;
    33 32
     import fr.ird.observe.persistence.ObserveTopiaApplicationContext;
    
    34 33
     import fr.ird.observe.persistence.ObserveTopiaConfiguration;
    
    35 34
     import fr.ird.observe.persistence.ObserveTopiaConfigurationFactory;
    
    36
    -import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
    
    35
    +import fr.ird.observe.persistence.migration.ObserveTopiaMigrationServiceAskUserToMigrate;
    
    37 36
     import fr.ird.observe.services.configuration.DataSourceCreateConfigurationDto;
    
    38 37
     import fr.ird.observe.services.configuration.DataSourceCreateWithNoReferentialImportException;
    
    39 38
     import fr.ird.observe.services.configuration.IncompatibleDataSourceCreateConfigurationException;
    
    ... ... @@ -44,7 +43,6 @@ import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfiguratio
    44 43
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG;
    
    45 44
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaSupport;
    
    46 45
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConnectionTopia;
    
    47
    -import fr.ird.observe.services.local.ObserveJdbcHelper;
    
    48 46
     import fr.ird.observe.services.local.ObserveSecurityHelper;
    
    49 47
     import fr.ird.observe.services.local.ObserveTopiaApplicationContextFactory;
    
    50 48
     import fr.ird.observe.services.service.BabModelVersionException;
    
    ... ... @@ -61,16 +59,21 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper;
    61 59
     import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    62 60
     import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    63 61
     import org.nuiton.topia.persistence.metadata.TopiaMetadataModelVisitor;
    
    62
    +import org.nuiton.topia.persistence.sql.PostgresJdbcHelper;
    
    63
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    64
    +import org.nuiton.topia.service.migration.version.TMSVersion;
    
    65
    +import org.nuiton.topia.service.migration.version.TMSVersionHibernateDao;
    
    64 66
     import org.nuiton.version.Version;
    
    65 67
     import org.nuiton.version.Versions;
    
    66 68
     
    
    67 69
     import java.io.File;
    
    68 70
     import java.io.IOException;
    
    69 71
     import java.nio.file.Files;
    
    72
    +import java.util.LinkedHashSet;
    
    73
    +import java.util.List;
    
    70 74
     import java.util.Optional;
    
    71 75
     import java.util.Set;
    
    72 76
     import java.util.UUID;
    
    73
    -import java.util.stream.Collectors;
    
    74 77
     
    
    75 78
     import static org.nuiton.i18n.I18n.l;
    
    76 79
     
    
    ... ... @@ -100,9 +103,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    100 103
     
    
    101 104
         @Override
    
    102 105
         public ObserveDataSourceInformation checkCanConnect(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException {
    
    103
    -        if (log.isTraceEnabled()) {
    
    104
    -            log.trace("checkCanConnect(" + dataSourceConfiguration + ")");
    
    105
    -        }
    
    106 106
     
    
    107 107
             Preconditions.checkState(dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaSupport);
    
    108 108
             ObserveDataSourceConfigurationTopiaSupport dataSourceConfigurationTopiaSupport = (ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration;
    
    ... ... @@ -137,11 +137,11 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    137 137
     
    
    138 138
                 // On tente une connection à la base
    
    139 139
                 ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forH2Database(h2DataSourceConfiguration.getDirectory(),
    
    140
    -                                                                                                          h2DataSourceConfiguration.getDbName(),
    
    141
    -                                                                                                          h2DataSourceConfiguration.getUsername(),
    
    142
    -                                                                                                          new String(h2DataSourceConfiguration.getPassword()),
    
    143
    -                                                                                                          false,
    
    144
    -                                                                                                          false);
    
    140
    +                    h2DataSourceConfiguration.getDbName(),
    
    141
    +                    h2DataSourceConfiguration.getUsername(),
    
    142
    +                    new String(h2DataSourceConfiguration.getPassword()),
    
    143
    +                    false,
    
    144
    +                    false);
    
    145 145
     
    
    146 146
     
    
    147 147
                 try {
    
    ... ... @@ -162,9 +162,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    162 162
                 ObserveDataSourceConfigurationTopiaPG pgDataSourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfigurationTopiaSupport;
    
    163 163
                 // On tente une connexion au serveur
    
    164 164
                 ObserveTopiaConfiguration topiaConfiguration = ObserveTopiaConfigurationFactory.forPostgresqlDatabase(pgDataSourceConfiguration.getJdbcUrl(),
    
    165
    -                                                                                                                  pgDataSourceConfiguration.getUsername(),
    
    166
    -                                                                                                                  new String(pgDataSourceConfiguration.getPassword()),
    
    167
    -                                                                                                                  false,
    
    165
    +                    pgDataSourceConfiguration.getUsername(),
    
    166
    +                    new String(pgDataSourceConfiguration.getPassword()),
    
    167
    +                    false,
    
    168 168
                         false);
    
    169 169
     
    
    170 170
                 try {
    
    ... ... @@ -187,9 +187,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    187 187
         public ObserveDataSourceConnectionTopia create(ObserveDataSourceConfiguration dataSourceConfiguration, DataSourceCreateConfigurationDto dataSourceCreateConfiguration)
    
    188 188
                 throws IncompatibleDataSourceCreateConfigurationException, DataSourceCreateWithNoReferentialImportException,
    
    189 189
                 BabModelVersionException, DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException {
    
    190
    -        if (log.isTraceEnabled()) {
    
    191
    -            log.trace("create(" + dataSourceConfiguration + ", " + dataSourceCreateConfiguration + ")");
    
    192
    -        }
    
    193 190
     
    
    194 191
             dataSourceCreateConfiguration.validateConfiguration();
    
    195 192
     
    
    ... ... @@ -274,9 +271,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    274 271
     
    
    275 272
                 if (importStandaloneReferantial) {
    
    276 273
     
    
    277
    -                if (log.isInfoEnabled()) {
    
    278
    -                    log.info("Import referential.");
    
    279
    -                }
    
    274
    +                log.info("Import referential.");
    
    280 275
     
    
    281 276
                     ObserveDataSourceConfiguration importDataSourceConfiguration = dataSourceCreateConfiguration.getImportReferentialDataSourceConfiguration();
    
    282 277
     
    
    ... ... @@ -336,9 +331,7 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    336 331
                     // Récupération du dump qui contient les données
    
    337 332
                     ImmutableSet<String> importDataIds = dataSourceCreateConfiguration.getImportDataIds();
    
    338 333
     
    
    339
    -                if (log.isInfoEnabled()) {
    
    340
    -                    log.info("Get data: " + importDataIds);
    
    341
    -                }
    
    334
    +                log.info("Get data: " + importDataIds);
    
    342 335
     
    
    343 336
                     request.dataIdsToAdd(importDataIds);
    
    344 337
     
    
    ... ... @@ -394,9 +387,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    394 387
     
    
    395 388
         @Override
    
    396 389
         public ObserveDataSourceConnectionTopia open(ObserveDataSourceConfiguration dataSourceConfiguration) throws DatabaseNotFoundException, DatabaseConnexionNotAuthorizedException, BabModelVersionException {
    
    397
    -        if (log.isTraceEnabled()) {
    
    398
    -            log.trace("open(" + dataSourceConfiguration + ")");
    
    399
    -        }
    
    400 390
     
    
    401 391
             ObserveDataSourceInformation dataSourceInformation = checkCanConnect(dataSourceConfiguration);
    
    402 392
     
    
    ... ... @@ -418,9 +408,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    418 408
     
    
    419 409
         @Override
    
    420 410
         public void close() {
    
    421
    -        if (log.isTraceEnabled()) {
    
    422
    -            log.trace("close()");
    
    423
    -        }
    
    424 411
     
    
    425 412
             ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration = serviceContext.getDataSourceConfiguration().orElseThrow(IllegalStateException::new);
    
    426 413
             Optional<ObserveTopiaApplicationContext> optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getTopiaApplicationContextIfPresent(dataSourceConfiguration);
    
    ... ... @@ -431,9 +418,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    431 418
     
    
    432 419
         @Override
    
    433 420
         public void destroy() throws DatabaseDestroyNotAuthorizedException {
    
    434
    -        if (log.isTraceEnabled()) {
    
    435
    -            log.trace("destroy()");
    
    436
    -        }
    
    437 421
     
    
    438 422
             ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration = serviceContext.getDataSourceConfiguration().orElseThrow(IllegalStateException::new);
    
    439 423
     
    
    ... ... @@ -461,7 +445,6 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    461 445
         public void backup(File backupFile) {
    
    462 446
     
    
    463 447
             if (!serviceContext.getTopiaApplicationContext().getConfiguration().isH2Configuration()) {
    
    464
    -
    
    465 448
                 throw new IllegalStateException("Cant backup a none H2 database.");
    
    466 449
             }
    
    467 450
     
    
    ... ... @@ -471,26 +454,32 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    471 454
     
    
    472 455
         @Override
    
    473 456
         public Set<ObserveDbUserDto> getUsers(ObserveDataSourceConfiguration dataSourceConfiguration) {
    
    474
    -        if (log.isTraceEnabled()) {
    
    475
    -            log.trace("getUsers(" + dataSourceConfiguration + ")");
    
    476
    -        }
    
    477 457
     
    
    478
    -        Set<ObserveDbUserDto> users = Sets.newHashSet();
    
    458
    +        Set<ObserveDbUserDto> users = new LinkedHashSet<>();
    
    479 459
     
    
    480 460
             // pas d'user pour les bases autres que postgresql
    
    481 461
             if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
    
    482 462
     
    
    483 463
                 ObserveDataSourceConfigurationTopiaPG sourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfiguration;
    
    484 464
     
    
    485
    -            ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration);
    
    486
    -
    
    487
    -            ObserveTopiaConfiguration topiaConfiguration = topiaApplicationContext.getConfiguration();
    
    465
    +            try (ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration)) {
    
    488 466
     
    
    489
    -            ObserveJdbcHelper observeJdbcHelper = new ObserveJdbcHelper(topiaConfiguration);
    
    467
    +                ObserveTopiaConfiguration topiaConfiguration = topiaApplicationContext.getConfiguration();
    
    490 468
     
    
    491
    -            users.addAll(observeJdbcHelper.getUsers());
    
    469
    +                PostgresJdbcHelper observeJdbcHelper = new PostgresJdbcHelper(topiaConfiguration);
    
    492 470
     
    
    493
    -            topiaApplicationContext.close();
    
    471
    +                Set<String> userNames = observeJdbcHelper.getRoles();
    
    472
    +                for (String userName : userNames) {
    
    473
    +                    ObserveDbUserDto user = new ObserveDbUserDto();
    
    474
    +                    user.setName(userName);
    
    475
    +                    if (topiaConfiguration.getJdbcConnectionUser().equals(userName)) {
    
    476
    +                        user.setRole(ObserveDbRole.ADMINISTRATOR);
    
    477
    +                    } else {
    
    478
    +                        user.setRole(ObserveDbRole.UNUSED);
    
    479
    +                    }
    
    480
    +                    users.add(user);
    
    481
    +                }
    
    482
    +            }
    
    494 483
     
    
    495 484
             }
    
    496 485
     
    
    ... ... @@ -499,22 +488,18 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    499 488
     
    
    500 489
         @Override
    
    501 490
         public void applySecurity(ObserveDataSourceConfiguration dataSourceConfiguration, ImmutableSet<ObserveDbUserDto> users) {
    
    502
    -        if (log.isTraceEnabled()) {
    
    503
    -            log.trace("applySecurity(" + dataSourceConfiguration + ", [" + Joiner.on(", ").join(users.stream().map(ObserveDbUserDto::getName).collect(Collectors.toList())) + "])");
    
    504
    -        }
    
    505 491
     
    
    506 492
             // pas de securité  pour les bases autres que postgresql
    
    507 493
             if (dataSourceConfiguration instanceof ObserveDataSourceConfigurationTopiaPG) {
    
    508 494
     
    
    509 495
                 ObserveDataSourceConfigurationTopiaPG sourceConfiguration = (ObserveDataSourceConfigurationTopiaPG) dataSourceConfiguration;
    
    510 496
     
    
    511
    -            ObserveTopiaApplicationContext optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration);
    
    512
    -
    
    513
    -            ObserveTopiaConfiguration topiaConfiguration = optionalTopiaApplicationContext.getConfiguration();
    
    514
    -
    
    515
    -            ObserveSecurityHelper securityHelper = new ObserveSecurityHelper(topiaConfiguration);
    
    497
    +            ObserveTopiaConfiguration topiaConfiguration;
    
    498
    +            try (ObserveTopiaApplicationContext optionalTopiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(sourceConfiguration)) {
    
    516 499
     
    
    517
    -            securityHelper.applySecurity(users, sourceConfiguration.isShowMigrationSql());
    
    500
    +                topiaConfiguration = optionalTopiaApplicationContext.getConfiguration();
    
    501
    +                new ObserveSecurityHelper(topiaConfiguration).applySecurity(users);
    
    502
    +            }
    
    518 503
     
    
    519 504
             }
    
    520 505
     
    
    ... ... @@ -522,14 +507,8 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    522 507
     
    
    523 508
         @Override
    
    524 509
         public void migrateData(ObserveDataSourceConfiguration dataSourceConfiguration) {
    
    525
    -        if (log.isTraceEnabled()) {
    
    526
    -            log.trace("migrateData(" + dataSourceConfiguration + ")");
    
    527
    -        }
    
    528
    -
    
    529 510
             ObserveTopiaApplicationContext topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext((ObserveDataSourceConfigurationTopiaSupport) dataSourceConfiguration);
    
    530
    -
    
    531 511
             topiaApplicationContext.getMigrationService().runSchemaMigration();
    
    532
    -
    
    533 512
         }
    
    534 513
     
    
    535 514
         @Override
    
    ... ... @@ -561,9 +540,9 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    561 540
     
    
    562 541
             Version version;
    
    563 542
     
    
    564
    -        ObserveJdbcHelper observeJdbcHelper = new ObserveJdbcHelper(topiaConfiguration);
    
    543
    +        PostgresJdbcHelper jdbcHelper = new PostgresJdbcHelper(topiaConfiguration);
    
    565 544
     
    
    566
    -        version = observeJdbcHelper.getVersion();
    
    545
    +        version = TMSVersionHibernateDao.getVersion(jdbcHelper, "tms_version").map(TMSVersion::toVersion).orElse(Version.VZERO);
    
    567 546
     
    
    568 547
             if (dataSourceConfiguration.isH2Database()) {
    
    569 548
     
    
    ... ... @@ -594,45 +573,36 @@ public class DataSourceServiceLocal extends ObserveServiceLocal implements DataS
    594 573
                 // stockées dans pg canWriteData, canWrite pour etre sur du resultat
    
    595 574
     
    
    596 575
                 // recherche des droits sur les données observers
    
    597
    -            Set<String> dataPrivileges = observeJdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_SEINE_SCHEMA_NAME, "trip");
    
    576
    +            Set<String> dataPrivileges = jdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_SEINE_SCHEMA_NAME, "trip");
    
    598 577
     
    
    599 578
                 readData = canRead(dataPrivileges);
    
    600 579
                 writeData = canWrite(dataPrivileges);
    
    601 580
     
    
    602 581
     
    
    603 582
                 // recherche des droits sur le referentiel
    
    604
    -            Set<String> referentielPrivileges = observeJdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_COMMON_SCHEMA_NAME, "vessel");
    
    583
    +            Set<String> referentielPrivileges = jdbcHelper.getTablePrivileges(ObserveSecurityHelper.OBSERVE_COMMON_SCHEMA_NAME, "vessel");
    
    605 584
     
    
    606 585
                 // Sur une base PG, on regarde en base ce que l'utilisateur peut lire/écrire
    
    607 586
                 writeReferential = canWrite(referentielPrivileges);
    
    608
    -
    
    609 587
             }
    
    610 588
     
    
    611
    -        if (log.isDebugEnabled()) {
    
    612
    -            log.debug("User can write referential : " + writeReferential + ", " +
    
    613
    -                    "read data : " + readData + ", " +
    
    614
    -                    "write data : " + writeData + ".");
    
    615
    -        }
    
    589
    +        log.debug(String.format("User can write referential : %s, read data : %s, write data : %s.", writeReferential, readData, writeData));
    
    616 590
     
    
    617
    -        ObserveMigrationConfigurationProvider observeMigrationConfigurationProvider = ObserveMigrationConfigurationProvider.get();
    
    591
    +        MigrationVersionResourceProvider observeMigrationConfigurationProvider = MigrationVersionResourceProvider.get();
    
    618 592
             return new ObserveDataSourceInformation(
    
    619 593
                     true,
    
    620 594
                     writeReferential,
    
    621 595
                     readData,
    
    622 596
                     writeData,
    
    623
    -                observeMigrationConfigurationProvider.getMinimumVersion(),
    
    597
    +                ObserveTopiaMigrationServiceAskUserToMigrate.getMinimumVersion(),
    
    624 598
                     version,
    
    625 599
                     observeMigrationConfigurationProvider.getVersionsAfter(version));
    
    626 600
         }
    
    627 601
     
    
    628 602
         private void close(ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration, ObserveTopiaApplicationContext topiaApplicationContext) {
    
    629 603
             if (topiaApplicationContext != null) {
    
    630
    -
    
    631
    -            if (log.isInfoEnabled()) {
    
    632
    -                log.info("Closing topia application context: " + dataSourceConfiguration);
    
    633
    -            }
    
    604
    +            log.info("Closing topia application context: " + dataSourceConfiguration);
    
    634 605
                 topiaApplicationContext.close();
    
    635
    -
    
    636 606
             }
    
    637 607
         }
    
    638 608
     
    

  • services-local/src/main/java/fr/ird/observe/services/local/service/sql/SqlScriptProducerServiceLocal.java
    ... ... @@ -24,7 +24,6 @@ package fr.ird.observe.services.local.service.sql;
    24 24
     
    
    25 25
     import com.google.common.collect.ImmutableSet;
    
    26 26
     import com.google.common.collect.ListMultimap;
    
    27
    -import org.nuiton.topia.persistence.util.TopiaBlobsContainer;
    
    28 27
     import fr.ird.observe.dto.reference.ReferentialDtoReference;
    
    29 28
     import fr.ird.observe.persistence.Entities;
    
    30 29
     import fr.ird.observe.persistence.ObserveEntityEnum;
    
    ... ... @@ -39,10 +38,10 @@ import org.apache.commons.collections4.CollectionUtils;
    39 38
     import org.apache.commons.logging.Log;
    
    40 39
     import org.apache.commons.logging.LogFactory;
    
    41 40
     import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    41
    +import org.nuiton.topia.persistence.util.TopiaBlobsContainer;
    
    42 42
     import org.nuiton.topia.service.sql.batch.SqlRequests;
    
    43 43
     import org.nuiton.topia.service.sql.batch.SqlResult;
    
    44 44
     import org.nuiton.topia.service.sql.batch.TopiaSqlBatchService;
    
    45
    -import org.nuiton.topia.service.sql.batch.actions.BlobsContainer;
    
    46 45
     import org.nuiton.topia.service.sql.batch.actions.TopiaSqlTableSelectArgument;
    
    47 46
     
    
    48 47
     import java.io.ByteArrayOutputStream;
    
    ... ... @@ -83,8 +82,8 @@ public class SqlScriptProducerServiceLocal extends ObserveServiceLocal implement
    83 82
     
    
    84 83
                     SqlRequests sqlRequests = sqlRequests(request, builder);
    
    85 84
                     SqlResult sqlResult = sqlBatchService.execute(sqlRequests);
    
    86
    -                ImmutableSet<BlobsContainer> blobsContainers = sqlResult.getBlobsContainers();
    
    87
    -                for (BlobsContainer blobsContainer : blobsContainers) {
    
    85
    +                ImmutableSet<TopiaBlobsContainer> blobsContainers = sqlResult.getBlobsContainers();
    
    86
    +                for (TopiaBlobsContainer blobsContainer : blobsContainers) {
    
    88 87
                         observeBlobContainers.add(new TopiaBlobsContainer(blobsContainer.getTableName(),
    
    89 88
                                                                             blobsContainer.getColumnName(),
    
    90 89
                                                                             blobsContainer.getBlobsById()));
    

  • services-local/src/test/java/fr/ird/observe/services/local/DataSourcesForTestManager.java
    ... ... @@ -10,23 +10,23 @@ package fr.ird.observe.services.local;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
    
    26 25
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    27 26
     import fr.ird.observe.test.TestHelper;
    
    28 27
     import org.apache.commons.logging.Log;
    
    29 28
     import org.apache.commons.logging.LogFactory;
    
    29
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    30 30
     import org.nuiton.version.Version;
    
    31 31
     
    
    32 32
     import java.io.File;
    
    ... ... @@ -100,7 +100,7 @@ public class DataSourcesForTestManager {
    100 100
             configurationTopiaH2.setDirectory(localDbFile);
    
    101 101
             configurationTopiaH2.setDbName("obstuna");
    
    102 102
             configurationTopiaH2.setAutoMigrate(true);
    
    103
    -        configurationTopiaH2.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
    
    103
    +        configurationTopiaH2.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
    
    104 104
             return configurationTopiaH2;
    
    105 105
     
    
    106 106
         }
    

  • services-local/src/test/java/fr/ird/observe/services/local/service/RigthTest.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.observe.services.local.service;
    10 10
      * it under the terms of the GNU General Public License as
    
    11 11
      * published by the Free Software Foundation, either version 3 of the
    
    12 12
      * License, or (at your option) any later version.
    
    13
    - * 
    
    13
    + *
    
    14 14
      * This program is distributed in the hope that it will be useful,
    
    15 15
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16 16
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17 17
      * GNU General Public License for more details.
    
    18
    - * 
    
    18
    + *
    
    19 19
      * You should have received a copy of the GNU General Public
    
    20 20
      * License along with this program.  If not, see
    
    21 21
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -25,7 +25,6 @@ package fr.ird.observe.services.local.service;
    25 25
     import fr.ird.observe.dto.data.seine.TripSeineDto;
    
    26 26
     import fr.ird.observe.dto.form.Form;
    
    27 27
     import fr.ird.observe.dto.referential.ProgramDto;
    
    28
    -import fr.ird.observe.persistence.migration.ObserveMigrationConfigurationProvider;
    
    29 28
     import fr.ird.observe.services.configuration.ObserveDataSourceConnection;
    
    30 29
     import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaPG;
    
    31 30
     import fr.ird.observe.services.security.UnauthorizedException;
    
    ... ... @@ -42,6 +41,7 @@ import fr.ird.observe.test.spi.DatabasePasswordConfiguration;
    42 41
     import org.junit.Assert;
    
    43 42
     import org.junit.Ignore;
    
    44 43
     import org.junit.Test;
    
    44
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    45 45
     
    
    46 46
     /**
    
    47 47
      * FIXME Ca sert à quoi ? et je comprends pas le mot rigth ?
    
    ... ... @@ -102,13 +102,12 @@ public class RigthTest extends ServiceLocalTestSupport {
    102 102
             configurationTopiaPG.setUsername(login);
    
    103 103
             configurationTopiaPG.setPassword('a');
    
    104 104
             configurationTopiaPG.setAutoMigrate(true);
    
    105
    -        configurationTopiaPG.setModelVersion(ObserveMigrationConfigurationProvider.get().getLastVersion());
    
    105
    +        configurationTopiaPG.setModelVersion(MigrationVersionResourceProvider.get().getLastVersion());
    
    106 106
     
    
    107 107
             return configurationTopiaPG;
    
    108 108
     
    
    109 109
         }
    
    110 110
     
    
    111
    -
    
    112 111
         public void testReadData(String login) throws DatabaseConnexionNotAuthorizedException, DatabaseNotFoundException, BabModelVersionException {
    
    113 112
     
    
    114 113
             TripSeineService service = localTestMethodResource.newService(TripSeineService.class);