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

Commits:

28 changed files:

Changes:

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUI.jcss
    ... ... @@ -18,8 +18,4 @@
    18 18
      * License along with this program.  If not, see
    
    19 19
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20 20
      * #L%
    
    21
    - */
    
    22
    -#activity {
    
    23
    -  _listNoLoad:true;
    
    24
    -  data:{model.getActivities()};
    
    25
    -}
    21
    + */
    \ No newline at end of file

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIHandler.java
    ... ... @@ -25,10 +25,13 @@ package fr.ird.observe.client.datasource.editor.content.data.ps.wellplan;
    25 25
     import fr.ird.observe.client.datasource.editor.content.data.table.ContentTableUIHandler;
    
    26 26
     import fr.ird.observe.client.datasource.editor.content.data.table.ContentTableUILayoutFocusTraversalPolicy;
    
    27 27
     import fr.ird.observe.client.datasource.editor.content.spi.ContentUIReferenceCache;
    
    28
    +import fr.ird.observe.client.datasource.editor.content.spi.ReferentialReferencesFilter;
    
    28 29
     import fr.ird.observe.dto.data.ps.wellplan.TripWellPlanDto;
    
    29 30
     import fr.ird.observe.dto.data.ps.wellplan.WellPlanDto;
    
    30 31
     import fr.ird.observe.dto.form.Form;
    
    32
    +import fr.ird.observe.dto.referential.common.SpeciesDto;
    
    31 33
     import fr.ird.observe.dto.referential.common.SpeciesReference;
    
    34
    +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryDto;
    
    32 35
     import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference;
    
    33 36
     import fr.ird.observe.dto.result.SaveResultDto;
    
    34 37
     import org.nuiton.jaxx.runtime.spi.UIHandler;
    
    ... ... @@ -37,6 +40,7 @@ import java.awt.Component;
    37 40
     import java.beans.PropertyChangeListener;
    
    38 41
     import java.util.Collections;
    
    39 42
     import java.util.List;
    
    43
    +import java.util.Objects;
    
    40 44
     import java.util.stream.Collectors;
    
    41 45
     
    
    42 46
     /**
    
    ... ... @@ -73,7 +77,8 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We
    73 77
     
    
    74 78
         @Override
    
    75 79
         protected void onAfterInitAddReferentialFilters(ContentUIReferenceCache referenceCache) {
    
    76
    -        referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_SPECIES, newPsSpeciesList(getClientConfig().getSpeciesListSeineLogbookCatchId()));
    
    80
    +        referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_WEIGHT_CATEGORY, newPsLogbookWeightCategoryList(getClientConfig().getSpeciesListSeineLogbookCatchId()));
    
    81
    +        referenceCache.addReferentialFilter(WellPlanDto.PROPERTY_SPECIES, newPsSpeciesList());
    
    77 82
         }
    
    78 83
     
    
    79 84
         @Override
    
    ... ... @@ -109,7 +114,7 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We
    109 114
                 newCategories = Collections.emptyList();
    
    110 115
             } else {
    
    111 116
                 List<WeightCategoryReference> referentialReferences = getModel().getReferenceCache().getReferentialReferences(WellPlanDto.PROPERTY_WEIGHT_CATEGORY);
    
    112
    -            newCategories = referentialReferences.stream().filter(r -> r.getSpecies().equals(species)).collect(Collectors.toList());
    
    117
    +            newCategories = referentialReferences.stream().filter(r -> Objects.equals(r.getSpecies(), species)).collect(Collectors.toList());
    
    113 118
                 WeightCategoryReference weightCategory = getModel().getTableEditBean().getWeightCategory();
    
    114 119
                 if (weightCategory != null && newCategories.contains(weightCategory)) {
    
    115 120
                     newCategory = weightCategory;
    
    ... ... @@ -119,4 +124,17 @@ public class WellPlanUIHandler extends ContentTableUIHandler<TripWellPlanDto, We
    119 124
             ui.getWeightCategory().setSelectedItem(newCategory);
    
    120 125
         }
    
    121 126
     
    
    127
    +    protected ReferentialReferencesFilter<SpeciesDto, SpeciesReference> newPsSpeciesList() {
    
    128
    +        return incomingReferences -> {
    
    129
    +            List<WeightCategoryReference> weightCategories = getModel().getReferenceCache().getReferentialReferences(WellPlanDto.PROPERTY_WEIGHT_CATEGORY);
    
    130
    +            return weightCategories.stream().map(WeightCategoryReference::getSpecies).collect(Collectors.toList());
    
    131
    +        };
    
    132
    +    }
    
    133
    +
    
    134
    +    protected ReferentialReferencesFilter<WeightCategoryDto, WeightCategoryReference> newPsLogbookWeightCategoryList(String speciesListId) {
    
    135
    +        return incomingReferences -> {
    
    136
    +            String tripId = getClientUIContext().getObserveSelectModel().getSeine().getTrip().getId();
    
    137
    +            return getPsCommonTripService().getLogbookWeightCategoryByListAndTrip(tripId, speciesListId).toList();
    
    138
    +        };
    
    139
    +    }
    
    122 140
     }

  • client-datasource-editor-ps/src/main/java/fr/ird/observe/client/datasource/editor/content/data/ps/wellplan/WellPlanUIModel.java
    ... ... @@ -29,7 +29,6 @@ import fr.ird.observe.dto.data.ps.wellplan.WellPlanDto;
    29 29
     import fr.ird.observe.dto.form.Form;
    
    30 30
     import fr.ird.observe.dto.reference.DataDtoReferenceSet;
    
    31 31
     
    
    32
    -import java.util.List;
    
    33 32
     import java.util.stream.Collectors;
    
    34 33
     
    
    35 34
     /**
    
    ... ... @@ -40,26 +39,15 @@ import java.util.stream.Collectors;
    40 39
      */
    
    41 40
     public class WellPlanUIModel extends ContentTableUIModel<TripWellPlanDto, WellPlanDto> {
    
    42 41
     
    
    43
    -    private List<ActivityReference> activities;
    
    44
    -
    
    45 42
         public WellPlanUIModel() {
    
    46 43
             super(TripWellPlanDto.class, WellPlanDto.class, TripWellPlanDto.PROPERTY_WELL_PLAN);
    
    47 44
         }
    
    48 45
     
    
    49 46
         @Override
    
    50 47
         public void openForm(Form<TripWellPlanDto> form) {
    
    51
    -        super.openForm(form);
    
    52
    -        String tripId = getBean().getId();
    
    48
    +        String tripId = form.getObject().getId();
    
    53 49
             DataDtoReferenceSet<ActivityReference> activities = getObserveDataSourcesManager().getMainDataSource().getPsLogbookActivityService().getActivitySeineByTrip(tripId);
    
    54
    -        setActivities(activities.stream().filter(ActivityReference::isSetOperation).collect(Collectors.toList()));
    
    55
    -    }
    
    56
    -
    
    57
    -    public List<ActivityReference> getActivities() {
    
    58
    -        return activities;
    
    59
    -    }
    
    60
    -
    
    61
    -    public void setActivities(List<ActivityReference> activities) {
    
    62
    -        this.activities = activities;
    
    63
    -        firePropertyChange("activities", activities);
    
    50
    +        getReferenceCache().setDataReferenceSet(WellPlanDto.PROPERTY_ACTIVITY, DataDtoReferenceSet.of(ActivityReference.class, activities.stream().filter(ActivityReference::isSetOperation).collect(Collectors.toList())));
    
    51
    +        super.openForm(form);
    
    64 52
         }
    
    65 53
     }

  • dto/src/main/models/Observe-23-data-ps-wellplan.model
    ... ... @@ -3,8 +3,8 @@ package fr.ird.observe.dto.data.ps.wellplan | form=self packagePriority=23
    3 3
     data.ps.wellplan.WellPlan > data.Data >> data.WellIdAware | references=species,well,weight,weightCategoryLabel
    
    4 4
     activity {*:1} fr.ird.observe.dto.data.ps.logbook.ActivityReference | notNull
    
    5 5
     well + {*:1} String | notNull
    
    6
    -species {*:1} fr.ird.observe.dto.referential.common.SpeciesReference | notNull
    
    7 6
     weightCategory {*:1} fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference | notNull
    
    7
    +species {*:1} fr.ird.observe.dto.referential.common.SpeciesReference | notNull
    
    8 8
     weight + {*:1} Float | notNull
    
    9 9
     
    
    10 10
     data.ps.wellplan.TripWellPlan > data.Commentable | form=data.ps.wellplan.WellPlan mainDto=data.ps.common.Trip
    

  • persistence/pom.xml
    ... ... @@ -391,38 +391,6 @@
    391 391
             </executions>
    
    392 392
           </plugin>
    
    393 393
     
    
    394
    -
    
    395
    -      <plugin>
    
    396
    -        <groupId>fr.ird.observe.toolkit</groupId>
    
    397
    -        <artifactId>toolbox-maven-plugin</artifactId>
    
    398
    -        <version>${project.version}</version>
    
    399
    -        <executions>
    
    400
    -          <execution>
    
    401
    -            <id>generate-entity-update-sql-files</id>
    
    402
    -            <goals>
    
    403
    -              <goal>generate-entity-update-sql-files</goal>
    
    404
    -            </goals>
    
    405
    -          </execution>
    
    406
    -        </executions>
    
    407
    -        <dependencies>
    
    408
    -          <dependency>
    
    409
    -            <groupId>${project.groupId}</groupId>
    
    410
    -            <artifactId>dto</artifactId>
    
    411
    -            <version>${project.version}</version>
    
    412
    -          </dependency>
    
    413
    -          <dependency>
    
    414
    -            <groupId>fr.ird.observe.toolkit</groupId>
    
    415
    -            <artifactId>common-persistence</artifactId>
    
    416
    -            <version>${project.version}</version>
    
    417
    -          </dependency>
    
    418
    -          <dependency>
    
    419
    -            <groupId>org.javassist</groupId>
    
    420
    -            <artifactId>javassist</artifactId>
    
    421
    -            <version>${lib.version.javassist}</version>
    
    422
    -          </dependency>
    
    423
    -        </dependencies>
    
    424
    -      </plugin>
    
    425
    -
    
    426 394
         </plugins>
    
    427 395
       </build>
    
    428 396
     </project>

  • persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java
    ... ... @@ -23,7 +23,6 @@ package fr.ird.observe.entities;
    23 23
      */
    
    24 24
     
    
    25 25
     import com.google.common.collect.ImmutableSet;
    
    26
    -import fr.ird.observe.entities.data.DataEntity;
    
    27 26
     import fr.ird.observe.entities.referential.ReferentialEntity;
    
    28 27
     import org.apache.logging.log4j.LogManager;
    
    29 28
     import org.apache.logging.log4j.Logger;
    
    ... ... @@ -33,13 +32,14 @@ import org.hibernate.tool.schema.TargetType;
    33 32
     import org.nuiton.topia.persistence.TopiaException;
    
    34 33
     import org.nuiton.topia.persistence.jdbc.JdbcHelper;
    
    35 34
     import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    36
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPathsBuilder;
    
    37 35
     import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    36
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelPaths;
    
    38 37
     import org.nuiton.topia.persistence.script.SqlScriptReader;
    
    39 38
     import org.nuiton.topia.persistence.script.TopiaSqlScript;
    
    40 39
     import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport;
    
    41 40
     import org.nuiton.topia.service.migration.TopiaMigrationService;
    
    42 41
     import org.nuiton.topia.service.script.TopiaSqlScriptGeneratorService;
    
    42
    +import org.nuiton.topia.service.script.table.DefaultTopiaSqlTablesPredicate;
    
    43 43
     import org.nuiton.topia.service.script.table.TopiaSqlTable;
    
    44 44
     import org.nuiton.topia.service.script.table.TopiaSqlTables;
    
    45 45
     import org.nuiton.topia.service.script.table.TopiaSqlTablesFactory;
    
    ... ... @@ -50,20 +50,19 @@ import java.util.LinkedHashSet;
    50 50
     import java.util.Objects;
    
    51 51
     import java.util.Set;
    
    52 52
     import java.util.UUID;
    
    53
    -import java.util.function.Predicate;
    
    54 53
     import java.util.stream.Collectors;
    
    55 54
     
    
    56 55
     public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicationContext implements TopiaMetadataModelSupport {
    
    57 56
     
    
    58 57
         static final String MIGRATION_SERVICE_NAME = "migration";
    
    59 58
         static final String SQL_SCRIPT_GENERATOR_BATCH_SERVICE_NAME = "sqlScriptGenerator";
    
    60
    -    private static final Set<String> SECTIONS = ImmutableSet.of(
    
    61
    -            ObserveEntityEnum.ll_observation_Branchline.name(),
    
    62
    -            ObserveEntityEnum.ll_observation_Basket.name(),
    
    63
    -            ObserveEntityEnum.ll_observation_Section.name());
    
    64
    -    private static final Set<String> SECTIONS_HOLDERS = ImmutableSet.of(
    
    65
    -            ObserveEntityEnum.ll_observation_Catch.name(),
    
    66
    -            ObserveEntityEnum.ll_observation_Tdr.name());
    
    59
    +    //    private static final Set<String> SECTIONS = ImmutableSet.of(
    
    60
    +//            ObserveEntityEnum.ll_observation_Branchline.name(),
    
    61
    +//            ObserveEntityEnum.ll_observation_Basket.name(),
    
    62
    +//            ObserveEntityEnum.ll_observation_Section.name());
    
    63
    +//    private static final Set<String> SECTIONS_HOLDERS = ImmutableSet.of(
    
    64
    +//            ObserveEntityEnum.ll_observation_Catch.name(),
    
    65
    +//            ObserveEntityEnum.ll_observation_Tdr.name());
    
    67 66
         private static final Logger log = LogManager.getLogger(ObserveTopiaApplicationContext.class);
    
    68 67
         @SuppressWarnings("SpellCheckingInspection")
    
    69 68
         private static final String INSERT_LAST_UPDATE_PATTERN = "INSERT INTO COMMON.LASTUPDATEDATE (TOPIAID, TOPIAVERSION, TOPIACREATEDATE, TYPE, LASTUPDATEDATE) VALUES ('fr.ird.observe.entities.LastUpdateDate#1236861982132#0.%03d', 0, CURRENT_TIMESTAMP, '%s', CURRENT_TIMESTAMP);";
    
    ... ... @@ -90,20 +89,6 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    90 89
             return new ObserveTopiaMetadataModelSupport();
    
    91 90
         }
    
    92 91
     
    
    93
    -    protected static boolean rejectAssociationType0(TopiaMetadataEntity metadataEntity, TopiaMetadataEntity propertyType) {
    
    94
    -        return (SECTIONS_HOLDERS.contains(propertyType.getType()) && SECTIONS.contains(metadataEntity.getType()))
    
    95
    -                || (ObserveEntityEnum.ps_logbook_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_logbook_Sample.name().equals(metadataEntity.getType()))
    
    96
    -                || (ObserveEntityEnum.ps_localmarket_Survey.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_localmarket_Batch.name().equals(metadataEntity.getType()))
    
    97
    -                ;
    
    98
    -    }
    
    99
    -
    
    100
    -    protected static boolean rejectReversedAssociationType0(TopiaMetadataEntity metadataEntity, TopiaMetadataEntity propertyType) {
    
    101
    -        return (ObserveEntityEnum.ll_observation_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ll_logbook_Activity.name().equals(metadataEntity.getType()))
    
    102
    -                || (ObserveEntityEnum.ps_observation_Activity.name().equals(propertyType.getType()) && ObserveEntityEnum.ps_logbook_Activity.name().equals(metadataEntity.getType()))
    
    103
    -                || (ObserveEntityEnum.ll_logbook_Sample.name().equals(propertyType.getType()) && ObserveEntityEnum.ll_logbook_Activity.name().equals(metadataEntity.getType()))
    
    104
    -                ;
    
    105
    -    }
    
    106
    -
    
    107 92
         @Override
    
    108 93
         public ObserveTopiaPersistenceContext newPersistenceContext() {
    
    109 94
             ObserveTopiaPersistenceContext persistenceContext = new ObserveTopiaPersistenceContext(
    
    ... ... @@ -207,6 +192,11 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    207 192
             return getTopiaMetadataModelSupport().getMetadataModel();
    
    208 193
         }
    
    209 194
     
    
    195
    +    @Override
    
    196
    +    public TopiaMetadataModelPaths getMetadataModelPaths() {
    
    197
    +        return getTopiaMetadataModelSupport().getMetadataModelPaths();
    
    198
    +    }
    
    199
    +
    
    210 200
         @Override
    
    211 201
         public boolean equals(Object o) {
    
    212 202
             if (this == o) return true;
    
    ... ... @@ -243,7 +233,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    243 233
     
    
    244 234
             if (tripSeineTables == null) {
    
    245 235
                 log.debug("Loading tripSeineTables.");
    
    246
    -            tripSeineTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), ObserveEntityEnum.ps_common_Trip);
    
    236
    +            tripSeineTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), ObserveEntityEnum.ps_common_Trip);
    
    247 237
                 log.info(String.format("For Trip, found %d tables to use.", tripSeineTables.size()));
    
    248 238
             }
    
    249 239
             return tripSeineTables;
    
    ... ... @@ -253,7 +243,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    253 243
     
    
    254 244
             if (tripLonglineTables == null) {
    
    255 245
                 log.debug("Loading tripLonglineTables.");
    
    256
    -            tripLonglineTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), ObserveEntityEnum.ll_common_Trip);
    
    246
    +            tripLonglineTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), ObserveEntityEnum.ll_common_Trip);
    
    257 247
                 log.info(String.format("For Trip, found %d tables to use.", tripLonglineTables.size()));
    
    258 248
                 TopiaSqlTable basketTable = tripLonglineTables.getTable(ObserveEntityEnum.ll_observation_Basket);
    
    259 249
     
    
    ... ... @@ -292,11 +282,10 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    292 282
         }
    
    293 283
     
    
    294 284
         public TopiaSqlTables getReferentialTables() {
    
    295
    -
    
    296 285
             if (referentialTables == null) {
    
    297 286
                 log.debug("Loading referentialTables.");
    
    298 287
                 referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(
    
    299
    -                    new TripReplicateTablesPredicate(),
    
    288
    +                    new DefaultTopiaSqlTablesPredicate(),
    
    300 289
                         Entities.REFERENCE_ENTITIES);
    
    301 290
             }
    
    302 291
             log.info(String.format("For Referential, found %d tables to use.", referentialTables.size()));
    
    ... ... @@ -305,112 +294,26 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat
    305 294
     
    
    306 295
         public <E extends ReferentialEntity<?, ?>> TopiaSqlTables getReferentialTable(Class<E> entityType) {
    
    307 296
             ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entityType);
    
    308
    -        return referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(new TripReplicateTablesPredicate(), entityEnum);
    
    309
    -    }
    
    310
    -
    
    311
    -    private TopiaMetadataModelSupport getTopiaMetadataModelSupport() {
    
    312
    -        return topiaMetadataModelSupport == null ? topiaMetadataModelSupport = newModelSupport() : topiaMetadataModelSupport;
    
    297
    +        return referentialTables = topiaSqlTablesFactory.newReplicateEntityTables(new DefaultTopiaSqlTablesPredicate(), entityEnum);
    
    313 298
         }
    
    314 299
     
    
    315 300
         public ObserveTopiaUsageModel getTopiaUsageModel() {
    
    316 301
             return topiaUsageModel == null ? topiaUsageModel = new ObserveTopiaUsageModel() : topiaUsageModel;
    
    317 302
         }
    
    318 303
     
    
    319
    -    private void executeSqlStatements0(TopiaSqlScript content) {
    
    320
    -
    
    321
    -        SqlScriptReader scriptLocation = content.getLocation();
    
    322
    -//        if (getConfiguration().isH2Configuration()) {
    
    323
    -//
    
    324
    -//            String protocol = scriptLocation.getProtocol();
    
    325
    -//            boolean local = LOCAL_PROTOCOLS.contains(protocol.toLowerCase());
    
    326
    -//
    
    327
    -//            Path tempFile = null;
    
    328
    -//            try {
    
    329
    -//                if (local) {
    
    330
    -//                    tempFile = Paths.get(scriptLocation.toURI());
    
    331
    -//                } else {
    
    332
    -//                    tempFile = Files.createTempFile("observeRestoreH2", ".sql");
    
    333
    -//                    Files.copy(scriptLocation.openStream(), tempFile);
    
    334
    -//                }
    
    335
    -////                log.info(String.format("Restore script size: %s to h2 from file : %s", StringUtil.convertMemory(Files.size(tempFile)), tempFile.toString()));
    
    336
    -//                JdbcH2Helper2 jdbcH2Helper = new JdbcH2Helper2(configuration);
    
    337
    -//
    
    338
    -//                jdbcH2Helper.restore(tempFile.toFile());
    
    339
    -//            } finally {
    
    340
    -//                if (!local && tempFile != null) {
    
    341
    -//                    Files.delete(tempFile);
    
    342
    -//                }
    
    343
    -//            }
    
    344
    -//
    
    345
    -//        } else {
    
    346
    -
    
    347
    -//            log.info(String.format("Load script (size: %s)", StringUtil.convertMemory(content.length)));
    
    348
    -
    
    349
    -        try (ObserveTopiaPersistenceContext persistenceContext = newPersistenceContext()) {
    
    350
    -            persistenceContext.executeSqlScript(scriptLocation);
    
    351
    -            persistenceContext.commit();
    
    352
    -        }
    
    353
    -//        }
    
    354
    -
    
    355
    -    }
    
    356
    -
    
    357 304
         public BlobIdsIterator newBlobIdsIterator(Path blobIdsPath) {
    
    358 305
             return new BlobIdsIterator(getMetadataModel(), blobIdsPath, this);
    
    359 306
         }
    
    360 307
     
    
    361
    -    private static class TripReplicateTablesPredicate implements TopiaSqlTablesFactory.TopiaSqlTablesPredicate {
    
    362
    -
    
    363
    -        private final Set<TopiaMetadataEntity> done = new LinkedHashSet<>();
    
    364
    -
    
    365
    -        @Override
    
    366
    -        public boolean acceptEntity(TopiaMetadataEntity metadataEntity) {
    
    367
    -            return done.add(metadataEntity);
    
    368
    -        }
    
    369
    -
    
    370
    -        @Override
    
    371
    -        public boolean acceptAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) {
    
    372
    -            return !rejectAssociationType0(metadataEntity, propertyType);
    
    373
    -        }
    
    374
    -
    
    375
    -        @Override
    
    376
    -        public boolean acceptReversedAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) {
    
    377
    -            return !rejectReversedAssociationType0(metadataEntity, propertyType);
    
    378
    -
    
    379
    -        }
    
    380
    -
    
    381
    -        @Override
    
    382
    -        public boolean acceptNmAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) {
    
    383
    -            return !rejectAssociationType0(metadataEntity, propertyType);
    
    384
    -        }
    
    385
    -
    
    308
    +    private TopiaMetadataModelSupport getTopiaMetadataModelSupport() {
    
    309
    +        return topiaMetadataModelSupport == null ? topiaMetadataModelSupport = newModelSupport() : topiaMetadataModelSupport;
    
    386 310
         }
    
    387 311
     
    
    388
    -    public static class ObserveDataEntityPathsBuilder extends TopiaMetadataEntityPathsBuilder {
    
    389
    -
    
    390
    -        public ObserveDataEntityPathsBuilder() {
    
    391
    -            super(e -> DataEntity.class.isAssignableFrom(ObserveEntityEnum.valueOf(e.getType()).getContract()));
    
    392
    -        }
    
    393
    -
    
    394
    -        @Override
    
    395
    -        protected Visitor createVisitor(Predicate<TopiaMetadataEntity> acceptType) {
    
    396
    -            return new ObServeVisitor(acceptType);
    
    397
    -        }
    
    398
    -
    
    399
    -        private static class ObServeVisitor extends Visitor {
    
    400
    -
    
    401
    -            public ObServeVisitor(Predicate<TopiaMetadataEntity> acceptType) {
    
    402
    -                super(acceptType);
    
    403
    -            }
    
    404
    -
    
    405
    -            @Override
    
    406
    -            protected boolean rejectReversedAssociationType(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) {
    
    407
    -                return rejectReversedAssociationType0(metadataEntity, propertyType) || super.rejectReversedAssociationType(metadataEntity, propertyName, propertyType);
    
    408
    -            }
    
    409
    -
    
    410
    -            @Override
    
    411
    -            protected boolean rejectAssociationType(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) {
    
    412
    -                return rejectAssociationType0(metadataEntity, propertyType) || super.rejectAssociationType(metadataEntity, propertyName, propertyType);
    
    413
    -            }
    
    312
    +    private void executeSqlStatements0(TopiaSqlScript content) {
    
    313
    +        SqlScriptReader scriptLocation = content.getLocation();
    
    314
    +        try (ObserveTopiaPersistenceContext persistenceContext = newPersistenceContext()) {
    
    315
    +            persistenceContext.executeSqlScript(scriptLocation);
    
    316
    +            persistenceContext.commit();
    
    414 317
             }
    
    415 318
         }
    
    416 319
     
    

  • persistence/src/main/models/Observe-21-data-ps-logbook.model
    ... ... @@ -14,7 +14,7 @@ seaSurfaceTemperature + {*:1} Float | sqlType=numeric
    14 14
     windDirection + {*:1} Integer
    
    15 15
     vesselActivity {*:1} referential.ps.common.VesselActivity
    
    16 16
     wind {*:0..1} referential.common.Wind
    
    17
    -relatedObservedActivity + {0..1} data.ps.observation.Activity
    
    17
    +relatedObservedActivity + {0..1} data.ps.observation.Activity | skipModelNavigation
    
    18 18
     floatingObject + {*} data.ps.logbook.FloatingObject | unique
    
    19 19
     observedSystem {*:*} referential.ps.logbook.ObservedSystem | unique
    
    20 20
     set + {0..1} data.ps.logbook.Set
    
    ... ... @@ -91,7 +91,7 @@ bigsWeight + {*:1} Float | sqlType=numeric
    91 91
     totalWeight + {*:1} Float | sqlType=numeric
    
    92 92
     weightedWeight + {*:1} Float | sqlType=numeric
    
    93 93
     subSampleNumber + {*:1} Integer
    
    94
    -activity {*:*} data.ps.logbook.Activity
    
    94
    +activity {*:*} data.ps.logbook.Activity | skipModelNavigation
    
    95 95
     sampleSpecies + {*} data.ps.logbook.SampleSpecies | ordered
    
    96 96
     
    
    97 97
     data.ps.logbook.SampleSpecies > data.DataEntity | entity
    

  • persistence/src/main/models/Observe-23-data-ps-wellplan.model
    1 1
     package fr.ird.observe.entities.data.ps.wellplan | dbSchema=ps_wellplan
    
    2 2
     
    
    3 3
     data.ps.wellplan.WellPlan > data.DataEntity | entity
    
    4
    -activity {*:1} data.ps.logbook.Activity
    
    4
    +activity {*:1} data.ps.logbook.Activity | skipModelNavigation
    
    5 5
     well + {*:1} String
    
    6 6
     species {*:1} referential.common.Species
    
    7 7
     weightCategory {*:1} referential.ps.logbook.WeightCategory
    

  • persistence/src/main/models/Observe-24-data-ps-localmarket.model
    ... ... @@ -5,7 +5,7 @@ species {*:1} referential.common.Species | notNull
    5 5
     packaging {*:1} referential.ps.localmarket.Packaging | notNull
    
    6 6
     count + {*:1} Integer
    
    7 7
     weight + {*:1} Float | sqlType=numeric
    
    8
    -survey {*:0..1} data.ps.localmarket.Survey
    
    8
    +survey {*:0..1} data.ps.localmarket.Survey | skipModelNavigation
    
    9 9
     origin + {*:1} String | hibernateAttributeType=text
    
    10 10
     comment + {*:1} String | hibernateAttributeType=text
    
    11 11
     
    

  • persistence/src/main/models/Observe-30-data-ll-observation.model
    ... ... @@ -44,9 +44,9 @@ haulingIdentifier + {*:1} Integer
    44 44
     floatline1Length + {*:1} Float
    
    45 45
     floatline2Length + {*:1} Float
    
    46 46
     branchline + {*} data.ll.observation.Branchline | unique orderBy=settingIdentifier
    
    47
    -catches {*} data.ll.observation.Catch
    
    48
    -tdr {*} data.ll.observation.Tdr
    
    49
    -set {*:1} data.ll.observation.Set
    
    47
    +catches {*} data.ll.observation.Catch | skipModelNavigation
    
    48
    +tdr {*} data.ll.observation.Tdr | skipModelNavigation
    
    49
    +set {*:1} data.ll.observation.Set | skipModelNavigation
    
    50 50
     getSection() data.ll.observation.Section
    
    51 51
     setSection(section data.ll.observation.Section)
    
    52 52
     
    
    ... ... @@ -68,8 +68,8 @@ tracelineLength + {*:1} Float | sqlType=numeric
    68 68
     hookLost + {*:1} Boolean
    
    69 69
     traceCutOff + {*:1} Boolean
    
    70 70
     hookType {*:0..1} referential.ll.common.HookType
    
    71
    -tdr {*} data.ll.observation.Tdr
    
    72
    -catches {*} data.ll.observation.Catch
    
    71
    +tdr {*} data.ll.observation.Tdr | skipModelNavigation
    
    72
    +catches {*} data.ll.observation.Catch | skipModelNavigation
    
    73 73
     baitType {*:0..1} referential.ll.common.BaitType
    
    74 74
     topType {*:0..1} referential.ll.common.LineType
    
    75 75
     tracelineType {*:0..1} referential.ll.common.LineType
    
    ... ... @@ -102,14 +102,14 @@ photoReferences + {*:1} String
    102 102
     number + {*:1} Integer
    
    103 103
     acquisitionMode + {*:1} int
    
    104 104
     tagNumber + {*:1} String
    
    105
    -basket {*:0..1} data.ll.observation.Basket
    
    106
    -branchline {*:0..1} data.ll.observation.Branchline
    
    105
    +basket {*:0..1} data.ll.observation.Basket | skipModelNavigation
    
    106
    +branchline {*:0..1} data.ll.observation.Branchline | skipModelNavigation
    
    107 107
     catchFate {*:1} referential.ll.common.CatchFate
    
    108 108
     discardHealthStatus {*:1} referential.ll.common.HealthStatus
    
    109 109
     sizeMeasure + {*} data.ll.observation.SizeMeasure | orderBy=topiaCreateDate
    
    110 110
     speciesCatch {*:1} referential.common.Species
    
    111 111
     predator {*:*} referential.common.Species
    
    112
    -section {*:0..1} data.ll.observation.Section
    
    112
    +section {*:0..1} data.ll.observation.Section | skipModelNavigation
    
    113 113
     maturityStatus {*:0..1} referential.ll.observation.MaturityStatus
    
    114 114
     stomachFullness {*:0..1} referential.ll.observation.StomachFullness
    
    115 115
     hookPosition {*:0..1} referential.ll.observation.HookPosition
    
    ... ... @@ -138,10 +138,10 @@ hookSize {*:1} referential.ll.common.HookSize
    138 138
     data.ll.observation.Section > data.DataEntity >> data.ll.observation.LonglineCompositionAware | entity
    
    139 139
     settingIdentifier + {*:1} Integer | notNull
    
    140 140
     haulingIdentifier + {*:1} Integer
    
    141
    -set {*:1} data.ll.observation.Set
    
    142
    -basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier 
    
    143
    -tdr {*} data.ll.observation.Tdr 
    
    144
    -catches {*} data.ll.observation.Catch 
    
    141
    +set {*:1} data.ll.observation.Set | skipModelNavigation
    
    142
    +basket + {*} data.ll.observation.Basket | unique orderBy=settingIdentifier
    
    143
    +tdr {*} data.ll.observation.Tdr | skipModelNavigation
    
    144
    +catches {*} data.ll.observation.Catch | skipModelNavigation
    
    145 145
     
    
    146 146
     data.ll.observation.SensorUsed > data.DataEntity | entity
    
    147 147
     data + {*:1} !java.sql.Blob
    
    ... ... @@ -254,11 +254,11 @@ minFishingDepth + {*:1} Float
    254 254
     maxFishingDepth + {*:1} Float
    
    255 255
     meanFishingDepth + {*:1} Float
    
    256 256
     medianFishingDepth + {*:1} Float
    
    257
    -branchline {*:0..1} data.ll.observation.Branchline
    
    257
    +branchline {*:0..1} data.ll.observation.Branchline | skipModelNavigation
    
    258 258
     sensorBrand {*:0..1} referential.ll.observation.SensorBrand
    
    259 259
     species {*:*} referential.common.Species
    
    260
    -section {*:0..1} data.ll.observation.Section
    
    261
    -basket {*:0..1} data.ll.observation.Basket
    
    260
    +section {*:0..1} data.ll.observation.Section | skipModelNavigation
    
    261
    +basket {*:0..1} data.ll.observation.Basket | skipModelNavigation
    
    262 262
     itemHorizontalPosition {*:0..1} referential.ll.observation.ItemHorizontalPosition
    
    263 263
     itemVerticalPosition {*:0..1} referential.ll.observation.ItemVerticalPosition
    
    264 264
     getDeploymentStartDate() Date
    

  • persistence/src/main/models/Observe-31-data-ll-logbook.model
    ... ... @@ -14,7 +14,7 @@ currentDirection + {*:1} Integer
    14 14
     vesselActivity {*:1} referential.ll.common.VesselActivity | lazy=false
    
    15 15
     dataQuality {*:0..1} referential.common.DataQuality
    
    16 16
     fpaZone {*:1} referential.common.FpaZone
    
    17
    -relatedObservedActivity + {0..1} data.ll.observation.Activity
    
    17
    +relatedObservedActivity + {0..1} data.ll.observation.Activity | skipModelNavigation
    
    18 18
     set + {0..1} data.ll.logbook.Set
    
    19 19
     sample + {0..1} data.ll.logbook.Sample
    
    20 20
     getStartDate() Date
    

  • persistence/src/test/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupportTest.java deleted
    1
    -package fr.ird.observe.entities;
    
    2
    -
    
    3
    -/*-
    
    4
    - * #%L
    
    5
    - * ObServe :: Persistence
    
    6
    - * %%
    
    7
    - * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8
    - * %%
    
    9
    - * This program is free software: you can redistribute it and/or modify
    
    10
    - * it under the terms of the GNU General Public License as
    
    11
    - * published by the Free Software Foundation, either version 3 of the
    
    12
    - * License, or (at your option) any later version.
    
    13
    - *
    
    14
    - * This program is distributed in the hope that it will be useful,
    
    15
    - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    - * GNU General Public License for more details.
    
    18
    - *
    
    19
    - * You should have received a copy of the GNU General Public
    
    20
    - * License along with this program.  If not, see
    
    21
    - * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    - * #L%
    
    23
    - */
    
    24
    -
    
    25
    -import com.google.common.collect.ImmutableMap;
    
    26
    -import fr.ird.observe.test.ObserveFixtures;
    
    27
    -import org.junit.Assert;
    
    28
    -import org.junit.Test;
    
    29
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    30
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath;
    
    31
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPathsBuilder;
    
    32
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    33
    -
    
    34
    -public class ObserveTopiaMetadataModelSupportTest {
    
    35
    -
    
    36
    -    @Test
    
    37
    -    public void testEntityPathsBuilder() {
    
    38
    -
    
    39
    -        TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel();
    
    40
    -
    
    41
    -        TopiaMetadataEntityPathsBuilder entityPathsBuilder = new ObserveTopiaApplicationContext.ObserveDataEntityPathsBuilder();
    
    42
    -
    
    43
    -        TopiaMetadataEntity tripPs = model.getEntity(ObserveEntityEnum.ps_common_Trip.name());
    
    44
    -        ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> pathsPs = entityPathsBuilder.build(model, tripPs);
    
    45
    -        Assert.assertNotNull(pathsPs);
    
    46
    -        Assert.assertEquals(ObserveFixtures.PERSISTENCE_PS_DATA_PATH, pathsPs.size());
    
    47
    -
    
    48
    -        TopiaMetadataEntity tripLl = model.getEntity(ObserveEntityEnum.ll_common_Trip.name());
    
    49
    -        ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> pathsLl = entityPathsBuilder.build(model, tripLl);
    
    50
    -        Assert.assertNotNull(pathsLl);
    
    51
    -        Assert.assertEquals(ObserveFixtures.PERSISTENCE_LL_DATA_PATH, pathsLl.size());
    
    52
    -    }
    
    53
    -
    
    54
    -    @Test
    
    55
    -    public void getDataEntityPaths() {
    
    56
    -
    
    57
    -        TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel();
    
    58
    -        ImmutableMap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = model.getDataEntityPaths();
    
    59
    -        Assert.assertNotNull(dataEntityPaths);
    
    60
    -        Assert.assertEquals(ObserveFixtures.PERSISTENCE_DATA_PATH, dataEntityPaths.size());
    
    61
    -        Assert.assertFalse(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.Trip.class).isPresent());
    
    62
    -        Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.GearUseFeatures.class).isPresent());
    
    63
    -        Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ps.common.GearUseFeaturesMeasurement.class).isPresent());
    
    64
    -        Assert.assertFalse(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.Trip.class).isPresent());
    
    65
    -        Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.GearUseFeatures.class).isPresent());
    
    66
    -        Assert.assertTrue(model.getDataEntityPath(fr.ird.observe.entities.data.ll.common.GearUseFeaturesMeasurement.class).isPresent());
    
    67
    -    }
    
    68
    -}

  • persistence/src/test/java/fr/ird/observe/entities/TopiaMetadataModelPathsTest.java
    1
    +package fr.ird.observe.entities;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Persistence
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.google.common.collect.ImmutableMap;
    
    26
    +import com.google.common.collect.ImmutableSet;
    
    27
    +import com.google.common.collect.Multimap;
    
    28
    +import fr.ird.observe.test.ObserveFixtures;
    
    29
    +import org.junit.Assert;
    
    30
    +import org.junit.Test;
    
    31
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    32
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath;
    
    33
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    34
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelPaths;
    
    35
    +
    
    36
    +import java.util.Collection;
    
    37
    +import java.util.List;
    
    38
    +import java.util.Map;
    
    39
    +import java.util.Optional;
    
    40
    +
    
    41
    +/**
    
    42
    + * Created on 13/09/2020.
    
    43
    + *
    
    44
    + * @author Tony Chemit - dev@tchemit.fr
    
    45
    + * @since 8.1.0
    
    46
    + */
    
    47
    +public class TopiaMetadataModelPathsTest {
    
    48
    +
    
    49
    +
    
    50
    +    @Test
    
    51
    +    public void getEntityPaths() {
    
    52
    +
    
    53
    +        TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel();
    
    54
    +        TopiaMetadataModelPaths paths = TopiaMetadataModelPaths.load(model);
    
    55
    +        Multimap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = paths.getEntityPaths();
    
    56
    +        Assert.assertNotNull(dataEntityPaths);
    
    57
    +        Assert.assertEquals(ObserveFixtures.PERSISTENCE_DATA_PATH, dataEntityPaths.asMap().size());
    
    58
    +        Assert.assertFalse(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.Trip.class)).isPresent());
    
    59
    +        Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.GearUseFeatures.class)).isPresent());
    
    60
    +        Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ps.common.GearUseFeaturesMeasurement.class)).isPresent());
    
    61
    +        Assert.assertFalse(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.Trip.class)).isPresent());
    
    62
    +        Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.GearUseFeatures.class)).isPresent());
    
    63
    +        Assert.assertTrue(paths.getEntityPathsForEntryPoint(model.getMetadataEntity(fr.ird.observe.entities.data.ll.common.GearUseFeaturesMeasurement.class)).isPresent());
    
    64
    +    }
    
    65
    +
    
    66
    +    @Test
    
    67
    +    public void getEntityPathsCount() {
    
    68
    +        ImmutableMap<String, Long> excepted = ObserveFixtures.PERSISTENCE_ENTITY_PATHS;
    
    69
    +        TopiaMetadataModel model = ObserveTopiaApplicationContext.newModelSupport().getMetadataModel();
    
    70
    +
    
    71
    +        TopiaMetadataModelPaths paths = TopiaMetadataModelPaths.load(model);
    
    72
    +        Multimap<TopiaMetadataEntity, TopiaMetadataEntityPath> dataEntityPaths = paths.getEntityPaths();
    
    73
    +
    
    74
    +        Assert.assertNotNull(paths);
    
    75
    +        for (Map.Entry<TopiaMetadataEntity, Collection<TopiaMetadataEntityPath>> entry : paths.asMap().entrySet()) {
    
    76
    +            int actualPathsCount = entry.getValue().stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum();
    
    77
    +            System.out.printf("%s=%d%n", ObserveEntityEnum.valueOf(entry.getKey().getType()), actualPathsCount);
    
    78
    +        }
    
    79
    +        for (Map.Entry<String, Long> entry : excepted.entrySet()) {
    
    80
    +            String type = entry.getKey();
    
    81
    +            Optional<TopiaMetadataEntity> optionalTopiaMetadataEntity = paths.keySet().stream().filter(k -> k.getType().equals(type)).findFirst();
    
    82
    +            Assert.assertTrue("Could not find expected type in result: " + type, optionalTopiaMetadataEntity.isPresent());
    
    83
    +            TopiaMetadataEntity topiaMetadataEntity = optionalTopiaMetadataEntity.get();
    
    84
    +            Collection<TopiaMetadataEntityPath> topiaMetadataLinks = paths.get(topiaMetadataEntity);
    
    85
    +            int expectedPathsCount = Math.toIntExact(entry.getValue());
    
    86
    +            int actualPathsCount = topiaMetadataLinks.stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum();
    
    87
    +            Assert.assertEquals(String.format("for type %s, expected links size: %d but was %d", type, expectedPathsCount, actualPathsCount), expectedPathsCount, actualPathsCount);
    
    88
    +        }
    
    89
    +        ImmutableSet<String> keys = excepted.keySet();
    
    90
    +        for (Map.Entry<TopiaMetadataEntity, Collection<TopiaMetadataEntityPath>> entry : paths.asMap().entrySet()) {
    
    91
    +            if (!keys.contains(entry.getKey().getType())) {
    
    92
    +
    
    93
    +                int actualPathsCount = entry.getValue().stream().map(TopiaMetadataEntityPath::getLinks).mapToInt(List::size).sum();
    
    94
    +                System.err.printf("%s=%d%n", ObserveEntityEnum.valueOf(entry.getKey().getType()), actualPathsCount);
    
    95
    +            }
    
    96
    +        }
    
    97
    +        Assert.assertEquals(excepted.size(), paths.asMap().size());
    
    98
    +        // at the moment only two entities with two paths (ll_logbook_Sample and ll_logbook_SamplePart)
    
    99
    +        Assert.assertEquals(excepted.size() + 2, paths.size());
    
    100
    +    }
    
    101
    +}

  • pom.xml
    ... ... @@ -174,7 +174,7 @@
    174 174
         <lib.version.h2>1.4.196</lib.version.h2>
    
    175 175
         <lib.version.nuiton.utils>3.0</lib.version.nuiton.utils>
    
    176 176
     
    
    177
    -<!--        <lib.version.java4all.topia>1.26-SNAPSHOT</lib.version.java4all.topia>-->
    
    177
    +        <lib.version.java4all.topia>1.27-SNAPSHOT</lib.version.java4all.topia>
    
    178 178
     <!--    <lib.version.java4all.eugene>3.0-alpha-34-SNAPSHOT</lib.version.java4all.eugene>-->
    
    179 179
     <!--    <lib.version.java4all.jaxx>3.0-alpha-79-SNAPSHOT</lib.version.java4all.jaxx>-->
    
    180 180
         <!--<lib.version.java4all.application-context>1.0.3-SNAPSHOT</lib.version.java4all.application-context>-->
    

  • server-core/src/main/filtered-resources/mapping
    ... ... @@ -192,6 +192,7 @@ POST /api/v1/data/ps/common/TripGearUseFeaturesService/save
    192 192
     DELETE /api/v1/data/ps/common/TripService/delete                                                                                     v1.data.ps.common.TripServiceRestApi.delete
    
    193 193
     GET    /api/v1/data/ps/common/TripService/exists                                                                                     v1.data.ps.common.TripServiceRestApi.exists
    
    194 194
     GET    /api/v1/data/ps/common/TripService/getAllTrip                                                                                 v1.data.ps.common.TripServiceRestApi.getAllTrip
    
    195
    +GET    /api/v1/data/ps/common/TripService/getLogbookWeightCategoryByListAndTrip                                                      v1.data.ps.common.TripServiceRestApi.getLogbookWeightCategoryByListAndTrip
    
    195 196
     GET    /api/v1/data/ps/common/TripService/getMatchingTripsVesselWithinDateRange                                                      v1.data.ps.common.TripServiceRestApi.getMatchingTripsVesselWithinDateRange
    
    196 197
     GET    /api/v1/data/ps/common/TripService/getSpeciesByListAndTrip                                                                    v1.data.ps.common.TripServiceRestApi.getSpeciesByListAndTrip
    
    197 198
     GET    /api/v1/data/ps/common/TripService/getTripMap                                                                                 v1.data.ps.common.TripServiceRestApi.getTripMap
    

  • services-api/src/main/java/fr/ird/observe/services/service/data/ps/common/TripService.java
    ... ... @@ -24,10 +24,19 @@ package fr.ird.observe.services.service.data.ps.common;
    24 24
     
    
    25 25
     import fr.ird.observe.dto.data.ps.common.TripDto;
    
    26 26
     import fr.ird.observe.dto.data.ps.common.TripReference;
    
    27
    +import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet;
    
    28
    +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference;
    
    29
    +import fr.ird.observe.services.spi.ReadDataPermission;
    
    30
    +import io.ultreia.java4all.http.spi.Get;
    
    31
    +import io.ultreia.java4all.http.spi.Nullable;
    
    27 32
     
    
    28 33
     /**
    
    29 34
      * @author Tony Chemit - dev@tchemit.fr
    
    30 35
      */
    
    31 36
     public interface TripService extends fr.ird.observe.services.service.data.TripService<TripDto, TripReference> {
    
    32 37
     
    
    38
    +    @Get
    
    39
    +    @ReadDataPermission
    
    40
    +    ReferentialDtoReferenceSet<WeightCategoryReference> getLogbookWeightCategoryByListAndTrip(@Nullable String tripId, String speciesListId);
    
    41
    +
    
    33 42
     }

  • services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/common/TripServiceLocal.java
    ... ... @@ -23,6 +23,7 @@ package fr.ird.observe.services.local.service.data.ps.common;
    23 23
      */
    
    24 24
     
    
    25 25
     import com.google.common.collect.ImmutableSet;
    
    26
    +import fr.ird.observe.dto.IdDto;
    
    26 27
     import fr.ird.observe.dto.data.TripAware;
    
    27 28
     import fr.ird.observe.dto.data.TripMapConfigDto;
    
    28 29
     import fr.ird.observe.dto.data.TripMapDto;
    
    ... ... @@ -33,10 +34,13 @@ import fr.ird.observe.dto.form.Form;
    33 34
     import fr.ird.observe.dto.reference.DataDtoReferenceSet;
    
    34 35
     import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet;
    
    35 36
     import fr.ird.observe.dto.referential.common.SpeciesReference;
    
    37
    +import fr.ird.observe.dto.referential.ps.logbook.WeightCategoryReference;
    
    36 38
     import fr.ird.observe.dto.result.SaveResultDto;
    
    37 39
     import fr.ird.observe.entities.data.ps.common.Trip;
    
    38 40
     import fr.ird.observe.entities.referential.common.Ocean;
    
    39 41
     import fr.ird.observe.entities.referential.common.Program;
    
    42
    +import fr.ird.observe.entities.referential.ps.logbook.WeightCategory;
    
    43
    +import fr.ird.observe.entities.referential.ps.logbook.WeightCategoryTopiaDao;
    
    40 44
     import fr.ird.observe.services.local.ObserveServiceContextLocal;
    
    41 45
     import fr.ird.observe.services.local.service.ObserveServiceLocal;
    
    42 46
     import fr.ird.observe.services.service.data.ps.common.TripService;
    
    ... ... @@ -50,6 +54,7 @@ import java.util.Comparator;
    50 54
     import java.util.Date;
    
    51 55
     import java.util.LinkedHashSet;
    
    52 56
     import java.util.List;
    
    57
    +import java.util.stream.Collectors;
    
    53 58
     
    
    54 59
     /**
    
    55 60
      * @author Tony Chemit - dev@tchemit.fr
    
    ... ... @@ -121,6 +126,18 @@ public class TripServiceLocal extends ObserveServiceLocal implements TripService
    121 126
             return getSpeciesByListAndOcean(speciesListId, ocean);
    
    122 127
         }
    
    123 128
     
    
    129
    +    @Override
    
    130
    +    public ReferentialDtoReferenceSet<WeightCategoryReference> getLogbookWeightCategoryByListAndTrip(String tripId, String speciesListId) {
    
    131
    +        Ocean ocean = null;
    
    132
    +        if (tripId != null) {
    
    133
    +            Trip trip = Trip.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), tripId);
    
    134
    +            ocean = trip.getOcean();
    
    135
    +        }
    
    136
    +        List<String> speciesByListAndOcean = getSpeciesByListAndOcean(speciesListId, ocean).stream().map(IdDto::getId).collect(Collectors.toList());
    
    137
    +        WeightCategoryTopiaDao weightCategoryList = WeightCategory.getDao(getTopiaPersistenceContext());
    
    138
    +        return WeightCategory.toReferenceSet(getReferentialLocale(), weightCategoryList.streamAll().filter(c -> c.getSpecies() == null || speciesByListAndOcean.contains(c.getSpecies().getTopiaId())), now());
    
    139
    +    }
    
    140
    +
    
    124 141
         @Override
    
    125 142
         public Form<TripDto> preCreate(String programId) {
    
    126 143
             Trip trip = Trip.newEntity(now());
    

  • services-local/src/test/java/fr/ird/observe/services/local/service/data/TripManagementServiceLocalTest.java
    ... ... @@ -96,7 +96,7 @@ public class TripManagementServiceLocalTest extends ServiceLocalTestSupport {
    96 96
             Assert.assertNotNull(result);
    
    97 97
     
    
    98 98
             DataDtoReferenceSet<TripReference> allTripSeineAfter = tripService.getAllTrip();
    
    99
    -        Assert.assertTrue(allTripSeineBefore.size() == allTripSeineAfter.size() + 1);
    
    99
    +        Assert.assertEquals(allTripSeineBefore.size(), allTripSeineAfter.size() + 1);
    
    100 100
         }
    
    101 101
     
    
    102 102
         @Test
    

  • templates/pom.xml
    ... ... @@ -63,7 +63,10 @@
    63 63
           <groupId>org.nuiton</groupId>
    
    64 64
           <artifactId>nuiton-decorator</artifactId>
    
    65 65
         </dependency>
    
    66
    -
    
    66
    +    <dependency>
    
    67
    +      <groupId>io.ultreia.java4all.topia</groupId>
    
    68
    +      <artifactId>persistence</artifactId>
    
    69
    +    </dependency>
    
    67 70
         <dependency>
    
    68 71
           <groupId>org.apache.commons</groupId>
    
    69 72
           <artifactId>commons-lang3</artifactId>
    

  • templates/src/main/java/fr/ird/observe/toolkit/templates/GeneratePersistence.java
    ... ... @@ -22,6 +22,9 @@ package fr.ird.observe.toolkit.templates;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import fr.ird.observe.toolkit.templates.entity.EntityLastUpdateDateFieldSqlScriptGenerator;
    
    26
    +import fr.ird.observe.toolkit.templates.entity.EntityLastUpdateDateTableSqlScriptGenerator;
    
    27
    +import fr.ird.observe.toolkit.templates.entity.EntityPathsGenerator;
    
    25 28
     import fr.ird.observe.toolkit.templates.entity.EntityTransformer;
    
    26 29
     import org.codehaus.plexus.component.annotations.Component;
    
    27 30
     import org.nuiton.eugene.Template;
    
    ... ... @@ -31,6 +34,7 @@ import org.nuiton.topia.templates.EntityHibernateMappingTransformer;
    31 34
     import org.nuiton.topia.templates.TopiaEntityDaoTransformer;
    
    32 35
     import org.nuiton.topia.templates.TopiaEntityEnumTransformer;
    
    33 36
     import org.nuiton.topia.templates.TopiaGenerator;
    
    37
    +import org.nuiton.topia.templates.TopiaMetadataModelClassGenerator;
    
    34 38
     import org.nuiton.topia.templates.TopiaMetadataModelGenerator;
    
    35 39
     import org.nuiton.topia.templates.TopiaPersistenceContextTransformer;
    
    36 40
     
    
    ... ... @@ -55,6 +59,10 @@ public class GeneratePersistence extends TopiaGenerator {
    55 59
                     ApplicationContextTransformer.class,
    
    56 60
                     TopiaPersistenceContextTransformer.class,
    
    57 61
                     TopiaEntityDaoTransformer.class,
    
    62
    +                EntityPathsGenerator.class,
    
    63
    +                EntityLastUpdateDateFieldSqlScriptGenerator.class,
    
    64
    +                EntityLastUpdateDateTableSqlScriptGenerator.class,
    
    65
    +                TopiaMetadataModelClassGenerator.class,
    
    58 66
                     TopiaMetadataModelGenerator.class
    
    59 67
             );
    
    60 68
         }
    

  • templates/src/main/java/fr/ird/observe/toolkit/templates/dto/DtoTransformer.java
    ... ... @@ -62,6 +62,7 @@ import org.nuiton.eugene.models.object.xml.ObjectModelParameterImpl;
    62 62
     import java.util.Arrays;
    
    63 63
     import java.util.Collection;
    
    64 64
     import java.util.Date;
    
    65
    +import java.util.LinkedHashMap;
    
    65 66
     import java.util.LinkedHashSet;
    
    66 67
     import java.util.LinkedList;
    
    67 68
     import java.util.Map;
    
    ... ... @@ -317,7 +318,7 @@ public class DtoTransformer extends BeanTransformer implements TemplateContract
    317 318
         private Map<String, String> getFormProperties(ObjectModelClass input, ObjectModelClass output) {
    
    318 319
             Collection<ObjectModelAttribute> attributes = new LinkedList<>(input.getAttributes());
    
    319 320
             attributes.addAll(input.getAllOtherAttributes());
    
    320
    -        Map<String, String> properties = new TreeMap<>();
    
    321
    +        Map<String, String> properties = new LinkedHashMap<>();
    
    321 322
             for (ObjectModelAttribute attr : attributes) {
    
    322 323
     
    
    323 324
                 if (!attr.isNavigable()) {
    

  • toolbox-maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/GenerateEntityUpdateSqlFilesMojo.javatemplates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateFieldSqlScriptGenerator.java
    1
    -package fr.ird.observe.maven.plugins.toolbox;
    
    1
    +package fr.ird.observe.toolkit.templates.entity;
    
    2 2
     
    
    3 3
     /*-
    
    4 4
      * #%L
    
    5
    - * ObServe Toolkit :: Maven plugin
    
    5
    + * ObServe Toolkit :: Templates
    
    6 6
      * %%
    
    7 7
      * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8 8
      * %%
    
    ... ... @@ -22,129 +22,73 @@ package fr.ird.observe.maven.plugins.toolbox;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -
    
    26 25
     import com.google.common.collect.ImmutableList;
    
    27 26
     import fr.ird.observe.spi.context.DtoEntityContext;
    
    28
    -import org.apache.maven.plugins.annotations.LifecyclePhase;
    
    29
    -import org.apache.maven.plugins.annotations.Mojo;
    
    30
    -import org.apache.maven.plugins.annotations.Parameter;
    
    31
    -import org.apache.maven.plugins.annotations.ResolutionScope;
    
    32
    -import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl;
    
    27
    +import org.codehaus.plexus.component.annotations.Component;
    
    28
    +import org.nuiton.eugene.Template;
    
    29
    +import org.nuiton.eugene.models.object.ObjectModelClass;
    
    30
    +import org.nuiton.eugene.models.object.ObjectModelClassifier;
    
    33 31
     import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    34 32
     import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath;
    
    35 33
     import org.nuiton.topia.persistence.metadata.TopiaMetadataLink;
    
    36
    -import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
    
    37 34
     import org.nuiton.topia.persistence.metadata.TopiaMetadataReverseAssociation;
    
    38
    -import org.nuiton.topia.persistence.script.SqlScriptWriter;
    
    35
    +import org.nuiton.topia.templates.TopiaMetadataModelGeneratorSupport;
    
    39 36
     
    
    40
    -import java.io.File;
    
    41 37
     import java.io.IOException;
    
    42
    -import java.net.URLClassLoader;
    
    43
    -import java.nio.file.Path;
    
    38
    +import java.io.Writer;
    
    44 39
     import java.util.Iterator;
    
    45 40
     import java.util.LinkedList;
    
    46 41
     import java.util.List;
    
    47 42
     import java.util.Optional;
    
    48 43
     
    
    49
    -@Mojo(name = "generate-entity-update-sql-files", threadSafe = true, defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE)
    
    50
    -public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport {
    
    51
    -    private static final String UPDATE_LAST_UPDATE_DATE_TABLE_SQL = "UPDATE common.lastUpdateDate SET lastUpdateDate = '%%1$s'::timestamp WHERE type ='%s'";
    
    44
    +/**
    
    45
    + * Created on 13/09/2020.
    
    46
    + *
    
    47
    + * @author Tony Chemit - dev@tchemit.fr
    
    48
    + * @since 1.27
    
    49
    + */
    
    50
    +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityLastUpdateDateFieldSqlScriptGenerator")
    
    51
    +public class EntityLastUpdateDateFieldSqlScriptGenerator extends TopiaMetadataModelGeneratorSupport {
    
    52
    +
    
    52 53
         private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_START = "UPDATE %s.%s SET lastUpdateDate = '%%1$s'::timestamp, topiaVersion = topiaVersion + 1";
    
    53 54
         private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_WHERE_EQUALS = " WHERE %s = '%%2$s'";
    
    54 55
         private static final String UPDATE_LAST_UPDATE_DATE_FIELD_SQL_WHERE_SELECT = " WHERE topiaId = ( %s )";
    
    55 56
         private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START = "SELECT %3$s FROM %1$s.%2$s %2$s";
    
    56 57
         private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_INNER_JOIN_REVERSE = " INNER JOIN %1$s.%2$s %2$s ON %2$s.%3$s = %4$s.%5$s";
    
    57 58
         private static final String UPDATE_LAST_UPDATE_DATA_FIELD_SQL_INNER_JOIN_SIMPLE = " INNER JOIN %1$s.%2$s %2$s ON %2$s.%3$s = %4$s.topiaId";
    
    58
    -    /**
    
    59
    -     * Verbose flag.
    
    60
    -     */
    
    61
    -    @Parameter(property = "generateEntityUpdateSqlFiles.verbose", defaultValue = "${maven.verbose}")
    
    62
    -    private boolean verbose;
    
    63
    -    /**
    
    64
    -     * Skip flag.
    
    65
    -     */
    
    66
    -    @Parameter(property = "generateEntityUpdateSqlFiles.skip", defaultValue = "false")
    
    67
    -    private boolean skip;
    
    68
    -
    
    69
    -    /**
    
    70
    -     * Where to generate files.
    
    71
    -     */
    
    72
    -    @Parameter(property = "generateEntityUpdateSqlFiles.outputDirectory", defaultValue = "${project.build.directory}/classes/", required = true)
    
    73
    -    private File outputDirectory;
    
    74
    -
    
    75
    -    @Override
    
    76
    -    public boolean isVerbose() {
    
    77
    -        return verbose;
    
    78
    -    }
    
    79
    -
    
    80
    -    @Override
    
    81
    -    public void setVerbose(boolean verbose) {
    
    82
    -        this.verbose = verbose;
    
    83
    -    }
    
    84
    -
    
    85
    -    @Override
    
    86
    -    protected Path createOutputFile() {
    
    87
    -        return null;
    
    88
    -    }
    
    89 59
     
    
    90 60
         @Override
    
    91
    -    public boolean isSkip() {
    
    92
    -        return skip;
    
    61
    +    public String getFilenameForClassifier(ObjectModelClassifier classifier) {
    
    62
    +        return super.getFilenameForClassifier(classifier) + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_FIELD_CLASSIFIER;
    
    93 63
         }
    
    94 64
     
    
    95 65
         @Override
    
    96
    -    protected void doAction() throws Exception {
    
    97
    -        URLClassLoader urlClassLoader = initClassLoader(getProject(), outputDirectory, true, false, true, true, true);
    
    98
    -
    
    99
    -        Thread thread = Thread.currentThread();
    
    100
    -        ClassLoader contextClassLoader = thread.getContextClassLoader();
    
    101
    -        thread.setContextClassLoader(urlClassLoader);
    
    102
    -        try {
    
    103
    -            TopiaMetadataModelSupportImpl model = (TopiaMetadataModelSupportImpl) urlClassLoader.loadClass("fr.ird.observe.entities.ObserveTopiaMetadataModelSupport").newInstance();
    
    104
    -            TopiaMetadataModel metadataModel = model.getMetadataModel();
    
    105
    -            Iterator<TopiaMetadataEntity> iterator = metadataModel.streamWithoutAbstract().iterator();
    
    106
    -            while (iterator.hasNext()) {
    
    107
    -                TopiaMetadataEntity topiaMetadataEntity = iterator.next();
    
    108
    -                processEntity(metadataModel, topiaMetadataEntity);
    
    109
    -            }
    
    110
    -        } finally {
    
    111
    -            thread.setContextClassLoader(contextClassLoader);
    
    66
    +    public void generateFromClass(Writer output, ObjectModelClass input) throws IOException {
    
    67
    +        TopiaMetadataEntity entity = getEntityEnumName(input);
    
    68
    +        if (entity != null && !entity.isAbstract()) {
    
    69
    +            processEntity(entity, output);
    
    112 70
             }
    
    113 71
         }
    
    114 72
     
    
    115
    -    protected void processEntity(TopiaMetadataModel metadataModel, TopiaMetadataEntity topiaMetadataEntity) throws IOException {
    
    116
    -
    
    117
    -        String fullyQualifiedName = topiaMetadataEntity.getFullyQualifiedName();
    
    118
    -        Path directory = outputDirectory.toPath();
    
    119
    -        String[] parts = fullyQualifiedName.split("\\.");
    
    120
    -        String simpleName = parts[parts.length - 1];
    
    121
    -        for (int i = 0; i < parts.length - 1; i++) {
    
    122
    -            directory = directory.resolve(parts[i]);
    
    123
    -        }
    
    124
    -        createDirectoryIfNecessary(directory.toFile());
    
    73
    +    protected void processEntity(TopiaMetadataEntity entity, Writer output) throws IOException {
    
    125 74
     
    
    126 75
             ImmutableList<TopiaMetadataEntity> types;
    
    127 76
             ImmutableList<TopiaMetadataLink> links;
    
    128
    -        Optional<TopiaMetadataEntityPath> optionalDataEntityPath = metadataModel.getDataEntityPath(topiaMetadataEntity);
    
    129
    -        if (optionalDataEntityPath.isPresent()) {
    
    130
    -            TopiaMetadataEntityPath dataEntityPath = optionalDataEntityPath.get();
    
    131
    -            links = dataEntityPath.getLinks();
    
    132
    -            types = TopiaMetadataEntityPath.getTypes(dataEntityPath);
    
    77
    +        Optional<TopiaMetadataEntityPath> optionalPath = getAllPaths(EntityLastUpdateDateTableSqlScriptGenerator::rejectType).getEntityPathsForEntryPoint(entity);
    
    78
    +        if (optionalPath.isPresent()) {
    
    79
    +            TopiaMetadataEntityPath path = optionalPath.get();
    
    80
    +            links = path.getLinks();
    
    81
    +            types = path.getTypes();
    
    133 82
             } else {
    
    134 83
                 // limit case, only one type
    
    135
    -            types = ImmutableList.of(topiaMetadataEntity);
    
    84
    +            types = ImmutableList.of(entity);
    
    136 85
                 // and no link
    
    137 86
                 links = ImmutableList.of();
    
    138 87
             }
    
    139 88
     
    
    140
    -        {
    
    141
    -            ImmutableList<String> requests = generateLastUpdateDateFieldRequests(types, links);
    
    142
    -            generate(directory.resolve(simpleName + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_FIELD_CLASSIFIER), requests);
    
    143
    -        }
    
    144
    -        {
    
    145
    -            ImmutableList<String> requests = generateLastUpdateDateTableRequests(types);
    
    146
    -            generate(directory.resolve(simpleName + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_TABLE_CLASSIFIER), requests);
    
    147
    -        }
    
    89
    +        ImmutableList<String> requests = generateLastUpdateDateFieldRequests(types, links);
    
    90
    +        generate(output, requests);
    
    91
    +
    
    148 92
         }
    
    149 93
     
    
    150 94
         private ImmutableList<String> generateLastUpdateDateFieldRequests(ImmutableList<TopiaMetadataEntity> types, ImmutableList<TopiaMetadataLink> links) {
    
    ... ... @@ -170,15 +114,6 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport {
    170 114
             return builder.build();
    
    171 115
         }
    
    172 116
     
    
    173
    -    private ImmutableList<String> generateLastUpdateDateTableRequests(ImmutableList<TopiaMetadataEntity> types) {
    
    174
    -        ImmutableList.Builder<String> builder = ImmutableList.builder();
    
    175
    -        for (TopiaMetadataEntity type : types.reverse()) {
    
    176
    -            String tableSql = String.format(UPDATE_LAST_UPDATE_DATE_TABLE_SQL, type.getFullyQualifiedName());
    
    177
    -            builder.add(tableSql + ";");
    
    178
    -        }
    
    179
    -        return builder.build();
    
    180
    -    }
    
    181
    -
    
    182 117
         private String generateLastUpdateDateFieldRequest(TopiaMetadataEntity type, List<TopiaMetadataLink> inProcess) {
    
    183 118
             String sql = String.format(UPDATE_LAST_UPDATE_DATE_FIELD_SQL_START, type.getDbSchemaName(), type.getDbTableName());
    
    184 119
             if (inProcess == null) {
    
    ... ... @@ -223,7 +158,7 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport {
    223 158
                 tableOwner = firstLink.getTarget();
    
    224 159
                 selectColumn = firstLink.getTarget().getDbColumnName(firstLink.getOwner().getDbTableName());
    
    225 160
             }
    
    226
    -        return String.format(UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START, tableOwner.getDbSchemaName(), tableOwner.getDbTableName(), tableOwner.getDbTableName() +"."+ selectColumn);
    
    161
    +        return String.format(UPDATE_LAST_UPDATE_DATA_FIELD_SQL_SELECT_START, tableOwner.getDbSchemaName(), tableOwner.getDbTableName(), tableOwner.getDbTableName() + "." + selectColumn);
    
    227 162
         }
    
    228 163
     
    
    229 164
         private String appendInnerJoin(TopiaMetadataLink lastLink, TopiaMetadataLink nextLink) {
    
    ... ... @@ -246,10 +181,4 @@ public class GenerateEntityUpdateSqlFilesMojo extends ToolboxMojoSupport {
    246 181
             return finalizeRequest(targetColumn);
    
    247 182
         }
    
    248 183
     
    
    249
    -    private void generate(Path file, ImmutableList<String> requests) throws IOException {
    
    250
    -        getLog().debug(String.format("Will write %d requests in file: %s", requests.size(), file));
    
    251
    -        try (SqlScriptWriter sqlScriptWriter = SqlScriptWriter.of(file)) {
    
    252
    -            requests.forEach(sqlScriptWriter::writeSql);
    
    253
    -        }
    
    254
    -    }
    
    255 184
     }

  • templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityLastUpdateDateTableSqlScriptGenerator.java
    1
    +package fr.ird.observe.toolkit.templates.entity;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Templates
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.google.common.collect.ImmutableList;
    
    26
    +import fr.ird.observe.spi.context.DtoEntityContext;
    
    27
    +import org.codehaus.plexus.component.annotations.Component;
    
    28
    +import org.nuiton.eugene.Template;
    
    29
    +import org.nuiton.eugene.models.object.ObjectModelClass;
    
    30
    +import org.nuiton.eugene.models.object.ObjectModelClassifier;
    
    31
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    32
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntityPath;
    
    33
    +import org.nuiton.topia.templates.TopiaMetadataModelGeneratorSupport;
    
    34
    +
    
    35
    +import java.io.IOException;
    
    36
    +import java.io.Writer;
    
    37
    +import java.util.Optional;
    
    38
    +
    
    39
    +/**
    
    40
    + * Created on 13/09/2020.
    
    41
    + *
    
    42
    + * @author Tony Chemit - dev@tchemit.fr
    
    43
    + * @since 1.27
    
    44
    + */
    
    45
    +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityLastUpdateDateTableSqlScriptGenerator")
    
    46
    +public class EntityLastUpdateDateTableSqlScriptGenerator extends TopiaMetadataModelGeneratorSupport {
    
    47
    +
    
    48
    +    private static final String UPDATE_LAST_UPDATE_DATE_TABLE_SQL = "UPDATE common.lastUpdateDate SET lastUpdateDate = '%%1$s'::timestamp WHERE type ='%s'";
    
    49
    +
    
    50
    +    protected static boolean rejectType(TopiaMetadataEntity entity) {
    
    51
    +        return entity.isAbstract() || entity.getFullyQualifiedName().contains(".referential");
    
    52
    +    }
    
    53
    +
    
    54
    +    @Override
    
    55
    +    public String getFilenameForClassifier(ObjectModelClassifier classifier) {
    
    56
    +        return super.getFilenameForClassifier(classifier) + DtoEntityContext.LAST_UPDATE_DATE_SQL_SCRIPT_TABLE_CLASSIFIER;
    
    57
    +    }
    
    58
    +
    
    59
    +    @Override
    
    60
    +    public void generateFromClass(Writer output, ObjectModelClass input) throws IOException {
    
    61
    +        TopiaMetadataEntity entity = getEntityEnumName(input);
    
    62
    +        if (entity != null && !entity.isAbstract()) {
    
    63
    +            processEntity(entity, output);
    
    64
    +        }
    
    65
    +    }
    
    66
    +
    
    67
    +    protected void processEntity(TopiaMetadataEntity entity, Writer output) throws IOException {
    
    68
    +
    
    69
    +        ImmutableList<TopiaMetadataEntity> types;
    
    70
    +        Optional<TopiaMetadataEntityPath> optionalPath = getAllPaths(EntityLastUpdateDateTableSqlScriptGenerator::rejectType).getEntityPathsForEntryPoint(entity);
    
    71
    +        if (optionalPath.isPresent()) {
    
    72
    +            TopiaMetadataEntityPath path = optionalPath.get();
    
    73
    +            types = path.getTypes();
    
    74
    +        } else {
    
    75
    +            // limit case, only one type
    
    76
    +            types = ImmutableList.of(entity);
    
    77
    +            // and no link
    
    78
    +        }
    
    79
    +        ImmutableList<String> requests = generateLastUpdateDateTableRequests(types);
    
    80
    +        generate(output, requests);
    
    81
    +
    
    82
    +    }
    
    83
    +
    
    84
    +    private ImmutableList<String> generateLastUpdateDateTableRequests(ImmutableList<TopiaMetadataEntity> types) {
    
    85
    +        ImmutableList.Builder<String> builder = ImmutableList.builder();
    
    86
    +        for (TopiaMetadataEntity type : types.reverse()) {
    
    87
    +            String tableSql = String.format(UPDATE_LAST_UPDATE_DATE_TABLE_SQL, type.getFullyQualifiedName());
    
    88
    +            builder.add(tableSql + ";");
    
    89
    +        }
    
    90
    +        return builder.build();
    
    91
    +    }
    
    92
    +
    
    93
    +}

  • persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaMetadataModelSupport.javatemplates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityPathsGenerator.java
    1
    -package fr.ird.observe.entities;
    
    1
    +package fr.ird.observe.toolkit.templates.entity;
    
    2 2
     
    
    3 3
     /*-
    
    4 4
      * #%L
    
    5
    - * ObServe :: Persistence
    
    5
    + * ObServe Toolkit :: Templates
    
    6 6
      * %%
    
    7 7
      * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    8 8
      * %%
    
    ... ... @@ -22,10 +22,23 @@ package fr.ird.observe.entities;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    -import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl;
    
    25
    +import org.codehaus.plexus.component.annotations.Component;
    
    26
    +import org.nuiton.eugene.Template;
    
    27
    +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity;
    
    28
    +import org.nuiton.topia.templates.TopiaMetadataEntityPathsGeneratorSupport;
    
    26 29
     
    
    27
    -public class ObserveTopiaMetadataModelSupport extends TopiaMetadataModelSupportImpl {
    
    28
    -    public ObserveTopiaMetadataModelSupport() {
    
    29
    -        super("fr.ird.observe.entities", "Observe", new ObserveTopiaApplicationContext.ObserveDataEntityPathsBuilder());
    
    30
    +/**
    
    31
    + * Created on 13/09/2020.
    
    32
    + *
    
    33
    + * @author Tony Chemit - dev@tchemit.fr
    
    34
    + * @since 8.1.0
    
    35
    + */
    
    36
    +@Component(role = Template.class, hint = "org.nuiton.topia.templates.EntityPathsGenerator")
    
    37
    +public class EntityPathsGenerator extends TopiaMetadataEntityPathsGeneratorSupport {
    
    38
    +
    
    39
    +    @Override
    
    40
    +    protected boolean rejectType(TopiaMetadataEntity entity) {
    
    41
    +        return EntityLastUpdateDateTableSqlScriptGenerator.rejectType(entity);
    
    30 42
         }
    
    43
    +
    
    31 44
     }

  • test/src/main/java/fr/ird/observe/test/ObserveFixtures.java
    ... ... @@ -78,10 +78,10 @@ public class ObserveFixtures {
    78 78
         public static final ImmutableMap<String, Long> TRIP_LONGLINE_1_TABLES_COUNT = loadFixturesMapCount("count-data-longline-1");
    
    79 79
         public static final ImmutableMap<String, Long> TRIP_LONGLINE_2_TABLES_COUNT = loadFixturesMapCount("count-data-longline-2");
    
    80 80
         public static final ImmutableMap<String, Long> TRIP_LONGLINE_3_TABLES_COUNT = loadFixturesMapCount("count-data-longline-3");
    
    81
    +    public static final ImmutableMap<String, Long> PERSISTENCE_ENTITY_PATHS = loadFixturesMapCount("entity-paths");
    
    82
    +
    
    81 83
         private static final ImmutableMap<String, String> GLOBAL = loadFixturesMap("global");
    
    82
    -    public static final int PERSISTENCE_PS_DATA_PATH = Integer.parseInt(GLOBAL.get("PERSISTENCE_PS_DATA_PATH"));
    
    83
    -    public static final int PERSISTENCE_LL_DATA_PATH = Integer.parseInt(GLOBAL.get("PERSISTENCE_LL_DATA_PATH"));
    
    84
    -    public static final int PERSISTENCE_DATA_PATH = PERSISTENCE_PS_DATA_PATH+PERSISTENCE_LL_DATA_PATH;
    
    84
    +    public static final int PERSISTENCE_DATA_PATH = PERSISTENCE_ENTITY_PATHS.size();
    
    85 85
         public static final String TRIP_SEINE_ID_1 = GLOBAL.get("TRIP_SEINE_ID_1");
    
    86 86
         public static final String TRIP_SEINE_ID_2 = GLOBAL.get("TRIP_SEINE_ID_2");
    
    87 87
         public static final String TRIP_SEINE_ID_3 = GLOBAL.get("TRIP_SEINE_ID_3");
    

  • test/src/main/resources/fixtures/entity-paths.properties
    1
    +###
    
    2
    +# #%L
    
    3
    +# ObServe :: Test
    
    4
    +# %%
    
    5
    +# Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
    
    6
    +# %%
    
    7
    +# This program is free software: you can redistribute it and/or modify
    
    8
    +# it under the terms of the GNU General Public License as
    
    9
    +# published by the Free Software Foundation, either version 3 of the
    
    10
    +# License, or (at your option) any later version.
    
    11
    +#
    
    12
    +# This program is distributed in the hope that it will be useful,
    
    13
    +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +# GNU General Public License for more details.
    
    16
    +#
    
    17
    +# You should have received a copy of the GNU General Public
    
    18
    +# License along with this program.  If not, see
    
    19
    +# <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    20
    +# #L%
    
    21
    +###
    
    22
    +ll_observation_Activity=1
    
    23
    +ll_observation_Set=2
    
    24
    +ll_observation_Encounter=2
    
    25
    +ll_observation_SensorUsed=2
    
    26
    +ll_observation_BaitsComposition=3
    
    27
    +ll_observation_FloatlinesComposition=3
    
    28
    +ll_observation_BranchlinesComposition=3
    
    29
    +ll_observation_HooksComposition=3
    
    30
    +ll_observation_Catch=3
    
    31
    +ll_observation_Section=3
    
    32
    +ll_observation_Tdr=3
    
    33
    +ll_observation_Basket=4
    
    34
    +ll_observation_SizeMeasure=4
    
    35
    +ll_observation_WeightMeasure=4
    
    36
    +ll_observation_Branchline=5
    
    37
    +ll_logbook_Activity=1
    
    38
    +ll_logbook_Set=2
    
    39
    +ll_logbook_BaitsComposition=3
    
    40
    +ll_logbook_FloatlinesComposition=3
    
    41
    +ll_logbook_HooksComposition=3
    
    42
    +ll_logbook_Catch=3
    
    43
    +ll_logbook_BranchlinesComposition=3
    
    44
    +ll_common_GearUseFeatures=1
    
    45
    +ll_common_GearUseFeaturesMeasurement=2
    
    46
    +ll_landing_Landing=1
    
    47
    +ll_landing_LandingPart=2
    
    48
    +ll_logbook_Sample=3
    
    49
    +ll_logbook_SamplePart=5
    
    50
    +ps_observation_Route=1
    
    51
    +ps_observation_Activity=2
    
    52
    +ps_observation_FloatingObject=3
    
    53
    +ps_observation_Set=3
    
    54
    +ps_observation_Catch=4
    
    55
    +ps_observation_Sample=4
    
    56
    +ps_observation_SchoolEstimate=4
    
    57
    +ps_observation_NonTargetCatchRelease=4
    
    58
    +ps_observation_ObjectSchoolEstimate=4
    
    59
    +ps_observation_ObjectObservedSpecies=4
    
    60
    +ps_observation_TransmittingBuoy=4
    
    61
    +ps_observation_FloatingObjectPart=4
    
    62
    +ps_observation_Size=5
    
    63
    +ps_logbook_Route=1
    
    64
    +ps_logbook_Activity=2
    
    65
    +ps_logbook_FloatingObject=3
    
    66
    +ps_logbook_Set=3
    
    67
    +ps_logbook_Catch=4
    
    68
    +ps_logbook_TransmittingBuoy=4
    
    69
    +ps_logbook_FloatingObjectPart=4
    
    70
    +ps_landing_Landing=1
    
    71
    +ps_wellplan_WellPlan=1
    
    72
    +ps_logbook_Sample=1
    
    73
    +ps_logbook_SampleSpecies=2
    
    74
    +ps_logbook_SampleSpeciesSize=3
    
    75
    +ps_localmarket_Batch=1
    
    76
    +ps_localmarket_Survey=1
    
    77
    +ps_localmarket_Sample=1
    
    78
    +ps_localmarket_SurveyPart=2
    
    79
    +ps_localmarket_SamplePart=2
    
    80
    +ps_common_GearUseFeatures=1
    
    81
    +ps_common_GearUseFeaturesMeasurement=2

  • test/src/main/resources/fixtures/global.properties
    ... ... @@ -56,7 +56,4 @@ VALIDATOR_CREATE_REFERENTIAL_COUNT_REAL=87
    56 56
     VALIDATOR_UPDATE_REFERENTIAL_COUNT_REAL=87
    
    57 57
     VALIDATOR_UPDATE_ENTITY_DATA_COUNT=40
    
    58 58
     
    
    59
    -ENTITIES_LIMIT_SIZE=100
    
    60
    -# for fr.ird.observe.entities.ObserveTopiaMetadataModelSupportTest
    
    61
    -PERSISTENCE_PS_DATA_PATH=32
    
    62
    -PERSISTENCE_LL_DATA_PATH=28
    \ No newline at end of file
    59
    +ENTITIES_LIMIT_SIZE=100
    \ No newline at end of file

  • toolbox-maven-plugin/pom.xml
    ... ... @@ -86,10 +86,6 @@
    86 86
           <groupId>io.ultreia.java4all</groupId>
    
    87 87
           <artifactId>application-context</artifactId>
    
    88 88
         </dependency>
    
    89
    -    <dependency>
    
    90
    -      <groupId>io.ultreia.java4all.topia</groupId>
    
    91
    -      <artifactId>persistence</artifactId>
    
    92
    -    </dependency>
    
    93 89
         <dependency>
    
    94 90
           <groupId>com.google.auto.service</groupId>
    
    95 91
           <artifactId>auto-service-annotations</artifactId>