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

Commits:

16 changed files:

Changes:

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationCapability.java
    ... ... @@ -75,8 +75,8 @@ public class RootNavigationCapability implements ReferenceContainerCapability<Ro
    75 75
             NavigationTreeConfig config = initializer.getConfig();
    
    76 76
             NavigationResult navigationResult = initializer.getNavigationResult();
    
    77 77
             List<ProgramReference> programs = initializer.getPrograms();
    
    78
    -        List<? extends RootNavigationTreeNodeProvider> rootNodeProviders = initializer.getRootNodeProviders();
    
    79
    -        List<? extends RootNavigationTreeNodeProvider> providers = rootNodeProviders.stream().filter(p -> config.isShowModule(p.getModule())).collect(Collectors.toList());
    
    78
    +        List<? extends RootNavigationTreeNodeProvider<?>> rootNodeProviders = initializer.getRootNodeProviders();
    
    79
    +        List<? extends RootNavigationTreeNodeProvider<?>> providers = rootNodeProviders.stream().filter(p -> config.isShowModule(p.getModule())).collect(Collectors.toList());
    
    80 80
             providers.forEach(p -> p.initRootDataNode(config, navigationResult, programs, rootNode));
    
    81 81
             if (config.isLoadReferential()) {
    
    82 82
                 providers.forEach(p -> p.initRootReferentialNode(rootNode, navigationResult));
    
    ... ... @@ -98,13 +98,13 @@ public class RootNavigationCapability implements ReferenceContainerCapability<Ro
    98 98
             return 0;
    
    99 99
         }
    
    100 100
     
    
    101
    -    public RootNavigationTreeNodeProvider getProvider(ProgramReference referenceType) {
    
    101
    +    public RootNavigationTreeNodeProvider<?> getProvider(ProgramReference referenceType) {
    
    102 102
             return getNode().getInitializer().getRootNodeProvider(referenceType);
    
    103 103
         }
    
    104 104
     
    
    105 105
         public NavigationNode newChildNode(ProgramReference reference) {
    
    106 106
             RootNavigationNode node = getNode();
    
    107
    -        RootNavigationTreeNodeProvider provider = getProvider(reference);
    
    107
    +        RootNavigationTreeNodeProvider<?> provider = getProvider(reference);
    
    108 108
             return provider.newChildNode(node, reference, 0);
    
    109 109
         }
    
    110 110
     
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationInitializer.java
    ... ... @@ -42,7 +42,7 @@ import java.util.Objects;
    42 42
      * @since 8.0.1
    
    43 43
      */
    
    44 44
     public class RootNavigationInitializer extends NavigationInitializer<RootNavigationContext> {
    
    45
    -    private final SingletonSupplier<List<? extends RootNavigationTreeNodeProvider>> rootNodeProviders;
    
    45
    +    private final SingletonSupplier<List<? extends RootNavigationTreeNodeProvider<?>>> rootNodeProviders;
    
    46 46
         private final SingletonSupplier<Boolean> canLoadChildrenOnOpen;
    
    47 47
         private final NavigationTreeConfig config;
    
    48 48
         private final NavigationResult navigationResult;
    
    ... ... @@ -73,7 +73,7 @@ public class RootNavigationInitializer extends NavigationInitializer<RootNavigat
    73 73
         protected void reload(NavigationContext<RootNavigationContext> context) {
    
    74 74
         }
    
    75 75
     
    
    76
    -    public final List<? extends RootNavigationTreeNodeProvider> getRootNodeProviders() {
    
    76
    +    public final List<? extends RootNavigationTreeNodeProvider<?>> getRootNodeProviders() {
    
    77 77
             return rootNodeProviders.get();
    
    78 78
         }
    
    79 79
     
    

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/navigation/tree/root/RootNavigationTreeNodeProvider.java
    ... ... @@ -30,11 +30,10 @@ import fr.ird.observe.client.datasource.editor.api.content.referential.Referenti
    30 30
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.NavigationNode;
    
    31 31
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    32 32
     import fr.ird.observe.dto.referential.ReferentialDto;
    
    33
    -import fr.ird.observe.dto.referential.common.GearType;
    
    34 33
     import fr.ird.observe.dto.referential.common.ProgramReference;
    
    35 34
     import fr.ird.observe.services.service.data.NavigationResult;
    
    36
    -import fr.ird.observe.spi.module.BusinessModule;
    
    37 35
     import fr.ird.observe.spi.module.BusinessProject;
    
    36
    +import fr.ird.observe.spi.module.ObserveBusinessModule;
    
    38 37
     
    
    39 38
     import java.util.Comparator;
    
    40 39
     import java.util.LinkedList;
    
    ... ... @@ -49,19 +48,17 @@ import java.util.stream.Collectors;
    49 48
      * @author Tony Chemit - dev@tchemit.fr
    
    50 49
      * @since 8.0
    
    51 50
      */
    
    52
    -public abstract class RootNavigationTreeNodeProvider {
    
    53
    -    public static List<RootNavigationTreeNodeProvider> PROVIDERS;
    
    54
    -    private final BusinessModule module;
    
    55
    -    //FIXME Add this in BusinessModule
    
    56
    -    private final GearType gearType;
    
    51
    +public abstract class RootNavigationTreeNodeProvider<B extends fr.ird.observe.spi.module.BusinessModule & ObserveBusinessModule> {
    
    52
    +    public static List<RootNavigationTreeNodeProvider<?>> PROVIDERS;
    
    53
    +    private final B module;
    
    57 54
         private final int priority;
    
    58 55
         private final ImmutableList<Class<? extends NavigationNode>> acceptedNodeTypes;
    
    59 56
         private final Class<? extends DataDtoReference> acceptedType;
    
    60 57
     
    
    61
    -    public static synchronized List<RootNavigationTreeNodeProvider> getProviders() {
    
    58
    +    public static synchronized List<RootNavigationTreeNodeProvider<?>> getProviders() {
    
    62 59
             if (PROVIDERS == null) {
    
    63 60
                 PROVIDERS = new LinkedList<>();
    
    64
    -            for (RootNavigationTreeNodeProvider o : ServiceLoader.load(RootNavigationTreeNodeProvider.class)) {
    
    61
    +            for (RootNavigationTreeNodeProvider<?> o : ServiceLoader.load(RootNavigationTreeNodeProvider.class)) {
    
    65 62
                     PROVIDERS.add(o);
    
    66 63
                 }
    
    67 64
                 PROVIDERS.sort(Comparator.comparing(RootNavigationTreeNodeProvider::priority));
    
    ... ... @@ -69,9 +66,8 @@ public abstract class RootNavigationTreeNodeProvider {
    69 66
             return PROVIDERS;
    
    70 67
         }
    
    71 68
     
    
    72
    -    protected RootNavigationTreeNodeProvider(BusinessProject project, BusinessModule module, GearType gearType, ImmutableList<Class<? extends NavigationNode>> acceptedNodeTypes, Class<? extends DataDtoReference> acceptedType) {
    
    69
    +    protected RootNavigationTreeNodeProvider(BusinessProject project, B module, ImmutableList<Class<? extends NavigationNode>> acceptedNodeTypes, Class<? extends DataDtoReference> acceptedType) {
    
    73 70
             this.module = Objects.requireNonNull(module);
    
    74
    -        this.gearType = gearType;
    
    75 71
             this.acceptedNodeTypes = acceptedNodeTypes;
    
    76 72
             this.acceptedType = acceptedType;
    
    77 73
             this.priority = Objects.requireNonNull(project).getModulePriority(module);
    
    ... ... @@ -124,7 +120,7 @@ public abstract class RootNavigationTreeNodeProvider {
    124 120
             return priority;
    
    125 121
         }
    
    126 122
     
    
    127
    -    public BusinessModule getModule() {
    
    123
    +    public B getModule() {
    
    128 124
             return module;
    
    129 125
         }
    
    130 126
     
    
    ... ... @@ -140,7 +136,7 @@ public abstract class RootNavigationTreeNodeProvider {
    140 136
         }
    
    141 137
     
    
    142 138
         public boolean accept(ProgramReference childrenReference) {
    
    143
    -        return gearType != null && Objects.equals(gearType, childrenReference.getGearType());
    
    139
    +        return module.accept(childrenReference);
    
    144 140
         }
    
    145 141
     
    
    146 142
         public ContentListUINavigationNode newChildNode(RootNavigationNode node, ProgramReference reference, int tripCount) {
    

  • client/datasource/editor/common/src/main/java/fr/ird/observe/client/datasource/editor/common/CommonRootNavigationTreeNodeProvider.java
    ... ... @@ -26,21 +26,18 @@ import com.google.auto.service.AutoService;
    26 26
     import com.google.common.collect.ImmutableList;
    
    27 27
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationTreeNodeProvider;
    
    28 28
     import fr.ird.observe.spi.module.ObserveBusinessProject;
    
    29
    +import fr.ird.observe.spi.module.common.BusinessModule;
    
    29 30
     
    
    30 31
     /**
    
    31 32
      * @author Tony Chemit - dev@tchemit.fr
    
    32 33
      * @since 8.0
    
    33 34
      */
    
    34 35
     @AutoService(RootNavigationTreeNodeProvider.class)
    
    35
    -public class CommonRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider {
    
    36
    +public class CommonRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider<BusinessModule> {
    
    36 37
     
    
    37 38
         public CommonRootNavigationTreeNodeProvider() {
    
    38
    -        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getCommonBusinessModule(), null,
    
    39
    +        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getCommonBusinessModule(),
    
    39 40
                   ImmutableList.of(fr.ird.observe.client.datasource.editor.common.referential.common.ReferentialHomeUINavigationNode.class), null);
    
    40 41
         }
    
    41 42
     
    
    42
    -//    @Override
    
    43
    -//    public void initRootDataNode(NavigationTreeConfig config, NavigationResult navigationResult, List<ProgramReference> programs, RootNavigationNode rootNode) {
    
    44
    -//    }
    
    45
    -
    
    46 43
     }

  • client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/LlRootNavigationTreeNodeProvider.java
    ... ... @@ -28,19 +28,19 @@ import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavi
    28 28
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationTreeNodeProvider;
    
    29 29
     import fr.ird.observe.client.datasource.editor.ll.data.common.TripListUINavigationNode;
    
    30 30
     import fr.ird.observe.dto.data.ll.common.TripReference;
    
    31
    -import fr.ird.observe.dto.referential.common.GearType;
    
    32 31
     import fr.ird.observe.dto.referential.common.ProgramReference;
    
    33 32
     import fr.ird.observe.spi.module.ObserveBusinessProject;
    
    33
    +import fr.ird.observe.spi.module.ll.BusinessModule;
    
    34 34
     
    
    35 35
     /**
    
    36 36
      * @author Tony Chemit - dev@tchemit.fr
    
    37 37
      * @since 8.0
    
    38 38
      */
    
    39 39
     @AutoService(RootNavigationTreeNodeProvider.class)
    
    40
    -public class LlRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider {
    
    40
    +public class LlRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider<BusinessModule> {
    
    41 41
     
    
    42 42
         public LlRootNavigationTreeNodeProvider() {
    
    43
    -        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getLlBusinessModule(), GearType.longline,
    
    43
    +        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getLlBusinessModule(),
    
    44 44
                   ImmutableList.of(TripListUINavigationNode.class,
    
    45 45
                                    fr.ird.observe.client.datasource.editor.ll.referential.common.ReferentialHomeUINavigationNode.class,
    
    46 46
                                    fr.ird.observe.client.datasource.editor.ll.referential.landing.ReferentialHomeUINavigationNode.class,
    

  • client/datasource/editor/ps/src/main/java/fr/ird/observe/client/datasource/editor/ps/PsRootNavigationTreeNodeProvider.java
    ... ... @@ -28,19 +28,19 @@ import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavi
    28 28
     import fr.ird.observe.client.datasource.editor.api.navigation.tree.root.RootNavigationTreeNodeProvider;
    
    29 29
     import fr.ird.observe.client.datasource.editor.ps.data.common.TripListUINavigationNode;
    
    30 30
     import fr.ird.observe.dto.data.ll.common.TripReference;
    
    31
    -import fr.ird.observe.dto.referential.common.GearType;
    
    32 31
     import fr.ird.observe.dto.referential.common.ProgramReference;
    
    33 32
     import fr.ird.observe.spi.module.ObserveBusinessProject;
    
    33
    +import fr.ird.observe.spi.module.ps.BusinessModule;
    
    34 34
     
    
    35 35
     /**
    
    36 36
      * @author Tony Chemit - dev@tchemit.fr
    
    37 37
      * @since 8.0
    
    38 38
      */
    
    39 39
     @AutoService(RootNavigationTreeNodeProvider.class)
    
    40
    -public class PsRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider {
    
    40
    +public class PsRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProvider<BusinessModule> {
    
    41 41
     
    
    42 42
         public PsRootNavigationTreeNodeProvider() {
    
    43
    -        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getPsBusinessModule(), GearType.seine,
    
    43
    +        super(ObserveBusinessProject.get(), ObserveBusinessProject.get().getPsBusinessModule(),
    
    44 44
                   ImmutableList.of(TripListUINavigationNode.class,
    
    45 45
                                    fr.ird.observe.client.datasource.editor.ps.referential.common.ReferentialHomeUINavigationNode.class,
    
    46 46
                                    fr.ird.observe.client.datasource.editor.ps.referential.observation.ReferentialHomeUINavigationNode.class),
    
    ... ... @@ -49,6 +49,6 @@ public class PsRootNavigationTreeNodeProvider extends RootNavigationTreeNodeProv
    49 49
     
    
    50 50
         @Override
    
    51 51
         public TripListUINavigationNode newChildNode(RootNavigationNode node, ProgramReference reference, int tripCount) {
    
    52
    -        return TripListUINavigationNode.create(reference, (int) tripCount);
    
    52
    +        return TripListUINavigationNode.create(reference, tripCount);
    
    53 53
         }
    
    54 54
     }

  • models/persistence/src/main/java/fr/ird/observe/entities/data/TripAwareTopiaDao.java
    ... ... @@ -62,7 +62,7 @@ public interface TripAwareTopiaDao<D extends DataDto & fr.ird.observe.dto.data.T
    62 62
     
    
    63 63
         List<E> getMatchingTripsVesselWithinDateRange(String id, String vesselId, Date startDate, Date endDate);
    
    64 64
     
    
    65
    -    List<R> getChildren(ReferentialLocale referentialLocale, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById);
    
    65
    +    List<R> getChildren(ReferentialLocale referentialLocale, String programId, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById);
    
    66 66
     
    
    67 67
         default void fillTripCountByProgramId(Map<String, Integer> map) {
    
    68 68
             TopiaEntityEnum entityEnum = ((AbstractObserveTopiaDao<?>) this).getTopiaEntityEnum();
    
    ... ... @@ -72,7 +72,7 @@ public interface TripAwareTopiaDao<D extends DataDto & fr.ird.observe.dto.data.T
    72 72
     
    
    73 73
         default List<E> getChildren(Program parent, Date lastUpdate) {
    
    74 74
             if (lastUpdate == null) {
    
    75
    -            return forProperties(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    75
    +            return forEquals(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    76 76
             }
    
    77 77
             return forLastUpdateDateGreaterThan(lastUpdate).addEquals(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    78 78
         }
    

  • models/persistence/src/main/java/fr/ird/observe/entities/data/ll/common/TripTopiaDao.java
    ... ... @@ -55,7 +55,7 @@ import java.util.stream.Collectors;
    55 55
     
    
    56 56
     public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwareTopiaDao<TripDto, TripReference, Trip> {
    
    57 57
     
    
    58
    -    public static final String GET_TRIP_REFERENCES = "SELECT" +
    
    58
    +    public static final String GET_ALL_TRIP_REFERENCES = "SELECT" +
    
    59 59
                 " t.program," +
    
    60 60
                 " t.topiaId," +
    
    61 61
                 " t.startDate," +
    
    ... ... @@ -66,6 +66,19 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    66 66
                 " t.observationsAvailability," +
    
    67 67
                 " t.logbookAvailability" +
    
    68 68
                 " FROM %s.%s t;";
    
    69
    +    public static final String GET_TRIP_REFERENCES = "SELECT" +
    
    70
    +            " t.program," +
    
    71
    +            " t.topiaId," +
    
    72
    +            " t.startDate," +
    
    73
    +            " t.endDate," +
    
    74
    +            " t.tripType," +
    
    75
    +            " t.observer," +
    
    76
    +            " t.vessel," +
    
    77
    +            " t.observationsAvailability," +
    
    78
    +            " t.logbookAvailability" +
    
    79
    +            " FROM %s.%s t" +
    
    80
    +            " WHERE t.program = '%s';";
    
    81
    +
    
    69 82
     
    
    70 83
         private static class TripMapActivityObsPointQuery extends TopiaSqlQuery<List<TripMapPoint>> {
    
    71 84
     
    
    ... ... @@ -269,7 +282,7 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    269 282
         }
    
    270 283
     
    
    271 284
         @Override
    
    272
    -    public List<TripReference> getChildren(ReferentialLocale referentialLocale, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById) {
    
    285
    +    public List<TripReference> getChildren(ReferentialLocale referentialLocale, String programId, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById) {
    
    273 286
     
    
    274 287
             String dbTableName = getTopiaEntityEnum().dbTableName();
    
    275 288
             Map<String, Integer> observationActivityCount = new TreeMap<>();
    
    ... ... @@ -281,12 +294,16 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    281 294
             Map<String, Integer> landingCount = new TreeMap<>();
    
    282 295
             fillCount(getCountSql(ObserveEntityEnum.ll_landing_Landing, dbTableName), landingCount);
    
    283 296
     
    
    284
    -        String sql = String.format(GET_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName);
    
    285
    -
    
    297
    +        String sql;
    
    298
    +        if (programId == null) {
    
    299
    +            sql = String.format(GET_ALL_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName);
    
    300
    +        } else {
    
    301
    +            sql = String.format(GET_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName, programId);
    
    302
    +        }
    
    286 303
             TopiaSqlQuery<TripReference> query = TopiaSqlQuery.wrap(sql, resultSet -> {
    
    287 304
                 TripDto dto = new TripDto();
    
    288
    -            String programId = resultSet.getString(1);
    
    289
    -            dto.setProgram(programById.get(programId));
    
    305
    +            String thisProgramId = resultSet.getString(1);
    
    306
    +            dto.setProgram(programById.get(thisProgramId));
    
    290 307
                 String id = resultSet.getString(2);
    
    291 308
                 dto.setId(id);
    
    292 309
                 dto.setStartDate(resultSet.getDate(3));
    

  • models/persistence/src/main/java/fr/ird/observe/entities/data/ps/common/TripTopiaDao.java
    ... ... @@ -59,7 +59,7 @@ import java.util.stream.Collectors;
    59 59
      */
    
    60 60
     public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwareTopiaDao<TripDto, TripReference, Trip> {
    
    61 61
     
    
    62
    -    public static final String GET_TRIP_REFERENCES = "SELECT" +
    
    62
    +    public static final String GET_ALL_TRIP_REFERENCES = "SELECT" +
    
    63 63
                 " t.program," +
    
    64 64
                 " t.topiaId," +
    
    65 65
                 " t.startDate," +
    
    ... ... @@ -68,6 +68,16 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    68 68
                 " t.vessel" +
    
    69 69
                 " FROM %s.%s t;";
    
    70 70
     
    
    71
    +    public static final String GET_TRIP_REFERENCES = "SELECT" +
    
    72
    +            " t.program," +
    
    73
    +            " t.topiaId," +
    
    74
    +            " t.startDate," +
    
    75
    +            " t.endDate," +
    
    76
    +            " t.observer," +
    
    77
    +            " t.vessel" +
    
    78
    +            " FROM %s.%s t" +
    
    79
    +            " WHERE t.program = '%s';";
    
    80
    +
    
    71 81
         private static class TripMapActivityObservationPointQuery extends TopiaSqlQuery<TripMapPoint> {
    
    72 82
     
    
    73 83
             private static final String SQL = "SELECT" +
    
    ... ... @@ -169,14 +179,20 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    169 179
         }
    
    170 180
     
    
    171 181
         @Override
    
    172
    -    public List<TripReference> getChildren(ReferentialLocale referentialLocale, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById) {
    
    182
    +    public List<TripReference> getChildren(ReferentialLocale referentialLocale, String programId, ImmutableMap<String, ProgramReference> programById, ImmutableMap<String, PersonReference> personById, ImmutableMap<String, VesselReference> vesselById) {
    
    173 183
             String dbTableName = getTopiaEntityEnum().dbTableName();
    
    174
    -        String sql = String.format(GET_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName);
    
    184
    +
    
    185
    +        String sql;
    
    186
    +        if (programId == null) {
    
    187
    +            sql = String.format(GET_ALL_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName);
    
    188
    +        } else {
    
    189
    +            sql = String.format(GET_TRIP_REFERENCES, getTopiaEntityEnum().dbSchemaName(), dbTableName, programId);
    
    190
    +        }
    
    175 191
             Map<String, Integer> observationRouteCount = new TreeMap<>();
    
    176 192
             fillCount(getCountSql(ObserveEntityEnum.ps_observation_Route, dbTableName), observationRouteCount);
    
    177 193
     
    
    178 194
             TopiaSqlQuery<TripReference> query = TopiaSqlQuery.wrap(sql, resultSet -> {
    
    179
    -            String programId = resultSet.getString(1);
    
    195
    +            String thisProgramId = resultSet.getString(1);
    
    180 196
                 String id = resultSet.getString(2);
    
    181 197
     
    
    182 198
                 Integer routeCount = observationRouteCount.getOrDefault(id, 0);
    
    ... ... @@ -186,7 +202,7 @@ public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements TripAwar
    186 202
                         return routeCount;
    
    187 203
                     }
    
    188 204
                 };
    
    189
    -            dto.setProgram(programById.get(programId));
    
    205
    +            dto.setProgram(programById.get(thisProgramId));
    
    190 206
                 dto.setId(id);
    
    191 207
                 dto.setStartDate(resultSet.getDate(3));
    
    192 208
                 dto.setEndDate(resultSet.getDate(4));
    

  • models/persistence/src/main/models/Observe-20-data-ps-observation.model
    ... ... @@ -189,7 +189,7 @@ data.ps.observation.TargetLength > data.DataEntity >> data.ps.observation.Length
    189 189
     length + {*:1} Float | sqlType=numeric digits=1
    
    190 190
     isLengthComputed + {*:1} boolean
    
    191 191
     count + {*:1} Integer
    
    192
    -weight + {*:1} Float | sqlType=numeric digits=1
    
    192
    +weight + {*:1} Float | sqlType=numeric digits=3
    
    193 193
     isWeightComputed + {*:1} boolean
    
    194 194
     acquisitionMode + {*:1} int
    
    195 195
     tagNumber + {*:1} String
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/NavigationServiceLocalSupport.java
    ... ... @@ -113,12 +113,12 @@ class NavigationServiceLocalSupport extends ObserveServiceLocal implements Navig
    113 113
             ArrayListMultimap<String, fr.ird.observe.dto.data.ll.common.TripReference> tripLlByProgram = ArrayListMultimap.create();
    
    114 114
             if (canReadData) {
    
    115 115
                 if (loadPs) {
    
    116
    -                List<fr.ird.observe.dto.data.ps.common.TripReference> trips = fr.ird.observe.entities.data.ps.common.Trip.SPI.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, programById, personById, vesselById);
    
    116
    +                List<fr.ird.observe.dto.data.ps.common.TripReference> trips = fr.ird.observe.entities.data.ps.common.Trip.SPI.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, null, programById, personById, vesselById);
    
    117 117
                     trips.forEach(t -> tripPsByProgram.put(t.getProgram().getId(), t));
    
    118 118
     
    
    119 119
                 }
    
    120 120
                 if (loadLl) {
    
    121
    -                List<fr.ird.observe.dto.data.ll.common.TripReference> tripLl = fr.ird.observe.entities.data.ll.common.Trip.SPI.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, programById, personById, vesselById);
    
    121
    +                List<fr.ird.observe.dto.data.ll.common.TripReference> tripLl = fr.ird.observe.entities.data.ll.common.Trip.SPI.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, null, programById, personById, vesselById);
    
    122 122
                     tripLl.forEach(t -> tripLlByProgram.put(t.getProgram().getId(), t));
    
    123 123
                 }
    
    124 124
             }
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripServiceLocalSupport.java
    ... ... @@ -182,8 +182,7 @@ public abstract class TripServiceLocalSupport<D extends OpenableDto & fr.ird.obs
    182 182
     
    
    183 183
             ImmutableSet<VesselReference> vessels = Vessel.toReferenceSet(referentialLocale, getTopiaPersistenceContext(), null).toSet();
    
    184 184
             ImmutableMap<String, VesselReference> vesselById = Maps.uniqueIndex(vessels, VesselReference::getId);
    
    185
    -
    
    186
    -        List<R> references = spi.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, programById, personById, vesselById);
    
    185
    +        List<R> references = spi.getDao(getTopiaPersistenceContext()).getChildren(referentialLocale, parentId, programById, personById, vesselById);
    
    187 186
             return DataDtoReferenceSet.of(spi.toReferenceType(), references, now());
    
    188 187
         }
    
    189 188
     
    

  • toolkit/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/ExecuteRunnerMojo.java
    ... ... @@ -33,6 +33,7 @@ import java.io.File;
    33 33
     import java.net.URLClassLoader;
    
    34 34
     import java.nio.file.Path;
    
    35 35
     import java.util.List;
    
    36
    +import java.util.Map;
    
    36 37
     
    
    37 38
     /**
    
    38 39
      * To execute the given
    
    ... ... @@ -76,11 +77,15 @@ public class ExecuteRunnerMojo extends ToolboxMojoSupport {
    76 77
         @Parameter(defaultValue = "${project.build.directory}/generated-sources/java", required = true)
    
    77 78
         private File targetRoot;
    
    78 79
     
    
    80
    +    @Parameter
    
    81
    +    private Map<String, String> extraProperties;
    
    82
    +
    
    79 83
         public static abstract class MojoRunnable implements Runnable {
    
    80 84
     
    
    81 85
             protected I18nKeySet getterFile;
    
    82 86
             protected Log log;
    
    83 87
             private boolean force;
    
    88
    +        private Map<String, String> extraProperties;
    
    84 89
     
    
    85 90
             public I18nKeySet getGetterFile() {
    
    86 91
                 return getterFile;
    
    ... ... @@ -105,6 +110,14 @@ public class ExecuteRunnerMojo extends ToolboxMojoSupport {
    105 110
             public void setForce(boolean force) {
    
    106 111
                 this.force = force;
    
    107 112
             }
    
    113
    +
    
    114
    +        public Map<String, String> getExtraProperties() {
    
    115
    +            return extraProperties;
    
    116
    +        }
    
    117
    +
    
    118
    +        public void setExtraProperties(Map<String, String> extraProperties) {
    
    119
    +            this.extraProperties = extraProperties;
    
    120
    +        }
    
    108 121
         }
    
    109 122
     
    
    110 123
         @Override
    
    ... ... @@ -136,6 +149,7 @@ public class ExecuteRunnerMojo extends ToolboxMojoSupport {
    136 149
                     MojoRunnable o = (MojoRunnable) urlClassLoader.loadClass(runnerType).getConstructor().newInstance();
    
    137 150
     
    
    138 151
                     o.setGetterFile(getterFile);
    
    152
    +                o.setExtraProperties(extraProperties);
    
    139 153
                     o.setLog(getLog());
    
    140 154
                     o.run();
    
    141 155
                 }
    

  • toolkit/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/persistence/ExtractSchema.java
    1
    +package fr.ird.observe.maven.plugins.toolbox.persistence;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2021 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 fr.ird.observe.maven.plugins.toolbox.ExecuteRunnerMojo;
    
    26
    +import org.nuiton.topia.persistence.script.TopiaSqlScript;
    
    27
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    28
    +import org.nuiton.version.Version;
    
    29
    +
    
    30
    +import java.io.File;
    
    31
    +import java.io.IOException;
    
    32
    +import java.nio.file.Files;
    
    33
    +import java.nio.file.Path;
    
    34
    +import java.nio.file.StandardCopyOption;
    
    35
    +import java.util.LinkedList;
    
    36
    +import java.util.List;
    
    37
    +
    
    38
    +/**
    
    39
    + * To extract a single schema DDL into a specific sql file.
    
    40
    + * <p>
    
    41
    + * Created on 20/01/2021.
    
    42
    + *
    
    43
    + * @author Tony Chemit - dev@tchemit.fr
    
    44
    + * @since 8.0.5
    
    45
    + */
    
    46
    +public class ExtractSchema extends ExecuteRunnerMojo.MojoRunnable {
    
    47
    +
    
    48
    +    @Override
    
    49
    +    public void run() {
    
    50
    +
    
    51
    +        Path targetDirectory = new File(System.getProperty("compile.target.directory")).toPath();
    
    52
    +        Path sourceDirectory = new File(System.getProperty("compile.source.directory")).toPath();
    
    53
    +
    
    54
    +        String schemaName = getExtraProperties().get("schemaName");
    
    55
    +
    
    56
    +        Version modelVersion = MigrationVersionResourceProvider.get().getLastVersion();
    
    57
    +
    
    58
    +        Path dbRootPath = sourceDirectory.getParent().resolve("resources").resolve("db").resolve("migration").resolve(modelVersion.getVersion());
    
    59
    +        Path targetDbRootPath = targetDirectory.resolve("db").resolve("migration").resolve(modelVersion.getVersion());
    
    60
    +        try {
    
    61
    +            processScript(true, dbRootPath.resolve("observe_full-schema-H2.sql"), targetDbRootPath, schemaName);
    
    62
    +            processScript(false, dbRootPath.resolve("observe_full-schema-PG.sql"), targetDbRootPath, schemaName);
    
    63
    +        } catch (Exception e) {
    
    64
    +            throw new IllegalStateException(e);
    
    65
    +        }
    
    66
    +    }
    
    67
    +
    
    68
    +    protected void processScript(boolean h2, Path incomingFullSchema, Path targetDbRootPath, String schemaName) throws IOException {
    
    69
    +        Path pathFullSchema = incomingFullSchema.getParent().resolve(incomingFullSchema.toFile().getName().replace("-schema-", "-schema-" + schemaName+"-"));
    
    70
    +        log.info(String.format("Generating schema %s schema [%s] (from %s).", schemaName, pathFullSchema.toFile().getName(), incomingFullSchema));
    
    71
    +        TopiaSqlScript script = TopiaSqlScript.of(incomingFullSchema);
    
    72
    +        Path pathCreateSchema = pathFullSchema.getParent().resolve(pathFullSchema.toFile().getName().replace("full", "create"));
    
    73
    +        Path pathFinalizeSchema = pathFullSchema.getParent().resolve(pathFullSchema.toFile().getName().replace("full", "finalize"));
    
    74
    +        List<String> createSchemaStatements = new LinkedList<>();
    
    75
    +        List<String> finalizeSchemaStatements = new LinkedList<>();
    
    76
    +        script.getLocation().forEach(statement -> {
    
    77
    +            String trim = statement.toLowerCase().trim();
    
    78
    +            if (trim.startsWith("create schema " + schemaName) || trim.startsWith("create table " + schemaName)) {
    
    79
    +                if (!h2) {
    
    80
    +                    statement = statement.replace("data blob", "data OID");
    
    81
    +                }
    
    82
    +                createSchemaStatements.add(statement);
    
    83
    +            } else {
    
    84
    +                if (trim.startsWith("alter table " + schemaName) || trim.startsWith("create index idx_" + schemaName)) {
    
    85
    +                    finalizeSchemaStatements.add(statement);
    
    86
    +                }
    
    87
    +            }
    
    88
    +        });
    
    89
    +
    
    90
    +        int createStatementCount = createSchemaStatements.size();
    
    91
    +        int finalizeStatementCount = finalizeSchemaStatements.size();
    
    92
    +
    
    93
    +        log.info(String.format("Generated create schema (%d statements) at %s.", createStatementCount, pathCreateSchema));
    
    94
    +        Files.write(pathCreateSchema, createSchemaStatements);
    
    95
    +        copyToTarget(pathCreateSchema, targetDbRootPath);
    
    96
    +
    
    97
    +        log.info(String.format("Generated finalize schema (%d statements) at %s.", finalizeStatementCount, pathFinalizeSchema));
    
    98
    +        Files.write(pathFinalizeSchema, finalizeSchemaStatements);
    
    99
    +        copyToTarget(pathFinalizeSchema, targetDbRootPath);
    
    100
    +    }
    
    101
    +
    
    102
    +    private void copyToTarget(Path source, Path targetDbRootPath) throws IOException {
    
    103
    +        Path target = targetDbRootPath.resolve(source.toFile().getName());
    
    104
    +        Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
    
    105
    +        getLog().debug(String.format("Copy from %s → %s", source.toFile().getName(), target));
    
    106
    +    }
    
    107
    +
    
    108
    +}

  • toolkit/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/persistence/ExtractTable.java
    1
    +package fr.ird.observe.maven.plugins.toolbox.persistence;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Maven plugin
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2021 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 fr.ird.observe.entities.ObserveTopiaApplicationContextSupport;
    
    26
    +import fr.ird.observe.entities.ObserveTopiaConfiguration;
    
    27
    +import fr.ird.observe.entities.ObserveTopiaConfigurationFactory;
    
    28
    +import fr.ird.observe.maven.plugins.toolbox.ExecuteRunnerMojo;
    
    29
    +import fr.ird.observe.services.configuration.topia.ObserveDataSourceConfigurationTopiaH2;
    
    30
    +import org.nuiton.topia.persistence.script.TopiaSqlScript;
    
    31
    +import org.nuiton.topia.service.migration.resources.MigrationVersionResourceProvider;
    
    32
    +import org.nuiton.version.Version;
    
    33
    +
    
    34
    +import java.io.File;
    
    35
    +import java.io.IOException;
    
    36
    +import java.lang.reflect.InvocationTargetException;
    
    37
    +import java.nio.file.Files;
    
    38
    +import java.nio.file.Path;
    
    39
    +import java.nio.file.StandardCopyOption;
    
    40
    +import java.util.LinkedList;
    
    41
    +import java.util.List;
    
    42
    +import java.util.function.BiFunction;
    
    43
    +
    
    44
    +/**
    
    45
    + * to extract a single table DDL into a specific sql file.
    
    46
    + * Created on 20/01/2021.
    
    47
    + *
    
    48
    + * @author Tony Chemit - dev@tchemit.fr
    
    49
    + * @since 8.0.5
    
    50
    + */
    
    51
    +public class ExtractTable extends ExecuteRunnerMojo.MojoRunnable {
    
    52
    +
    
    53
    +    @Override
    
    54
    +    public void run() {
    
    55
    +
    
    56
    +        Path targetDirectory = new File(System.getProperty("compile.target.directory")).toPath();
    
    57
    +        Path sourceDirectory = new File(System.getProperty("compile.source.directory")).toPath();
    
    58
    +
    
    59
    +        String schemaName = getExtraProperties().get("schemaName");
    
    60
    +        String tableName = getExtraProperties().get("tableName");
    
    61
    +
    
    62
    +        Version modelVersion = MigrationVersionResourceProvider.get().getLastVersion();
    
    63
    +
    
    64
    +        Path dbRootPath = sourceDirectory.getParent().resolve("resources").resolve("db").resolve("migration").resolve(modelVersion.getVersion());
    
    65
    +        Path targetDbRootPath = targetDirectory.resolve("db").resolve("migration").resolve(modelVersion.getVersion());
    
    66
    +        try {
    
    67
    +            processScript(true, dbRootPath.resolve("observe_full-schema-H2.sql"), targetDbRootPath, schemaName, tableName);
    
    68
    +            processScript(false, dbRootPath.resolve("observe_full-schema-PG.sql"), targetDbRootPath, schemaName, tableName);
    
    69
    +        } catch (Exception e) {
    
    70
    +            throw new IllegalStateException(e);
    
    71
    +        }
    
    72
    +    }
    
    73
    +
    
    74
    +    protected void processScript(boolean h2, Path incomingFullSchema, Path targetDbRootPath, String schemaName, String tableName) throws IOException {
    
    75
    +        String suffix = schemaName + "." + tableName;
    
    76
    +        Path pathFullSchema = incomingFullSchema.getParent().resolve(incomingFullSchema.toFile().getName().replace("-schema-", "-table-" + suffix+"-"));
    
    77
    +        log.info(String.format("Generating table %s.%s schema [%s] (from %s).", schemaName, tableName, pathFullSchema.toFile().getName(), incomingFullSchema));
    
    78
    +        TopiaSqlScript script = TopiaSqlScript.of(incomingFullSchema);
    
    79
    +        Path pathCreateSchema = pathFullSchema.getParent().resolve(pathFullSchema.toFile().getName().replace("full", "create"));
    
    80
    +        Path pathFinalizeSchema = pathFullSchema.getParent().resolve(pathFullSchema.toFile().getName().replace("full", "finalize"));
    
    81
    +        List<String> createSchemaStatements = new LinkedList<>();
    
    82
    +        List<String> finalizeSchemaStatements = new LinkedList<>();
    
    83
    +
    
    84
    +        String suffix2 = schemaName + "_" + tableName;
    
    85
    +        script.getLocation().forEach(statement -> {
    
    86
    +            String trim = statement.toLowerCase().trim();
    
    87
    +            if (trim.startsWith("create table " + suffix)) {
    
    88
    +                if (!h2) {
    
    89
    +                    statement = statement.replace("data blob", "data OID");
    
    90
    +                }
    
    91
    +                createSchemaStatements.add(statement);
    
    92
    +            } else {
    
    93
    +                if (trim.startsWith("alter table " + suffix) || trim.startsWith("create index idx_" + suffix2)) {
    
    94
    +                    finalizeSchemaStatements.add(statement);
    
    95
    +                }
    
    96
    +            }
    
    97
    +        });
    
    98
    +
    
    99
    +        int createStatementCount = createSchemaStatements.size();
    
    100
    +        int finalizeStatementCount = finalizeSchemaStatements.size();
    
    101
    +
    
    102
    +        log.info(String.format("Generated create table (%d statements) at %s.", createStatementCount, pathCreateSchema));
    
    103
    +        Files.write(pathCreateSchema, createSchemaStatements);
    
    104
    +        copyToTarget(pathCreateSchema, targetDbRootPath);
    
    105
    +
    
    106
    +        log.info(String.format("Generated finalize table (%d statements) at %s.", finalizeStatementCount, pathFinalizeSchema));
    
    107
    +        Files.write(pathFinalizeSchema, finalizeSchemaStatements);
    
    108
    +        copyToTarget(pathFinalizeSchema, targetDbRootPath);
    
    109
    +    }
    
    110
    +
    
    111
    +    private void copyToTarget(Path source, Path targetDbRootPath) throws IOException {
    
    112
    +        Path target = targetDbRootPath.resolve(source.toFile().getName());
    
    113
    +        Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING);
    
    114
    +        getLog().debug(String.format("Copy from %s → %s", source.toFile().getName(), target));
    
    115
    +    }
    
    116
    +}

  • toolkit/maven-plugin/src/main/java/fr/ird/observe/maven/plugins/toolbox/persistence/GenerateEmptyDatabases.java
    ... ... @@ -115,11 +115,11 @@ public class GenerateEmptyDatabases extends ExecuteRunnerMojo.MojoRunnable {
    115 115
             log.info(String.format("Generated full schema (%d statements) at %s.", fullStatementCount, pathFullSchema));
    
    116 116
             copyToTarget(pathFullSchema, targetDbRootPath);
    
    117 117
     
    
    118
    -        log.info(String.format("Generated create schema (%d statements) at %s.", createStatementCount, pathFullSchema));
    
    118
    +        log.info(String.format("Generated create schema (%d statements) at %s.", createStatementCount, pathCreateSchema));
    
    119 119
             Files.write(pathCreateSchema, createSchemaStatements);
    
    120 120
             copyToTarget(pathCreateSchema, targetDbRootPath);
    
    121 121
     
    
    122
    -        log.info(String.format("Generated finalize schema (%d statements) at %s.", finalizeStatementCount, pathFullSchema));
    
    122
    +        log.info(String.format("Generated finalize schema (%d statements) at %s.", finalizeStatementCount, pathFinalizeSchema));
    
    123 123
             Files.write(pathFinalizeSchema, finalizeSchemaStatements);
    
    124 124
             copyToTarget(pathFinalizeSchema, targetDbRootPath);
    
    125 125
         }