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

Commits:

11 changed files:

Changes:

  • t3-actions/src/main/java/fr/ird/t3/actions/io/input/test/FakeT3AvdthServiceContext.java
    ... ... @@ -24,7 +24,6 @@ import fr.ird.t3.T3Config;
    24 24
     import fr.ird.t3.T3ConfigOption;
    
    25 25
     import fr.ird.t3.T3IOUtil;
    
    26 26
     import fr.ird.t3.entities.T3EntityHelper;
    
    27
    -import fr.ird.t3.entities.T3JdbcHelper;
    
    28 27
     import fr.ird.t3.entities.T3TopiaApplicationContext;
    
    29 28
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    30 29
     import fr.ird.t3.entities.user.T3Users;
    
    ... ... @@ -33,7 +32,6 @@ import fr.ird.t3.services.T3ServiceContext;
    33 32
     import fr.ird.t3.services.T3ServiceFactory;
    
    34 33
     import org.apache.commons.logging.Log;
    
    35 34
     import org.apache.commons.logging.LogFactory;
    
    36
    -import org.junit.Assume;
    
    37 35
     import org.junit.rules.TestWatcher;
    
    38 36
     import org.junit.runner.Description;
    
    39 37
     import org.mockito.Mockito;
    
    ... ... @@ -43,7 +41,6 @@ import org.nuiton.version.Version;
    43 41
     
    
    44 42
     import java.io.Closeable;
    
    45 43
     import java.io.File;
    
    46
    -import java.nio.file.Path;
    
    47 44
     import java.util.Date;
    
    48 45
     import java.util.Locale;
    
    49 46
     import java.util.Properties;
    
    ... ... @@ -63,7 +60,6 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    63 60
         private final boolean injectReferential;
    
    64 61
         protected T3TopiaPersistenceContext transaction;
    
    65 62
         private T3TopiaApplicationContext rootContext;
    
    66
    -    private T3Users t3Users;
    
    67 63
         private File testDir;
    
    68 64
         private T3Config applicationConfiguration;
    
    69 65
         private Locale locale;
    
    ... ... @@ -71,26 +67,15 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    71 67
         private boolean initOk;
    
    72 68
         private MSAccessTestConfiguration msConfig;
    
    73 69
     
    
    74
    -    public FakeT3AvdthServiceContext() {
    
    75
    -        this(false);
    
    76
    -    }
    
    77
    -
    
    78
    -    public FakeT3AvdthServiceContext(boolean injectReferential) {
    
    79
    -        this.injectReferential = injectReferential;
    
    80
    -    }
    
    81
    -
    
    82 70
         public FakeT3AvdthServiceContext(boolean injectReferential, MSAccessTestConfiguration msConfig) {
    
    83 71
             this.injectReferential = injectReferential;
    
    84 72
             this.msConfig = msConfig;
    
    73
    +        setLocale(Locale.FRANCE);
    
    85 74
         }
    
    86 75
     
    
    87 76
         @Override
    
    88 77
         public T3Users getT3Users() {
    
    89
    -        return t3Users;
    
    90
    -    }
    
    91
    -
    
    92
    -    public void setT3Users(T3Users t3Users) {
    
    93
    -        this.t3Users = t3Users;
    
    78
    +        return null;
    
    94 79
         }
    
    95 80
     
    
    96 81
         public boolean isInitOk() {
    
    ... ... @@ -116,7 +101,7 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    116 101
             return rootContext;
    
    117 102
         }
    
    118 103
     
    
    119
    -    public T3TopiaPersistenceContext newTransaction() throws TopiaException {
    
    104
    +    private T3TopiaPersistenceContext newTransaction() throws TopiaException {
    
    120 105
             return rootContext.newPersistenceContext();
    
    121 106
         }
    
    122 107
     
    
    ... ... @@ -167,14 +152,12 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    167 152
         protected void starting(Description description) {
    
    168 153
             super.starting(description);
    
    169 154
             testName = description.getMethodName();
    
    170
    -
    
    171 155
             testDir = T3IOUtil.getTestSpecificDirectory(description.getTestClass(), description.getMethodName());
    
    172 156
             log.info(String.format("Test dir = %s", testDir));
    
    173 157
             Properties defaultProps = new Properties();
    
    174 158
             defaultProps.put(T3ConfigOption.DATA_DIRECTORY.getKey(), testDir);
    
    175 159
             File treatmentDirectory = new File(testDir, "treatment");
    
    176 160
             FileUtil.createDirectoryIfNecessary(treatmentDirectory);
    
    177
    -
    
    178 161
             T3Config realConfiguration = new T3Config(defaultProps) {
    
    179 162
                 @Override
    
    180 163
                 public void init() {
    
    ... ... @@ -183,14 +166,12 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    183 166
             };
    
    184 167
             realConfiguration.init();
    
    185 168
             Version t3DataVersion = realConfiguration.getT3DataVersion();
    
    186
    -
    
    187 169
             applicationConfiguration = Mockito.mock(T3Config.class);
    
    188 170
             Mockito.when(applicationConfiguration.getDataDirectory()).thenReturn(testDir);
    
    189 171
             Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory()).thenReturn(treatmentDirectory);
    
    190 172
             Mockito.when(applicationConfiguration.getT3DataVersion()).thenReturn(t3DataVersion);
    
    191 173
             Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory(Mockito.anyString(), Mockito.anyBoolean())).thenCallRealMethod();
    
    192 174
             Mockito.when(applicationConfiguration.getApplicationVersion()).thenReturn(realConfiguration.getApplicationVersion());
    
    193
    -
    
    194 175
             if (msConfig != null) {
    
    195 176
                 boolean b = msConfig.beforeClass() && msConfig.setup(testName);
    
    196 177
                 if (!b) {
    
    ... ... @@ -199,19 +180,7 @@ public class FakeT3AvdthServiceContext extends TestWatcher implements T3ServiceC
    199 180
                 }
    
    200 181
             }
    
    201 182
             try {
    
    202
    -            // where to put h2 database
    
    203
    -            File dbDirectory = new File(testDir, "h2-database");
    
    204
    -            if (injectReferential) {
    
    205
    -                Path scriptPath = new File(new File("").getAbsolutePath()).getParentFile().toPath().resolve(".mvn").resolve("cache").resolve("test");
    
    206
    -                File scriptsDirectory = T3JdbcHelper.getScriptsDirectory(scriptPath.toFile(), "h2", t3DataVersion);
    
    207
    -                String[] list = scriptsDirectory.list((dir, name) -> name.endsWith(".sql") && name.contains("-referential"));
    
    208
    -                if (list == null || list.length != 1) {
    
    209
    -                    throw new IllegalStateException(String.format("Can't find h2 referential db from %s", scriptsDirectory));
    
    210
    -                }
    
    211
    -                rootContext = T3TopiaApplicationContext.newEmbeddedBackupDb(dbDirectory, scriptsDirectory.toPath().resolve(list[0]).toFile());
    
    212
    -            } else {
    
    213
    -                rootContext = T3TopiaApplicationContext.newEmbeddedDb(dbDirectory);
    
    214
    -            }
    
    183
    +            rootContext = T3TopiaApplicationContext.newTestTopiaApplicationContext(testDir, t3DataVersion, injectReferential);
    
    215 184
                 initOk = true;
    
    216 185
             } catch (Exception e) {
    
    217 186
                 initOk = false;
    

  • t3-actions/src/test/java/fr/ird/t3/models/LengthCompositionModelHelperTest.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -102,10 +102,9 @@ public class LengthCompositionModelHelperTest {
    102 102
     
    
    103 103
             models.put(species2, model);
    
    104 104
     
    
    105
    +        DecoratorService decoratorService = serviceContext.newService(DecoratorService.class);
    
    105 106
     
    
    106
    -        String s = LengthCompositionModelHelper.decorateModel(
    
    107
    -                serviceContext.newService(DecoratorService.class),
    
    108
    -                "Mon titre", "Value titre", models);
    
    107
    +        String s = LengthCompositionModelHelper.decorateModel(decoratorService, "Mon titre", "Value titre", models);
    
    109 108
             if (log.isInfoEnabled()) {
    
    110 109
                 log.info("Result :\n" + s);
    
    111 110
             }
    

  • t3-actions/src/test/java/fr/ird/t3/models/WeightCompositionModelHelperTest.java
    ... ... @@ -20,7 +20,6 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.models;
    
    22 22
     
    
    23
    -import com.google.common.collect.Sets;
    
    24 23
     import fr.ird.t3.FakeT3ServiceContext;
    
    25 24
     import fr.ird.t3.T3ActionFixtures;
    
    26 25
     import fr.ird.t3.entities.reference.Species;
    
    ... ... @@ -32,7 +31,6 @@ import org.junit.Test;
    32 31
     
    
    33 32
     import java.util.HashMap;
    
    34 33
     import java.util.Map;
    
    35
    -import java.util.Set;
    
    36 34
     
    
    37 35
     /**
    
    38 36
      * To test {@link WeightCompositionModelHelper}.
    
    ... ... @@ -54,9 +52,6 @@ public class WeightCompositionModelHelperTest {
    54 52
     
    
    55 53
             Species species1 = fixtures.species1();
    
    56 54
             Species species2 = fixtures.species2();
    
    57
    -        Species species3 = fixtures.species3();
    
    58
    -
    
    59
    -        Set<Species> species = Sets.newHashSet(species1, species2, species3);
    
    60 55
     
    
    61 56
             WeightCompositionAggregateModel model = new WeightCompositionAggregateModel();
    
    62 57
             WeightCompositionModel model1 = new WeightCompositionModel(fixtures.weightCategoryTreatment1());
    
    ... ... @@ -80,9 +75,7 @@ public class WeightCompositionModelHelperTest {
    80 75
             model3.addWeights(weights);
    
    81 76
             model.addModel(model3);
    
    82 77
     
    
    83
    -        String s = WeightCompositionModelHelper.decorateModel(
    
    84
    -                serviceContext.newService(DecoratorService.class),
    
    85
    -                "Mon titre", model);
    
    78
    +        String s = WeightCompositionModelHelper.decorateModel(serviceContext.newService(DecoratorService.class), "Mon titre", model);
    
    86 79
             log.info("Result :\n" + s);
    
    87 80
         }
    
    88 81
     }

  • t3-domain/src/main/java/fr/ird/t3/actions/stratum/SchoolTypeIndeterminate.java
    1
    +package fr.ird.t3.actions.stratum;
    
    2
    +
    
    3
    +/**
    
    4
    + * Created by tchemit on 07/03/2018.
    
    5
    + *
    
    6
    + * @author Tony Chemit - dev@tchemit.fr
    
    7
    + */
    
    8
    +public enum SchoolTypeIndeterminate {
    
    9
    +}

  • t3-domain/src/main/java/fr/ird/t3/entities/T3TopiaApplicationContext.java
    ... ... @@ -10,12 +10,12 @@ package fr.ird.t3.entities;
    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%
    
    ... ... @@ -32,12 +32,14 @@ import org.nuiton.topia.persistence.TopiaConfiguration;
    32 32
     import org.nuiton.topia.persistence.TopiaConfigurationBuilder;
    
    33 33
     import org.nuiton.topia.persistence.TopiaException;
    
    34 34
     import org.nuiton.util.RecursiveProperties;
    
    35
    +import org.nuiton.version.Version;
    
    35 36
     
    
    36 37
     import java.io.File;
    
    37 38
     import java.io.IOException;
    
    38 39
     import java.io.InputStream;
    
    39 40
     import java.io.InputStreamReader;
    
    40 41
     import java.net.URL;
    
    42
    +import java.nio.file.Path;
    
    41 43
     import java.util.Objects;
    
    42 44
     import java.util.Properties;
    
    43 45
     
    
    ... ... @@ -47,6 +49,10 @@ public class T3TopiaApplicationContext extends AbstractT3TopiaApplicationContext
    47 49
         private static final String T3_USER_DB_PROPERTIES = "/t3-datadb.properties";
    
    48 50
         private static final Log log = LogFactory.getLog(T3TopiaApplicationContext.class);
    
    49 51
     
    
    52
    +    private T3TopiaApplicationContext(TopiaConfiguration topiaConfiguration) {
    
    53
    +        super(topiaConfiguration);
    
    54
    +    }
    
    55
    +
    
    50 56
         /**
    
    51 57
          * Open a new topia root context from the given jdbc configuration.
    
    52 58
          *
    
    ... ... @@ -83,7 +89,6 @@ public class T3TopiaApplicationContext extends AbstractT3TopiaApplicationContext
    83 89
             return new T3TopiaApplicationContext(topiaConfiguration);
    
    84 90
         }
    
    85 91
     
    
    86
    -
    
    87 92
         /**
    
    88 93
          * Open a new topia root context for the user t3 db using a embedded db (this should be a h2 db).
    
    89 94
          * <p/>
    
    ... ... @@ -110,6 +115,21 @@ public class T3TopiaApplicationContext extends AbstractT3TopiaApplicationContext
    110 115
             return new T3TopiaApplicationContext(topiaConfiguration);
    
    111 116
         }
    
    112 117
     
    
    118
    +    public static T3TopiaApplicationContext newTestTopiaApplicationContext(File testDir, Version t3DataVersion, boolean injectReferential) throws IOException {
    
    119
    +        File dbDirectory = new File(testDir, "h2-database");
    
    120
    +        if (injectReferential) {
    
    121
    +            Path scriptPath = new File(new File("").getAbsolutePath()).getParentFile().toPath().resolve(".mvn").resolve("cache").resolve("test");
    
    122
    +            File scriptsDirectory = T3JdbcHelper.getScriptsDirectory(scriptPath.toFile(), "h2", t3DataVersion);
    
    123
    +            String[] list = scriptsDirectory.list((dir, name) -> name.endsWith(".sql") && name.contains("-referential"));
    
    124
    +            if (list == null || list.length != 1) {
    
    125
    +                throw new IllegalStateException(String.format("Can't find h2 referential db from %s", scriptsDirectory));
    
    126
    +            }
    
    127
    +            return newEmbeddedBackupDb(dbDirectory, scriptsDirectory.toPath().resolve(list[0]).toFile());
    
    128
    +        } else {
    
    129
    +            return newEmbeddedDb(dbDirectory);
    
    130
    +        }
    
    131
    +    }
    
    132
    +
    
    113 133
         /**
    
    114 134
          * Open a new topia root context for the user t3 db using a embedded db (this should be a h2 db).
    
    115 135
          * <p/>
    
    ... ... @@ -119,7 +139,7 @@ public class T3TopiaApplicationContext extends AbstractT3TopiaApplicationContext
    119 139
          * @param backupFile backup file to load in db
    
    120 140
          * @return the new fresh root context of the db
    
    121 141
          */
    
    122
    -    public static T3TopiaApplicationContext newEmbeddedBackupDb(File dbLocation, File backupFile) {
    
    142
    +    private static T3TopiaApplicationContext newEmbeddedBackupDb(File dbLocation, File backupFile) {
    
    123 143
     
    
    124 144
             Properties configuration = new Properties();
    
    125 145
     
    
    ... ... @@ -143,8 +163,4 @@ public class T3TopiaApplicationContext extends AbstractT3TopiaApplicationContext
    143 163
             return new T3JdbcHelper(getConfiguration());
    
    144 164
         }
    
    145 165
     
    
    146
    -    private T3TopiaApplicationContext(TopiaConfiguration topiaConfiguration) {
    
    147
    -        super(topiaConfiguration);
    
    148
    -    }
    
    149
    -
    
    150 166
     }

  • t3-domain/src/main/java/fr/ird/t3/models/LengthCompositionModelHelper.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -21,13 +21,13 @@
    21 21
     package fr.ird.t3.models;
    
    22 22
     
    
    23 23
     import com.google.common.base.Strings;
    
    24
    -import com.google.common.collect.Lists;
    
    25 24
     import fr.ird.t3.entities.reference.Species;
    
    25
    +import fr.ird.t3.entities.reference.WeightCategories;
    
    26 26
     import fr.ird.t3.entities.reference.WeightCategoryTreatment;
    
    27
    -import fr.ird.t3.entities.reference.WeightCategoryTreatmentTopiaDao;
    
    28 27
     import fr.ird.t3.services.DecoratorService;
    
    29 28
     import org.nuiton.decorator.Decorator;
    
    30 29
     
    
    30
    +import java.util.ArrayList;
    
    31 31
     import java.util.Collections;
    
    32 32
     import java.util.Comparator;
    
    33 33
     import java.util.List;
    
    ... ... @@ -43,7 +43,7 @@ import static org.nuiton.i18n.I18n.l;
    43 43
      * @author Tony Chemit - dev@tchemit.fr
    
    44 44
      * @since 1.3.1
    
    45 45
      */
    
    46
    -public class LengthCompositionModelHelper {
    
    46
    +public final class LengthCompositionModelHelper {
    
    47 47
     
    
    48 48
         private static final Comparator<Species> SPECIES_COMPARATOR = Comparator.comparingInt(Species::getCode);
    
    49 49
     
    
    ... ... @@ -55,96 +55,64 @@ public class LengthCompositionModelHelper {
    55 55
                                            String title,
    
    56 56
                                            String valueTitle,
    
    57 57
                                            Map<Species, LengthCompositionAggregateModel> models) {
    
    58
    -
    
    59 58
             StringBuilder inResume = new StringBuilder();
    
    60
    -
    
    61 59
             Locale locale = decoratorService.getLocale();
    
    62
    -
    
    63 60
             String lengthClassLabel = l(locale, "t3.common.lengthClass");
    
    64
    -
    
    65 61
             int lengthClassColumnLength = lengthClassLabel.length();
    
    66 62
             int valueColumnLength = 15;
    
    67 63
             int rateColumnLength = 15;
    
    68
    -
    
    69
    -        Decorator<Species> decorator =
    
    70
    -                decoratorService.getDecorator(locale, Species.class, null);
    
    71
    -
    
    64
    +        Decorator<Species> decorator = decoratorService.getDecorator(locale, Species.class, null);
    
    72 65
             Decorator<WeightCategoryTreatment> decorator2 =
    
    73 66
                     decoratorService.getDecorator(locale, WeightCategoryTreatment.class, null);
    
    74
    -
    
    75
    -        List<Species> speciesList = Lists.newArrayList(models.keySet());
    
    67
    +        List<Species> speciesList = new ArrayList<>(models.keySet());
    
    76 68
             speciesList.sort(SPECIES_COMPARATOR);
    
    77 69
             int origMaxLength = 10 + (lengthClassColumnLength) + (valueColumnLength + rateColumnLength);
    
    78 70
             int maxLength = origMaxLength;
    
    79
    -
    
    80 71
             maxLength = Math.max(maxLength, l(locale, "t3.common.forAllWeightCategories").length() + 4);
    
    81
    -
    
    82 72
             for (Species species : speciesList) {
    
    83 73
                 int l = decorator.toString(species).length() + 4;
    
    84 74
                 maxLength = Math.max(maxLength, l);
    
    85 75
                 LengthCompositionAggregateModel model = models.get(species);
    
    86
    -
    
    87 76
                 Set<WeightCategoryTreatment> weightCategories = model.getWeightCategories();
    
    88 77
                 for (WeightCategoryTreatment weightCategory : weightCategories) {
    
    89 78
                     int l2 = l(locale, "t3.common.weightCategory", decorator2.toString(weightCategory)).length() + 4;
    
    90 79
                     maxLength = Math.max(maxLength, l2);
    
    91 80
                 }
    
    92 81
             }
    
    93
    -
    
    94 82
             if (maxLength > origMaxLength) {
    
    95 83
                 lengthClassColumnLength += maxLength - origMaxLength;
    
    96 84
             }
    
    97
    -
    
    98 85
             CompositionTableModel header = new CompositionTableModel();
    
    99 86
             String lineFormat = "| %1$-" + lengthClassColumnLength + "s | %2$-" + valueColumnLength + "s - %3$-" + rateColumnLength + "s |\n";
    
    100
    -
    
    101 87
             header.setLineFormat(lineFormat);
    
    102 88
             header.setHeader(
    
    103 89
                     String.format("| %1$-" + lengthClassColumnLength + "s | %2$-" + (valueColumnLength + rateColumnLength + 3) + "s |\n", lengthClassLabel, valueTitle));
    
    104
    -
    
    105 90
             header.setSeparatorFormat3(
    
    106 91
                     Strings.padEnd("|", lengthClassColumnLength + 3, '-') +
    
    107 92
                             Strings.padEnd("|", (valueColumnLength + rateColumnLength + 6), '-') + "|\n");
    
    108
    -
    
    109 93
             header.setCategoryFormat("| %1$-" + (maxLength - 4) + "s |\n");
    
    110 94
             header.setSeparatorFormat(Strings.padEnd("|", maxLength - 1, '-') + "|\n");
    
    111 95
             header.setSeparatorFormat2(Strings.padEnd("|", maxLength - 1, '=') + "|\n");
    
    112 96
             header.setTopSeparatorFormat(Strings.padEnd("=", maxLength, '=') + "\n");
    
    113 97
             header.setBottomSeparatorFormat(Strings.padEnd("=", maxLength, '=') + "\n");
    
    114
    -
    
    115 98
             inResume.append(title).append('\n');
    
    116 99
             inResume.append(header.getTopSeparatorFormat());
    
    117 100
             inResume.append(header.getHeader());
    
    118
    -
    
    119 101
             for (Species species : speciesList) {
    
    120
    -
    
    121 102
                 inResume.append(header.getSeparatorFormat2());
    
    122
    -            inResume.append(String.format(header.getCategoryFormat(),
    
    123
    -                    decorator.toString(species)));
    
    124
    -
    
    103
    +            inResume.append(String.format(header.getCategoryFormat(), decorator.toString(species)));
    
    125 104
                 LengthCompositionAggregateModel model = models.get(species);
    
    126
    -
    
    127
    -            List<WeightCategoryTreatment> weightCategories = Lists.newArrayList(model.getWeightCategories());
    
    128
    -            weightCategories.sort(WeightCategoryTreatmentTopiaDao.newComparator());
    
    129
    -
    
    105
    +            List<WeightCategoryTreatment> weightCategories = new ArrayList<>(model.getWeightCategories());
    
    106
    +            WeightCategories.sort(weightCategories);
    
    130 107
                 for (WeightCategoryTreatment weightCategory : weightCategories) {
    
    131 108
                     LengthCompositionModel lengthCompositionModel = model.getModel(weightCategory);
    
    132 109
                     if (!lengthCompositionModel.isEmpty()) {
    
    133 110
                         inResume.append(header.getSeparatorFormat());
    
    134
    -                    decorateModel(
    
    135
    -                            header,
    
    136
    -                            decoratorService,
    
    137
    -                            model,
    
    138
    -                            weightCategory,
    
    139
    -                            inResume
    
    140
    -                    );
    
    111
    +                    decorateModel(header, decoratorService, model, weightCategory, inResume);
    
    141 112
                     }
    
    142
    -
    
    143 113
                 }
    
    144 114
             }
    
    145
    -
    
    146 115
             inResume.append(header.getBottomSeparatorFormat());
    
    147
    -
    
    148 116
             return inResume.toString();
    
    149 117
         }
    
    150 118
     
    
    ... ... @@ -153,78 +121,43 @@ public class LengthCompositionModelHelper {
    153 121
                                           LengthCompositionAggregateModel model,
    
    154 122
                                           WeightCategoryTreatment weightCategory,
    
    155 123
                                           StringBuilder inResume) {
    
    156
    -
    
    157 124
             Decorator<WeightCategoryTreatment> decorator2 =
    
    158 125
                     decoratorService.getDecorator(decoratorService.getLocale(), WeightCategoryTreatment.class, null);
    
    159
    -
    
    160
    -        LengthCompositionModel m;
    
    161
    -
    
    162
    -        String categoryLibelle;
    
    163
    -
    
    164 126
             Locale locale = decoratorService.getLocale();
    
    165
    -
    
    166
    -        String totalLibelle = l(locale, "t3.common.total");
    
    167
    -        String averageLengthLibelle = l(locale, "t3.common.averageLength");
    
    168
    -
    
    127
    +        String totalLabel = l(locale, "t3.common.total");
    
    128
    +        String averageLengthLabel = l(locale, "t3.common.averageLength");
    
    129
    +        LengthCompositionModel m;
    
    130
    +        String categoryLabel;
    
    169 131
             if (weightCategory == null) {
    
    170
    -
    
    171 132
                 m = model.getTotalModel();
    
    172
    -            categoryLibelle = l(locale, "t3.common.forAllWeightCategories");
    
    133
    +            categoryLabel = l(locale, "t3.common.forAllWeightCategories");
    
    173 134
             } else {
    
    174 135
                 m = model.getModel(weightCategory);
    
    175
    -
    
    176
    -            categoryLibelle =
    
    177
    -                    l(locale, "t3.common.weightCategory",
    
    178
    -                            decorator2.toString(weightCategory));
    
    136
    +            categoryLabel = l(locale, "t3.common.weightCategory", decorator2.toString(weightCategory));
    
    179 137
             }
    
    180
    -
    
    181 138
             if (!m.isEmpty()) {
    
    182
    -
    
    183
    -            inResume.append(String.format(header.getCategoryFormat(), categoryLibelle));
    
    139
    +            inResume.append(String.format(header.getCategoryFormat(), categoryLabel));
    
    184 140
                 inResume.append(header.getSeparatorFormat());
    
    185
    -
    
    186 141
                 String lineFormat = header.getLineFormat();
    
    187
    -
    
    188
    -            List<Integer> lengthClasses = Lists.newArrayList(m.getLengthClasses());
    
    142
    +            List<Integer> lengthClasses = new ArrayList<>(m.getLengthClasses());
    
    189 143
                 Collections.sort(lengthClasses);
    
    190
    -
    
    191 144
                 float totalRate = 0;
    
    192 145
                 float totalCount = 0;
    
    193
    -
    
    194 146
                 float totalLength = 0;
    
    195
    -
    
    196 147
                 for (Integer lengthClass : lengthClasses) {
    
    197
    -
    
    198 148
                     float weightRate1 = m.getRate(lengthClass);
    
    199 149
                     totalRate += weightRate1;
    
    200 150
                     float value = m.getValue(lengthClass);
    
    201
    -                inResume.append(String.format(
    
    202
    -                        lineFormat,
    
    203
    -                        lengthClass,
    
    204
    -                        value,
    
    205
    -                        (100 * weightRate1) + "%"));
    
    151
    +                inResume.append(String.format(lineFormat, lengthClass, value, (100 * weightRate1) + "%"));
    
    206 152
                     totalCount += value;
    
    207 153
                     totalLength += lengthClass * value;
    
    208 154
                 }
    
    209
    -
    
    210 155
                 float averageLength = totalLength / totalCount;
    
    211
    -
    
    212 156
                 inResume.append(header.getSeparatorFormat3());
    
    213
    -
    
    214
    -            inResume.append(String.format(
    
    215
    -                    lineFormat,
    
    216
    -                    totalLibelle,
    
    217
    -                    totalCount,
    
    218
    -                    (100 * totalRate) + "%"));
    
    219
    -
    
    157
    +            inResume.append(String.format(lineFormat, totalLabel, totalCount, (100 * totalRate) + "%"));
    
    220 158
                 if (weightCategory != null) {
    
    221
    -                inResume.append(String.format(
    
    222
    -                        lineFormat,
    
    223
    -                        averageLengthLibelle,
    
    224
    -                        averageLength,
    
    225
    -                        "-"));
    
    159
    +                inResume.append(String.format(lineFormat, averageLengthLabel, averageLength, "-"));
    
    226 160
                 }
    
    227
    -
    
    228 161
             }
    
    229 162
         }
    
    230 163
     }

  • t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
    ... ... @@ -8,21 +8,19 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    20 20
      */
    
    21 21
     package fr.ird.t3.services;
    
    22 22
     
    
    23
    -import com.google.common.base.Preconditions;
    
    24
    -import com.google.common.collect.Lists;
    
    25
    -import com.google.common.collect.Maps;
    
    23
    +import fr.ird.t3.actions.stratum.SchoolTypeIndeterminate;
    
    26 24
     import fr.ird.t3.entities.data.Activity;
    
    27 25
     import fr.ird.t3.entities.data.CompleteTrip;
    
    28 26
     import fr.ird.t3.entities.data.Route;
    
    ... ... @@ -58,11 +56,14 @@ import org.nuiton.decorator.JXPathDecorator;
    58 56
     import org.nuiton.topia.persistence.TopiaEntity;
    
    59 57
     
    
    60 58
     import java.text.SimpleDateFormat;
    
    59
    +import java.util.ArrayList;
    
    61 60
     import java.util.Collection;
    
    62 61
     import java.util.Date;
    
    62
    +import java.util.LinkedHashMap;
    
    63 63
     import java.util.List;
    
    64 64
     import java.util.Locale;
    
    65 65
     import java.util.Map;
    
    66
    +import java.util.Objects;
    
    66 67
     
    
    67 68
     import static org.nuiton.i18n.I18n.l;
    
    68 69
     
    
    ... ... @@ -75,85 +76,60 @@ import static org.nuiton.i18n.I18n.l;
    75 76
     public class DecoratorService extends T3ServiceSupport implements T3ServiceSingleton {
    
    76 77
     
    
    77 78
         public static final String WITH_ID = "withId";
    
    78
    -
    
    79
    +    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
    
    79 80
         private final DecoratorMulti18nProvider decoratorProvider;
    
    80 81
     
    
    81
    -    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
    
    82
    +    public DecoratorService() {
    
    83
    +        decoratorProvider = new T3DecoratorProvider();
    
    84
    +    }
    
    82 85
     
    
    83 86
         public static String formatDate(Date date) {
    
    84 87
             return DATE_FORMAT.format(date);
    
    85 88
         }
    
    86 89
     
    
    87
    -    public DecoratorService() {
    
    88
    -        decoratorProvider = new T3DecoratorProvider();
    
    89
    -    }
    
    90
    -
    
    91
    -    public <O> Decorator<O> getDecorator(Locale locale,
    
    92
    -                                         Class<O> type,
    
    93
    -                                         String context) {
    
    94
    -        Preconditions.checkNotNull(type, "Decorator type can not be null!");
    
    95
    -        Decorator<O> decorator = decoratorProvider.getDecoratorByType(locale, type, context);
    
    96
    -        Preconditions.checkNotNull(
    
    97
    -                decorator,
    
    98
    -                "Could not find decorator for type " + type +
    
    99
    -                        " and context " + context
    
    100
    -        );
    
    101
    -        return decorator;
    
    90
    +    public <O> Decorator<O> getDecorator(Locale locale, Class<O> type, String context) {
    
    91
    +        Decorator<O> decorator = decoratorProvider.getDecoratorByType(Objects.requireNonNull(locale), Objects.requireNonNull(type), context);
    
    92
    +        return Objects.requireNonNull(decorator,
    
    93
    +                String.format("Could not find decorator for type %s and context %s", type, context));
    
    102 94
         }
    
    103 95
     
    
    104 96
         public String decorate(Locale locale, Object o, String context) {
    
    105
    -        Decorator<?> decorator = getDecorator(locale, o.getClass(), context);
    
    97
    +        Decorator<?> decorator = getDecorator(locale, Objects.requireNonNull(o).getClass(), context);
    
    106 98
             return decorator.toString(o);
    
    107 99
         }
    
    108 100
     
    
    109 101
         public <O> List<O> sortToList(Locale locale, Collection<O> beans, String context) {
    
    110
    -        Preconditions.checkNotNull(beans);
    
    111
    -        List<O> list = Lists.newArrayList(beans);
    
    102
    +        List<O> list = new ArrayList<>(Objects.requireNonNull(beans));
    
    112 103
             getDecoratorAndSort(locale, context, list);
    
    113 104
             return list;
    
    114 105
         }
    
    115 106
     
    
    116
    -    public <E extends TopiaEntity> Map<String, String> sortAndDecorate(Locale locale,
    
    117
    -                                                                       Collection<E> beans,
    
    118
    -                                                                       String context) {
    
    119
    -        Preconditions.checkNotNull(beans);
    
    120
    -        List<E> list = Lists.newArrayList(beans);
    
    121
    -
    
    107
    +    public <E extends TopiaEntity> Map<String, String> sortAndDecorate(Locale locale, Collection<E> beans, String context) {
    
    108
    +        List<E> list = new ArrayList<>(Objects.requireNonNull(beans));
    
    122 109
             Decorator<E> decorator = getDecoratorAndSort(locale, context, list);
    
    123
    -        Map<String, String> result = Maps.newLinkedHashMap();
    
    110
    +        Map<String, String> result = new LinkedHashMap<>();
    
    124 111
             for (E bean : list) {
    
    125 112
                 result.put(bean.getTopiaId(), decorator.toString(bean));
    
    126 113
             }
    
    127 114
             return result;
    
    128 115
         }
    
    129 116
     
    
    130
    -    public <E extends Idable> Map<String, String> sortAndDecorateIdAbles(Locale locale,
    
    131
    -                                                                         Collection<E> beans,
    
    132
    -                                                                         String context) {
    
    133
    -
    
    134
    -        Preconditions.checkNotNull(beans);
    
    135
    -        List<E> list = Lists.newArrayList(beans);
    
    136
    -
    
    117
    +    public <E extends Idable> Map<String, String> sortAndDecorateIdAbles(Locale locale, Collection<E> beans, String context) {
    
    118
    +        List<E> list = new ArrayList<>(Objects.requireNonNull(beans));
    
    137 119
             Decorator<E> decorator = getDecoratorAndSort(locale, context, list);
    
    138
    -        Map<String, String> result = Maps.newLinkedHashMap();
    
    120
    +        Map<String, String> result = new LinkedHashMap<>();
    
    139 121
             for (E bean : list) {
    
    140 122
                 result.put(bean.getId(), decorator.toString(bean));
    
    141 123
             }
    
    142 124
             return result;
    
    143 125
         }
    
    144 126
     
    
    145
    -    protected <O> Decorator<O> getDecoratorAndSort(Locale locale,
    
    146
    -                                                   String context,
    
    147
    -                                                   List<O> list) {
    
    127
    +    private <O> Decorator<O> getDecoratorAndSort(Locale locale, String context, List<O> list) {
    
    148 128
             Decorator<O> decorator = null;
    
    149 129
             if (CollectionUtils.isNotEmpty(list)) {
    
    150
    -            O object = list.get(0);
    
    151
    -            Preconditions.checkNotNull(object);
    
    152
    -            decorator = decoratorProvider.getDecorator(locale, object, context);
    
    153
    -            Preconditions.checkNotNull(
    
    154
    -                    decorator,
    
    155
    -                    "Could not find decorator for type " + object.getClass() +
    
    156
    -                            " and context " + context
    
    130
    +            O object = Objects.requireNonNull(list.get(0));
    
    131
    +            decorator = Objects.requireNonNull(decoratorProvider.getDecorator(locale, object, context),
    
    132
    +                    String.format("Could not find decorator for type %s and context %s", object.getClass(), context)
    
    157 133
                 );
    
    158 134
                 DecoratorUtil.sort((JXPathDecorator<O>) decorator, list, 0);
    
    159 135
             }
    
    ... ... @@ -171,6 +147,9 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
    171 147
                 // trip type decorator
    
    172 148
                 registerJXPathDecorator(locale, TripType.class, "${label}$s");
    
    173 149
     
    
    150
    +            // SchoolTypeIndeterminate decorator
    
    151
    +            registerJXPathDecorator(locale, SchoolTypeIndeterminate.class, "${label}$s");
    
    152
    +
    
    174 153
                 // route decorator
    
    175 154
                 registerJXPathDecorator(locale, Route.class, "${trip/vesselLabel}$s - ${trip/landingDate}$td/%2$tm/%2$tY - ${date}$td/%3$tm/%3$tY");
    
    176 155
     
    
    ... ... @@ -259,20 +238,17 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
    259 238
         private static class ZoneStratumAwareMetaJXPathDecorator extends JXPathDecorator<ZoneStratumAwareMeta> {
    
    260 239
     
    
    261 240
             private static final long serialVersionUID = 1L;
    
    262
    -
    
    263 241
             private final Locale locale;
    
    264 242
     
    
    265
    -        public ZoneStratumAwareMetaJXPathDecorator(String expression,
    
    266
    -                                                   Context<ZoneStratumAwareMeta> context,
    
    267
    -                                                   Locale locale) throws IllegalArgumentException, NullPointerException {
    
    243
    +        ZoneStratumAwareMetaJXPathDecorator(String expression, Context<ZoneStratumAwareMeta> context, Locale locale) {
    
    268 244
                 super(ZoneStratumAwareMeta.class, expression, context);
    
    269 245
                 this.locale = locale;
    
    270 246
             }
    
    271 247
     
    
    272 248
             @SuppressWarnings({"RawUseOfParameterizedType", "RedundantCast", "unchecked"})
    
    273 249
             @Override
    
    274
    -        protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxcontext, String token) {
    
    275
    -            Comparable tokenValue = super.getTokenValue(jxcontext, token);
    
    250
    +        protected Comparable<Comparable<?>> getTokenValue(JXPathContext jxContext, String token) {
    
    251
    +            Comparable tokenValue = super.getTokenValue(jxContext, token);
    
    276 252
                 return (Comparable) l(locale, (String) tokenValue);
    
    277 253
             }
    
    278 254
         }
    

  • t3-domain/src/main/java/fr/ird/t3/services/T3ServiceSupport.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -22,14 +22,13 @@ package fr.ird.t3.services;
    22 22
     
    
    23 23
     import fr.ird.t3.T3Config;
    
    24 24
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    25
    -
    
    26
    -import java.util.Locale;
    
    27
    -import java.util.function.Supplier;
    
    28
    -
    
    29 25
     import fr.ird.t3.entities.user.T3Users;
    
    30 26
     import org.nuiton.topia.persistence.TopiaException;
    
    31 27
     import org.nuiton.util.TimeLog;
    
    32 28
     
    
    29
    +import java.util.Locale;
    
    30
    +import java.util.function.Supplier;
    
    31
    +
    
    33 32
     /**
    
    34 33
      * Service support.
    
    35 34
      *
    
    ... ... @@ -38,16 +37,15 @@ import org.nuiton.util.TimeLog;
    38 37
      */
    
    39 38
     public class T3ServiceSupport implements T3Service {
    
    40 39
     
    
    41
    -    protected TimeLog timeLog;
    
    42
    -
    
    43 40
         protected T3ServiceContext serviceContext;
    
    41
    +    private TimeLog timeLog;
    
    44 42
     
    
    45 43
         @Override
    
    46 44
         public void setServiceContext(T3ServiceContext serviceContext) {
    
    47 45
             this.serviceContext = serviceContext;
    
    48 46
         }
    
    49 47
     
    
    50
    -    public T3Users getT3UserStorage() {
    
    48
    +    public T3Users getT3Users() {
    
    51 49
             return serviceContext.getT3Users();
    
    52 50
         }
    
    53 51
     
    
    ... ... @@ -71,20 +69,10 @@ public class T3ServiceSupport implements T3Service {
    71 69
             return serviceContext.newService(clazz);
    
    72 70
         }
    
    73 71
     
    
    74
    -    protected void flushTransaction(String message) throws TopiaException {
    
    72
    +    protected void flushTransaction(String classifier) throws TopiaException {
    
    75 73
             long s0 = TimeLog.getTime();
    
    76
    -
    
    77 74
             getT3TopiaPersistenceContext().get().getHibernateSupport().getHibernateSession().flush();
    
    78
    -
    
    79
    -        getTimeLog().log(s0, message);
    
    80
    -    }
    
    81
    -
    
    82
    -    protected void flushTransaction(String message, String classifier) throws TopiaException {
    
    83
    -        long s0 = TimeLog.getTime();
    
    84
    -
    
    85
    -        getT3TopiaPersistenceContext().get().getHibernateSupport().getHibernateSession().flush();
    
    86
    -
    
    87
    -        getTimeLog().log(s0, message, classifier);
    
    75
    +        getTimeLog().log(s0, "Flush transaction for trip", classifier);
    
    88 76
         }
    
    89 77
     
    
    90 78
         protected TimeLog getTimeLog() {
    

  • t3-domain/src/main/java/fr/ird/t3/services/UserService.java
    ... ... @@ -41,15 +41,15 @@ import java.util.UUID;
    41 41
     public class UserService extends T3ServiceSupport implements T3ServiceInjectable {
    
    42 42
     
    
    43 43
         public Optional<T3User> getUserByLogin(String login) {
    
    44
    -        return getT3UserStorage().usersStream().whereLogin().isEquals(login).filter().findFirst();
    
    44
    +        return getT3Users().usersStream().whereLogin().isEquals(login).filter().findFirst();
    
    45 45
         }
    
    46 46
     
    
    47 47
         public T3User getUserById(String userId) throws TopiaNotFoundException {
    
    48
    -        return getT3UserStorage().usersStream().whereId().isEquals(userId).filter().findFirst().orElseThrow(() -> new TopiaNotFoundException(userId));
    
    48
    +        return getT3Users().usersStream().whereId().isEquals(userId).filter().findFirst().orElseThrow(() -> new TopiaNotFoundException(userId));
    
    49 49
         }
    
    50 50
     
    
    51 51
         public List<T3User> getUsers() {
    
    52
    -        return getT3UserStorage().getUsers();
    
    52
    +        return getT3Users().getUsers();
    
    53 53
         }
    
    54 54
     
    
    55 55
         public void createUser(T3User user) {
    
    ... ... @@ -61,7 +61,7 @@ public class UserService extends T3ServiceSupport implements T3ServiceInjectable
    61 61
                     .login(user.getLogin())
    
    62 62
                     .password(newPassword)
    
    63 63
                     .build();
    
    64
    -        getT3UserStorage().getUsers().add(userToSave);
    
    64
    +        getT3Users().getUsers().add(userToSave);
    
    65 65
             user.setId(userToSave.getId());
    
    66 66
             commit();
    
    67 67
         }
    
    ... ... @@ -82,7 +82,7 @@ public class UserService extends T3ServiceSupport implements T3ServiceInjectable
    82 82
     
    
    83 83
         public void deleteUser(String userId) {
    
    84 84
             T3User user = getUserById(userId);
    
    85
    -        getT3UserStorage().getUsers().remove(user);
    
    85
    +        getT3Users().getUsers().remove(user);
    
    86 86
             commit();
    
    87 87
         }
    
    88 88
     
    
    ... ... @@ -139,11 +139,11 @@ public class UserService extends T3ServiceSupport implements T3ServiceInjectable
    139 139
         }
    
    140 140
     
    
    141 141
         public UserDatabase getUserInputDatabase(String dbConfigurationId) {
    
    142
    -        return getT3UserStorage().getInput(dbConfigurationId);
    
    142
    +        return getT3Users().getInput(dbConfigurationId);
    
    143 143
         }
    
    144 144
     
    
    145 145
         public UserDatabase getUserOutputDatabase(String dbConfigurationId) {
    
    146
    -        return getT3UserStorage().getOutput(dbConfigurationId);
    
    146
    +        return getT3Users().getOutput(dbConfigurationId);
    
    147 147
         }
    
    148 148
     
    
    149 149
         public boolean checkPassword(T3User user, String password) {
    
    ... ... @@ -162,7 +162,7 @@ public class UserService extends T3ServiceSupport implements T3ServiceInjectable
    162 162
         }
    
    163 163
     
    
    164 164
         private void commit() {
    
    165
    -        getT3UserStorage().save();
    
    165
    +        getT3Users().save();
    
    166 166
         }
    
    167 167
     
    
    168 168
     }

  • t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
    ... ... @@ -76,7 +76,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
    76 76
             list.add(catInconnu);
    
    77 77
             list.add(catBound);
    
    78 78
     
    
    79
    -        WeightCategoryTreatmentTopiaDao.sortWeightCategoryTreatments(list);
    
    79
    +        WeightCategories.sort(list);
    
    80 80
     
    
    81 81
             Assert.assertEquals(list.get(0), catBound);
    
    82 82
             Assert.assertEquals(list.get(1), catUnbound);
    
    ... ... @@ -113,8 +113,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
    113 113
             list.add(catInconnu);
    
    114 114
             list.add(catBound);
    
    115 115
     
    
    116
    -        Comparator<WeightCategoryTreatment> comparator =
    
    117
    -                WeightCategoryTreatmentTopiaDao.newComparator();
    
    116
    +        Comparator<WeightCategory> comparator =WeightCategories.newComparator();
    
    118 117
     
    
    119 118
             int compare;
    
    120 119
     
    
    ... ... @@ -127,7 +126,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
    127 126
             compare = comparator.compare(catBound2, catUnbound);
    
    128 127
             Assert.assertTrue(compare < 0);
    
    129 128
     
    
    130
    -        WeightCategoryTreatmentTopiaDao.sortWeightCategoryTreatments(list);
    
    129
    +        WeightCategories.sort(list);
    
    131 130
     
    
    132 131
             Assert.assertEquals(list.get(0), catBound);
    
    133 132
             Assert.assertEquals(list.get(1), catBound2);
    

  • t3-test/src/main/java/fr/ird/t3/FakeT3ServiceContext.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -21,7 +21,6 @@
    21 21
     package fr.ird.t3;
    
    22 22
     
    
    23 23
     import fr.ird.t3.entities.T3EntityHelper;
    
    24
    -import fr.ird.t3.entities.T3JdbcHelper;
    
    25 24
     import fr.ird.t3.entities.T3TopiaApplicationContext;
    
    26 25
     import fr.ird.t3.entities.T3TopiaPersistenceContext;
    
    27 26
     import fr.ird.t3.entities.user.T3Users;
    
    ... ... @@ -39,7 +38,6 @@ import org.nuiton.version.Version;
    39 38
     
    
    40 39
     import java.io.Closeable;
    
    41 40
     import java.io.File;
    
    42
    -import java.nio.file.Path;
    
    43 41
     import java.util.Date;
    
    44 42
     import java.util.Locale;
    
    45 43
     import java.util.Properties;
    
    ... ... @@ -59,11 +57,9 @@ public class FakeT3ServiceContext extends TestWatcher implements T3ServiceContex
    59 57
         private final boolean injectReferential;
    
    60 58
         protected T3TopiaPersistenceContext transaction;
    
    61 59
         private T3TopiaApplicationContext rootContext;
    
    62
    -    private T3Users t3Users;
    
    63 60
         private File testDir;
    
    64 61
         private T3Config applicationConfiguration;
    
    65 62
         private Locale locale;
    
    66
    -    private String testName;
    
    67 63
         private boolean initOk;
    
    68 64
     
    
    69 65
         public FakeT3ServiceContext() {
    
    ... ... @@ -72,15 +68,12 @@ public class FakeT3ServiceContext extends TestWatcher implements T3ServiceContex
    72 68
     
    
    73 69
         public FakeT3ServiceContext(boolean injectReferential) {
    
    74 70
             this.injectReferential = injectReferential;
    
    71
    +        setLocale(Locale.FRANCE);
    
    75 72
         }
    
    76 73
     
    
    77 74
         @Override
    
    78 75
         public T3Users getT3Users() {
    
    79
    -        return t3Users;
    
    80
    -    }
    
    81
    -
    
    82
    -    public void setT3Users(T3Users t3Users) {
    
    83
    -        this.t3Users = t3Users;
    
    76
    +        return null;
    
    84 77
         }
    
    85 78
     
    
    86 79
         public boolean isInitOk() {
    
    ... ... @@ -148,25 +141,15 @@ public class FakeT3ServiceContext extends TestWatcher implements T3ServiceContex
    148 141
             return testDir;
    
    149 142
         }
    
    150 143
     
    
    151
    -    public String getTestName() {
    
    152
    -        return testName;
    
    153
    -    }
    
    154
    -
    
    155 144
         @Override
    
    156 145
         protected void starting(Description description) {
    
    157 146
             super.starting(description);
    
    158
    -        testName = description.getMethodName();
    
    159
    -
    
    160 147
             testDir = T3IOUtil.getTestSpecificDirectory(description.getTestClass(), description.getMethodName());
    
    161
    -        if (log.isInfoEnabled()) {
    
    162
    -            log.info("Test dir = " + testDir);
    
    163
    -        }
    
    164
    -
    
    148
    +        log.info(String.format("Test dir = %s", testDir));
    
    165 149
             Properties defaultProps = new Properties();
    
    166 150
             defaultProps.put(T3ConfigOption.DATA_DIRECTORY.getKey(), testDir);
    
    167 151
             File treatmentDirectory = new File(testDir, "treatment");
    
    168 152
             FileUtil.createDirectoryIfNecessary(treatmentDirectory);
    
    169
    -
    
    170 153
             T3Config realConfiguration = new T3Config(defaultProps) {
    
    171 154
                 @Override
    
    172 155
                 public void init() {
    
    ... ... @@ -175,37 +158,15 @@ public class FakeT3ServiceContext extends TestWatcher implements T3ServiceContex
    175 158
             };
    
    176 159
             realConfiguration.init();
    
    177 160
             Version t3DataVersion = realConfiguration.getT3DataVersion();
    
    178
    -
    
    179 161
             applicationConfiguration = Mockito.mock(T3Config.class);
    
    180 162
             Mockito.when(applicationConfiguration.getDataDirectory()).thenReturn(testDir);
    
    181 163
             Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory()).thenReturn(treatmentDirectory);
    
    182 164
             Mockito.when(applicationConfiguration.getT3DataVersion()).thenReturn(t3DataVersion);
    
    183 165
             Mockito.when(applicationConfiguration.getTreatmentWorkingDirectory(Mockito.anyString(), Mockito.anyBoolean())).thenCallRealMethod();
    
    184 166
             Mockito.when(applicationConfiguration.getApplicationVersion()).thenReturn(realConfiguration.getApplicationVersion());
    
    185
    -
    
    186 167
             try {
    
    187
    -
    
    188
    -            // where to put h2 database
    
    189
    -            File dbDirectory = new File(testDir, "h2-database");
    
    190
    -
    
    191
    -            if (injectReferential) {
    
    192
    -                Path scriptPath = new File(new File("").getAbsolutePath()).getParentFile().toPath().resolve(".mvn").resolve("cache").resolve("test");
    
    193
    -                File scriptsDirectory = T3JdbcHelper.getScriptsDirectory(scriptPath.toFile(), "h2", t3DataVersion);
    
    194
    -
    
    195
    -                String[] list = scriptsDirectory.list((dir, name) -> name.endsWith(".sql") && name.contains("-referential"));
    
    196
    -                if (list == null || list.length != 1) {
    
    197
    -                    throw new IllegalStateException(String.format("Can't find h2 referential db from %s", scriptsDirectory));
    
    198
    -                }
    
    199
    -                rootContext = T3TopiaApplicationContext.newEmbeddedBackupDb(dbDirectory, scriptsDirectory.toPath().resolve(list[0]).toFile());
    
    200
    -            } else {
    
    201
    -                rootContext = T3TopiaApplicationContext.newEmbeddedDb(dbDirectory);
    
    202
    -            }
    
    203
    -//            if (injectReferential) {
    
    204
    -//                // inject in db the referentiel
    
    205
    -//                T3SqlScriptsImporter.importReferential(new File(""), this, T3SqlScriptsImporter.SKIP_SPECIES_LENGTH_STEP_FILE);
    
    206
    -//            }
    
    168
    +            rootContext = T3TopiaApplicationContext.newTestTopiaApplicationContext(testDir, t3DataVersion, injectReferential);
    
    207 169
                 initOk = true;
    
    208
    -
    
    209 170
             } catch (Exception e) {
    
    210 171
                 initOk = false;
    
    211 172
                 throw new IllegalStateException("Could not start db", e);