[Git][ultreiaio/ird-t3][develop] Fix loading trips with no ocean
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: 19e6e2e5 by Tony CHEMIT at 2018-02-21T16:15:01+01:00 Fix loading trips with no ocean - - - - - 3 changed files: - t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java - t3-web/src/main/java/fr/ird/t3/web/actions/admin/TripListAction.java - t3-web/src/main/java/fr/ird/t3/web/actions/json/GetTripsAction.java Changes: ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java @@ -32,7 +32,6 @@ import fr.ird.t3.entities.T3UserTopiaPersistenceContext; import fr.ird.t3.entities.data.TripTopiaDao; import fr.ird.t3.entities.reference.Idable; import fr.ird.t3.entities.reference.Ocean; -import fr.ird.t3.entities.reference.OceanImpl; import fr.ird.t3.services.DecoratorService; import fr.ird.t3.services.DefaultT3ServiceContext; import fr.ird.t3.services.FreeMarkerService; @@ -343,6 +342,8 @@ public class T3ActionSupport extends ActionSupport implements T3TopiaPersistence protected TripListModel loadTripListModel(TripTopiaDao tripDAO) throws TopiaException { + TripTopiaDao.EMPTY_OCEAN.setLabel1(t("t3.common.nullOcean")); + long t0 = TimeLog.getTime(); if (log.isInfoEnabled()) { log.info("Loading tripListModel..."); @@ -357,24 +358,7 @@ public class T3ActionSupport extends ActionSupport implements T3TopiaPersistence List<Ocean> allOceans = new ArrayList<>(allByOcean.keySet()); - if (allOceans.contains(TripTopiaDao.EMPTY_OCEAN)) { - - // there is some trips with no oceans - Ocean nullOcean = new OceanImpl(); - nullOcean.setLabel1(t("t3.common.nullOcean")); - nullOcean.setTopiaId("null"); - - Collection<String> ids = allByOcean.get(TripTopiaDao.EMPTY_OCEAN); - if (log.isInfoEnabled()) { - log.info(String.format("Add a nullOcean : %s for %d trip(s).", nullOcean.getLabel1(), ids.size())); - } - allOceans.remove(null); - allOceans.add(nullOcean); - - allByOcean.putAll(nullOcean, ids); - allByOcean.removeAll(TripTopiaDao.EMPTY_OCEAN); - } - TIME_LOG.log(t0, String.format("loadTripListModel for %d trips.", result.getNbTrips())); + TIME_LOG.log(t0, String.format("loadTripListModel for %d trip(s) (%d ocean(s)).", result.getNbTrips(), allOceans.size())); allOceans = sortToList(allOceans); result.setOceans(allOceans); ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/admin/TripListAction.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/admin/TripListAction.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/admin/TripListAction.java @@ -41,38 +41,38 @@ import org.apache.commons.logging.LogFactory; */ public class TripListAction extends T3ActionSupport { - protected static final Log log = LogFactory.getLog(TripListAction.class); + private static final Log log = LogFactory.getLog(TripListAction.class); private static final long serialVersionUID = 1L; @InjectDAO(entityType = Trip.class) - protected transient TripTopiaDao tripDAO; + private transient TripTopiaDao tripDAO; @InjectFromDAO(entityType = Trip.class, method = "findAllYearsUsedInTrip") - protected Collection<Integer> allYears; + private Collection<Integer> allYears; @InjectFromDAO(entityType = Country.class, method = "findAllFleetUsedInTrip") - protected Collection<Country> allFleets; + private Collection<Country> allFleets; @InjectFromDAO(entityType = Country.class, method = "findAllFlagUsedInTrip") - protected Collection<Country> allFlags; + private Collection<Country> allFlags; @InjectFromDAO(entityType = Vessel.class, method = "findAllUsedInTrip") - protected Collection<Vessel> allVessels; + private Collection<Vessel> allVessels; - protected Map<String, String> years; + private Map<String, String> years; - protected Map<String, String> oceans; + private Map<String, String> oceans; - protected Map<String, String> fleets; + private Map<String, String> fleets; - protected Map<String, String> flags; + private Map<String, String> flags; - protected Map<String, String> vessels; + private Map<String, String> vessels; - protected TripListModel tripListModel; + private TripListModel tripListModel; - protected boolean back; + private boolean back; public Map<String, String> getYears() { return years; ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/json/GetTripsAction.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetTripsAction.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetTripsAction.java @@ -20,7 +20,6 @@ */ package fr.ird.t3.web.actions.json; -import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ird.t3.entities.data.Trip; import fr.ird.t3.entities.data.TripDTO; @@ -33,18 +32,18 @@ import fr.ird.t3.entities.reference.Vessel; import fr.ird.t3.entities.reference.VesselTopiaDao; import fr.ird.t3.services.ioc.InjectDAO; import fr.ird.t3.web.actions.admin.TripListModel; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaException; import org.nuiton.util.PagerBeanUtil; import org.nuiton.util.TimeLog; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + /** * Obtains a list of trips. * @@ -54,32 +53,25 @@ import org.nuiton.util.TimeLog; public class GetTripsAction extends AbstractJSONPaginedAction { private static final long serialVersionUID = 1L; - - /** Logger. */ private static final Log log = LogFactory.getLog(GetTripsAction.class); - private static final TimeLog TIME_LOG = new TimeLog(GetTripsAction.class); @InjectDAO(entityType = Trip.class) - protected transient TripTopiaDao tripDAO; - + private transient TripTopiaDao tripDAO; @InjectDAO(entityType = Ocean.class) - protected transient OceanTopiaDao oceanDAO; - + private transient OceanTopiaDao oceanDAO; @InjectDAO(entityType = Country.class) - protected transient CountryTopiaDao countryDAO; - + private transient CountryTopiaDao countryDAO; @InjectDAO(entityType = Vessel.class) - protected transient VesselTopiaDao vesselDAO; + private transient VesselTopiaDao vesselDAO; - protected List<TripDTO> trips; + private TripListModel model; + private List<TripDTO> trips; public List<TripDTO> getTrips() { return trips; } - protected TripListModel model; - @Override public String execute() throws Exception { @@ -102,17 +94,17 @@ public class GetTripsAction extends AbstractJSONPaginedAction { List<String> oceanIds = model.getOceanIds(); - allTripIds = Lists.newArrayList(); + allTripIds = new ArrayList<>(); if (CollectionUtils.isNotEmpty(oceanIds)) { for (String oceanId : oceanIds) { Ocean ocean; - if ("null".equals(oceanId)) { - ocean = null; + if (TripTopiaDao.EMPTY_OCEAN.getTopiaId().equals(oceanId)) { + ocean = TripTopiaDao.EMPTY_OCEAN; } else { - ocean = oceanDAO.findByTopiaId(oceanId); + ocean = oceanDAO.forTopiaIdEquals(oceanId).findUnique(); } Collection<String> allByOcean = tripsByOcean.get(ocean); allTripIds.addAll(allByOcean); @@ -120,7 +112,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction { } } else { - allTripIds = Lists.newArrayList(tripsByOcean.values()); + allTripIds = new ArrayList<>(tripsByOcean.values()); } if (log.isInfoEnabled()) { @@ -130,7 +122,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction { t0 = TimeLog.getTime(); if (CollectionUtils.isEmpty(allTripIds)) { - allTrips = Lists.newArrayList(); + allTrips = new ArrayList<>(); } else { allTrips = tripDAO.findAllByIds(allTripIds); } @@ -142,20 +134,15 @@ public class GetTripsAction extends AbstractJSONPaginedAction { filterYears(allTrips); } if (log.isInfoEnabled()) { - log.info("Nb total trips (after year filter) " + allTrips.size()); + log.info(String.format("Nb total trips (after year filter) %d", allTrips.size())); } - if (CollectionUtils.isNotEmpty(allTrips) && - model.isVesselFilter() || - model.isFlagFilter() || - model.isFleetFilter()) { - + if (CollectionUtils.isNotEmpty(allTrips) && model.isVesselFilter() || model.isFlagFilter() || model.isFleetFilter()) { filterVessels(allTrips); } if (log.isInfoEnabled()) { - log.info("Nb total trips (after vessel / flag / fleet filter) " + - allTrips.size()); + log.info(String.format("Nb total trips (after vessel / flag / fleet filter) %d", allTrips.size())); } TIME_LOG.log(t0, "all filter"); @@ -192,7 +179,7 @@ public class GetTripsAction extends AbstractJSONPaginedAction { } } - private void filterVessels(List<Trip> allTrips) throws TopiaException { + private void filterVessels(List<Trip> allTrips) { Collection<Vessel> vessels = VesselTopiaDao.getAllVessels(allTrips); @@ -270,9 +257,8 @@ public class GetTripsAction extends AbstractJSONPaginedAction { return pager.getRecords(); } - protected <E extends TopiaEntity> Collection<E> loadEntities(TopiaDao<E> dao, - Iterable<String> ids) throws TopiaException { - Collection<E> result = Lists.newArrayList(); + protected <E extends TopiaEntity> Collection<E> loadEntities(TopiaDao<E> dao, Iterable<String> ids) { + Collection<E> result = new ArrayList<>(); for (String id : ids) { E e = dao.forTopiaIdEquals(id).findUnique(); result.add(e); @@ -281,11 +267,8 @@ public class GetTripsAction extends AbstractJSONPaginedAction { } protected <E> List<E> getPageFromList(List<E> elements) { - PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager); List<E> subList = PagerBeanUtil.getPage(elements, pager.getPageIndex(), pager.getPageSize()); - List<E> result = new ArrayList<E>(subList); - - return result; + return new ArrayList<>(subList); } } View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/19e6e2e502638a48564ef16caeac79416... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/19e6e2e502638a48564ef16caeac79416... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT