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

Commits:

3 changed files:

Changes:

  • t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java
    ... ... @@ -32,7 +32,6 @@ import fr.ird.t3.entities.T3UserTopiaPersistenceContext;
    32 32
     import fr.ird.t3.entities.data.TripTopiaDao;
    
    33 33
     import fr.ird.t3.entities.reference.Idable;
    
    34 34
     import fr.ird.t3.entities.reference.Ocean;
    
    35
    -import fr.ird.t3.entities.reference.OceanImpl;
    
    36 35
     import fr.ird.t3.services.DecoratorService;
    
    37 36
     import fr.ird.t3.services.DefaultT3ServiceContext;
    
    38 37
     import fr.ird.t3.services.FreeMarkerService;
    
    ... ... @@ -343,6 +342,8 @@ public class T3ActionSupport extends ActionSupport implements T3TopiaPersistence
    343 342
     
    
    344 343
         protected TripListModel loadTripListModel(TripTopiaDao tripDAO) throws TopiaException {
    
    345 344
     
    
    345
    +        TripTopiaDao.EMPTY_OCEAN.setLabel1(t("t3.common.nullOcean"));
    
    346
    +
    
    346 347
             long t0 = TimeLog.getTime();
    
    347 348
             if (log.isInfoEnabled()) {
    
    348 349
                 log.info("Loading tripListModel...");
    
    ... ... @@ -357,24 +358,7 @@ public class T3ActionSupport extends ActionSupport implements T3TopiaPersistence
    357 358
     
    
    358 359
             List<Ocean> allOceans = new ArrayList<>(allByOcean.keySet());
    
    359 360
     
    
    360
    -        if (allOceans.contains(TripTopiaDao.EMPTY_OCEAN)) {
    
    361
    -
    
    362
    -            // there is some trips with no oceans
    
    363
    -            Ocean nullOcean = new OceanImpl();
    
    364
    -            nullOcean.setLabel1(t("t3.common.nullOcean"));
    
    365
    -            nullOcean.setTopiaId("null");
    
    366
    -
    
    367
    -            Collection<String> ids = allByOcean.get(TripTopiaDao.EMPTY_OCEAN);
    
    368
    -            if (log.isInfoEnabled()) {
    
    369
    -                log.info(String.format("Add a nullOcean : %s for %d trip(s).", nullOcean.getLabel1(), ids.size()));
    
    370
    -            }
    
    371
    -            allOceans.remove(null);
    
    372
    -            allOceans.add(nullOcean);
    
    373
    -
    
    374
    -            allByOcean.putAll(nullOcean, ids);
    
    375
    -            allByOcean.removeAll(TripTopiaDao.EMPTY_OCEAN);
    
    376
    -        }
    
    377
    -        TIME_LOG.log(t0, String.format("loadTripListModel for %d trips.", result.getNbTrips()));
    
    361
    +        TIME_LOG.log(t0, String.format("loadTripListModel for %d trip(s) (%d ocean(s)).", result.getNbTrips(), allOceans.size()));
    
    378 362
     
    
    379 363
             allOceans = sortToList(allOceans);
    
    380 364
             result.setOceans(allOceans);
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/admin/TripListAction.java
    ... ... @@ -41,38 +41,38 @@ import org.apache.commons.logging.LogFactory;
    41 41
      */
    
    42 42
     public class TripListAction extends T3ActionSupport {
    
    43 43
     
    
    44
    -    protected static final Log log = LogFactory.getLog(TripListAction.class);
    
    44
    +    private static final Log log = LogFactory.getLog(TripListAction.class);
    
    45 45
     
    
    46 46
         private static final long serialVersionUID = 1L;
    
    47 47
     
    
    48 48
         @InjectDAO(entityType = Trip.class)
    
    49
    -    protected transient TripTopiaDao tripDAO;
    
    49
    +    private transient TripTopiaDao tripDAO;
    
    50 50
     
    
    51 51
         @InjectFromDAO(entityType = Trip.class, method = "findAllYearsUsedInTrip")
    
    52
    -    protected Collection<Integer> allYears;
    
    52
    +    private Collection<Integer> allYears;
    
    53 53
     
    
    54 54
         @InjectFromDAO(entityType = Country.class, method = "findAllFleetUsedInTrip")
    
    55
    -    protected Collection<Country> allFleets;
    
    55
    +    private Collection<Country> allFleets;
    
    56 56
     
    
    57 57
         @InjectFromDAO(entityType = Country.class, method = "findAllFlagUsedInTrip")
    
    58
    -    protected Collection<Country> allFlags;
    
    58
    +    private Collection<Country> allFlags;
    
    59 59
     
    
    60 60
         @InjectFromDAO(entityType = Vessel.class, method = "findAllUsedInTrip")
    
    61
    -    protected Collection<Vessel> allVessels;
    
    61
    +    private Collection<Vessel> allVessels;
    
    62 62
     
    
    63
    -    protected Map<String, String> years;
    
    63
    +    private Map<String, String> years;
    
    64 64
     
    
    65
    -    protected Map<String, String> oceans;
    
    65
    +    private Map<String, String> oceans;
    
    66 66
     
    
    67
    -    protected Map<String, String> fleets;
    
    67
    +    private Map<String, String> fleets;
    
    68 68
     
    
    69
    -    protected Map<String, String> flags;
    
    69
    +    private Map<String, String> flags;
    
    70 70
     
    
    71
    -    protected Map<String, String> vessels;
    
    71
    +    private Map<String, String> vessels;
    
    72 72
     
    
    73
    -    protected TripListModel tripListModel;
    
    73
    +    private TripListModel tripListModel;
    
    74 74
     
    
    75
    -    protected boolean back;
    
    75
    +    private boolean back;
    
    76 76
     
    
    77 77
         public Map<String, String> getYears() {
    
    78 78
             return years;
    

  • t3-web/src/main/java/fr/ird/t3/web/actions/json/GetTripsAction.java
    ... ... @@ -20,7 +20,6 @@
    20 20
      */
    
    21 21
     package fr.ird.t3.web.actions.json;
    
    22 22
     
    
    23
    -import com.google.common.collect.Lists;
    
    24 23
     import com.google.common.collect.Multimap;
    
    25 24
     import fr.ird.t3.entities.data.Trip;
    
    26 25
     import fr.ird.t3.entities.data.TripDTO;
    
    ... ... @@ -33,18 +32,18 @@ import fr.ird.t3.entities.reference.Vessel;
    33 32
     import fr.ird.t3.entities.reference.VesselTopiaDao;
    
    34 33
     import fr.ird.t3.services.ioc.InjectDAO;
    
    35 34
     import fr.ird.t3.web.actions.admin.TripListModel;
    
    36
    -import java.util.ArrayList;
    
    37
    -import java.util.Collection;
    
    38
    -import java.util.List;
    
    39 35
     import org.apache.commons.collections.CollectionUtils;
    
    40 36
     import org.apache.commons.logging.Log;
    
    41 37
     import org.apache.commons.logging.LogFactory;
    
    42 38
     import org.nuiton.topia.persistence.TopiaDao;
    
    43 39
     import org.nuiton.topia.persistence.TopiaEntity;
    
    44
    -import org.nuiton.topia.persistence.TopiaException;
    
    45 40
     import org.nuiton.util.PagerBeanUtil;
    
    46 41
     import org.nuiton.util.TimeLog;
    
    47 42
     
    
    43
    +import java.util.ArrayList;
    
    44
    +import java.util.Collection;
    
    45
    +import java.util.List;
    
    46
    +
    
    48 47
     /**
    
    49 48
      * Obtains a list of trips.
    
    50 49
      *
    
    ... ... @@ -54,32 +53,25 @@ import org.nuiton.util.TimeLog;
    54 53
     public class GetTripsAction extends AbstractJSONPaginedAction {
    
    55 54
     
    
    56 55
         private static final long serialVersionUID = 1L;
    
    57
    -
    
    58
    -    /** Logger. */
    
    59 56
         private static final Log log = LogFactory.getLog(GetTripsAction.class);
    
    60
    -
    
    61 57
         private static final TimeLog TIME_LOG = new TimeLog(GetTripsAction.class);
    
    62 58
     
    
    63 59
         @InjectDAO(entityType = Trip.class)
    
    64
    -    protected transient TripTopiaDao tripDAO;
    
    65
    -
    
    60
    +    private transient TripTopiaDao tripDAO;
    
    66 61
         @InjectDAO(entityType = Ocean.class)
    
    67
    -    protected transient OceanTopiaDao oceanDAO;
    
    68
    -
    
    62
    +    private transient OceanTopiaDao oceanDAO;
    
    69 63
         @InjectDAO(entityType = Country.class)
    
    70
    -    protected transient CountryTopiaDao countryDAO;
    
    71
    -
    
    64
    +    private transient CountryTopiaDao countryDAO;
    
    72 65
         @InjectDAO(entityType = Vessel.class)
    
    73
    -    protected transient VesselTopiaDao vesselDAO;
    
    66
    +    private transient VesselTopiaDao vesselDAO;
    
    74 67
     
    
    75
    -    protected List<TripDTO> trips;
    
    68
    +    private TripListModel model;
    
    69
    +    private List<TripDTO> trips;
    
    76 70
     
    
    77 71
         public List<TripDTO> getTrips() {
    
    78 72
             return trips;
    
    79 73
         }
    
    80 74
     
    
    81
    -    protected TripListModel model;
    
    82
    -
    
    83 75
         @Override
    
    84 76
         public String execute() throws Exception {
    
    85 77
     
    
    ... ... @@ -102,17 +94,17 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    102 94
     
    
    103 95
                 List<String> oceanIds = model.getOceanIds();
    
    104 96
     
    
    105
    -            allTripIds = Lists.newArrayList();
    
    97
    +            allTripIds = new ArrayList<>();
    
    106 98
     
    
    107 99
                 if (CollectionUtils.isNotEmpty(oceanIds)) {
    
    108 100
                     for (String oceanId : oceanIds) {
    
    109 101
     
    
    110 102
                         Ocean ocean;
    
    111 103
     
    
    112
    -                    if ("null".equals(oceanId)) {
    
    113
    -                        ocean = null;
    
    104
    +                    if (TripTopiaDao.EMPTY_OCEAN.getTopiaId().equals(oceanId)) {
    
    105
    +                        ocean = TripTopiaDao.EMPTY_OCEAN;
    
    114 106
                         } else {
    
    115
    -                        ocean = oceanDAO.findByTopiaId(oceanId);
    
    107
    +                        ocean = oceanDAO.forTopiaIdEquals(oceanId).findUnique();
    
    116 108
                         }
    
    117 109
                         Collection<String> allByOcean = tripsByOcean.get(ocean);
    
    118 110
                         allTripIds.addAll(allByOcean);
    
    ... ... @@ -120,7 +112,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    120 112
                 }
    
    121 113
             } else {
    
    122 114
     
    
    123
    -            allTripIds = Lists.newArrayList(tripsByOcean.values());
    
    115
    +            allTripIds = new ArrayList<>(tripsByOcean.values());
    
    124 116
             }
    
    125 117
     
    
    126 118
             if (log.isInfoEnabled()) {
    
    ... ... @@ -130,7 +122,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    130 122
             t0 = TimeLog.getTime();
    
    131 123
     
    
    132 124
             if (CollectionUtils.isEmpty(allTripIds)) {
    
    133
    -            allTrips = Lists.newArrayList();
    
    125
    +            allTrips = new ArrayList<>();
    
    134 126
             } else {
    
    135 127
                 allTrips = tripDAO.findAllByIds(allTripIds);
    
    136 128
             }
    
    ... ... @@ -142,20 +134,15 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    142 134
                 filterYears(allTrips);
    
    143 135
             }
    
    144 136
             if (log.isInfoEnabled()) {
    
    145
    -            log.info("Nb total trips (after year filter) " + allTrips.size());
    
    137
    +            log.info(String.format("Nb total trips (after year filter) %d", allTrips.size()));
    
    146 138
             }
    
    147 139
     
    
    148
    -        if (CollectionUtils.isNotEmpty(allTrips) &&
    
    149
    -                model.isVesselFilter() ||
    
    150
    -                model.isFlagFilter() ||
    
    151
    -                model.isFleetFilter()) {
    
    152
    -
    
    140
    +        if (CollectionUtils.isNotEmpty(allTrips) && model.isVesselFilter() || model.isFlagFilter() || model.isFleetFilter()) {
    
    153 141
                 filterVessels(allTrips);
    
    154 142
             }
    
    155 143
     
    
    156 144
             if (log.isInfoEnabled()) {
    
    157
    -            log.info("Nb total trips (after vessel / flag / fleet filter) " +
    
    158
    -                             allTrips.size());
    
    145
    +            log.info(String.format("Nb total trips (after vessel / flag / fleet filter) %d", allTrips.size()));
    
    159 146
             }
    
    160 147
     
    
    161 148
             TIME_LOG.log(t0, "all filter");
    
    ... ... @@ -192,7 +179,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    192 179
             }
    
    193 180
         }
    
    194 181
     
    
    195
    -    private void filterVessels(List<Trip> allTrips) throws TopiaException {
    
    182
    +    private void filterVessels(List<Trip> allTrips) {
    
    196 183
     
    
    197 184
     
    
    198 185
             Collection<Vessel> vessels = VesselTopiaDao.getAllVessels(allTrips);
    
    ... ... @@ -270,9 +257,8 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    270 257
             return pager.getRecords();
    
    271 258
         }
    
    272 259
     
    
    273
    -    protected <E extends TopiaEntity> Collection<E> loadEntities(TopiaDao<E> dao,
    
    274
    -                                                                 Iterable<String> ids) throws TopiaException {
    
    275
    -        Collection<E> result = Lists.newArrayList();
    
    260
    +    protected <E extends TopiaEntity> Collection<E> loadEntities(TopiaDao<E> dao, Iterable<String> ids) {
    
    261
    +        Collection<E> result = new ArrayList<>();
    
    276 262
             for (String id : ids) {
    
    277 263
                 E e = dao.forTopiaIdEquals(id).findUnique();
    
    278 264
                 result.add(e);
    
    ... ... @@ -281,11 +267,8 @@ public class GetTripsAction extends AbstractJSONPaginedAction {
    281 267
         }
    
    282 268
     
    
    283 269
         protected <E> List<E> getPageFromList(List<E> elements) {
    
    284
    -
    
    285 270
             PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager);
    
    286 271
             List<E> subList = PagerBeanUtil.getPage(elements, pager.getPageIndex(), pager.getPageSize());
    
    287
    -        List<E> result = new ArrayList<E>(subList);
    
    288
    -
    
    289
    -        return result;
    
    272
    +        return new ArrayList<>(subList);
    
    290 273
         }
    
    291 274
     }