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

Commits:

12 changed files:

Changes:

  • t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
    ... ... @@ -42,6 +42,13 @@ import fr.ird.t3.entities.reference.Vessel;
    42 42
     import fr.ird.t3.entities.type.T3Date;
    
    43 43
     import fr.ird.t3.entities.type.T3Point;
    
    44 44
     import fr.ird.t3.entities.type.T3PointImpl;
    
    45
    +import org.apache.commons.collections.CollectionUtils;
    
    46
    +import org.apache.commons.lang3.tuple.MutablePair;
    
    47
    +import org.apache.commons.logging.Log;
    
    48
    +import org.apache.commons.logging.LogFactory;
    
    49
    +import org.nuiton.topia.persistence.TopiaException;
    
    50
    +import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    51
    +
    
    45 52
     import java.io.Serializable;
    
    46 53
     import java.sql.Connection;
    
    47 54
     import java.sql.PreparedStatement;
    
    ... ... @@ -53,12 +60,6 @@ import java.util.Comparator;
    53 60
     import java.util.Date;
    
    54 61
     import java.util.List;
    
    55 62
     import java.util.Set;
    
    56
    -import org.apache.commons.collections.CollectionUtils;
    
    57
    -import org.apache.commons.lang3.tuple.MutablePair;
    
    58
    -import org.apache.commons.logging.Log;
    
    59
    -import org.apache.commons.logging.LogFactory;
    
    60
    -import org.nuiton.topia.persistence.TopiaException;
    
    61
    -import org.nuiton.topia.persistence.support.TopiaSqlQuery;
    
    62 63
     
    
    63 64
     /**
    
    64 65
      * Client implementation of the Trip dao.
    
    ... ... @@ -214,8 +215,8 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
    214 215
         }
    
    215 216
     
    
    216 217
         public List<Integer> findAllYearsUsedInTrip() throws TopiaException {
    
    217
    -        T3Date minDate = getFirstLandingDate();
    
    218
    -        T3Date maxDate = getLastLandingDate();
    
    218
    +        T3Date minDate = getFirstLandingDate(null);
    
    219
    +        T3Date maxDate = getLastLandingDate(null);
    
    219 220
             int minYear = minDate.getYear();
    
    220 221
             int maxYear = maxDate.getYear();
    
    221 222
             Set<Integer> years = Sets.newHashSet();
    
    ... ... @@ -227,9 +228,10 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
    227 228
             return result;
    
    228 229
         }
    
    229 230
     
    
    230
    -    public T3Date getFirstLandingDate() throws TopiaException {
    
    231
    +    public T3Date getFirstLandingDate(Boolean samplesOnly) throws TopiaException {
    
    231 232
     
    
    232
    -        String hql = " SELECT min(t.landingDate) FROM TripImpl t";
    
    233
    +        String samplesOnlyFilter = samplesOnly == null ? "" : (" WHERE t.samplesOnly = " + samplesOnly);
    
    234
    +        String hql = " SELECT min(t.landingDate) FROM TripImpl t" + samplesOnlyFilter;
    
    233 235
             Date date = findAnyOrNull(hql);
    
    234 236
     //        Date date = (Date) createQuery().
    
    235 237
     //                executeToObject(getContext(),
    
    ... ... @@ -243,9 +245,10 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
    243 245
             return result;
    
    244 246
         }
    
    245 247
     
    
    246
    -    public T3Date getLastLandingDate() throws TopiaException {
    
    248
    +    public T3Date getLastLandingDate(Boolean samplesOnly) throws TopiaException {
    
    247 249
     
    
    248
    -        String hql = " SELECT max(t.landingDate) FROM TripImpl t";
    
    250
    +        String samplesOnlyFilter = samplesOnly == null ? "" : (" WHERE t.samplesOnly = " + samplesOnly);
    
    251
    +        String hql = " SELECT max(t.landingDate) FROM TripImpl t" + samplesOnlyFilter;
    
    249 252
             Date date = findAnyOrNull(hql);
    
    250 253
     
    
    251 254
     //        Date date = (Date) createQuery().
    

  • t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
    ... ... @@ -59,6 +59,17 @@ public class ActivityImpl extends ActivityAbstract {
    59 59
         );
    
    60 60
     
    
    61 61
         protected Integer quadrant;
    
    62
    +    private transient Date date;
    
    63
    +
    
    64
    +    @Override
    
    65
    +    public Date getDate() {
    
    66
    +        return date != null ? date : getRoute().getDate();
    
    67
    +    }
    
    68
    +
    
    69
    +    @Override
    
    70
    +    public void setDate(Date date) {
    
    71
    +        this.date = date;
    
    72
    +    }
    
    62 73
     
    
    63 74
         @Override
    
    64 75
         public Trip getTrip() {
    

  • t3-domain/src/main/java/fr/ird/t3/entities/data/ComputedDataHelper.java
    ... ... @@ -53,6 +53,9 @@ public class ComputedDataHelper {
    53 53
         public static <E extends ComputedDataAware> void deleteComputedDataLevel0(Collection<E> entities) {
    
    54 54
             if (CollectionUtils.isNotEmpty(entities)) {
    
    55 55
                 for (E entity : entities) {
    
    56
    +                if (entity==null) {
    
    57
    +                    continue;
    
    58
    +                }
    
    56 59
                     entity.deleteComputedDataLevel0();
    
    57 60
                 }
    
    58 61
             }
    

  • t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
    ... ... @@ -25,10 +25,11 @@ import com.google.common.collect.ImmutableMap;
    25 25
     import com.google.common.collect.Sets;
    
    26 26
     import fr.ird.t3.entities.T3Functions;
    
    27 27
     import fr.ird.t3.entities.data.Trip;
    
    28
    +import org.nuiton.topia.persistence.TopiaException;
    
    29
    +
    
    28 30
     import java.util.Collection;
    
    29 31
     import java.util.HashSet;
    
    30 32
     import java.util.Set;
    
    31
    -import org.nuiton.topia.persistence.TopiaException;
    
    32 33
     
    
    33 34
     /**
    
    34 35
      * {@link Country} user dao operations.
    
    ... ... @@ -41,14 +42,14 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
    41 42
         /**
    
    42 43
          * Obtains all countries used as fleet for any trip in the database.
    
    43 44
          *
    
    45
    +     * @param samplesOnly if null no filter else filter on value
    
    44 46
          * @return the set of fleet countries used by any trip in the database
    
    45 47
          * @throws TopiaException if any problem while querying the database
    
    46 48
          */
    
    47
    -    public Set<E> findAllFleetUsedInTrip() throws TopiaException {
    
    49
    +    public Set<E> findAllFleetUsedInTrip(Boolean samplesOnly) throws TopiaException {
    
    48 50
     
    
    49
    -        String hql = "SELECT DISTINCT(c) " +
    
    50
    -                "FROM CountryImpl c, TripImpl t " +
    
    51
    -                "WHERE t.vessel.fleetCountry = c.id";
    
    51
    +        String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
    
    52
    +        String hql = "SELECT DISTINCT(c) FROM CountryImpl c, TripImpl t WHERE t.vessel.fleetCountry = c.id" + samplesOnlyFilter;
    
    52 53
     
    
    53 54
     //        TopiaQuery query = createQuery("c")
    
    54 55
     //                .addFrom(Trip.class, "t")
    

  • t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
    ... ... @@ -77,13 +77,13 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
    77 77
             for (String tripId : tripList) {
    
    78 78
     
    
    79 79
                 int i = tripId.indexOf('#');
    
    80
    -            String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
    
    80
    +            String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1).replace(".", "").replace("#", "") + "#";
    
    81 81
     
    
    82 82
                 log.info("Route prefix: " + routeIdPrefix);
    
    83 83
                 List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
    
    84 84
                     @Override
    
    85 85
                     public PreparedStatement prepareQuery(Connection connection) throws SQLException {
    
    86
    -                    PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
    
    86
    +                    PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ? ORDER BY date");
    
    87 87
                         preparedStatement.setString(1, tripId);
    
    88 88
                         return preparedStatement;
    
    89 89
                     }
    
    ... ... @@ -94,9 +94,8 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
    94 94
                     }
    
    95 95
                 });
    
    96 96
     
    
    97
    -
    
    98
    -            Set<Date> days = new LinkedHashSet<>();
    
    99 97
                 int activityIndex = 0;
    
    98
    +            Set<Date> days = new LinkedHashSet<>();
    
    100 99
                 for (TripActivity activity : activityList) {
    
    101 100
     
    
    102 101
                     String dayDateStr = df.format(activity.date);
    
    ... ... @@ -105,10 +104,10 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
    105 104
                     if (days.add(activity.date)) {
    
    106 105
     
    
    107 106
                         log.info(String.format("[%s] new Route: %s", tripId, routeId));
    
    108
    -                    // create new route
    
    107
    +                    activityIndex = 0;
    
    109 108
                         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 109
                     }
    
    111
    -                queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
    
    110
    +                queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activityIndex++, activity.activity));
    
    112 111
                 }
    
    113 112
     
    
    114 113
                 if (!activityList.isEmpty()) {
    

  • t3-domain/src/main/xmi/t3-persistence.zargo
    No preview for this file type
  • t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
    ... ... @@ -101,13 +101,13 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
    101 101
     
    
    102 102
             T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
    
    103 103
     
    
    104
    -        result = dao.getFirstLandingDate();
    
    104
    +        result = dao.getFirstLandingDate(null);
    
    105 105
             Assert.assertNotNull(result);
    
    106 106
             Assert.assertEquals(endDate, result);
    
    107 107
     
    
    108 108
             T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
    
    109 109
     
    
    110
    -        result = dao.getFirstLandingDate();
    
    110
    +        result = dao.getFirstLandingDate(null);
    
    111 111
             Assert.assertNotNull(result);
    
    112 112
             Assert.assertEquals(startDate, result);
    
    113 113
         }
    
    ... ... @@ -122,13 +122,13 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
    122 122
     
    
    123 123
             T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
    
    124 124
     
    
    125
    -        result = dao.getLastLandingDate();
    
    125
    +        result = dao.getLastLandingDate(null);
    
    126 126
             Assert.assertNotNull(result);
    
    127 127
             Assert.assertEquals(startDate, result);
    
    128 128
     
    
    129 129
             T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
    
    130 130
     
    
    131
    -        result = dao.getLastLandingDate();
    
    131
    +        result = dao.getLastLandingDate(null);
    
    132 132
             Assert.assertNotNull(result);
    
    133 133
             Assert.assertEquals(endDate, result);
    
    134 134
         }
    

  • t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
    ... ... @@ -63,7 +63,7 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest {
    63 63
     
    
    64 64
             T3PersistenceFixtures.newTrip(tx, vessel);
    
    65 65
     
    
    66
    -        Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip();
    
    66
    +        Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip(null);
    
    67 67
             Assert.assertNotNull(result);
    
    68 68
             Assert.assertEquals(1, result.size());
    
    69 69
             Assert.assertEquals(country, result.iterator().next());
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/data/level0/AbstractLevel0ConfigureAction.java
    ... ... @@ -67,7 +67,7 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
    67 67
         @InjectDecoratedBeans(beanType = VesselSimpleType.class)
    
    68 68
         protected Map<String, String> vesselSimpleTypes;
    
    69 69
     
    
    70
    -    @InjectDecoratedBeans(beanType = Country.class, pathIds = "configuration.")
    
    70
    +    @InjectDecoratedBeans(beanType = Country.class)
    
    71 71
         protected Map<String, String> fleets;
    
    72 72
     
    
    73 73
         protected AbstractLevel0ConfigureAction(Class<C> configurationType) {
    
    ... ... @@ -99,7 +99,7 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
    99 99
             injectOnly(InjectDecoratedBeans.class);
    
    100 100
         }
    
    101 101
     
    
    102
    -    public final String prepareConfiguration() throws Exception {
    
    102
    +    public final String prepareConfiguration() {
    
    103 103
     
    
    104 104
             if (!isConfigurationInSession() && !hasFieldErrors()) {
    
    105 105
     
    
    ... ... @@ -110,7 +110,7 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
    110 110
         }
    
    111 111
     
    
    112 112
         @Override
    
    113
    -    public final String execute() throws Exception {
    
    113
    +    public final String execute() {
    
    114 114
     
    
    115 115
             // init action context in session
    
    116 116
             prepareActionContext();
    
    ... ... @@ -136,14 +136,14 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
    136 136
          */
    
    137 137
         protected void loadDefaultConfiguration(C config) throws TopiaException {
    
    138 138
     
    
    139
    -        T3Date minDate = tripDAO.getFirstLandingDate();
    
    139
    +        T3Date minDate = tripDAO.getFirstLandingDate(false);
    
    140 140
             config.setMinDate(minDate);
    
    141 141
             config.setBeginDate(minDate);
    
    142
    -        T3Date maxDate = tripDAO.getLastLandingDate();
    
    142
    +        T3Date maxDate = tripDAO.getLastLandingDate(false);
    
    143 143
             config.setMaxDate(maxDate);
    
    144 144
             config.setEndDate(maxDate);
    
    145 145
             config.setVesselSimpleTypes(sortToList(vesselSimpleTypeDAO.findAllUsedInTrip(false)));
    
    146
    -        config.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip()));
    
    146
    +        config.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip(false)));
    
    147 147
     
    
    148 148
             if (log.isInfoEnabled()) {
    
    149 149
                 log.info("beginDate : " + config.getBeginDate());
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/data/level2/ConfigureLevel2Step1Action.java
    ... ... @@ -201,8 +201,8 @@ public class ConfigureLevel2Step1Action extends AbstractConfigureAction<Level2Co
    201 201
                 conf.setTimeStep(3);
    
    202 202
     
    
    203 203
                 // use first and last landing date
    
    204
    -            T3Date firstLandingDate = tripDAO.getFirstLandingDate();
    
    205
    -            T3Date lastLandingDate = tripDAO.getLastLandingDate();
    
    204
    +            T3Date firstLandingDate = tripDAO.getFirstLandingDate(null);
    
    205
    +            T3Date lastLandingDate = tripDAO.getLastLandingDate(null);
    
    206 206
                 conf.setMinDate(firstLandingDate);
    
    207 207
                 conf.setBeginDate(firstLandingDate);
    
    208 208
                 conf.setMaxDate(lastLandingDate);
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/data/level3/ConfigureLevel3Step1Action.java
    ... ... @@ -196,8 +196,8 @@ public class ConfigureLevel3Step1Action extends AbstractConfigureAction<Level3Co
    196 196
                 conf.setTimeStep(3);
    
    197 197
     
    
    198 198
                 // use first and last landing date
    
    199
    -            T3Date firstLandingDate = tripDAO.getFirstLandingDate();
    
    200
    -            T3Date lastLandingDate = tripDAO.getLastLandingDate();
    
    199
    +            T3Date firstLandingDate = tripDAO.getFirstLandingDate(null);
    
    200
    +            T3Date lastLandingDate = tripDAO.getLastLandingDate(null);
    
    201 201
                 conf.setMinDate(firstLandingDate);
    
    202 202
                 conf.setBeginDate(firstLandingDate);
    
    203 203
                 conf.setMaxDate(lastLandingDate);
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java
    ... ... @@ -135,15 +135,15 @@ public class ExportConfigureAction extends AbstractConfigureAction<ExportConfigu
    135 135
     
    
    136 136
                 // grab data and store once for all in configuration
    
    137 137
     
    
    138
    -            T3Date beginDate = tripDAO.getFirstLandingDate();
    
    138
    +            T3Date beginDate = tripDAO.getFirstLandingDate(null);
    
    139 139
                 conf.setMinDate(beginDate);
    
    140 140
                 conf.setBeginDate(beginDate);
    
    141 141
     
    
    142
    -            T3Date endDate = tripDAO.getLastLandingDate();
    
    142
    +            T3Date endDate = tripDAO.getLastLandingDate(null);
    
    143 143
                 conf.setMaxDate(endDate);
    
    144 144
                 conf.setEndDate(endDate);
    
    145 145
     
    
    146
    -            conf.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip()));
    
    146
    +            conf.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip(null)));
    
    147 147
     
    
    148 148
                 conf.setOceans(sortToList(oceanDAO.findAllUsedInActivity()));
    
    149 149