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

Commits:

11 changed files:

Changes:

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialog.jcss
    ... ... @@ -57,7 +57,7 @@
    57 57
     }
    
    58 58
     
    
    59 59
     #idTimestamp {
    
    60
    -  text:{model.getIdTimestamp()};
    
    60
    +  text:{model.getIdTimestamp() + ""};
    
    61 61
       enabled:false;
    
    62 62
     }
    
    63 63
     
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/avdth/ImportDialogModel.java
    ... ... @@ -289,8 +289,8 @@ public class ImportDialogModel extends AbstractJavaBean {
    289 289
             return importFile == null ? "" : removeMsAccessExtension(importFile.getAbsolutePath());
    
    290 290
         }
    
    291 291
     
    
    292
    -    public String getIdTimestamp() {
    
    293
    -        return now.getTime() + "";
    
    292
    +    public long getIdTimestamp() {
    
    293
    +        return now.getTime() ;
    
    294 294
         }
    
    295 295
     
    
    296 296
         public boolean isImportDone() {
    

  • core/api/services/src/main/java/fr/ird/observe/services/service/data/ps/AvdthDataImportConfiguration.java
    ... ... @@ -43,7 +43,7 @@ public class AvdthDataImportConfiguration implements JsonAware {
    43 43
         /**
    
    44 44
          * Id prefix to use to create new data.
    
    45 45
          */
    
    46
    -    private final String idTimestamp;
    
    46
    +    private final long idTimestamp;
    
    47 47
         /**
    
    48 48
          * Program id where to attach imported trip.
    
    49 49
          */
    
    ... ... @@ -83,7 +83,7 @@ public class AvdthDataImportConfiguration implements JsonAware {
    83 83
         private final ProgressionModel progressionModel;
    
    84 84
     
    
    85 85
         public AvdthDataImportConfiguration(Date now,
    
    86
    -                                        String idTimestamp,
    
    86
    +                                        long idTimestamp,
    
    87 87
                                             String programId,
    
    88 88
                                             String oceanId,
    
    89 89
                                             ReferentialLocale referentialLocale,
    
    ... ... @@ -138,7 +138,7 @@ public class AvdthDataImportConfiguration implements JsonAware {
    138 138
             return now;
    
    139 139
         }
    
    140 140
     
    
    141
    -    public String getIdTimestamp() {
    
    141
    +    public long getIdTimestamp() {
    
    142 142
             return idTimestamp;
    
    143 143
         }
    
    144 144
     
    

  • core/persistence/java/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java
    ... ... @@ -36,6 +36,7 @@ import io.ultreia.java4all.util.sql.SqlScript;
    36 36
     import org.nuiton.topia.persistence.TagValues;
    
    37 37
     import org.nuiton.topia.persistence.TopiaConfiguration;
    
    38 38
     import org.nuiton.topia.persistence.TopiaEntity;
    
    39
    +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport;
    
    39 40
     import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter;
    
    40 41
     import org.nuiton.topia.service.sql.blob.TopiaEntitySqlBlobModel;
    
    41 42
     import org.nuiton.topia.service.sql.model.TopiaEntitySqlModel;
    
    ... ... @@ -96,7 +97,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    96 97
         }
    
    97 98
     
    
    98 99
         @Override
    
    99
    -    public ObserveIdFactoryForBulk newIdFactoryForBulk(long timestamp) {
    
    100
    +    public TopiaIdFactoryForBulkSupport newIdFactoryForBulk(long timestamp) {
    
    100 101
             return new ObserveIdFactoryForBulk(timestamp);
    
    101 102
         }
    
    102 103
     
    

  • core/persistence/resources/src/main/java/fr/ird/observe/persistence/avdth/data/DataReader.java
    ... ... @@ -27,9 +27,8 @@ import fr.ird.observe.persistence.avdth.coordinate.CoordinateHelper;
    27 27
     import fr.ird.observe.persistence.avdth.coordinate.IntToCoordinate;
    
    28 28
     import fr.ird.observe.services.service.data.ps.AvdthDataImportConfiguration;
    
    29 29
     import fr.ird.observe.spi.context.DtoEntityContext;
    
    30
    -import io.ultreia.java4all.lang.Strings;
    
    31 30
     import org.apache.commons.lang3.mutable.MutableInt;
    
    32
    -import org.nuiton.topia.persistence.TopiaIdFactory;
    
    31
    +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport;
    
    33 32
     
    
    34 33
     import java.sql.ResultSet;
    
    35 34
     import java.sql.SQLException;
    
    ... ... @@ -46,28 +45,19 @@ public abstract class DataReader<E extends DataEntity> {
    46 45
          * Configuration of import (with also import context).
    
    47 46
          */
    
    48 47
         private final ImportEngine context;
    
    49
    -    /**
    
    50
    -     * Size of the random part.
    
    51
    -     */
    
    52
    -    private final int randomPartSize;
    
    53 48
         /**
    
    54 49
          * Internal topia Id factory.
    
    55 50
          */
    
    56
    -    private final TopiaIdFactory topiaIdFactory;
    
    57
    -    /**
    
    58
    -     * Fixed id timestamp.
    
    59
    -     */
    
    60
    -    private final String idTimestamp;
    
    51
    +    private final TopiaIdFactoryForBulkSupport topiaIdFactory;
    
    61 52
         /**
    
    62
    -     * Internal counter to simulate id on none persisted entries.
    
    53
    +     * Internal counter of created entities of this type.
    
    63 54
          */
    
    64 55
         private int count = 0;
    
    65 56
     
    
    66 57
         public DataReader(ImportEngine context) {
    
    67 58
             this.context = Objects.requireNonNull(context);
    
    68
    -        this.topiaIdFactory = context.getPersistenceApplicationContext().getTopiaIdFactory();
    
    69
    -        this.idTimestamp = context.getConfiguration().getIdTimestamp();
    
    70
    -        this.randomPartSize = 8;
    
    59
    +        long idTimestamp = context.getConfiguration().getIdTimestamp();
    
    60
    +        this.topiaIdFactory = context.getPersistenceApplicationContext().newIdFactoryForBulk(idTimestamp);
    
    71 61
         }
    
    72 62
     
    
    73 63
         public ImportEngine context() {
    
    ... ... @@ -89,12 +79,14 @@ public abstract class DataReader<E extends DataEntity> {
    89 79
         }
    
    90 80
     
    
    91 81
         protected final <EE extends DataEntity> EE newEntity(DtoEntityContext<?, ?, EE, ?> spi) {
    
    92
    -        String id = topiaIdFactory.newTopiaId(spi.toEntityType(), idTimestamp, Strings.leftPad("" + (count++), randomPartSize, '0'));
    
    82
    +        String id = topiaIdFactory.newTopiaId(spi.toEntityType());
    
    83
    +        count++;
    
    93 84
             return spi.newEntity(id);
    
    94 85
         }
    
    95 86
     
    
    96 87
         protected final <EE extends DataEntity> EE newEntity(DtoEntityContext<?, ?, EE, ?> spi, MutableInt count) {
    
    97
    -        String id = topiaIdFactory.newTopiaId(spi.toEntityType(), idTimestamp, Strings.leftPad("" + count.incrementAndGet(), randomPartSize, '0'));
    
    88
    +        String id = topiaIdFactory.newTopiaId(spi.toEntityType());
    
    89
    +        count.increment();
    
    98 90
             return spi.newEntity(id);
    
    99 91
         }
    
    100 92
     
    

  • core/persistence/test/src/test/java/fr/ird/observe/persistence/avdth/data/AvdthDataBuilderTestSupport.java
    ... ... @@ -130,7 +130,7 @@ public abstract class AvdthDataBuilderTestSupport extends PersistenceTestSupport
    130 130
             boolean doInlineImport = doInlineImport();
    
    131 131
             AvdthDataImportConfiguration configuration = new AvdthDataImportConfiguration(
    
    132 132
                     AvdthFixtures.DATE,
    
    133
    -                "20200601",
    
    133
    +                20200601L,
    
    134 134
                     "fr.ird.referential.ps.common.Program#1239832686262#0.42751447061198444",
    
    135 135
                     getOceanId(),
    
    136 136
                     ReferentialLocale.FR,
    

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializer.java
    ... ... @@ -24,8 +24,8 @@ package fr.ird.observe.spi.io;
    24 24
     
    
    25 25
     import com.google.gson.Gson;
    
    26 26
     import fr.ird.observe.entities.Entity;
    
    27
    -import fr.ird.observe.entities.ObserveIdFactoryForBulk;
    
    28 27
     import fr.ird.observe.entities.ToolkitTopiaPersistenceContextSupport;
    
    28
    +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport;
    
    29 29
     
    
    30 30
     import java.util.Date;
    
    31 31
     import java.util.List;
    
    ... ... @@ -42,7 +42,7 @@ public class EntityDeserializer {
    42 42
     
    
    43 43
         private final EntityDeserializerContext context;
    
    44 44
     
    
    45
    -    public EntityDeserializer(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, ObserveIdFactoryForBulk idFactory, Date now) {
    
    45
    +    public EntityDeserializer(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, TopiaIdFactoryForBulkSupport idFactory, Date now) {
    
    46 46
             this.context = new EntityDeserializerContext(persistenceContext, gson,idFactory, now);
    
    47 47
         }
    
    48 48
     
    

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/io/EntityDeserializerContext.java
    ... ... @@ -24,13 +24,13 @@ package fr.ird.observe.spi.io;
    24 24
     
    
    25 25
     import com.google.gson.Gson;
    
    26 26
     import fr.ird.observe.entities.Entity;
    
    27
    -import fr.ird.observe.entities.ObserveIdFactoryForBulk;
    
    28 27
     import fr.ird.observe.entities.ToolkitTopiaPersistenceContextSupport;
    
    29 28
     import fr.ird.observe.entities.data.DataEntity;
    
    30 29
     import fr.ird.observe.entities.referential.ReferentialEntity;
    
    31 30
     import io.ultreia.java4all.util.json.adapters.DateAdapter;
    
    32 31
     import org.apache.logging.log4j.LogManager;
    
    33 32
     import org.apache.logging.log4j.Logger;
    
    33
    +import org.nuiton.topia.persistence.TopiaIdFactoryForBulkSupport;
    
    34 34
     import org.nuiton.topia.persistence.TopiaNoResultException;
    
    35 35
     
    
    36 36
     import javax.sql.rowset.serial.SerialBlob;
    
    ... ... @@ -62,7 +62,7 @@ public class EntityDeserializerContext {
    62 62
         private static final Logger log = LogManager.getLogger(EntityDeserializerContext.class);
    
    63 63
         private final ToolkitTopiaPersistenceContextSupport persistenceContext;
    
    64 64
         private final Gson gson;
    
    65
    -    private final ObserveIdFactoryForBulk idFactory;
    
    65
    +    private final TopiaIdFactoryForBulkSupport idFactory;
    
    66 66
         private final Date now;
    
    67 67
         private final DateAdapter dataAdapter;
    
    68 68
         private final List<Entity> created;
    
    ... ... @@ -73,7 +73,7 @@ public class EntityDeserializerContext {
    73 73
             return id != null && id.startsWith(ID_REFERENCE_PREFIX);
    
    74 74
         }
    
    75 75
     
    
    76
    -    public EntityDeserializerContext(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, ObserveIdFactoryForBulk idFactory, Date now) {
    
    76
    +    public EntityDeserializerContext(ToolkitTopiaPersistenceContextSupport persistenceContext, Supplier<Gson> gson, TopiaIdFactoryForBulkSupport idFactory, Date now) {
    
    77 77
             this.persistenceContext = Objects.requireNonNull(persistenceContext);
    
    78 78
             this.gson = Objects.requireNonNull(gson).get();
    
    79 79
             this.idFactory = idFactory;
    

  • toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactory.java
    ... ... @@ -175,4 +175,16 @@ public interface TopiaIdFactory extends Serializable {
    175 175
             return result;
    
    176 176
         }
    
    177 177
     
    
    178
    +    /**
    
    179
    +     * Generates a random decimal (between 0 and 1) used as random part in a id.
    
    180
    +     *
    
    181
    +     * @return generate random as a string
    
    182
    +     */
    
    183
    +    default String generateRandom() {
    
    184
    +        double random = Math.random();
    
    185
    +        while (Double.toString(random).contains("E-")) {
    
    186
    +            random = Math.random();
    
    187
    +        }
    
    188
    +        return random + "";
    
    189
    +    }
    
    178 190
     }

  • toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactoryForBulkSupport.java
    ... ... @@ -27,7 +27,7 @@ import java.util.TreeMap;
    27 27
     import java.util.concurrent.atomic.AtomicLong;
    
    28 28
     
    
    29 29
     /**
    
    30
    - * A special id factory where the timestamp part is fixed and the random part is performed by a sequence (by type).
    
    30
    + * A special id factory where the timestamp part is fixed and the random part is performed by a sequence (by type) plus always a random part.
    
    31 31
      * <p>
    
    32 32
      * Created on 09/03/2022.
    
    33 33
      *
    
    ... ... @@ -37,8 +37,6 @@ import java.util.concurrent.atomic.AtomicLong;
    37 37
     public class TopiaIdFactoryForBulkSupport implements TopiaIdFactory {
    
    38 38
     
    
    39 39
         private static final long serialVersionUID = 1L;
    
    40
    -    private static final String ID_SUFFIX = "000000000000000000%d";
    
    41
    -    private static final int SUFFIX_LENGTH = ID_SUFFIX.length() - 1;
    
    42 40
         private final String timestampPart;
    
    43 41
         private final Map<String, AtomicLong> count;
    
    44 42
     
    
    ... ... @@ -52,13 +50,8 @@ public class TopiaIdFactoryForBulkSupport implements TopiaIdFactory {
    52 50
             return newTopiaId(idPrefix, timestampPart, getRandom(idPrefix));
    
    53 51
         }
    
    54 52
     
    
    55
    -    private String getRandom(String type) {
    
    56
    -        String result = String.format(ID_SUFFIX, count.computeIfAbsent(type, s -> new AtomicLong()).incrementAndGet());
    
    57
    -        int length = result.length();
    
    58
    -        if (length > SUFFIX_LENGTH) {
    
    59
    -            result = result.substring(length - SUFFIX_LENGTH);
    
    60
    -        }
    
    61
    -        return result;
    
    53
    +    protected String getRandom(String type) {
    
    54
    +        return count.computeIfAbsent(type, s -> new AtomicLong()).incrementAndGet() + generateRandom().substring(1);
    
    62 55
         }
    
    63 56
     }
    
    64 57
     
    

  • toolkit/persistence/src/main/java/org/nuiton/topia/persistence/TopiaIdFactorySupport.java
    ... ... @@ -34,15 +34,7 @@ public class TopiaIdFactorySupport implements TopiaIdFactory {
    34 34
     
    
    35 35
         @Override
    
    36 36
         public String newTopiaIdFromIdPrefix(String idPrefix) {
    
    37
    -        return newTopiaId(idPrefix, System.currentTimeMillis() + "", getRandom());
    
    38
    -    }
    
    39
    -
    
    40
    -    private String getRandom() {
    
    41
    -        double random = Math.random();
    
    42
    -        while (Double.toString(random).contains("E-")) {
    
    43
    -            random = Math.random();
    
    44
    -        }
    
    45
    -        return random + "";
    
    37
    +        return newTopiaId(idPrefix, System.currentTimeMillis() + "", generateRandom());
    
    46 38
         }
    
    47 39
     }
    
    48 40