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

Commits:

18 changed files:

Changes:

  • client/datasource/editor/api/src/main/java/fr/ird/observe/client/datasource/editor/api/content/data/list/ContentListUINavigationInitializer.java
    ... ... @@ -70,7 +70,6 @@ public class ContentListUINavigationInitializer extends NavigationInitializer<Co
    70 70
         protected void reload(NavigationContext<ContentListUINavigationContext> context) {
    
    71 71
             //FIXME Make sure we need to reload data
    
    72 72
             parentReference = context.reloadReference(parentReference);
    
    73
    -        //FIXME Make this more performant: only reload references that has changed
    
    74 73
             references.reload();
    
    75 74
         }
    
    76 75
     
    

  • models/persistence/src/main/java/fr/ird/observe/entities/data/TripAwareTopiaDao.java
    ... ... @@ -23,11 +23,15 @@ package fr.ird.observe.entities.data;
    23 23
      */
    
    24 24
     
    
    25 25
     import com.google.common.collect.ArrayListMultimap;
    
    26
    +import com.google.common.collect.ImmutableSet;
    
    26 27
     import fr.ird.observe.dto.data.DataDto;
    
    27 28
     import fr.ird.observe.dto.data.TripMapConfigDto;
    
    28 29
     import fr.ird.observe.dto.data.TripMapPoint;
    
    29 30
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    31
    +import fr.ird.observe.entities.referential.common.Program;
    
    32
    +import org.nuiton.topia.persistence.TopiaDao;
    
    30 33
     import org.nuiton.topia.persistence.TopiaEntityEnum;
    
    34
    +import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
    
    31 35
     import org.nuiton.topia.persistence.support.SqlFunction;
    
    32 36
     import org.nuiton.topia.persistence.support.TopiaSqlSupport;
    
    33 37
     
    
    ... ... @@ -35,6 +39,7 @@ import java.sql.ResultSet;
    35 39
     import java.util.Date;
    
    36 40
     import java.util.LinkedHashSet;
    
    37 41
     import java.util.List;
    
    42
    +import java.util.Map;
    
    38 43
     
    
    39 44
     /**
    
    40 45
      * Created on 14/10/2020.
    
    ... ... @@ -42,12 +47,16 @@ import java.util.List;
    42 47
      * @author Tony Chemit - dev@tchemit.fr
    
    43 48
      * @since 8.0.1
    
    44 49
      */
    
    45
    -public interface TripAwareTopiaDao<D extends DataDto & fr.ird.observe.dto.data.TripAware, R extends DataDtoReference & fr.ird.observe.dto.data.TripAware, E extends DataEntity<D, R> & TripAware<D, R>> {
    
    50
    +public interface TripAwareTopiaDao<D extends DataDto & fr.ird.observe.dto.data.TripAware, R extends DataDtoReference & fr.ird.observe.dto.data.TripAware, E extends DataEntity<D, R> & TripAware<D, R>> extends TopiaDao<E> {
    
    46 51
     
    
    47 52
         String GET_TRIP_IDS_BY_PROGRAM_ID = "SELECT program, topiaId FROM %S.%s t ORDER BY program";
    
    48 53
     
    
    49 54
         LinkedHashSet<TripMapPoint> extractTripMapActivityPoints(TripMapConfigDto tripMapConfig);
    
    50 55
     
    
    56
    +    TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forLastUpdateDateGreaterThan(Date lastUpdateDate);
    
    57
    +
    
    58
    +    <O> List<O> findAll(String hql, Map<String, Object> hqlParameters);
    
    59
    +
    
    51 60
         List<E> getMatchingTripsVesselWithinDateRange(String id, String vesselId, Date startDate, Date endDate);
    
    52 61
     
    
    53 62
         void fillTripIdByProgramId(ArrayListMultimap<String, String> map);
    
    ... ... @@ -59,4 +68,15 @@ public interface TripAwareTopiaDao<D extends DataDto & fr.ird.observe.dto.data.T
    59 68
                 return null;
    
    60 69
             });
    
    61 70
         }
    
    71
    +
    
    72
    +    default List<E> getChildren(Program parent, Date lastUpdate) {
    
    73
    +        if (lastUpdate == null) {
    
    74
    +            return forProperties(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    75
    +        }
    
    76
    +        return forLastUpdateDateGreaterThan(lastUpdate).addEquals(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    77
    +    }
    
    78
    +
    
    79
    +    default ImmutableSet<String> getChildrenIds(Program parent) {
    
    80
    +        return ImmutableSet.copyOf(forProperties(TripAware.PROPERTY_PROGRAM, parent).findAllIds());
    
    81
    +    }
    
    62 82
     }

  • models/persistence/src/main/java/fr/ird/observe/entities/data/ps/observation/ActivityImpl.java
    ... ... @@ -32,6 +32,7 @@ import fr.ird.observe.dto.referential.common.SpeciesReference;
    32 32
     import fr.ird.observe.dto.referential.ps.common.VesselActivityReference;
    
    33 33
     import fr.ird.observe.entities.referential.ps.observation.ObservedSystem;
    
    34 34
     
    
    35
    +import java.util.Date;
    
    35 36
     import java.util.stream.Collectors;
    
    36 37
     
    
    37 38
     /**
    
    ... ... @@ -105,7 +106,7 @@ public class ActivityImpl extends ActivityAbstract {
    105 106
         public ActivityReference toReference(ReferentialLocale referentialLocale) {
    
    106 107
             ActivityReference reference = super.toReference(referentialLocale);
    
    107 108
             if (isFloatingObjectNotEmpty()) {
    
    108
    -            reference.setFloatingObject(FloatingObject.SPI.toReferenceSet(referentialLocale, getFloatingObject()).toList());
    
    109
    +            reference.setFloatingObject(FloatingObject.SPI.toReferenceSet(referentialLocale, getFloatingObject(), new Date()).toList());
    
    109 110
             }
    
    110 111
             return reference;
    
    111 112
         }
    

  • server/core/src/main/filtered-resources/mapping
    ... ... @@ -102,6 +102,7 @@ GET /api/v1/data/ll/common/TripService/exists
    102 102
     GET    /api/v1/data/ll/common/TripService/getAllTrip                                                                                 v1.data.ll.common.TripServiceRestApi.getAllTrip
    
    103 103
     GET    /api/v1/data/ll/common/TripService/getBrothers                                                                                v1.data.ll.common.TripServiceRestApi.getBrothers
    
    104 104
     GET    /api/v1/data/ll/common/TripService/getChildren                                                                                v1.data.ll.common.TripServiceRestApi.getChildren
    
    105
    +GET    /api/v1/data/ll/common/TripService/getChildrenUpdate                                                                          v1.data.ll.common.TripServiceRestApi.getChildrenUpdate
    
    105 106
     GET    /api/v1/data/ll/common/TripService/getMatchingTripsVesselWithinDateRange                                                      v1.data.ll.common.TripServiceRestApi.getMatchingTripsVesselWithinDateRange
    
    106 107
     GET    /api/v1/data/ll/common/TripService/getParentBrothers                                                                          v1.data.ll.common.TripServiceRestApi.getParentBrothers
    
    107 108
     GET    /api/v1/data/ll/common/TripService/getSpeciesByListAndTrip                                                                    v1.data.ll.common.TripServiceRestApi.getSpeciesByListAndTrip
    
    ... ... @@ -116,6 +117,7 @@ DELETE /api/v1/data/ll/landing/LandingService/delete
    116 117
     GET    /api/v1/data/ll/landing/LandingService/exists                                                                                 v1.data.ll.landing.LandingServiceRestApi.exists
    
    117 118
     GET    /api/v1/data/ll/landing/LandingService/getBrothers                                                                            v1.data.ll.landing.LandingServiceRestApi.getBrothers
    
    118 119
     GET    /api/v1/data/ll/landing/LandingService/getChildren                                                                            v1.data.ll.landing.LandingServiceRestApi.getChildren
    
    120
    +GET    /api/v1/data/ll/landing/LandingService/getChildrenUpdate                                                                      v1.data.ll.landing.LandingServiceRestApi.getChildrenUpdate
    
    119 121
     GET    /api/v1/data/ll/landing/LandingService/loadDto                                                                                v1.data.ll.landing.LandingServiceRestApi.loadDto
    
    120 122
     GET    /api/v1/data/ll/landing/LandingService/loadForm                                                                               v1.data.ll.landing.LandingServiceRestApi.loadForm
    
    121 123
     GET    /api/v1/data/ll/landing/LandingService/loadReferenceToRead                                                                    v1.data.ll.landing.LandingServiceRestApi.loadReferenceToRead
    
    ... ... @@ -135,6 +137,7 @@ DELETE /api/v1/data/ll/logbook/ActivityService/delete
    135 137
     GET    /api/v1/data/ll/logbook/ActivityService/exists                                                                                v1.data.ll.logbook.ActivityServiceRestApi.exists
    
    136 138
     GET    /api/v1/data/ll/logbook/ActivityService/getBrothers                                                                           v1.data.ll.logbook.ActivityServiceRestApi.getBrothers
    
    137 139
     GET    /api/v1/data/ll/logbook/ActivityService/getChildren                                                                           v1.data.ll.logbook.ActivityServiceRestApi.getChildren
    
    140
    +GET    /api/v1/data/ll/logbook/ActivityService/getChildrenUpdate                                                                     v1.data.ll.logbook.ActivityServiceRestApi.getChildrenUpdate
    
    138 141
     GET    /api/v1/data/ll/logbook/ActivityService/loadDto                                                                               v1.data.ll.logbook.ActivityServiceRestApi.loadDto
    
    139 142
     GET    /api/v1/data/ll/logbook/ActivityService/loadForm                                                                              v1.data.ll.logbook.ActivityServiceRestApi.loadForm
    
    140 143
     GET    /api/v1/data/ll/logbook/ActivityService/loadReferenceToRead                                                                   v1.data.ll.logbook.ActivityServiceRestApi.loadReferenceToRead
    
    ... ... @@ -145,6 +148,7 @@ DELETE /api/v1/data/ll/logbook/SampleService/delete
    145 148
     GET    /api/v1/data/ll/logbook/SampleService/exists                                                                                  v1.data.ll.logbook.SampleServiceRestApi.exists
    
    146 149
     GET    /api/v1/data/ll/logbook/SampleService/getBrothers                                                                             v1.data.ll.logbook.SampleServiceRestApi.getBrothers
    
    147 150
     GET    /api/v1/data/ll/logbook/SampleService/getChildren                                                                             v1.data.ll.logbook.SampleServiceRestApi.getChildren
    
    151
    +GET    /api/v1/data/ll/logbook/SampleService/getChildrenUpdate                                                                       v1.data.ll.logbook.SampleServiceRestApi.getChildrenUpdate
    
    148 152
     GET    /api/v1/data/ll/logbook/SampleService/loadDto                                                                                 v1.data.ll.logbook.SampleServiceRestApi.loadDto
    
    149 153
     GET    /api/v1/data/ll/logbook/SampleService/loadForm                                                                                v1.data.ll.logbook.SampleServiceRestApi.loadForm
    
    150 154
     GET    /api/v1/data/ll/logbook/SampleService/loadReferenceToRead                                                                     v1.data.ll.logbook.SampleServiceRestApi.loadReferenceToRead
    
    ... ... @@ -171,6 +175,7 @@ DELETE /api/v1/data/ll/observation/ActivityService/delete
    171 175
     GET    /api/v1/data/ll/observation/ActivityService/exists                                                                            v1.data.ll.observation.ActivityServiceRestApi.exists
    
    172 176
     GET    /api/v1/data/ll/observation/ActivityService/getBrothers                                                                       v1.data.ll.observation.ActivityServiceRestApi.getBrothers
    
    173 177
     GET    /api/v1/data/ll/observation/ActivityService/getChildren                                                                       v1.data.ll.observation.ActivityServiceRestApi.getChildren
    
    178
    +GET    /api/v1/data/ll/observation/ActivityService/getChildrenUpdate                                                                 v1.data.ll.observation.ActivityServiceRestApi.getChildrenUpdate
    
    174 179
     GET    /api/v1/data/ll/observation/ActivityService/loadDto                                                                           v1.data.ll.observation.ActivityServiceRestApi.loadDto
    
    175 180
     GET    /api/v1/data/ll/observation/ActivityService/loadForm                                                                          v1.data.ll.observation.ActivityServiceRestApi.loadForm
    
    176 181
     GET    /api/v1/data/ll/observation/ActivityService/loadReferenceToRead                                                               v1.data.ll.observation.ActivityServiceRestApi.loadReferenceToRead
    
    ... ... @@ -204,6 +209,7 @@ GET /api/v1/data/ps/common/TripService/exists
    204 209
     GET    /api/v1/data/ps/common/TripService/getAllTrip                                                                                 v1.data.ps.common.TripServiceRestApi.getAllTrip
    
    205 210
     GET    /api/v1/data/ps/common/TripService/getBrothers                                                                                v1.data.ps.common.TripServiceRestApi.getBrothers
    
    206 211
     GET    /api/v1/data/ps/common/TripService/getChildren                                                                                v1.data.ps.common.TripServiceRestApi.getChildren
    
    212
    +GET    /api/v1/data/ps/common/TripService/getChildrenUpdate                                                                          v1.data.ps.common.TripServiceRestApi.getChildrenUpdate
    
    207 213
     GET    /api/v1/data/ps/common/TripService/getMatchingTripsVesselWithinDateRange                                                      v1.data.ps.common.TripServiceRestApi.getMatchingTripsVesselWithinDateRange
    
    208 214
     GET    /api/v1/data/ps/common/TripService/getParentBrothers                                                                          v1.data.ps.common.TripServiceRestApi.getParentBrothers
    
    209 215
     GET    /api/v1/data/ps/common/TripService/getSpeciesByListAndTrip                                                                    v1.data.ps.common.TripServiceRestApi.getSpeciesByListAndTrip
    
    ... ... @@ -218,6 +224,7 @@ DELETE /api/v1/data/ps/observation/ActivityService/delete
    218 224
     GET    /api/v1/data/ps/observation/ActivityService/exists                                                                            v1.data.ps.observation.ActivityServiceRestApi.exists
    
    219 225
     GET    /api/v1/data/ps/observation/ActivityService/getBrothers                                                                       v1.data.ps.observation.ActivityServiceRestApi.getBrothers
    
    220 226
     GET    /api/v1/data/ps/observation/ActivityService/getChildren                                                                       v1.data.ps.observation.ActivityServiceRestApi.getChildren
    
    227
    +GET    /api/v1/data/ps/observation/ActivityService/getChildrenUpdate                                                                 v1.data.ps.observation.ActivityServiceRestApi.getChildrenUpdate
    
    221 228
     GET    /api/v1/data/ps/observation/ActivityService/loadDto                                                                           v1.data.ps.observation.ActivityServiceRestApi.loadDto
    
    222 229
     GET    /api/v1/data/ps/observation/ActivityService/loadForm                                                                          v1.data.ps.observation.ActivityServiceRestApi.loadForm
    
    223 230
     GET    /api/v1/data/ps/observation/ActivityService/loadReferenceToRead                                                               v1.data.ps.observation.ActivityServiceRestApi.loadReferenceToRead
    
    ... ... @@ -248,6 +255,7 @@ DELETE /api/v1/data/ps/observation/RouteService/delete
    248 255
     GET    /api/v1/data/ps/observation/RouteService/exists                                                                               v1.data.ps.observation.RouteServiceRestApi.exists
    
    249 256
     GET    /api/v1/data/ps/observation/RouteService/getBrothers                                                                          v1.data.ps.observation.RouteServiceRestApi.getBrothers
    
    250 257
     GET    /api/v1/data/ps/observation/RouteService/getChildren                                                                          v1.data.ps.observation.RouteServiceRestApi.getChildren
    
    258
    +GET    /api/v1/data/ps/observation/RouteService/getChildrenUpdate                                                                    v1.data.ps.observation.RouteServiceRestApi.getChildrenUpdate
    
    251 259
     GET    /api/v1/data/ps/observation/RouteService/isActivityEndOfSearchFound                                                           v1.data.ps.observation.RouteServiceRestApi.isActivityEndOfSearchFound
    
    252 260
     GET    /api/v1/data/ps/observation/RouteService/loadDto                                                                              v1.data.ps.observation.RouteServiceRestApi.loadDto
    
    253 261
     GET    /api/v1/data/ps/observation/RouteService/loadForm                                                                             v1.data.ps.observation.RouteServiceRestApi.loadForm
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/actions/report/ReportServiceLocalSupport.java
    ... ... @@ -34,7 +34,7 @@ import fr.ird.observe.dto.report.Report;
    34 34
     import fr.ird.observe.dto.report.ReportOperation;
    
    35 35
     import fr.ird.observe.dto.report.ReportRequest;
    
    36 36
     import fr.ird.observe.dto.report.ReportVariable;
    
    37
    -import fr.ird.observe.entities.AbstractObserveTopiaDao;
    
    37
    +import fr.ird.observe.entities.data.TripAwareTopiaDao;
    
    38 38
     import fr.ird.observe.entities.data.ll.common.GearUseFeatures;
    
    39 39
     import fr.ird.observe.entities.data.ll.common.GearUseFeaturesMeasurement;
    
    40 40
     import fr.ird.observe.entities.data.ps.common.Trip;
    
    ... ... @@ -485,9 +485,9 @@ public class ReportServiceLocalSupport extends ObserveServiceLocal implements Re
    485 485
                     paramsFixes.put(name, value);
    
    486 486
                 }
    
    487 487
             }
    
    488
    -        AbstractObserveTopiaDao<?> dao = (AbstractObserveTopiaDao<?>) getTopiaPersistenceContext().getDao(Trip.class);
    
    488
    +        TripAwareTopiaDao<?, ?, ?> dao = (TripAwareTopiaDao<?, ?, ?>) getTopiaPersistenceContext().getDao(Trip.class);
    
    489 489
             log.debug(String.format("Request: %s, params: %s", request, paramsFixes));
    
    490
    -        return dao.findAllFromHql(request, paramsFixes);
    
    490
    +        return dao.findAll(request, paramsFixes);
    
    491 491
         }
    
    492 492
     
    
    493 493
         private void doPopulateRepeatVariables(Report report, ImmutableSet<String> tripId) {
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/EditableDataServiceLocalSupport.java
    ... ... @@ -120,10 +120,6 @@ public abstract class EditableDataServiceLocalSupport<PE extends Entity, D exten
    120 120
             return spi.newEntity(now());
    
    121 121
         }
    
    122 122
     
    
    123
    -    protected DataDtoReferenceSet<R> toReferenceSet(Collection<E> entities) {
    
    124
    -        return spi.toReferenceSet(getReferentialLocale(), entities);
    
    125
    -    }
    
    126
    -
    
    127 123
         protected DataDtoReferenceSet<R> toReferenceSet(Collection<E> entities, Date now) {
    
    128 124
             return spi.toReferenceSet(getReferentialLocale(), entities, now);
    
    129 125
         }
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/OpenableDataServiceLocalSupport.java
    ... ... @@ -27,6 +27,7 @@ import fr.ird.observe.dto.data.OpenableDto;
    27 27
     import fr.ird.observe.dto.form.Form;
    
    28 28
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    29 29
     import fr.ird.observe.dto.reference.DataDtoReferenceSet;
    
    30
    +import fr.ird.observe.dto.reference.UpdatedDataDtoReferenceSet;
    
    30 31
     import fr.ird.observe.dto.result.SaveResultDto;
    
    31 32
     import fr.ird.observe.entities.Entity;
    
    32 33
     import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
    
    ... ... @@ -36,9 +37,11 @@ import fr.ird.observe.services.service.data.OpenableDataService;
    36 37
     import fr.ird.observe.spi.context.DataDtoEntityContext;
    
    37 38
     import fr.ird.observe.spi.context.DtoEntityContext;
    
    38 39
     import org.nuiton.topia.persistence.TopiaDao;
    
    40
    +import org.nuiton.topia.persistence.TopiaEntity;
    
    39 41
     
    
    40 42
     import java.util.Collection;
    
    41 43
     import java.util.Date;
    
    44
    +import java.util.stream.Collectors;
    
    42 45
     import java.util.stream.Stream;
    
    43 46
     
    
    44 47
     /**
    
    ... ... @@ -72,6 +75,14 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten
    72 75
             return getChildren(parent);
    
    73 76
         }
    
    74 77
     
    
    78
    +    @Override
    
    79
    +    public UpdatedDataDtoReferenceSet<R> getChildrenUpdate(String parentId, Date lastUpdate) {
    
    80
    +        PE parent = loadParentEntity(parentId);
    
    81
    +        ImmutableSet<String> allIds = getChildrenIds(parent);
    
    82
    +        Collection<E> children0 = getChildren0(parent, lastUpdate);
    
    83
    +        return new UpdatedDataDtoReferenceSet<R>(allIds, toReferenceSet(children0, now()));
    
    84
    +    }
    
    85
    +
    
    75 86
         @Override
    
    76 87
         public DataDtoReferenceSet<R> getBrothers(String id) {
    
    77 88
             return getBrothers(parentSpi, propertyName, spi, id);
    
    ... ... @@ -105,7 +116,7 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten
    105 116
         @Override
    
    106 117
         public void move(String newParentId, ImmutableSet<String> ids) {
    
    107 118
             PE parent = loadParentEntity(newParentId);
    
    108
    -        Collection<E> collection = parent.get(propertyName);
    
    119
    +        Collection<E> collection = getChildren0(parent, null);
    
    109 120
             for (String id : ids) {
    
    110 121
                 E entity = loadEntity(id);
    
    111 122
                 collection.add(entity);
    
    ... ... @@ -142,10 +153,6 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten
    142 153
             return spi.newEntity(now());
    
    143 154
         }
    
    144 155
     
    
    145
    -    protected DataDtoReferenceSet<R> toReferenceSet(Collection<E> entities) {
    
    146
    -        return spi.toReferenceSet(getReferentialLocale(), entities);
    
    147
    -    }
    
    148
    -
    
    149 156
         protected DataDtoReferenceSet<R> toReferenceSet(Collection<E> entities, Date now) {
    
    150 157
             return spi.toReferenceSet(getReferentialLocale(), entities, now);
    
    151 158
         }
    
    ... ... @@ -182,9 +189,22 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten
    182 189
             return spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), id);
    
    183 190
         }
    
    184 191
     
    
    185
    -    protected DataDtoReferenceSet<R> getChildren(PE parent) {
    
    186
    -        Collection<E> parents = parent.get(propertyName);
    
    187
    -        return spi.toReferenceSet(getReferentialLocale(), parents);
    
    192
    +    protected final DataDtoReferenceSet<R> getChildren(PE parent) {
    
    193
    +        Collection<E> parents = getChildren0(parent, null);
    
    194
    +        return spi.toReferenceSet(getReferentialLocale(), parents, now());
    
    195
    +    }
    
    196
    +
    
    197
    +    protected Collection<E> getChildren0(PE parent, Date lastUpdate) {
    
    198
    +        Collection<E> collection = parent.get(propertyName);
    
    199
    +        if (lastUpdate != null) {
    
    200
    +            collection = collection.stream().filter(e -> e.getLastUpdateDate().after(lastUpdate)).collect(Collectors.toList());
    
    201
    +        }
    
    202
    +        return collection;
    
    203
    +    }
    
    204
    +
    
    205
    +    protected ImmutableSet<String> getChildrenIds(PE parent) {
    
    206
    +        Collection<E> collection = getChildren0(parent, null);
    
    207
    +        return collection.stream().map(TopiaEntity::getTopiaId).collect(ImmutableSet.toImmutableSet());
    
    188 208
         }
    
    189 209
     
    
    190 210
         protected PE getParent(String id) {
    

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripServiceLocalSupport.java
    ... ... @@ -50,6 +50,7 @@ import org.nuiton.topia.persistence.script.SqlScriptConsumer;
    50 50
     import org.nuiton.topia.persistence.script.TopiaSqlScript;
    
    51 51
     import org.nuiton.util.DateUtil;
    
    52 52
     
    
    53
    +import java.util.Collection;
    
    53 54
     import java.util.Comparator;
    
    54 55
     import java.util.Date;
    
    55 56
     import java.util.LinkedHashSet;
    
    ... ... @@ -71,7 +72,7 @@ public abstract class TripServiceLocalSupport<D extends OpenableDto & fr.ird.obs
    71 72
         }
    
    72 73
     
    
    73 74
         @Override
    
    74
    -    public void setServiceContext(ObserveServiceContextLocal serviceContext) {
    
    75
    +    public final void setServiceContext(ObserveServiceContextLocal serviceContext) {
    
    75 76
             super.setServiceContext(serviceContext);
    
    76 77
             sqlScriptProducerService = serviceContext.newService(SqlScriptProducerService.class);
    
    77 78
         }
    
    ... ... @@ -86,16 +87,10 @@ public abstract class TripServiceLocalSupport<D extends OpenableDto & fr.ird.obs
    86 87
             return getProgramBrothers(parentSpi, programId);
    
    87 88
         }
    
    88 89
     
    
    89
    -    @Override
    
    90
    -    protected DataDtoReferenceSet<R> getChildren(Program parent) {
    
    91
    -        List<E> entities = getDao().forEquals(TripAware.PROPERTY_PROGRAM, parent).findAll();
    
    92
    -        return toReferenceSet(entities);
    
    93
    -    }
    
    94
    -
    
    95 90
         @Override
    
    96 91
         public ImmutableSet<R> getMatchingTripsVesselWithinDateRange(String tripId, String vesselId, Date startDate, Date endDate) {
    
    97 92
             List<E> trips = getDao().getMatchingTripsVesselWithinDateRange(tripId, vesselId, startDate, endDate);
    
    98
    -        return toReferenceSet(trips).toSet();
    
    93
    +        return toReferenceSet(trips, now()).toSet();
    
    99 94
         }
    
    100 95
     
    
    101 96
         @Override
    
    ... ... @@ -157,10 +152,20 @@ public abstract class TripServiceLocalSupport<D extends OpenableDto & fr.ird.obs
    157 152
         }
    
    158 153
     
    
    159 154
         @Override
    
    160
    -    protected SaveResultDto onSave(Program parent, E entity, D dto) {
    
    155
    +    protected final SaveResultDto onSave(Program parent, E entity, D dto) {
    
    161 156
             if (entity.isPersisted()) {
    
    162 157
                 entity.updateEndDate();
    
    163 158
             }
    
    164 159
             return saveEntity(entity);
    
    165 160
         }
    
    161
    +
    
    162
    +    @Override
    
    163
    +    protected final Collection<E> getChildren0(Program parent, Date lastUpdate) {
    
    164
    +        return getDao().getChildren(parent, lastUpdate);
    
    165
    +    }
    
    166
    +
    
    167
    +    @Override
    
    168
    +    protected final ImmutableSet<String> getChildrenIds(Program parent) {
    
    169
    +        return getDao().getChildrenIds(parent);
    
    170
    +    }
    
    166 171
     }

  • services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/FloatingObjectServiceLocalSupport.java
    ... ... @@ -89,7 +89,7 @@ class FloatingObjectServiceLocalSupport extends EditableDataServiceLocalSupport<
    89 89
         @Override
    
    90 90
         public DataDtoReferenceSet<FloatingObjectReference> getChildren(String activityId) {
    
    91 91
             Set<FloatingObject> entities = loadParentEntity(activityId).getFloatingObject();
    
    92
    -        return toReferenceSet(entities);
    
    92
    +        return toReferenceSet(entities, now());
    
    93 93
         }
    
    94 94
     
    
    95 95
         @Override
    

  • toolkit/dto/src/main/java/fr/ird/observe/dto/reference/DtoReferenceCollection.java
    ... ... @@ -102,6 +102,10 @@ public abstract class DtoReferenceCollection<R extends DtoReference> implements
    102 102
             return stream().filter(id -> idsList.contains(id.getId()));
    
    103 103
         }
    
    104 104
     
    
    105
    +    public Stream<R> subSet(Collection<String> ids) {
    
    106
    +        return stream().filter(id -> ids.contains(id.getId()));
    
    107
    +    }
    
    108
    +
    
    105 109
         public ImmutableSet<R> toSet() {
    
    106 110
             return ImmutableSet.copyOf(references);
    
    107 111
         }
    

  • toolkit/dto/src/main/java/fr/ird/observe/dto/reference/LazyDataDtoReferenceSet.java
    ... ... @@ -56,15 +56,15 @@ public abstract class LazyDataDtoReferenceSet<R extends DataDtoReference> implem
    56 56
         }
    
    57 57
     
    
    58 58
         public final DataDtoReferenceSet<R> reload() {
    
    59
    -        clear();
    
    59
    +        createDelegate();
    
    60 60
             return get();
    
    61 61
         }
    
    62 62
     
    
    63
    -    public void clear() {
    
    64
    -        delegate = null;
    
    65
    -    }
    
    66
    -
    
    67 63
         public final Class<R> getReferenceType() {
    
    68 64
             return referenceType;
    
    69 65
         }
    
    66
    +
    
    67
    +    protected DataDtoReferenceSet<R> getDelegate() {
    
    68
    +        return delegate;
    
    69
    +    }
    
    70 70
     }

  • toolkit/dto/src/main/java/fr/ird/observe/dto/reference/UpdatedDataDtoReferenceSet.java
    1
    +package fr.ird.observe.dto.reference;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe Toolkit :: Dto
    
    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 com.google.common.collect.ImmutableSet;
    
    26
    +import fr.ird.observe.dto.ObserveDto;
    
    27
    +
    
    28
    +import java.util.LinkedHashSet;
    
    29
    +import java.util.List;
    
    30
    +import java.util.Objects;
    
    31
    +import java.util.Set;
    
    32
    +import java.util.stream.Collectors;
    
    33
    +
    
    34
    +/**
    
    35
    + * Created on 14/01/2021.
    
    36
    + *
    
    37
    + * @author Tony Chemit - dev@tchemit.fr
    
    38
    + * @since 8.0.3
    
    39
    + */
    
    40
    +public class UpdatedDataDtoReferenceSet<R extends DataDtoReference> implements ObserveDto {
    
    41
    +
    
    42
    +    private final ImmutableSet<String> allIds;
    
    43
    +    private final DataDtoReferenceSet<R> updatedReferences;
    
    44
    +
    
    45
    +    public UpdatedDataDtoReferenceSet(ImmutableSet<String> allIds, DataDtoReferenceSet<R> updatedReferences) {
    
    46
    +        this.allIds = Objects.requireNonNull(allIds);
    
    47
    +        this.updatedReferences = Objects.requireNonNull(updatedReferences);
    
    48
    +    }
    
    49
    +
    
    50
    +    public ImmutableSet<String> getAllIds() {
    
    51
    +        return allIds;
    
    52
    +    }
    
    53
    +
    
    54
    +    public DataDtoReferenceSet<R> getUpdatedReferences() {
    
    55
    +        return updatedReferences;
    
    56
    +    }
    
    57
    +
    
    58
    +    public DataDtoReferenceSet<R> mergeTo(DataDtoReferenceSet<R> incoming) {
    
    59
    +        Set<String> previousIdsToKeep = new LinkedHashSet<>(getAllIds());
    
    60
    +        previousIdsToKeep.removeAll(updatedReferences.toIds());
    
    61
    +        List<R> collect = incoming.subSet(previousIdsToKeep).collect(Collectors.toList());
    
    62
    +        collect.addAll(getUpdatedReferences().toArrayList());
    
    63
    +        return DataDtoReferenceSet.of(incoming.getType(), collect, getUpdatedReferences().getLastUpdate());
    
    64
    +    }
    
    65
    +}

  • toolkit/persistence/src/main/java/fr/ird/observe/entities/AbstractObserveTopiaDao.java
    ... ... @@ -22,50 +22,28 @@ package fr.ird.observe.entities;
    22 22
      * #L%
    
    23 23
      */
    
    24 24
     
    
    25
    +import fr.ird.observe.dto.IdDto;
    
    26
    +import org.nuiton.topia.persistence.HqlAndParametersBuilder;
    
    27
    +import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep;
    
    25 28
     import org.nuiton.topia.persistence.internal.AbstractTopiaDao;
    
    26
    -import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    27 29
     
    
    28
    -import java.sql.Connection;
    
    29
    -import java.sql.PreparedStatement;
    
    30
    -import java.sql.ResultSet;
    
    31
    -import java.sql.SQLException;
    
    32
    -import java.sql.Timestamp;
    
    30
    +import java.util.Date;
    
    33 31
     import java.util.List;
    
    34 32
     import java.util.Map;
    
    35 33
     
    
    36 34
     public abstract class AbstractObserveTopiaDao<E extends Entity> extends AbstractTopiaDao<E> {
    
    37 35
     
    
    38
    -    private final GetLastUpdateDateSqlQuery getLastUpdateDateSqlQuery;
    
    36
    +    public TopiaQueryBuilderAddCriteriaOrRunQueryStep<E> forLastUpdateDateGreaterThan(Date lastUpdateDate) {
    
    37
    +        HqlAndParametersBuilder<E> hqlAndParametersBuilder = newHqlAndParametersBuilder();
    
    38
    +        hqlAndParametersBuilder.addGreaterThan(IdDto.PROPERTY_LAST_UPDATE_DATE, lastUpdateDate);
    
    39
    +        return new InnerTopiaQueryBuilderAddCriteriaOrRunQueryStep<>(this, hqlAndParametersBuilder) {
    
    39 40
     
    
    40
    -    protected AbstractObserveTopiaDao() {
    
    41
    -        String schemaName = getTopiaEntityEnum().dbSchemaName();
    
    42
    -        String tableName = getTopiaEntityEnum().dbTableName();
    
    43
    -        getLastUpdateDateSqlQuery = new GetLastUpdateDateSqlQuery(schemaName, tableName);
    
    41
    +        };
    
    44 42
         }
    
    45 43
     
    
    46
    -    private static class GetLastUpdateDateSqlQuery extends TopiaSqlQuery<Timestamp> {
    
    47
    -
    
    48
    -        protected final String sql;
    
    49
    -
    
    50
    -        private GetLastUpdateDateSqlQuery(String schemaName, String tableName) {
    
    51
    -            this.sql = "SELECT max(" + Entity.PROPERTY_LAST_UPDATE_DATE + ") FROM " + schemaName + "." + tableName;
    
    52
    -        }
    
    53
    -
    
    54
    -        @Override
    
    55
    -        public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    56
    -            return connection.prepareStatement(sql);
    
    57
    -        }
    
    58
    -
    
    59
    -        @Override
    
    60
    -        public Timestamp prepareResult(ResultSet set) throws SQLException {
    
    61
    -            return set.getTimestamp(1);
    
    62
    -        }
    
    63
    -
    
    64
    -    }
    
    65
    -
    
    66
    -    public <O> List<O> findAllFromHql(String hql, Map<String, Object> hqlParameters) {
    
    67
    -        return findAll(hql, hqlParameters);
    
    44
    +    @Override
    
    45
    +    public <O> List<O> findAll(String hql, Map<String, Object> hqlParameters) {
    
    46
    +        return super.findAll(hql, hqlParameters);
    
    68 47
         }
    
    69 48
     
    
    70
    -
    
    71 49
     }

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/context/DataDtoEntityContext.java
    ... ... @@ -51,11 +51,6 @@ public class DataDtoEntityContext<D extends DataDto, R extends DataDtoReference,
    51 51
             super(dtoType, referenceType, entityType, entityTypeImpl, daoFunction);
    
    52 52
         }
    
    53 53
     
    
    54
    -    @Override
    
    55
    -    public DataDtoReferenceSet<R> toReferenceSet(ReferentialLocale referentialLocale, Collection<E> entities) {
    
    56
    -        return (DataDtoReferenceSet<R>) super.toReferenceSet(referentialLocale, entities);
    
    57
    -    }
    
    58
    -
    
    59 54
         @Override
    
    60 55
         public DataDtoReferenceSet<R> toReferenceSet(ReferentialLocale referentialLocale, Collection<E> entities, Date now) {
    
    61 56
             return (DataDtoReferenceSet<R>) super.toReferenceSet(referentialLocale, entities.stream(), now);
    

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/context/DtoEntityContextSupport.java
    ... ... @@ -75,15 +75,6 @@ public abstract class DtoEntityContextSupport<D extends IdDto, R extends DtoRefe
    75 75
     
    
    76 76
         protected abstract void fromDto(ReferentialLocale referentialLocale, E entity, D dto);
    
    77 77
     
    
    78
    -    protected DtoReferenceCollection<R> toReferenceSet(ReferentialLocale referentialLocale, Collection<E> entities) {
    
    79
    -        ImmutableSet.Builder<R> references = ImmutableSet.builder();
    
    80
    -        for (E entity : entities) {
    
    81
    -            @SuppressWarnings("unchecked") R reference = ((EntityToDto<?, R>) entity).toReference(referentialLocale);
    
    82
    -            references.add(reference);
    
    83
    -        }
    
    84
    -        return createReferenceSet(referentialLocale, references.build(), null);
    
    85
    -    }
    
    86
    -
    
    87 78
         @Override
    
    88 79
         public UpdateLastUpdateDateFieldScript getUpdateLastUpdateDateFieldScript() {
    
    89 80
             return updateLastUpdateDateFieldScript;
    

  • toolkit/persistence/src/main/java/fr/ird/observe/spi/context/ReferentialDtoEntityContext.java
    ... ... @@ -50,11 +50,6 @@ public class ReferentialDtoEntityContext<D extends ReferentialDto, R extends Ref
    50 50
             super(dtoType, referenceType, entityType, entityTypeImpl, daoFunction);
    
    51 51
         }
    
    52 52
     
    
    53
    -    @Override
    
    54
    -    public ReferentialDtoReferenceSet<R> toReferenceSet(ReferentialLocale referentialLocale, Collection<E> entities) {
    
    55
    -        return (ReferentialDtoReferenceSet<R>) super.toReferenceSet(referentialLocale, entities);
    
    56
    -    }
    
    57
    -
    
    58 53
         @Override
    
    59 54
         public ReferentialDtoReferenceSet<R> toReferenceSet(ReferentialLocale referentialLocale, Collection<E> entities, Date now) {
    
    60 55
             return (ReferentialDtoReferenceSet<R>) super.toReferenceSet(referentialLocale, entities, now);
    

  • toolkit/service/src/main/java/fr/ird/observe/services/service/data/OpenableDataService.java
    ... ... @@ -27,6 +27,7 @@ import fr.ird.observe.dto.data.DataDto;
    27 27
     import fr.ird.observe.dto.form.Form;
    
    28 28
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    29 29
     import fr.ird.observe.dto.reference.DataDtoReferenceSet;
    
    30
    +import fr.ird.observe.dto.reference.UpdatedDataDtoReferenceSet;
    
    30 31
     import fr.ird.observe.dto.result.SaveResultDto;
    
    31 32
     import fr.ird.observe.security.Permission;
    
    32 33
     import fr.ird.observe.services.service.ObserveService;
    
    ... ... @@ -37,6 +38,8 @@ import io.ultreia.java4all.http.spi.Get;
    37 38
     import io.ultreia.java4all.http.spi.Internal;
    
    38 39
     import io.ultreia.java4all.http.spi.Post;
    
    39 40
     
    
    41
    +import java.util.Date;
    
    42
    +
    
    40 43
     /**
    
    41 44
      * Created on 13/10/2020.
    
    42 45
      *
    
    ... ... @@ -50,6 +53,10 @@ public interface OpenableDataService<D extends DataDto, R extends DataDtoReferen
    50 53
         @MethodCredential(Permission.READ_DATA)
    
    51 54
         DataDtoReferenceSet<R> getChildren(String parentId);
    
    52 55
     
    
    56
    +    @Get
    
    57
    +    @MethodCredential(Permission.READ_DATA)
    
    58
    +    UpdatedDataDtoReferenceSet<R> getChildrenUpdate(String parentId, Date lastUpdate);
    
    59
    +
    
    53 60
         @Get
    
    54 61
         @MethodCredential(Permission.READ_DATA)
    
    55 62
         DataDtoReferenceSet<R> getBrothers(String id);
    

  • toolkit/service/src/main/java/fr/ird/observe/spi/context/EmptyChildrenDataReferenceSet.java
    ... ... @@ -26,6 +26,8 @@ import fr.ird.observe.dto.decoration.DecoratorServiceSupport;
    26 26
     import fr.ird.observe.dto.reference.DataDtoReference;
    
    27 27
     import fr.ird.observe.dto.reference.DataDtoReferenceSet;
    
    28 28
     import fr.ird.observe.dto.reference.LazyDataDtoReferenceSet;
    
    29
    +import fr.ird.observe.dto.reference.UpdatedDataDtoReferenceSet;
    
    30
    +import fr.ird.observe.services.service.data.OpenableDataService;
    
    29 31
     import fr.ird.observe.spi.ServicesProvider;
    
    30 32
     
    
    31 33
     import java.util.Comparator;
    
    ... ... @@ -59,7 +61,18 @@ public class EmptyChildrenDataReferenceSet<R extends DataDtoReference> extends L
    59 61
     
    
    60 62
         @Override
    
    61 63
         protected DataDtoReferenceSet<R> createDelegate() {
    
    62
    -        DataDtoReferenceSet<R> result = spi.getService(servicesProvider).getChildren(parentId);
    
    64
    +        DataDtoReferenceSet<R> previousResult = getDelegate();
    
    65
    +        DataDtoReferenceSet<R> result;
    
    66
    +        OpenableDataService<?, R> service = spi.getService(servicesProvider);
    
    67
    +        if (previousResult == null) {
    
    68
    +            // first time load all data
    
    69
    +            result = service.getChildren(parentId);
    
    70
    +        } else {
    
    71
    +            // ask an update of data
    
    72
    +            UpdatedDataDtoReferenceSet<R> updateResult = service.getChildrenUpdate(parentId, previousResult.getLastUpdate());
    
    73
    +            // merge it with previous data
    
    74
    +            result = updateResult.mergeTo(previousResult);
    
    75
    +        }
    
    63 76
             result.sort(spi.getReferenceComparator());
    
    64 77
             decoratorService.installDecorator(result);
    
    65 78
             return result;