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

Commits:

27 changed files:

Changes:

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
    ... ... @@ -21,6 +21,8 @@
    21 21
     package fr.ird.t3.actions.data.level0;
    
    22 22
     
    
    23 23
     import fr.ird.t3.actions.T3Action;
    
    24
    +import fr.ird.t3.entities.data.Route;
    
    25
    +import fr.ird.t3.entities.data.RouteTopiaDao;
    
    24 26
     import fr.ird.t3.entities.data.Trip;
    
    25 27
     import fr.ird.t3.entities.data.TripTopiaDao;
    
    26 28
     import fr.ird.t3.entities.reference.Country;
    
    ... ... @@ -54,6 +56,9 @@ public abstract class AbstractLevel0Action<C extends AbstractLevel0Configuration
    54 56
         @InjectDAO(entityType = Trip.class)
    
    55 57
         protected TripTopiaDao tripDAO;
    
    56 58
     
    
    59
    +    @InjectDAO(entityType = Route.class)
    
    60
    +    protected RouteTopiaDao routeDAO;
    
    61
    +
    
    57 62
         @InjectEntitiesById(entityType = Country.class)
    
    58 63
         protected List<Country> fleets;
    
    59 64
     
    

  • t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU Affero General Public License as published by
    
    9 9
      * the Free Software Foundation, either version 3 of the License, or
    
    10 10
      * (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU Affero General Public License
    
    18 18
      * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19 19
      * #L%
    
    ... ... @@ -22,26 +22,21 @@ package fr.ird.t3.actions.data.level0;
    22 22
     
    
    23 23
     import com.google.common.collect.ImmutableSet;
    
    24 24
     import com.google.common.collect.Iterables;
    
    25
    -import com.google.common.collect.Lists;
    
    26
    -import com.google.common.collect.Multimap;
    
    27 25
     import com.web_tomorrow.utils.suntimes.SunTimes;
    
    28 26
     import fr.ird.t3.entities.data.Activity;
    
    29
    -import fr.ird.t3.entities.data.ActivityTopiaDao;
    
    27
    +import fr.ird.t3.entities.data.Route;
    
    30 28
     import fr.ird.t3.entities.data.Trip;
    
    31 29
     import fr.ird.t3.entities.reference.VesselActivity;
    
    32 30
     import fr.ird.t3.entities.type.T3Point;
    
    33
    -import java.util.Calendar;
    
    34
    -import java.util.Collection;
    
    35
    -import java.util.Collections;
    
    36
    -import java.util.Date;
    
    37
    -import java.util.List;
    
    38 31
     import org.apache.commons.collections.CollectionUtils;
    
    39
    -import org.apache.commons.lang3.time.DateUtils;
    
    40 32
     import org.apache.commons.logging.Log;
    
    41 33
     import org.apache.commons.logging.LogFactory;
    
    42 34
     import org.nuiton.topia.persistence.TopiaException;
    
    43
    -import org.nuiton.util.DateUtil;
    
    44 35
     
    
    36
    +import java.util.Collection;
    
    37
    +import java.util.Date;
    
    38
    +import java.util.List;
    
    39
    +import java.util.Objects;
    
    45 40
     
    
    46 41
     import static org.nuiton.i18n.I18n.l;
    
    47 42
     
    
    ... ... @@ -56,22 +51,20 @@ import static org.nuiton.i18n.I18n.l;
    56 51
      */
    
    57 52
     public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEffortsConfiguration> {
    
    58 53
     
    
    59
    -    /** Logger. */
    
    60
    -    private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
    
    61
    -
    
    62 54
         /**
    
    63 55
          * Les codes des activités surlequel on ne calcule pas d'effort de pêche.
    
    64 56
          *
    
    65 57
          * @since 2.0
    
    66 58
          */
    
    67
    -    protected static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
    
    59
    +    private static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
    
    68 60
                 4,  // route sans veille
    
    69 61
                 7,  // avarie
    
    70 62
                 8,  // à la cape
    
    71 63
                 10, // en attente
    
    72 64
                 15  // au port
    
    73 65
         );
    
    74
    -
    
    66
    +    /** Logger. */
    
    67
    +    private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
    
    75 68
         protected float totalTimeAtSeaN0;
    
    76 69
     
    
    77 70
         protected float totalFishingTimeN0;
    
    ... ... @@ -127,146 +120,110 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
    127 120
             return result;
    
    128 121
         }
    
    129 122
     
    
    130
    -    protected boolean executeForTrip(Trip trip) throws TopiaException {
    
    123
    +    private boolean executeForTrip(Trip trip) throws TopiaException {
    
    131 124
     
    
    132 125
             // compute time at sea
    
    133
    -        float timeAtSea = computeTimeAtSea(trip);
    
    134
    -        totalTimeAtSeaN0 += timeAtSea;
    
    135
    -
    
    136
    -        trip.setComputedTimeAtSeaN0(timeAtSea);
    
    137
    -        incrementsProgression();
    
    138
    -
    
    139
    -        // compute fishing time
    
    140
    -        float fishingTime = computeFishingTime(trip);
    
    141
    -        totalFishingTimeN0 += fishingTime;
    
    142
    -        trip.setComputedFishingTimeN0(fishingTime);
    
    143
    -        incrementsProgression();
    
    144
    -
    
    145
    -        // compute search time
    
    146
    -        float searchTime = computeTripSearchTime(trip, fishingTime);
    
    147
    -        totalSearchTimeN0 += searchTime;
    
    148
    -        trip.setComputedSearchTimeN0(searchTime);
    
    149
    -
    
    150
    -        incrementsProgression();
    
    151
    -
    
    152
    -        String message = l(locale, "t3.level0.computeTripEffort",
    
    153
    -                decorate(trip),
    
    154
    -                trip.getComputedTimeAtSeaN0(),
    
    155
    -                trip.getComputedFishingTimeN0(),
    
    156
    -                trip.getComputedSearchTimeN0()
    
    157
    -        );
    
    158
    -        addInfoMessage(message);
    
    159
    -        if (log.isInfoEnabled()) {
    
    160
    -            log.info(message);
    
    161
    -        }
    
    162
    -        markTripAsTreated(trip);
    
    163
    -        return true;
    
    164
    -    }
    
    165
    -
    
    166
    -    protected float computeTimeAtSea(Trip trip) {
    
    167 126
     
    
    168
    -        float setTimeAtSea;
    
    127
    +        Route firstRoute = Objects.requireNonNull(trip.getRoute().get(0));
    
    128
    +        Route lastRoute = Objects.requireNonNull(Iterables.getLast(trip.getRoute()));
    
    169 129
     
    
    170
    -        // date depart - date dpq = nb jours
    
    171
    -        // result = nb heures entre le départ et l'arrivée
    
    172
    -        Calendar calendarDep = DateUtils.toCalendar(trip.getDepartureDate());
    
    173
    -        calendarDep.set(Calendar.MINUTE, 0);
    
    174
    -        calendarDep.set(Calendar.SECOND, 0);
    
    175
    -        calendarDep.set(Calendar.MILLISECOND, 0);
    
    176
    -        Calendar calendarLanding = DateUtils.toCalendar(trip.getLandingDate());
    
    177
    -        calendarLanding.set(Calendar.MINUTE, 0);
    
    178
    -        calendarLanding.set(Calendar.SECOND, 0);
    
    179
    -        calendarLanding.set(Calendar.MILLISECOND, 0);
    
    130
    +        for (Route route : trip.getRoute()) {
    
    180 131
     
    
    181
    -        int months = DateUtil.getDifferenceInHours(calendarDep.getTime(), calendarLanding.getTime());
    
    182
    -        setTimeAtSea = months;
    
    132
    +//            float timeAtSea = computeTimeAtSea(route);
    
    133
    +//            totalTimeAtSeaN0 += timeAtSea;
    
    134
    +            totalTimeAtSeaN0 += 24;
    
    183 135
     
    
    184
    -        if (log.isDebugEnabled()) {
    
    185
    -            log.debug(decorate(trip) + " : time at sea = " + setTimeAtSea);
    
    186
    -        }
    
    187
    -        return setTimeAtSea;
    
    188
    -    }
    
    189
    -
    
    190
    -    protected float computeFishingTime(Trip trip) throws TopiaException {
    
    191
    -
    
    192
    -        float setFishingTime = 0;
    
    136
    +//            route.setComputedTimeAtSeaN0(timeAtSea);
    
    137
    +//            incrementsProgression();
    
    193 138
     
    
    194
    -        if (!trip.isActivityEmpty()) {
    
    139
    +            // compute fishing time
    
    140
    +            Float fishingTime = computeFishingTime(firstRoute, lastRoute, route);
    
    141
    +            route.setComputedFishingTimeN0(fishingTime);
    
    142
    +            incrementsProgression();
    
    195 143
     
    
    196
    -            Multimap<Long, Activity> activitiesByDay = ActivityTopiaDao.groupActivitiesByDay(trip.getActivity());
    
    144
    +            if (fishingTime == null) {
    
    197 145
     
    
    198
    -            List<Long> daysIds = Lists.newArrayList(activitiesByDay.keySet());
    
    199
    -            Collections.sort(daysIds);
    
    200
    -
    
    201
    -            long firstDay = daysIds.get(0);
    
    202
    -            long lastDay = Iterables.getLast(daysIds);
    
    146
    +                route.setComputedSearchTimeN0(null);
    
    147
    +                incrementsProgression();
    
    148
    +                continue;
    
    149
    +            }
    
    203 150
     
    
    204
    -            for (Long dayId : daysIds) {
    
    151
    +            totalFishingTimeN0 += fishingTime;
    
    152
    +            // compute search time
    
    153
    +            float searchTime = computeTripSearchTime(route, fishingTime);
    
    154
    +            totalSearchTimeN0 += searchTime;
    
    155
    +            route.setComputedSearchTimeN0(searchTime);
    
    205 156
     
    
    206
    -                Collection<Activity> activities = activitiesByDay.get(dayId);
    
    157
    +            incrementsProgression();
    
    207 158
     
    
    208
    -                if (dayId == firstDay || lastDay == dayId) {
    
    209
    -                    float currentFishingTime = computeSetFishingTimeForFirstOrLayDay(activities);
    
    210
    -                    setFishingTime += currentFishingTime;
    
    211
    -                    continue;
    
    212
    -                }
    
    159
    +            String message = l(locale, "t3.level0.computeTripEffort",
    
    160
    +                    decorate(route),
    
    161
    +                    route.getComputedFishingTimeN0(),
    
    162
    +                    route.getComputedSearchTimeN0()
    
    163
    +            );
    
    213 164
     
    
    214
    -                Date date = new Date(dayId);
    
    215
    -                if (!canComputeSetFishingTime(activities)) {
    
    165
    +            addInfoMessage(message);
    
    166
    +            if (log.isInfoEnabled()) {
    
    167
    +                log.info(message);
    
    168
    +            }
    
    169
    +        }
    
    170
    +        markTripAsTreated(trip);
    
    171
    +        return true;
    
    172
    +    }
    
    216 173
     
    
    217
    -                    String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(trip), date);
    
    218
    -                    addInfoMessage(message);
    
    219
    -                    if (log.isInfoEnabled()) {
    
    220
    -                        log.info(message);
    
    221
    -                    }
    
    174
    +    private Float computeFishingTime(Route firstRoute, Route lastRoute, Route route) throws TopiaException {
    
    222 175
     
    
    223
    -                    continue;
    
    224
    -                }
    
    176
    +        Collection<Activity> activities = route.getActivity();
    
    225 177
     
    
    178
    +        if (Objects.equals(firstRoute, route) || Objects.equals(lastRoute, route)) {
    
    179
    +            return computeSetFishingTimeForFirstOrLayDay(activities);
    
    180
    +        }
    
    226 181
     
    
    227
    -                T3Point point;
    
    182
    +        Date date = route.getDate();
    
    183
    +        if (!canComputeSetFishingTime(activities)) {
    
    228 184
     
    
    229
    -                if (activities.size() == 1) {
    
    185
    +            String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(route));
    
    186
    +            addInfoMessage(message);
    
    187
    +            if (log.isInfoEnabled()) {
    
    188
    +                log.info(message);
    
    189
    +            }
    
    190
    +            return null;
    
    191
    +        }
    
    230 192
     
    
    231
    -                    // only one activity for this day,
    
    232
    -                    Activity activity = activities.iterator().next();
    
    233
    -                    point = activity.toPoint();
    
    193
    +        T3Point point;
    
    234 194
     
    
    235
    -                    if (log.isDebugEnabled()) {
    
    236
    -                        log.debug("Day [" + date + "] , single activity,  point : " + point);
    
    237
    -                    }
    
    238
    -                } else {
    
    195
    +        if (activities.size() == 1) {
    
    239 196
     
    
    240
    -                    // compute barycenter for all activities of the day
    
    241
    -                    point = tripDAO.getBarycenterForActivitiesOfADay(trip, date);
    
    197
    +            // only one activity for this day,
    
    198
    +            Activity activity = activities.iterator().next();
    
    199
    +            point = activity.toPoint();
    
    242 200
     
    
    243
    -                    if (log.isDebugEnabled()) {
    
    244
    -                        log.debug("Day [" + date + "] Computed barycenter point " + point);
    
    245
    -                    }
    
    246
    -                }
    
    201
    +            if (log.isDebugEnabled()) {
    
    202
    +                log.debug("Day [" + date + "] , single activity,  point : " + point);
    
    203
    +            }
    
    204
    +        } else {
    
    247 205
     
    
    248
    -                // compute day duration for this point and day (in minutes)
    
    249
    -                double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
    
    206
    +            // compute barycenter for all activities of the day
    
    207
    +            point = routeDAO.getBarycenterForActivitiesOfADay(route, date);
    
    250 208
     
    
    251
    -                if (log.isInfoEnabled()) {
    
    252
    -                    log.info("Day [" + date + "] duration = " + duration);
    
    253
    -                }
    
    254
    -                // add it to setTime
    
    255
    -                setFishingTime += duration;
    
    209
    +            if (log.isDebugEnabled()) {
    
    210
    +                log.debug("Day [" + date + "] Computed barycenter point " + point);
    
    256 211
                 }
    
    257 212
             }
    
    258 213
     
    
    259
    -        if (log.isDebugEnabled()) {
    
    260
    -            log.debug(decorate(trip) + " - fishing time = " + setFishingTime);
    
    261
    -        }
    
    214
    +        // compute day duration for this point and day (in minutes)
    
    215
    +        double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
    
    262 216
     
    
    263
    -        return setFishingTime;
    
    217
    +        if (log.isInfoEnabled()) {
    
    218
    +            log.info("Day [" + date + "] duration = " + duration);
    
    219
    +        }
    
    220
    +        return (float) duration;
    
    264 221
         }
    
    265 222
     
    
    266
    -    protected float computeTripSearchTime(Trip trip, float fishingTime) {
    
    223
    +    private float computeTripSearchTime(Route route, float fishingTime) {
    
    267 224
     
    
    268 225
             // compute sum of catches time
    
    269
    -        float catchesTime = trip.getTotalSetsDuration();
    
    226
    +        float catchesTime = route.getTotalSetsDuration();
    
    270 227
     
    
    271 228
             if (log.isDebugEnabled()) {
    
    272 229
                 log.debug("Total catches time = " + catchesTime);
    
    ... ... @@ -274,12 +231,12 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
    274 231
             float result = fishingTime - catchesTime;
    
    275 232
     
    
    276 233
             if (log.isDebugEnabled()) {
    
    277
    -            log.debug(decorate(trip) + " - trip search time = " + result);
    
    234
    +            log.debug(decorate(route) + " - trip search time = " + result);
    
    278 235
             }
    
    279 236
             return result;
    
    280 237
         }
    
    281 238
     
    
    282
    -    protected float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
    
    239
    +    private float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
    
    283 240
     
    
    284 241
             float result = 0f;
    
    285 242
             for (Activity activity : activities) {
    
    ... ... @@ -289,7 +246,7 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
    289 246
     
    
    290 247
         }
    
    291 248
     
    
    292
    -    protected boolean canComputeSetFishingTime(Collection<Activity> activities) {
    
    249
    +    private boolean canComputeSetFishingTime(Collection<Activity> activities) {
    
    293 250
             boolean result = false;
    
    294 251
             for (Activity activity : activities) {
    
    295 252
                 VesselActivity vesselActivity = activity.getVesselActivity();
    

  • t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
    ... ... @@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Trip %s total rf1 catches weight %s / t
    42 42
     t3.level0.computeRF2.resume.skip.for.trip=Trip %s has not elementary landing (trip not used to compute rf2)
    
    43 43
     t3.level0.computeRF2.resume.total.rf1=Sum total rf1 catches weight %s  / Sum total landing weight %s
    
    44 44
     t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=SetDuration data not found (ocean %s, fleet %s, school type %s, year %s)
    
    45
    -t3.level0.computeTripEffort=Trip efforts %s (sea %s, fishing%s, search%s)
    
    46
    -t3.level0.computeTripEffortSkipForDay=Trip %s, Day (%s) without fihsing time (only activities of type « at harbour » or « under way without prospection »)
    
    45
    +t3.level0.computeTripEffort=Trip efforts %s (fishing %s, search %s)
    
    46
    +t3.level0.computeTripEffortSkipForDay=Trip %s, day without fishing time (only activities of type « at harbour » or « under way without prospection »)
    
    47 47
     t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Weight category %s,  weight \= %s, propWeight \= %s (activity %s)
    
    48 48
     t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Well (%s) with well plan filled %s wellSetAllSpecies, total weight %s
    
    49 49
     t3.level0.convertCatchesWeightCategories.resume.for.species=Species %s < logBook total weight \= %s , converted total weight \= %s>
    

  • t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
    ... ... @@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Marée %s Poids total des captures rf1i
    42 42
     t3.level0.computeRF2.resume.skip.for.trip=La marée %s ne possède pas de lots commerciaux (non prise en compte dans le calcul du rf2)
    
    43 43
     t3.level0.computeRF2.resume.total.rf1=Poids cumulé des captures rf1isées %s  / Poids cumulé des ventes %s
    
    44 44
     t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=Donnée SetDuration non trouvée (ocean %s, flotte %s, type de banc %s, année %s)
    
    45
    -t3.level0.computeTripEffort=Efforts de la marée %s (mer %s, pêche %s, recherche %s)
    
    46
    -t3.level0.computeTripEffortSkipForDay=Marée %s, Journée (%s) sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
    
    45
    +t3.level0.computeTripEffort=Efforts de la marée %s (pêche %s, recherche %s)
    
    46
    +t3.level0.computeTripEffortSkipForDay=Marée %s, jour sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
    
    47 47
     t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Catégorie de poids %s,  poids \= %s, poids pondéré\= %s (activité %s)
    
    48 48
     t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Cuve avec plan de cuve (%s) avec %s wellSetAllSpecies, poids total %s
    
    49 49
     t3.level0.convertCatchesWeightCategories.resume.for.species=Espèce %s < poids total des captures du livre de bord \= %s , poids total converti \= %s>
    

  • t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
    1
    +package fr.ird.t3.entities.data;
    
    2
    +
    
    3
    +import fr.ird.t3.entities.type.T3Point;
    
    4
    +import fr.ird.t3.entities.type.T3PointImpl;
    
    5
    +import org.nuiton.topia.persistence.TopiaException;
    
    6
    +import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    7
    +
    
    8
    +import java.sql.Connection;
    
    9
    +import java.sql.PreparedStatement;
    
    10
    +import java.sql.ResultSet;
    
    11
    +import java.sql.SQLException;
    
    12
    +import java.util.Date;
    
    13
    +
    
    14
    +public class AbstractRouteTopiaDao<E extends Route> extends GeneratedRouteTopiaDao<E> {
    
    15
    +
    
    16
    +    public T3Point getBarycenterForActivitiesOfADay(E route, Date day) throws TopiaException {
    
    17
    +
    
    18
    +        TopiaSqlQuery<T3Point> query = new GetT3PointQuery<E>(route, day);
    
    19
    +        return topiaSqlSupport.findSingleResult(query);
    
    20
    +    }
    
    21
    +
    
    22
    +    private static class GetT3PointQuery<E extends Route> extends TopiaSqlQuery<T3Point> {
    
    23
    +        private final E route;
    
    24
    +
    
    25
    +        private final Date day;
    
    26
    +
    
    27
    +        public GetT3PointQuery(E route, Date day) {
    
    28
    +            this.route = route;
    
    29
    +            this.day = day;
    
    30
    +        }
    
    31
    +
    
    32
    +        @Override
    
    33
    +        public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    34
    +            PreparedStatement ps = connection.prepareStatement(
    
    35
    +                    "SELECT ST_X(record.point), ST_Y(record.point) FROM " +
    
    36
    +                            "(" +
    
    37
    +                            "   SELECT ST_Centroid(ST_Collect(a.the_geom)) AS point" +
    
    38
    +                            "   FROM activity a " +
    
    39
    +                            "   WHERE a.route = ? AND a.date::DATE = ?" +
    
    40
    +                            ") AS record;");
    
    41
    +            ps.setString(1, route.getTopiaId());
    
    42
    +            ps.setDate(2, new java.sql.Date(day.getTime()));
    
    43
    +            return ps;
    
    44
    +        }
    
    45
    +
    
    46
    +        @Override
    
    47
    +        public T3Point prepareResult(ResultSet set) throws SQLException {
    
    48
    +            float x = set.getFloat(1);
    
    49
    +            float y = set.getFloat(2);
    
    50
    +            return new T3PointImpl(x, y);
    
    51
    +        }
    
    52
    +    }
    
    53
    +
    
    54
    +}
    
    55
    +

  • t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
    ... ... @@ -128,13 +128,13 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
    128 128
     //            query = createQuery("t")
    
    129 129
     //                    .setSelect("t.id")
    
    130 130
     //                    .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
    
    131
    -            hql = "SELECT t.id FROM TripImpl t WHERE size(t.activity) = 0";
    
    131
    +            hql = "SELECT t.id FROM TripImpl as t WHERE size(t.route) = 0";
    
    132 132
     //            params = Collections.emptyList();
    
    133 133
             } else {
    
    134 134
     //            query = new TopiaQuery(Activity.class, "a")
    
    135 135
     //                    .setSelect("distinct(a.trip.id)")
    
    136 136
     //                    .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
    
    137
    -            hql = "SELECT DISTINCT(a.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
    
    137
    +            hql = "SELECT DISTINCT(a.route.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
    
    138 138
                 paramsBuilder.put("ocean", ocean);
    
    139 139
     //            params = Lists.<Object>newArrayList("ocean", ocean);
    
    140 140
             }
    

  • t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
    ... ... @@ -26,12 +26,13 @@ import fr.ird.t3.entities.reference.VesselActivity;
    26 26
     import fr.ird.t3.entities.type.T3Point;
    
    27 27
     import fr.ird.t3.entities.type.T3PointImpl;
    
    28 28
     import fr.ird.type.CoordinateHelper;
    
    29
    +import org.apache.commons.logging.Log;
    
    30
    +import org.apache.commons.logging.LogFactory;
    
    31
    +
    
    29 32
     import java.util.Calendar;
    
    30 33
     import java.util.Collection;
    
    31 34
     import java.util.Date;
    
    32 35
     import java.util.Set;
    
    33
    -import org.apache.commons.logging.Log;
    
    34
    -import org.apache.commons.logging.LogFactory;
    
    35 36
     
    
    36 37
     /**
    
    37 38
      * Implementation of {@link Activity} with manual quadrant
    
    ... ... @@ -60,6 +61,11 @@ public class ActivityImpl extends ActivityAbstract {
    60 61
         protected Integer quadrant;
    
    61 62
     
    
    62 63
         @Override
    
    64
    +    public Trip getTrip() {
    
    65
    +        return getRoute().getTrip();
    
    66
    +    }
    
    67
    +
    
    68
    +    @Override
    
    63 69
         public Integer getQuadrant() {
    
    64 70
             if (quadrant == null) {
    
    65 71
     
    

  • t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
    1
    +package fr.ird.t3.entities.data;
    
    2
    +
    
    3
    +public class RouteImpl extends RouteAbstract {
    
    4
    +
    
    5
    +    private static final long serialVersionUID = 1L;
    
    6
    +
    
    7
    +    /** @return the sum of all activities set duration in hours. */
    
    8
    +    @Override
    
    9
    +    public float getTotalSetsDuration() {
    
    10
    +        float result = 0;
    
    11
    +        if (!isActivityEmpty()) {
    
    12
    +            for (Activity activity : getActivity()) {
    
    13
    +
    
    14
    +                // get the setDuration
    
    15
    +                Float setTime = activity.getSetDuration();
    
    16
    +
    
    17
    +                result += setTime == null ? 0f : setTime;
    
    18
    +            }
    
    19
    +        }
    
    20
    +        return result / 60;
    
    21
    +    }
    
    22
    +
    
    23
    +    @Override
    
    24
    +    public void deleteComputedDataLevel0() {
    
    25
    +        setComputedFishingTimeN0(null);
    
    26
    +        setComputedSearchTimeN0(null);
    
    27
    +        ComputedDataHelper.deleteComputedDataLevel0(getActivity());
    
    28
    +    }
    
    29
    +
    
    30
    +    @Override
    
    31
    +    public void deleteComputedData() {
    
    32
    +        ComputedDataHelper.deleteComputedDatas(this);
    
    33
    +    }
    
    34
    +
    
    35
    +    @Override
    
    36
    +    public void deleteComputedDataLevel1() {
    
    37
    +        ComputedDataHelper.deleteComputedDataLevel1(getActivity());
    
    38
    +    }
    
    39
    +
    
    40
    +    @Override
    
    41
    +    public void deleteComputedDataLevel2() {
    
    42
    +        ComputedDataHelper.deleteComputedDataLevel2(getActivity());
    
    43
    +    }
    
    44
    +
    
    45
    +    @Override
    
    46
    +    public void deleteComputedDataLevel3() {
    
    47
    +        ComputedDataHelper.deleteComputedDataLevel3(getActivity());
    
    48
    +    }
    
    49
    +}

  • t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
    ... ... @@ -30,9 +30,17 @@ import fr.ird.t3.entities.reference.Ocean;
    30 30
     import fr.ird.t3.entities.reference.Species;
    
    31 31
     import fr.ird.t3.entities.reference.Vessel;
    
    32 32
     import fr.ird.t3.entities.reference.VesselImpl;
    
    33
    +import org.nuiton.util.DateUtil;
    
    33 34
     
    
    34 35
     import java.util.Collection;
    
    36
    +import java.util.Date;
    
    37
    +import java.util.LinkedList;
    
    38
    +import java.util.List;
    
    39
    +import java.util.Objects;
    
    40
    +import java.util.Optional;
    
    35 41
     import java.util.Set;
    
    42
    +import java.util.stream.Collectors;
    
    43
    +import java.util.stream.Stream;
    
    36 44
     
    
    37 45
     import static org.nuiton.i18n.I18n.n;
    
    38 46
     
    
    ... ... @@ -119,21 +127,21 @@ public class TripImpl extends TripAbstract {
    119 127
             return result;
    
    120 128
         }
    
    121 129
     
    
    122
    -    /** @return the sum of all activities set duration in hours. */
    
    123
    -    @Override
    
    124
    -    public float getTotalSetsDuration() {
    
    125
    -        float result = 0;
    
    126
    -        if (!isActivityEmpty()) {
    
    127
    -            for (Activity activity : getActivity()) {
    
    128
    -
    
    129
    -                // get the setDuration
    
    130
    -                Float setTime = activity.getSetDuration();
    
    131
    -
    
    132
    -                result += setTime == null ? 0f : setTime;
    
    133
    -            }
    
    134
    -        }
    
    135
    -        return result / 60;
    
    136
    -    }
    
    130
    +//    /** @return the sum of all activities set duration in hours. */
    
    131
    +//    @Override
    
    132
    +//    public float getTotalSetsDuration() {
    
    133
    +//        float result = 0;
    
    134
    +//        if (!isActivityEmpty()) {
    
    135
    +//            for (Activity activity : getActivity()) {
    
    136
    +//
    
    137
    +//                // get the setDuration
    
    138
    +//                Float setTime = activity.getSetDuration();
    
    139
    +//
    
    140
    +//                result += setTime == null ? 0f : setTime;
    
    141
    +//            }
    
    142
    +//        }
    
    143
    +//        return result / 60;
    
    144
    +//    }
    
    137 145
     
    
    138 146
         @Override
    
    139 147
         public float getElementaryCatchTotalWeight(Collection<Species> species) {
    
    ... ... @@ -436,19 +444,17 @@ public class TripImpl extends TripAbstract {
    436 444
             setCompletionStatus(null);
    
    437 445
             setRf1(null);
    
    438 446
             setRf2(null);
    
    439
    -        setComputedFishingTimeN0(null);
    
    440
    -        setComputedSearchTimeN0(null);
    
    441
    -        setComputedTimeAtSeaN0(null);
    
    447
    +//        setComputedFishingTimeN0(null);
    
    448
    +//        setComputedSearchTimeN0(null);
    
    449
    +//        setComputedTimeAtSeaN0(null);
    
    442 450
     
    
    443
    -        ComputedDataHelper.deleteComputedDataLevel0(getActivity());
    
    451
    +        ComputedDataHelper.deleteComputedDataLevel0(getRoute());
    
    444 452
             ComputedDataHelper.deleteComputedDataLevel0(getSample());
    
    445 453
             ComputedDataHelper.deleteComputedDataLevel0(getWell());
    
    446 454
         }
    
    447 455
     
    
    448 456
         @Override
    
    449 457
         public void deleteComputedDataLevel1() {
    
    450
    -
    
    451
    -        // level 1 flags
    
    452 458
             setExtrapolateSampleCountedAndMeasured(false);
    
    453 459
             setStandardizeSampleMeasures(false);
    
    454 460
             setComputeWeightOfCategoriesForSet(false);
    
    ... ... @@ -457,27 +463,97 @@ public class TripImpl extends TripAbstract {
    457 463
             setConvertSetSpeciesFrequencyToWeight(false);
    
    458 464
             setConvertSampleSetSpeciesFrequencyToWeight(false);
    
    459 465
     
    
    460
    -        ComputedDataHelper.deleteComputedDataLevel1(getActivity());
    
    466
    +        ComputedDataHelper.deleteComputedDataLevel1(getRoute());
    
    461 467
             ComputedDataHelper.deleteComputedDataLevel1(getSample());
    
    462 468
             ComputedDataHelper.deleteComputedDataLevel1(getWell());
    
    463 469
         }
    
    464 470
     
    
    465 471
         @Override
    
    466 472
         public void deleteComputedDataLevel2() {
    
    467
    -        // level 2 flags
    
    468
    -
    
    469
    -        ComputedDataHelper.deleteComputedDataLevel2(getActivity());
    
    473
    +        ComputedDataHelper.deleteComputedDataLevel2(getRoute());
    
    470 474
             ComputedDataHelper.deleteComputedDataLevel2(getSample());
    
    471 475
             ComputedDataHelper.deleteComputedDataLevel2(getWell());
    
    472 476
         }
    
    473 477
     
    
    474 478
         @Override
    
    475 479
         public void deleteComputedDataLevel3() {
    
    476
    -        // level 3 flags
    
    477
    -
    
    478
    -        ComputedDataHelper.deleteComputedDataLevel3(getActivity());
    
    480
    +        ComputedDataHelper.deleteComputedDataLevel3(getRoute());
    
    479 481
             ComputedDataHelper.deleteComputedDataLevel3(getSample());
    
    480 482
             ComputedDataHelper.deleteComputedDataLevel3(getWell());
    
    481 483
         }
    
    482 484
     
    
    485
    +    @Override
    
    486
    +    public int getComputedTimeAtSeaN0() {
    
    487
    +        return 24 * sizeRoute();
    
    488
    +    }
    
    489
    +
    
    490
    +    @Override
    
    491
    +    public int sizeActivity() {
    
    492
    +        return (int) activityStream().count();
    
    493
    +    }
    
    494
    +
    
    495
    +    @Override
    
    496
    +    public boolean isActivityEmpty() {
    
    497
    +        return isRouteEmpty() || activityStream().count() == 0;
    
    498
    +    }
    
    499
    +
    
    500
    +    @Override
    
    501
    +    public boolean isActivityNotEmpty() {
    
    502
    +        return isRouteNotEmpty() && activityStream().count() > 0;
    
    503
    +    }
    
    504
    +
    
    505
    +    @Override
    
    506
    +    public List<Activity> getActivity() {
    
    507
    +        return activityStream().collect(Collectors.toList());
    
    508
    +    }
    
    509
    +
    
    510
    +    @Override
    
    511
    +    public void setActivity(List<Activity> activities) {
    
    512
    +        clearRoute();
    
    513
    +        for (Activity activity : activities) {
    
    514
    +            addActivity(activity);
    
    515
    +        }
    
    516
    +    }
    
    517
    +
    
    518
    +    @Override
    
    519
    +    public Activity getActivityByTopiaId(String topiaId) {
    
    520
    +        return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
    
    521
    +    }
    
    522
    +
    
    523
    +    @Override
    
    524
    +    public Collection<String> getActivityTopiaIds() {
    
    525
    +        return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
    
    526
    +    }
    
    527
    +
    
    528
    +    @Override
    
    529
    +    public void addActivity(Activity activity) {
    
    530
    +        Date date = DateUtil.getDay(activity.getDate());
    
    531
    +        Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
    
    532
    +        Route route;
    
    533
    +        if (optionalRoute.isPresent()) {
    
    534
    +            route = optionalRoute.get();
    
    535
    +        } else {
    
    536
    +            route = new RouteImpl();
    
    537
    +            route.setDate(date);
    
    538
    +            addRoute(route);
    
    539
    +        }
    
    540
    +        route.addActivity(activity);
    
    541
    +    }
    
    542
    +
    
    543
    +    @Override
    
    544
    +    public List<Route> getRoute() {
    
    545
    +        List<Route> route = super.getRoute();
    
    546
    +        if (route == null) {
    
    547
    +            setRoute(route = new LinkedList<>());
    
    548
    +        }
    
    549
    +        return route;
    
    550
    +    }
    
    551
    +
    
    552
    +    private Stream<Route> routeStream() {
    
    553
    +        return getRoute().stream();
    
    554
    +    }
    
    555
    +
    
    556
    +    private Stream<Activity> activityStream() {
    
    557
    +        return routeStream().flatMap(r -> r.getActivity().stream());
    
    558
    +    }
    
    483 559
     }

  • t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
    ... ... @@ -126,7 +126,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
    126 126
     //                .addParam("oceanId", oceanId);
    
    127 127
     
    
    128 128
             String hql = "SELECT DISTINCT(c) " +
    
    129
    -                "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
    
    129
    +                "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
    
    130 130
                     "WHERE t.vessel.fleetCountry = c.id AND a.ocean.id = :oceanId";
    
    131 131
     //        FIXME : trouvé pk cela est aussi long...
    
    132 132
     //                .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) > 0")
    
    ... ... @@ -155,7 +155,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
    155 155
     //                .addParam("oceanId", oceanId);
    
    156 156
     
    
    157 157
             String hql = "SELECT DISTINCT(c) " +
    
    158
    -                "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
    
    158
    +                "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
    
    159 159
                     "WHERE t.vessel.flagCountry = c.id AND a.ocean.id = :oceanId";
    
    160 160
     //        FIXME : trouvé pk cela est aussi long...
    
    161 161
     //                .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) >0")
    

  • t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
    ... ... @@ -37,11 +37,11 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
    37 37
         /**
    
    38 38
          * Obtains all vessel simple types used by all trips in the database.
    
    39 39
          *
    
    40
    -     * @param sampleOnly if null no filter else filter on value
    
    40
    +     * @param samplesOnly if null no filter else filter on value
    
    41 41
          * @return the set of used vessel simple types in trips in the database
    
    42 42
          * @throws TopiaException if any problem while querying the database
    
    43 43
          */
    
    44
    -    public Set<E> findAllUsedInTrip(Boolean sampleOnly) throws TopiaException {
    
    44
    +    public Set<E> findAllUsedInTrip(Boolean samplesOnly) throws TopiaException {
    
    45 45
     
    
    46 46
     //        TopiaQuery query = createQuery("vst")
    
    47 47
     //                .addFrom(Trip.class, "t")
    
    ... ... @@ -50,8 +50,8 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
    50 50
     //                          Vessel.PROPERTY_VESSEL_TYPE + "." +
    
    51 51
     //                          VesselType.PROPERTY_VESSEL_SIMPLE_TYPE + " = vst.id");
    
    52 52
     
    
    53
    -        String sampleOnlyFilter = sampleOnly == null ? "" : (" AND t.sampleOnly = " + sampleOnly);
    
    54
    -        String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + sampleOnlyFilter;
    
    53
    +        String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
    
    54
    +        String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + samplesOnlyFilter;
    
    55 55
             return new HashSet<>(findAll(hql));
    
    56 56
     //        return T3EntityHelper.querytoSet(hql, this);
    
    57 57
         }
    

  • t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
    ... ... @@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
    25 25
     import com.google.common.collect.Maps;
    
    26 26
     import fr.ird.t3.entities.data.Activity;
    
    27 27
     import fr.ird.t3.entities.data.CompleteTrip;
    
    28
    +import fr.ird.t3.entities.data.Route;
    
    28 29
     import fr.ird.t3.entities.data.Sample;
    
    29 30
     import fr.ird.t3.entities.data.Trip;
    
    30 31
     import fr.ird.t3.entities.data.Well;
    
    ... ... @@ -167,6 +168,9 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
    167 168
                 // trip decorator
    
    168 169
                 registerJXPathDecorator(locale, Trip.class, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY");
    
    169 170
     
    
    171
    +            // route decorator
    
    172
    +            registerJXPathDecorator(locale, Route.class, "${trip.vesselLabel}$s - ${trip.landingDate}$td/%2$tm/%2$tY - ${date}$td/%3$tm/%3$tY");
    
    173
    +
    
    170 174
                 // trip (with topiaid) decorator
    
    171 175
                 registerJXPathDecorator(locale, Trip.class, WITH_ID, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY [${topiaId}$s]");
    
    172 176
     
    

  • t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
    1
    +package fr.ird.t3.services.migration;
    
    2
    +
    
    3
    +/*
    
    4
    + * #%L
    
    5
    + * T3 :: Domain
    
    6
    + * %%
    
    7
    + * Copyright (C) 2010 - 2017 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 Affero General Public License as published by
    
    11
    + * the Free Software Foundation, either version 3 of the License, or
    
    12
    + * (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 Affero General Public License
    
    20
    + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    21
    + * #L%
    
    22
    + */
    
    23
    +
    
    24
    +import com.google.auto.service.AutoService;
    
    25
    +import org.apache.commons.logging.Log;
    
    26
    +import org.apache.commons.logging.LogFactory;
    
    27
    +import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
    
    28
    +import org.nuiton.topia.persistence.TopiaException;
    
    29
    +import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    30
    +import org.nuiton.topia.persistence.support.TopiaSqlSupport;
    
    31
    +import org.nuiton.util.DateUtil;
    
    32
    +import org.nuiton.version.Versions;
    
    33
    +
    
    34
    +import java.sql.Connection;
    
    35
    +import java.sql.PreparedStatement;
    
    36
    +import java.sql.ResultSet;
    
    37
    +import java.sql.SQLException;
    
    38
    +import java.text.SimpleDateFormat;
    
    39
    +import java.util.Date;
    
    40
    +import java.util.LinkedHashSet;
    
    41
    +import java.util.List;
    
    42
    +import java.util.Set;
    
    43
    +
    
    44
    +/**
    
    45
    + * Created by tchemit on 18/02/2018.
    
    46
    + *
    
    47
    + * @author Tony Chemit - dev@tchemit.fr
    
    48
    + */
    
    49
    +@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
    
    50
    +public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
    
    51
    +
    
    52
    +    private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
    
    53
    +
    
    54
    +    public T3MigrationCallbackV2_2() {
    
    55
    +        super(Versions.valueOf("2.2"));
    
    56
    +    }
    
    57
    +
    
    58
    +    @Override
    
    59
    +    protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
    
    60
    +        addScript("07", "add-Route-table", queries);
    
    61
    +
    
    62
    +
    
    63
    +        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    
    64
    +
    
    65
    +        List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
    
    66
    +            @Override
    
    67
    +            public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    68
    +                return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
    
    69
    +            }
    
    70
    +
    
    71
    +            @Override
    
    72
    +            public String prepareResult(ResultSet set) throws SQLException {
    
    73
    +                return set.getString(1);
    
    74
    +            }
    
    75
    +        });
    
    76
    +
    
    77
    +        for (String tripId : tripList) {
    
    78
    +
    
    79
    +            int i = tripId.indexOf('#');
    
    80
    +            String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
    
    81
    +
    
    82
    +            log.info("Route prefix: " + routeIdPrefix);
    
    83
    +            List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
    
    84
    +                @Override
    
    85
    +                public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    86
    +                    PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
    
    87
    +                    preparedStatement.setString(1, tripId);
    
    88
    +                    return preparedStatement;
    
    89
    +                }
    
    90
    +
    
    91
    +                @Override
    
    92
    +                public TripActivity prepareResult(ResultSet set) throws SQLException {
    
    93
    +                    return new TripActivity(set.getString(1), set.getDate(2));
    
    94
    +                }
    
    95
    +            });
    
    96
    +
    
    97
    +
    
    98
    +            Set<Date> days = new LinkedHashSet<>();
    
    99
    +            int activityIndex = 0;
    
    100
    +            for (TripActivity activity : activityList) {
    
    101
    +
    
    102
    +                String dayDateStr = df.format(activity.date);
    
    103
    +                String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
    
    104
    +
    
    105
    +                if (days.add(activity.date)) {
    
    106
    +
    
    107
    +                    log.info(String.format("[%s] new Route: %s", tripId, routeId));
    
    108
    +                    // create new route
    
    109
    +                    queries.add(String.format("INSERT INTO Route(topiaId, topiaVersion, topiaCreateDate, trip, trip_idx, date) VALUES('%s', 0, CURRENT_TIMESTAMP, '%s', %d, to_date('%s', 'YYY-MM-DD'));", routeId, tripId, days.size() - 1, dayDateStr));
    
    110
    +                }
    
    111
    +                queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
    
    112
    +            }
    
    113
    +
    
    114
    +            if (!activityList.isEmpty()) {
    
    115
    +                queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
    
    116
    +            }
    
    117
    +        }
    
    118
    +
    
    119
    +        addScript("08", "remove-Trip-fields", queries);
    
    120
    +    }
    
    121
    +
    
    122
    +    private static class TripActivity {
    
    123
    +
    
    124
    +        private final String activity;
    
    125
    +        private final Date date;
    
    126
    +
    
    127
    +        private TripActivity(String activity, Date date) {
    
    128
    +            this.activity = activity;
    
    129
    +            this.date = DateUtil.getDay(date);
    
    130
    +        }
    
    131
    +    }
    
    132
    +
    
    133
    +}

  • t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- T3 :: Domain
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU Affero General Public License as published by
    
    9
    +-- the Free Software Foundation, either version 3 of the License, or
    
    10
    +-- (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU Affero General Public License
    
    18
    +-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19
    +-- #L%
    
    20
    +---
    
    21
    +CREATE TABLE Route( topiaid VARCHAR(255) PRIMARY KEY NOT NULL, topiaversion BIGINT NOT NULL, topiacreatedate TIMESTAMP NOT NULL, trip VARCHAR(255) NOT NULL, trip_idx INTEGER NOT NULL, date DATE NOT NULL, computedFishingTimeN0 REAL, computedSearchTimeN0 REAL);
    
    22
    +CREATE UNIQUE INDEX uk_route ON Route(trip, date);
    
    23
    +ALTER TABLE Route ADD CONSTRAINT fk_route_trip FOREIGN KEY (trip) REFERENCES Trip(topiaid);
    
    24
    +CREATE INDEX idx_route_trip ON Route(trip);
    
    25
    +
    
    26
    +ALTER TABLE Activity ADD COLUMN route VARCHAR(255);
    
    27
    +ALTER TABLE Activity ADD COLUMN route_idx INTEGER;
    
    28
    +ALTER TABLE Activity ADD CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
    
    29
    +CREATE INDEX idx_activity_route ON Activity(route);

  • t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
    1
    +---
    
    2
    +-- #%L
    
    3
    +-- T3 :: Domain
    
    4
    +-- %%
    
    5
    +-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
    
    6
    +-- %%
    
    7
    +-- This program is free software: you can redistribute it and/or modify
    
    8
    +-- it under the terms of the GNU Affero General Public License as published by
    
    9
    +-- the Free Software Foundation, either version 3 of the License, or
    
    10
    +-- (at your option) any later version.
    
    11
    +--
    
    12
    +-- This program is distributed in the hope that it will be useful,
    
    13
    +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14
    +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15
    +-- GNU General Public License for more details.
    
    16
    +--
    
    17
    +-- You should have received a copy of the GNU Affero General Public License
    
    18
    +-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    19
    +-- #L%
    
    20
    +---
    
    21
    +
    
    22
    +ALTER TABLE Activity DROP COLUMN trip;
    
    23
    +ALTER TABLE Activity DROP COLUMN trip_idx;
    
    24
    +ALTER TABLE Activity DROP COLUMN date;
    
    25
    +ALTER TABLE Trip DROP COLUMN computedfishingtimen0;
    
    26
    +ALTER TABLE Trip DROP COLUMN computedsearchtimen0;
    
    27
    +ALTER TABLE Trip DROP COLUMN computedtimeatsean0;
    
    28
    +ALTER TABLE Activity ALTER COLUMN route_idx SET NOT NULL;
    \ No newline at end of file

  • t3-domain/src/main/xmi/t3-persistence.properties
    ... ... @@ -22,11 +22,17 @@
    22 22
     model.tagValue.notGenerateToString=true
    
    23 23
     model.tagValue.generateOperatorForDAOHelper=true
    
    24 24
     model.tagValue.constantPrefix=PROPERTY_
    
    25
    -model.tagValue.version=2.1
    
    25
    +model.tagValue.version=2.2
    
    26 26
     model.tagValue.indexForeignKeys=true
    
    27 27
     
    
    28
    -fr.ird.t3.entities.data.Trip.attribute.activity.stereotype=ordered
    
    29
    -fr.ird.t3.entities.data.Trip.attribute.activity.tagvalue.orderBy=date
    
    28
    +fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
    
    29
    +fr.ird.t3.entities.data.Route.attribute.activity.stereotype=ordered
    
    30
    +
    
    31
    +fr.ird.t3.entities.data.Trip.attribute.route.tagvalue.orderBy=date
    
    32
    +fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date
    
    33
    +
    
    34
    +fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date
    
    35
    +fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time
    
    30 36
     
    
    31 37
     fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text
    
    32 38
     fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text
    

  • t3-domain/src/main/xmi/t3-persistence.zargo
    No preview for this file type
  • t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
    ... ... @@ -56,8 +56,8 @@ public class T3PersistenceFixtures {
    56 56
             return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
    
    57 57
         }
    
    58 58
     
    
    59
    -    public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean sampleOnly) {
    
    60
    -        return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, sampleOnly);
    
    59
    +    public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean samplesOnly) {
    
    60
    +        return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, samplesOnly);
    
    61 61
         }
    
    62 62
     
    
    63 63
         public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
    

  • t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
    ... ... @@ -55,11 +55,12 @@ import fr.ird.t3.io.input.access.T3AccessEntityMeta;
    55 55
     import fr.ird.t3.io.input.access.T3AccessEntityMetaProvider;
    
    56 56
     import fr.ird.t3.io.input.access.T3AccessReferentielEntityMeta;
    
    57 57
     import fr.ird.t3.io.input.access.type.IntToBoolean;
    
    58
    -import java.util.Date;
    
    59
    -import java.util.Set;
    
    60 58
     import org.apache.commons.logging.Log;
    
    61 59
     import org.apache.commons.logging.LogFactory;
    
    62 60
     
    
    61
    +import java.util.Date;
    
    62
    +import java.util.Set;
    
    63
    +
    
    63 64
     /**
    
    64 65
      * Provider of {@link T3AccessEntityMeta}.
    
    65 66
      *
    
    ... ... @@ -86,9 +87,7 @@ public class T3AccessEntityMetaProviderAvdth33 implements T3AccessEntityMetaProv
    86 87
                             Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
    
    87 88
                             Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
    
    88 89
                     },
    
    89
    -                new Object[]{
    
    90
    -                        Activity.PROPERTY_TRIP, Trip.class
    
    91
    -                },
    
    90
    +                new Object[]{ /* Nothing to do any longer */},
    
    92 91
                     Activity.PROPERTY_DATE, Date.class, "D_ACT",
    
    93 92
                     Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
    
    94 93
                     Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
    

  • t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
    ... ... @@ -163,7 +163,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
    163 163
                                 int nbUnsafe,
    
    164 164
                                 int nbSafeWithoutwell,
    
    165 165
                                 int nbUnsafeWithoutWell,
    
    166
    -                            boolean sampleOnly,
    
    166
    +                            boolean samplesOnly,
    
    167 167
                                 boolean canCreateVessel,
    
    168 168
                                 boolean createVirtualVessel) throws Exception {
    
    169 169
     
    
    ... ... @@ -172,7 +172,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
    172 172
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
    
    173 173
     
    
    174 174
                 AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    175
    -                    inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
    
    175
    +                    inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
    
    176 176
                 );
    
    177 177
                 T3ActionContext<AnalyzeInputSourceConfiguration> context =
    
    178 178
                         serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
    

  • t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
    ... ... @@ -115,14 +115,14 @@ public class ImportInputSourceActionIT implements T3AVDTHV33Test {
    115 115
         }
    
    116 116
     
    
    117 117
         public void testExecute(int nbSafe, int nbUnsafe,
    
    118
    -                            boolean sampleOnly,
    
    118
    +                            boolean samplesOnly,
    
    119 119
                                 boolean canCreateVessel,
    
    120 120
                                 boolean createVirtualVessel) throws Exception {
    
    121 121
     
    
    122 122
             if (msConfig.doTest(serviceContext.getTestName())) {
    
    123 123
     
    
    124 124
                 AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    125
    -                    inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
    
    125
    +                    inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
    
    126 126
                 );
    
    127 127
     
    
    128 128
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
    

  • t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
    ... ... @@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
    34 34
     import fr.ird.t3.entities.data.LocalMarketSampleWell;
    
    35 35
     import fr.ird.t3.entities.data.LocalMarketSurvey;
    
    36 36
     import fr.ird.t3.entities.data.Sample;
    
    37
    +import fr.ird.t3.entities.data.SampleSet;
    
    37 38
     import fr.ird.t3.entities.data.SampleSpecies;
    
    38 39
     import fr.ird.t3.entities.data.SampleSpeciesFrequency;
    
    39
    -import fr.ird.t3.entities.data.SampleSet;
    
    40 40
     import fr.ird.t3.entities.data.Trip;
    
    41 41
     import fr.ird.t3.entities.data.Well;
    
    42 42
     import fr.ird.t3.entities.data.WellPlan;
    
    ... ... @@ -98,9 +98,7 @@ public class T3AccessEntityMetaProviderAvdth35 implements T3AccessEntityMetaProv
    98 98
                             Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
    
    99 99
                             Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
    
    100 100
                     },
    
    101
    -                new Object[]{
    
    102
    -                        Activity.PROPERTY_TRIP, Trip.class
    
    103
    -                },
    
    101
    +                new Object[]{/* Nothing to do any longer */},
    
    104 102
                     Activity.PROPERTY_DATE, Date.class, "D_ACT",
    
    105 103
                     Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
    
    106 104
                     Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
    

  • t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
    ... ... @@ -165,7 +165,7 @@ public class AnalyzeInputSourceActionITSupport {
    165 165
                                 int nbUnsafe,
    
    166 166
                                 int nbSafeWithoutwell,
    
    167 167
                                 int nbUnsafeWithoutWell,
    
    168
    -                            boolean sampleOnly,
    
    168
    +                            boolean samplesOnly,
    
    169 169
                                 boolean canCreateVessel,
    
    170 170
                                 boolean createVirtualVessel) throws Exception {
    
    171 171
     
    
    ... ... @@ -174,7 +174,7 @@ public class AnalyzeInputSourceActionITSupport {
    174 174
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
    
    175 175
     
    
    176 176
                 AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    177
    -                    inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
    
    177
    +                    inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
    
    178 178
                 );
    
    179 179
                 T3ActionContext<AnalyzeInputSourceConfiguration> context =
    
    180 180
                         serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
    

  • t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
    ... ... @@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
    116 116
         }
    
    117 117
     
    
    118 118
         public void testExecute(int nbSafe, int nbUnsafe,
    
    119
    -                            boolean sampleOnly,
    
    119
    +                            boolean samplesOnly,
    
    120 120
                                 boolean canCreateVessel,
    
    121 121
                                 boolean createVirtualVessel) throws Exception {
    
    122 122
     
    
    123 123
             if (msConfig.doTest(serviceContext.getTestName())) {
    
    124 124
     
    
    125 125
                 AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    126
    -                    inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
    
    126
    +                    inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
    
    127 127
                 );
    
    128 128
     
    
    129 129
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
    

  • t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
    ... ... @@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
    34 34
     import fr.ird.t3.entities.data.LocalMarketSampleWell;
    
    35 35
     import fr.ird.t3.entities.data.LocalMarketSurvey;
    
    36 36
     import fr.ird.t3.entities.data.Sample;
    
    37
    +import fr.ird.t3.entities.data.SampleSet;
    
    37 38
     import fr.ird.t3.entities.data.SampleSpecies;
    
    38 39
     import fr.ird.t3.entities.data.SampleSpeciesFrequency;
    
    39
    -import fr.ird.t3.entities.data.SampleSet;
    
    40 40
     import fr.ird.t3.entities.data.Trip;
    
    41 41
     import fr.ird.t3.entities.data.Well;
    
    42 42
     import fr.ird.t3.entities.data.WellPlan;
    
    ... ... @@ -100,9 +100,7 @@ public class T3AccessEntityMetaProviderAvdth36 implements T3AccessEntityMetaProv
    100 100
                             Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
    
    101 101
                             Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
    
    102 102
                     },
    
    103
    -                new Object[]{
    
    104
    -                        Activity.PROPERTY_TRIP, Trip.class
    
    105
    -                },
    
    103
    +                new Object[]{ /* Nothing to do any longer */},
    
    106 104
                     Activity.PROPERTY_DATE, Date.class, "D_ACT",
    
    107 105
                     Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
    
    108 106
                     Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
    

  • t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
    ... ... @@ -168,7 +168,7 @@ public class AnalyzeInputSourceActionITSupport {
    168 168
                                 int nbUnsafe,
    
    169 169
                                 int nbSafeWithoutwell,
    
    170 170
                                 int nbUnsafeWithoutWell,
    
    171
    -                            boolean sampleOnly,
    
    171
    +                            boolean samplesOnly,
    
    172 172
                                 boolean canCreateVessel,
    
    173 173
                                 boolean createVirtualVessel) throws Exception {
    
    174 174
     
    
    ... ... @@ -177,7 +177,7 @@ public class AnalyzeInputSourceActionITSupport {
    177 177
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
    
    178 178
     
    
    179 179
                 AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    180
    -                    inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
    
    180
    +                    inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
    
    181 181
                 );
    
    182 182
                 T3ActionContext<AnalyzeInputSourceConfiguration> context =
    
    183 183
                         serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
    

  • t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
    ... ... @@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
    116 116
         }
    
    117 117
     
    
    118 118
         public void testExecute(int nbSafe, int nbUnsafe,
    
    119
    -                            boolean sampleOnly,
    
    119
    +                            boolean samplesOnly,
    
    120 120
                                 boolean canCreateVessel,
    
    121 121
                                 boolean createVirtualVessel) throws Exception {
    
    122 122
     
    
    123 123
             if (msConfig.doTest(serviceContext.getTestName())) {
    
    124 124
     
    
    125 125
                 AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
    
    126
    -                    inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
    
    126
    +                    inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
    
    127 127
                 );
    
    128 128
     
    
    129 129
                 T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();