Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
9d608f1e
by Tony CHEMIT at 2018-02-20T19:29:19+01:00
-
92556d11
by Tony CHEMIT at 2018-02-20T20:40:10+01:00
-
9c95acac
by Tony CHEMIT at 2018-02-20T20:40:17+01:00
22 changed files:
- t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
- t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
- t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
- t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
- + t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
- + t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
- t3-domain/src/main/xmi/t3-persistence.properties
- t3-domain/src/main/xmi/t3-persistence.zargo
- + t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
- t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/HarbourTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/OceanTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/SpecieDAOImplTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselSimpleTypeTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselTopiaDaoTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
- t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
- t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
- t3-input-avdthv35/src/test/resources/t3-TopiaContextImpl.properties
- t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
Changes:
| ... | ... | @@ -36,6 +36,7 @@ import fr.ird.t3.entities.T3Functions; |
| 36 | 36 |
import fr.ird.t3.entities.T3Predicates;
|
| 37 | 37 |
import fr.ird.t3.entities.reference.Harbour;
|
| 38 | 38 |
import fr.ird.t3.entities.reference.Ocean;
|
| 39 |
+import fr.ird.t3.entities.reference.OceanImpl;
|
|
| 39 | 40 |
import fr.ird.t3.entities.reference.OceanTopiaDao;
|
| 40 | 41 |
import fr.ird.t3.entities.reference.Vessel;
|
| 41 | 42 |
import fr.ird.t3.entities.type.T3Date;
|
| ... | ... | @@ -127,19 +128,21 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao< |
| 127 | 128 |
// query = createQuery("t")
|
| 128 | 129 |
// .setSelect("t.id")
|
| 129 | 130 |
// .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
|
| 130 |
- 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";
|
|
| 131 | 132 |
// params = Collections.emptyList();
|
| 132 | 133 |
} else {
|
| 133 | 134 |
// query = new TopiaQuery(Activity.class, "a")
|
| 134 | 135 |
// .setSelect("distinct(a.trip.id)")
|
| 135 | 136 |
// .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
|
| 136 |
- 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";
|
|
| 137 | 138 |
paramsBuilder.put("ocean", ocean);
|
| 138 | 139 |
// params = Lists.<Object>newArrayList("ocean", ocean);
|
| 139 | 140 |
}
|
| 140 | 141 |
return findAll(hql, paramsBuilder.build());
|
| 141 | 142 |
}
|
| 142 | 143 |
|
| 144 |
+ public static final Ocean EMPTY_OCEAN = new OceanImpl();
|
|
| 145 |
+ |
|
| 143 | 146 |
public Multimap<Ocean, String> findAllIdsByOcean() throws TopiaException {
|
| 144 | 147 |
|
| 145 | 148 |
Set<Ocean> oceans = topiaDaoSupplier.getDao(Ocean.class, OceanTopiaDao.class).findAllUsedInActivity();
|
| ... | ... | @@ -154,7 +157,7 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao< |
| 154 | 157 |
// add trips with no ocean (http://forge.codelutin.com/issues/1134)
|
| 155 | 158 |
List<String> tripsWithNoOcean = findAllIdsByOcean(null);
|
| 156 | 159 |
if (CollectionUtils.isNotEmpty(tripsWithNoOcean)) {
|
| 157 |
- result.putAll(null, tripsWithNoOcean);
|
|
| 160 |
+ result.putAll(EMPTY_OCEAN, tripsWithNoOcean);
|
|
| 158 | 161 |
}
|
| 159 | 162 |
return result;
|
| 160 | 163 |
}
|
| ... | ... | @@ -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 |
|
| ... | ... | @@ -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 |
|
| ... | ... | @@ -480,4 +488,73 @@ public class TripImpl extends TripAbstract { |
| 480 | 488 |
ComputedDataHelper.deleteComputedDataLevel3(getWell());
|
| 481 | 489 |
}
|
| 482 | 490 |
|
| 491 |
+ @Override
|
|
| 492 |
+ public int sizeActivity() {
|
|
| 493 |
+ return (int) activityStream().count();
|
|
| 494 |
+ }
|
|
| 495 |
+ |
|
| 496 |
+ @Override
|
|
| 497 |
+ public boolean isActivityEmpty() {
|
|
| 498 |
+ return isRouteEmpty() || activityStream().count() == 0;
|
|
| 499 |
+ }
|
|
| 500 |
+ |
|
| 501 |
+ @Override
|
|
| 502 |
+ public boolean isActivityNotEmpty() {
|
|
| 503 |
+ return isRouteNotEmpty() && activityStream().count() > 0;
|
|
| 504 |
+ }
|
|
| 505 |
+ |
|
| 506 |
+ @Override
|
|
| 507 |
+ public List<Activity> getActivity() {
|
|
| 508 |
+ return activityStream().collect(Collectors.toList());
|
|
| 509 |
+ }
|
|
| 510 |
+ |
|
| 511 |
+ @Override
|
|
| 512 |
+ public void setActivity(List<Activity> activities) {
|
|
| 513 |
+ clearRoute();
|
|
| 514 |
+ for (Activity activity : activities) {
|
|
| 515 |
+ addActivity(activity);
|
|
| 516 |
+ }
|
|
| 517 |
+ }
|
|
| 518 |
+ |
|
| 519 |
+ @Override
|
|
| 520 |
+ public Activity getActivityByTopiaId(String topiaId) {
|
|
| 521 |
+ return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
|
|
| 522 |
+ }
|
|
| 523 |
+ |
|
| 524 |
+ @Override
|
|
| 525 |
+ public Collection<String> getActivityTopiaIds() {
|
|
| 526 |
+ return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
|
|
| 527 |
+ }
|
|
| 528 |
+ |
|
| 529 |
+ @Override
|
|
| 530 |
+ public void addActivity(Activity activity) {
|
|
| 531 |
+ Date date = DateUtil.getDay(activity.getDate());
|
|
| 532 |
+ Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
|
|
| 533 |
+ Route route;
|
|
| 534 |
+ if (optionalRoute.isPresent()) {
|
|
| 535 |
+ route = optionalRoute.get();
|
|
| 536 |
+ } else {
|
|
| 537 |
+ route = new RouteImpl();
|
|
| 538 |
+ route.setDate(date);
|
|
| 539 |
+ addRoute(route);
|
|
| 540 |
+ }
|
|
| 541 |
+ route.addActivity(activity);
|
|
| 542 |
+ }
|
|
| 543 |
+ |
|
| 544 |
+ @Override
|
|
| 545 |
+ public List<Route> getRoute() {
|
|
| 546 |
+ List<Route> route = super.getRoute();
|
|
| 547 |
+ if (route == null) {
|
|
| 548 |
+ setRoute(route = new LinkedList<>());
|
|
| 549 |
+ }
|
|
| 550 |
+ return route;
|
|
| 551 |
+ }
|
|
| 552 |
+ |
|
| 553 |
+ private Stream<Route> routeStream() {
|
|
| 554 |
+ return getRoute().stream();
|
|
| 555 |
+ }
|
|
| 556 |
+ |
|
| 557 |
+ private Stream<Activity> activityStream() {
|
|
| 558 |
+ return routeStream().flatMap(r -> r.getActivity().stream());
|
|
| 559 |
+ }
|
|
| 483 | 560 |
}
|
| ... | ... | @@ -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")
|
| 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 |
+ for (TripActivity activity : activityList) {
|
|
| 100 |
+ |
|
| 101 |
+ String dayDateStr = df.format(activity.date);
|
|
| 102 |
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
|
|
| 103 |
+ |
|
| 104 |
+ if (days.add(activity.date)) {
|
|
| 105 |
+ |
|
| 106 |
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
|
|
| 107 |
+ // create new route
|
|
| 108 |
+ queries.add(String.format("INSERT INTO Route(topiaId, topiaVersion, topiaCreateDate, trip, date) VALUES('%s', 0, CURRENT_TIMESTAMP, '%s', to_date('%s', 'YYY-MM-DD'));", routeId, tripId, dayDateStr));
|
|
| 109 |
+ }
|
|
| 110 |
+ queries.add(String.format("UPDATE Activity SET route = '%s', topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activity.activity));
|
|
| 111 |
+ }
|
|
| 112 |
+ |
|
| 113 |
+ if (!activityList.isEmpty()) {
|
|
| 114 |
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
|
|
| 115 |
+ }
|
|
| 116 |
+ }
|
|
| 117 |
+ |
|
| 118 |
+ queries.add("ALTER TABLE Activity DROP COLUMN trip;");
|
|
| 119 |
+ queries.add("ALTER TABLE Activity DROP COLUMN date;");
|
|
| 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 |
+}
|
| 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, date DATE NOT NULL, computedFishingTimeN0 REAL, computedSearchTimeN0 REAL, computedTimeAtSeaN0 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 CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
|
|
| 28 |
+CREATE INDEX idx_activity_route ON Activity(route);
|
| ... | ... | @@ -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
|
No preview for this file type
| 1 |
+package fr.ird.t3.entities;
|
|
| 2 |
+ |
|
| 3 |
+import fr.ird.t3.entities.data.Activity;
|
|
| 4 |
+import fr.ird.t3.entities.data.Trip;
|
|
| 5 |
+import fr.ird.t3.entities.reference.Country;
|
|
| 6 |
+import fr.ird.t3.entities.reference.Harbour;
|
|
| 7 |
+import fr.ird.t3.entities.reference.Ocean;
|
|
| 8 |
+import fr.ird.t3.entities.reference.Species;
|
|
| 9 |
+import fr.ird.t3.entities.reference.Vessel;
|
|
| 10 |
+import fr.ird.t3.entities.reference.VesselSimpleType;
|
|
| 11 |
+import fr.ird.t3.entities.reference.VesselType;
|
|
| 12 |
+ |
|
| 13 |
+import java.util.Date;
|
|
| 14 |
+import java.util.Objects;
|
|
| 15 |
+ |
|
| 16 |
+/**
|
|
| 17 |
+ * Created by tchemit on 20/02/2018.
|
|
| 18 |
+ *
|
|
| 19 |
+ * @author Tony Chemit - dev@tchemit.fr
|
|
| 20 |
+ */
|
|
| 21 |
+public class T3PersistenceFixtures {
|
|
| 22 |
+ |
|
| 23 |
+ public static Activity newActivity(T3TopiaPersistenceContext tx, Ocean ocean) {
|
|
| 24 |
+ return newActivity(tx, ocean, new Date());
|
|
| 25 |
+ }
|
|
| 26 |
+ |
|
| 27 |
+ public static Ocean newOcean(T3TopiaPersistenceContext tx) {
|
|
| 28 |
+ return newOcean(tx, 0);
|
|
| 29 |
+ }
|
|
| 30 |
+ |
|
| 31 |
+ public static Ocean newOcean(T3TopiaPersistenceContext tx, int code) {
|
|
| 32 |
+ return tx.getOceanDao().create(Ocean.PROPERTY_CODE, code);
|
|
| 33 |
+ }
|
|
| 34 |
+ |
|
| 35 |
+ public static Country newCountry(T3TopiaPersistenceContext tx, int code) {
|
|
| 36 |
+ return tx.getCountryDao().create(Country.PROPERTY_CODE, code);
|
|
| 37 |
+ }
|
|
| 38 |
+ |
|
| 39 |
+ public static Activity newActivity(T3TopiaPersistenceContext tx, Ocean ocean, Date date) {
|
|
| 40 |
+ return Objects.requireNonNull(tx.getActivityDao()).create(Activity.PROPERTY_OCEAN, Objects.requireNonNull(ocean), Activity.PROPERTY_DATE, Objects.requireNonNull(date));
|
|
| 41 |
+ }
|
|
| 42 |
+ |
|
| 43 |
+ public static Trip newTrip(T3TopiaPersistenceContext tx) {
|
|
| 44 |
+ return tx.getTripDao().create();
|
|
| 45 |
+ }
|
|
| 46 |
+ |
|
| 47 |
+ public static Trip newTrip(T3TopiaPersistenceContext tx, Vessel vessel) {
|
|
| 48 |
+ return tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
|
|
| 49 |
+ }
|
|
| 50 |
+ |
|
| 51 |
+ public static Trip newTrip(T3TopiaPersistenceContext tx, Harbour harbour) {
|
|
| 52 |
+ return tx.getTripDao().create(Trip.PROPERTY_LANDING_HARBOUR, harbour);
|
|
| 53 |
+ }
|
|
| 54 |
+ |
|
| 55 |
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date) {
|
|
| 56 |
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
|
|
| 57 |
+ }
|
|
| 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);
|
|
| 61 |
+ }
|
|
| 62 |
+ |
|
| 63 |
+ public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
|
|
| 64 |
+ return tx.getHarbourDao().create(Harbour.PROPERTY_CODE, code);
|
|
| 65 |
+ }
|
|
| 66 |
+ |
|
| 67 |
+ public static Species newSpecies(T3TopiaPersistenceContext tx, int code) {
|
|
| 68 |
+ return tx.getSpeciesDao().create(Species.PROPERTY_CODE, code);
|
|
| 69 |
+ }
|
|
| 70 |
+ |
|
| 71 |
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, int code) {
|
|
| 72 |
+ return tx.getVesselDao().create(Vessel.PROPERTY_CODE, code);
|
|
| 73 |
+ }
|
|
| 74 |
+ |
|
| 75 |
+ public static VesselType newVesselType(T3TopiaPersistenceContext tx, int code, VesselSimpleType vesselSimpleType) {
|
|
| 76 |
+ return tx.getVesselTypeDao().create(VesselType.PROPERTY_CODE, code, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType);
|
|
| 77 |
+ }
|
|
| 78 |
+ |
|
| 79 |
+ public static VesselSimpleType newVesselSimpleType(T3TopiaPersistenceContext tx, int code) {
|
|
| 80 |
+ return tx.getVesselSimpleTypeDao().create(VesselSimpleType.PROPERTY_CODE, code);
|
|
| 81 |
+ }
|
|
| 82 |
+ |
|
| 83 |
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, Country country, int code) {
|
|
| 84 |
+ return tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country, Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, code);
|
|
| 85 |
+ }
|
|
| 86 |
+ |
|
| 87 |
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, VesselType vesselType, int code) {
|
|
| 88 |
+ return tx.getVesselDao().create(Vessel.PROPERTY_VESSEL_TYPE, vesselType, Vessel.PROPERTY_CODE, code);
|
|
| 89 |
+ }
|
|
| 90 |
+}
|
| ... | ... | @@ -22,17 +22,19 @@ package fr.ird.t3.entities.data; |
| 22 | 22 |
|
| 23 | 23 |
import com.google.common.collect.Multimap;
|
| 24 | 24 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 25 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 25 | 26 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 26 | 27 |
import fr.ird.t3.entities.reference.Ocean;
|
| 27 |
-import fr.ird.t3.entities.reference.OceanTopiaDao;
|
|
| 28 | 28 |
import fr.ird.t3.entities.type.T3Date;
|
| 29 |
+import org.junit.Assert;
|
|
| 30 |
+import org.junit.Before;
|
|
| 31 |
+import org.junit.Test;
|
|
| 32 |
+ |
|
| 29 | 33 |
import java.util.Arrays;
|
| 30 | 34 |
import java.util.Collection;
|
| 35 |
+import java.util.Collections;
|
|
| 31 | 36 |
import java.util.Date;
|
| 32 | 37 |
import java.util.List;
|
| 33 |
-import org.junit.Assert;
|
|
| 34 |
-import org.junit.Before;
|
|
| 35 |
-import org.junit.Test;
|
|
| 36 | 38 |
|
| 37 | 39 |
/**
|
| 38 | 40 |
* Tests the trip dao {@link TripTopiaDao}.
|
| ... | ... | @@ -42,36 +44,23 @@ import org.junit.Test; |
| 42 | 44 |
*/
|
| 43 | 45 |
public class TripTopiaDaoTest extends AbstractDatabaseTest {
|
| 44 | 46 |
|
| 45 |
- T3TopiaPersistenceContext tx;
|
|
| 46 |
- |
|
| 47 |
- TripTopiaDao dao;
|
|
| 48 |
- |
|
| 49 |
- OceanTopiaDao oceanDAO;
|
|
| 50 |
- |
|
| 51 |
- ActivityTopiaDao activitDAO;
|
|
| 47 |
+ private T3TopiaPersistenceContext tx;
|
|
| 48 |
+ private TripTopiaDao dao;
|
|
| 52 | 49 |
|
| 53 | 50 |
@Before
|
| 54 |
- public void setUp() throws Exception {
|
|
| 55 |
- |
|
| 51 |
+ public void setUp() {
|
|
| 56 | 52 |
tx = beginTransaction();
|
| 57 | 53 |
dao = tx.getTripDao();
|
| 58 |
- oceanDAO = tx.getOceanDao();
|
|
| 59 |
- activitDAO = tx.getActivityDao();
|
|
| 60 | 54 |
}
|
| 61 | 55 |
|
| 62 | 56 |
@Test
|
| 63 |
- public void findAllBetweenLandingDate() throws Exception {
|
|
| 57 |
+ public void findAllBetweenLandingDate() {
|
|
| 64 | 58 |
|
| 65 | 59 |
T3Date startDate = T3Date.newDate(1, 2010);
|
| 66 | 60 |
T3Date endDate = T3Date.newDate(1, 2011);
|
| 67 | 61 |
|
| 68 |
- Trip trip = dao.create(Trip.PROPERTY_CODE, 0,
|
|
| 69 |
- Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate(),
|
|
| 70 |
- Trip.PROPERTY_SAMPLES_ONLY, false
|
|
| 71 |
- );
|
|
| 72 |
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1,
|
|
| 73 |
- Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate(),
|
|
| 74 |
- Trip.PROPERTY_SAMPLES_ONLY, true);
|
|
| 62 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate(), false);
|
|
| 63 |
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate(), true);
|
|
| 75 | 64 |
|
| 76 | 65 |
List<Trip> result;
|
| 77 | 66 |
|
| ... | ... | @@ -103,20 +92,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 103 | 92 |
}
|
| 104 | 93 |
|
| 105 | 94 |
@Test
|
| 106 |
- public void getFirstLandingDate() throws Exception {
|
|
| 95 |
+ public void getFirstLandingDate() {
|
|
| 107 | 96 |
|
| 108 | 97 |
T3Date startDate = T3Date.newDate(1, 2010);
|
| 109 | 98 |
T3Date endDate = T3Date.newDate(1, 2011);
|
| 110 | 99 |
|
| 111 | 100 |
T3Date result;
|
| 112 | 101 |
|
| 113 |
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
|
|
| 102 |
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
|
|
| 114 | 103 |
|
| 115 | 104 |
result = dao.getFirstLandingDate();
|
| 116 | 105 |
Assert.assertNotNull(result);
|
| 117 | 106 |
Assert.assertEquals(endDate, result);
|
| 118 | 107 |
|
| 119 |
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
|
|
| 108 |
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
|
|
| 120 | 109 |
|
| 121 | 110 |
result = dao.getFirstLandingDate();
|
| 122 | 111 |
Assert.assertNotNull(result);
|
| ... | ... | @@ -124,20 +113,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 124 | 113 |
}
|
| 125 | 114 |
|
| 126 | 115 |
@Test
|
| 127 |
- public void getLastLandingDate() throws Exception {
|
|
| 116 |
+ public void getLastLandingDate() {
|
|
| 128 | 117 |
|
| 129 | 118 |
T3Date startDate = T3Date.newDate(1, 2010);
|
| 130 | 119 |
T3Date endDate = T3Date.newDate(1, 2011);
|
| 131 | 120 |
|
| 132 | 121 |
T3Date result;
|
| 133 | 122 |
|
| 134 |
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
|
|
| 123 |
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
|
|
| 135 | 124 |
|
| 136 | 125 |
result = dao.getLastLandingDate();
|
| 137 | 126 |
Assert.assertNotNull(result);
|
| 138 | 127 |
Assert.assertEquals(startDate, result);
|
| 139 | 128 |
|
| 140 |
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
|
|
| 129 |
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
|
|
| 141 | 130 |
|
| 142 | 131 |
result = dao.getLastLandingDate();
|
| 143 | 132 |
Assert.assertNotNull(result);
|
| ... | ... | @@ -145,20 +134,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 145 | 134 |
}
|
| 146 | 135 |
|
| 147 | 136 |
@Test
|
| 148 |
- public void findAllYearsUsedInTrip() throws Exception {
|
|
| 137 |
+ public void findAllYearsUsedInTrip() {
|
|
| 149 | 138 |
|
| 150 | 139 |
T3Date startDate = T3Date.newDate(1, 2010);
|
| 151 | 140 |
T3Date endDate = T3Date.newDate(1, 2011);
|
| 152 | 141 |
|
| 153 | 142 |
List<Integer> result;
|
| 154 | 143 |
|
| 155 |
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
|
|
| 144 |
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
|
|
| 156 | 145 |
|
| 157 | 146 |
result = dao.findAllYearsUsedInTrip();
|
| 158 | 147 |
Assert.assertNotNull(result);
|
| 159 |
- Assert.assertEquals(Arrays.asList(2011), result);
|
|
| 148 |
+ Assert.assertEquals(Collections.singletonList(2011), result);
|
|
| 160 | 149 |
|
| 161 |
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
|
|
| 150 |
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
|
|
| 162 | 151 |
|
| 163 | 152 |
result = dao.findAllYearsUsedInTrip();
|
| 164 | 153 |
Assert.assertNotNull(result);
|
| ... | ... | @@ -230,22 +219,22 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 230 | 219 |
// }
|
| 231 | 220 |
|
| 232 | 221 |
@Test
|
| 233 |
- public void findAllIdsByOcean() throws Exception {
|
|
| 222 |
+ public void findAllIdsByOcean() {
|
|
| 234 | 223 |
|
| 235 |
- Ocean ocean1 = oceanDAO.create(Ocean.PROPERTY_CODE, 1);
|
|
| 236 |
- Ocean ocean2 = oceanDAO.create(Ocean.PROPERTY_CODE, 2);
|
|
| 224 |
+ Ocean ocean1 = T3PersistenceFixtures.newOcean(tx, 1);
|
|
| 225 |
+ Ocean ocean2 = T3PersistenceFixtures.newOcean(tx, 2);
|
|
| 237 | 226 |
|
| 238 |
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, new Date());
|
|
| 239 |
- Activity activity1 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean1);
|
|
| 227 |
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, new Date());
|
|
| 228 |
+ Activity activity1 = T3PersistenceFixtures.newActivity(tx, ocean1);
|
|
| 240 | 229 |
trip1.addActivity(activity1);
|
| 241 |
- Activity activity11 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
|
|
| 230 |
+ Activity activity11 = T3PersistenceFixtures.newActivity(tx, ocean2);
|
|
| 242 | 231 |
trip1.addActivity(activity11);
|
| 243 | 232 |
|
| 244 |
- Trip trip2 = dao.create(Trip.PROPERTY_CODE, 2, Trip.PROPERTY_LANDING_DATE, new Date());
|
|
| 245 |
- Activity activity2 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
|
|
| 233 |
+ Trip trip2 = T3PersistenceFixtures.newTrip(tx, 2, new Date());
|
|
| 234 |
+ Activity activity2 = T3PersistenceFixtures.newActivity(tx, ocean2);
|
|
| 246 | 235 |
trip2.addActivity(activity2);
|
| 247 | 236 |
|
| 248 |
- Trip trip3 = dao.create(Trip.PROPERTY_CODE, 3, Trip.PROPERTY_LANDING_DATE, new Date());
|
|
| 237 |
+ Trip trip3 = T3PersistenceFixtures.newTrip(tx, 3, new Date());
|
|
| 249 | 238 |
|
| 250 | 239 |
Multimap<Ocean, String> result = dao.findAllIdsByOcean();
|
| 251 | 240 |
|
| ... | ... | @@ -263,7 +252,7 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 263 | 252 |
Assert.assertTrue(trips.contains(trip1.getTopiaId()));
|
| 264 | 253 |
Assert.assertTrue(trips.contains(trip2.getTopiaId()));
|
| 265 | 254 |
|
| 266 |
- trips = result.get(null);
|
|
| 255 |
+ trips = result.get(TripTopiaDao.EMPTY_OCEAN);
|
|
| 267 | 256 |
Assert.assertNotNull(trips);
|
| 268 | 257 |
Assert.assertEquals(1, trips.size());
|
| 269 | 258 |
Assert.assertTrue(trips.contains(trip3.getTopiaId()));
|
| ... | ... | @@ -283,25 +272,24 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest { |
| 283 | 272 |
}
|
| 284 | 273 |
|
| 285 | 274 |
@Test
|
| 286 |
- public void findAllByIds() throws Exception {
|
|
| 287 |
- |
|
| 288 |
- Ocean ocean1 = oceanDAO.create(Ocean.PROPERTY_CODE, 1);
|
|
| 289 |
- Ocean ocean2 = oceanDAO.create(Ocean.PROPERTY_CODE, 2);
|
|
| 275 |
+ public void findAllByIds() {
|
|
| 290 | 276 |
|
| 277 |
+ Ocean ocean1 = T3PersistenceFixtures.newOcean(tx, 1);
|
|
| 278 |
+ Ocean ocean2 = T3PersistenceFixtures.newOcean(tx, 2);
|
|
| 291 | 279 |
|
| 292 |
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, new Date());
|
|
| 293 |
- Activity activity1 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean1);
|
|
| 280 |
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, new Date());
|
|
| 281 |
+ Activity activity1 = T3PersistenceFixtures.newActivity(tx, ocean1);
|
|
| 294 | 282 |
trip1.addActivity(activity1);
|
| 295 |
- Activity activity11 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
|
|
| 283 |
+ Activity activity11 = T3PersistenceFixtures.newActivity(tx, ocean2);
|
|
| 296 | 284 |
trip1.addActivity(activity11);
|
| 297 | 285 |
|
| 298 |
- Trip trip2 = dao.create(Trip.PROPERTY_CODE, 2, Trip.PROPERTY_LANDING_DATE, new Date());
|
|
| 299 |
- Activity activity2 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
|
|
| 286 |
+ Trip trip2 = T3PersistenceFixtures.newTrip(tx, 2, new Date());
|
|
| 287 |
+ Activity activity2 = T3PersistenceFixtures.newActivity(tx, ocean2);
|
|
| 300 | 288 |
trip2.addActivity(activity2);
|
| 301 | 289 |
|
| 302 | 290 |
List<Trip> result;
|
| 303 | 291 |
|
| 304 |
- result = dao.findAllByIds(Arrays.asList(trip1.getTopiaId()));
|
|
| 292 |
+ result = dao.findAllByIds(Collections.singletonList(trip1.getTopiaId()));
|
|
| 305 | 293 |
|
| 306 | 294 |
Assert.assertNotNull(result);
|
| 307 | 295 |
Assert.assertEquals(1, result.size());
|
| ... | ... | @@ -21,14 +21,17 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 | 26 |
import fr.ird.t3.entities.data.Activity;
|
| 26 | 27 |
import fr.ird.t3.entities.data.CorrectedElementaryCatch;
|
| 27 | 28 |
import fr.ird.t3.entities.data.Trip;
|
| 28 |
-import java.util.Set;
|
|
| 29 | 29 |
import org.junit.Assert;
|
| 30 |
+import org.junit.Before;
|
|
| 30 | 31 |
import org.junit.Test;
|
| 31 | 32 |
|
| 33 |
+import java.util.Set;
|
|
| 34 |
+ |
|
| 32 | 35 |
/**
|
| 33 | 36 |
* Test the user dao {@link AbstractCountryTopiaDao}.
|
| 34 | 37 |
*
|
| ... | ... | @@ -37,44 +40,44 @@ import org.junit.Test; |
| 37 | 40 |
*/
|
| 38 | 41 |
public class CountryTopiaDaoTest extends AbstractDatabaseTest {
|
| 39 | 42 |
|
| 40 |
- @Test
|
|
| 41 |
- public void findAllFleetUsedInTrip() throws Exception {
|
|
| 42 |
- |
|
| 43 |
- T3TopiaPersistenceContext tx = beginTransaction();
|
|
| 43 |
+ private Country country;
|
|
| 44 |
+ private Vessel vessel;
|
|
| 45 |
+ private Vessel vessel2;
|
|
| 46 |
+ private Ocean ocean;
|
|
| 47 |
+ private T3TopiaPersistenceContext tx;
|
|
| 48 |
+ private CountryTopiaDao dao;
|
|
| 49 |
+ |
|
| 50 |
+ @Before
|
|
| 51 |
+ public void setUp() {
|
|
| 52 |
+ tx = beginTransaction();
|
|
| 53 |
+ dao = tx.getCountryDao();
|
|
| 54 |
+ country = T3PersistenceFixtures.newCountry(tx, 0);
|
|
| 55 |
+ Country country2 = T3PersistenceFixtures.newCountry(tx, 1);
|
|
| 56 |
+ vessel = T3PersistenceFixtures.newVessel(tx, country, 0);
|
|
| 57 |
+ vessel2 = T3PersistenceFixtures.newVessel(tx, country2, 1);
|
|
| 58 |
+ ocean = T3PersistenceFixtures.newOcean(tx, 0);
|
|
| 59 |
+ }
|
|
| 44 | 60 |
|
| 45 |
- CountryTopiaDao dao = tx.getCountryDao();
|
|
| 61 |
+ @Test
|
|
| 62 |
+ public void findAllFleetUsedInTrip() {
|
|
| 46 | 63 |
|
| 47 |
- Country country = dao.create(Country.PROPERTY_CODE, 0);
|
|
| 48 |
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
|
|
| 49 |
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
|
|
| 50 |
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
|
|
| 51 |
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
|
|
| 64 |
+ T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 52 | 65 |
|
| 53 |
- Set<Country> result = dao.findAllFleetUsedInTrip();
|
|
| 66 |
+ Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip();
|
|
| 54 | 67 |
Assert.assertNotNull(result);
|
| 55 | 68 |
Assert.assertEquals(1, result.size());
|
| 56 | 69 |
Assert.assertEquals(country, result.iterator().next());
|
| 57 | 70 |
}
|
| 58 | 71 |
|
| 59 | 72 |
@Test
|
| 60 |
- public void findAllFleetUsedInCatch() throws Exception {
|
|
| 61 |
- |
|
| 62 |
- T3TopiaPersistenceContext tx = beginTransaction();
|
|
| 63 |
- |
|
| 64 |
- CountryTopiaDao dao = tx.getCountryDao();
|
|
| 73 |
+ public void findAllFleetUsedInCatch() {
|
|
| 65 | 74 |
|
| 66 |
- Country country = dao.create(Country.PROPERTY_CODE, 0);
|
|
| 67 |
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
|
|
| 68 |
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
|
|
| 69 |
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
|
|
| 70 |
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
|
|
| 75 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 71 | 76 |
|
| 72 |
- // create another trip without any activity (so withou also any corrected catches)
|
|
| 73 |
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
|
|
| 77 |
+ // create another trip without any activity (so without also any corrected catches)
|
|
| 78 |
+ T3PersistenceFixtures.newTrip(tx, vessel2);
|
|
| 74 | 79 |
|
| 75 |
- Activity activity = tx.getActivityDao().create(
|
|
| 76 |
- Activity.PROPERTY_TRIP, trip
|
|
| 77 |
- );
|
|
| 80 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
|
|
| 78 | 81 |
trip.addActivity(activity);
|
| 79 | 82 |
|
| 80 | 83 |
CorrectedElementaryCatch catche = tx.getCorrectedElementaryCatchDao().create();
|
| ... | ... | @@ -89,27 +92,15 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest { |
| 89 | 92 |
}
|
| 90 | 93 |
|
| 91 | 94 |
@Test
|
| 92 |
- public void findAllFleetUsedInSample() throws Exception {
|
|
| 93 |
- |
|
| 94 |
- T3TopiaPersistenceContext tx = beginTransaction();
|
|
| 95 |
+ public void findAllFleetUsedInSample() {
|
|
| 95 | 96 |
|
| 96 |
- Ocean ocean = tx.getOceanDao().create();
|
|
| 97 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 97 | 98 |
|
| 98 |
- CountryTopiaDao dao = tx.getCountryDao();
|
|
| 99 | 99 |
|
| 100 |
- Country country = dao.create(Country.PROPERTY_CODE, 0);
|
|
| 101 |
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
|
|
| 102 |
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
|
|
| 103 |
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
|
|
| 104 |
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
|
|
| 100 |
+ // create another trip without any activity (so without also any corrected catches)
|
|
| 101 |
+ T3PersistenceFixtures.newTrip(tx, vessel2);
|
|
| 105 | 102 |
|
| 106 |
- // create another trip without any activity (so withou also any corrected catches)
|
|
| 107 |
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
|
|
| 108 |
- |
|
| 109 |
- Activity activity = tx.getActivityDao().create(
|
|
| 110 |
- Activity.PROPERTY_TRIP, trip,
|
|
| 111 |
- Activity.PROPERTY_OCEAN, ocean
|
|
| 112 |
- );
|
|
| 103 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
|
|
| 113 | 104 |
trip.addActivity(activity);
|
| 114 | 105 |
|
| 115 | 106 |
Set<Country> result;
|
| ... | ... | @@ -132,32 +123,17 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest { |
| 132 | 123 |
}
|
| 133 | 124 |
|
| 134 | 125 |
@Test
|
| 135 |
- public void findAllFlagUsedInSample() throws Exception {
|
|
| 136 |
- |
|
| 137 |
- T3TopiaPersistenceContext tx = beginTransaction();
|
|
| 138 |
- |
|
| 139 |
- Ocean ocean = tx.getOceanDao().create();
|
|
| 126 |
+ public void findAllFlagUsedInSample() {
|
|
| 140 | 127 |
|
| 141 |
- CountryTopiaDao dao = tx.getCountryDao();
|
|
| 142 |
- |
|
| 143 |
- Country country = dao.create(Country.PROPERTY_CODE, 0);
|
|
| 144 |
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
|
|
| 145 |
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
|
|
| 146 |
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
|
|
| 147 |
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
|
|
| 128 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 148 | 129 |
|
| 149 | 130 |
// create another trip without any activity (so withou also any corrected catches)
|
| 150 |
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
|
|
| 131 |
+ T3PersistenceFixtures.newTrip(tx, vessel2);
|
|
| 151 | 132 |
|
| 152 |
- Activity activity = tx.getActivityDao().create(
|
|
| 153 |
- Activity.PROPERTY_TRIP, trip,
|
|
| 154 |
- Activity.PROPERTY_OCEAN, ocean
|
|
| 155 |
- );
|
|
| 133 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
|
|
| 156 | 134 |
trip.addActivity(activity);
|
| 157 | 135 |
|
| 158 |
- Set<Country> result;
|
|
| 159 |
- |
|
| 160 |
- result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
|
|
| 136 |
+ Set<Country> result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
|
|
| 161 | 137 |
Assert.assertNotNull(result);
|
| 162 | 138 |
//FIXME Should be zero when we will fix the request...
|
| 163 | 139 |
// Assert.assertEquals(0, result.size());
|
| ... | ... | @@ -166,10 +142,10 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest { |
| 166 | 142 |
// SetSpeciesFrequency f =
|
| 167 | 143 |
// tx.getSetSpeciesFrequencyDAO(tx).create(SetSpeciesFrequency.PROPERTY_ACTIVITY, activity);
|
| 168 | 144 |
|
| 169 |
- result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
|
|
| 170 |
- Assert.assertNotNull(result);
|
|
| 171 |
- Assert.assertEquals(1, result.size());
|
|
| 172 |
- Assert.assertEquals(country, result.iterator().next());
|
|
| 145 |
+// result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
|
|
| 146 |
+// Assert.assertNotNull(result);
|
|
| 147 |
+// Assert.assertEquals(1, result.size());
|
|
| 148 |
+// Assert.assertEquals(country, result.iterator().next());
|
|
| 173 | 149 |
}
|
| 174 | 150 |
|
| 175 | 151 |
}
|
| ... | ... | @@ -21,12 +21,13 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 |
-import fr.ird.t3.entities.data.Trip;
|
|
| 26 |
-import java.util.Set;
|
|
| 27 | 26 |
import org.junit.Assert;
|
| 28 | 27 |
import org.junit.Test;
|
| 29 | 28 |
|
| 29 |
+import java.util.Set;
|
|
| 30 |
+ |
|
| 30 | 31 |
/**
|
| 31 | 32 |
* Test the user dao {@link AbstractHarbourTopiaDao}.
|
| 32 | 33 |
*
|
| ... | ... | @@ -36,20 +37,14 @@ import org.junit.Test; |
| 36 | 37 |
public class HarbourTopiaDaoTest extends AbstractDatabaseTest {
|
| 37 | 38 |
|
| 38 | 39 |
@Test
|
| 39 |
- public void findAllUsedInLandingTrip() throws Exception {
|
|
| 40 |
- |
|
| 40 |
+ public void findAllUsedInLandingTrip() {
|
|
| 41 | 41 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 42 | 42 |
|
| 43 |
- HarbourTopiaDao dao = tx.getHarbourDao();
|
|
| 44 |
- |
|
| 45 |
- Harbour harbour = dao.create(Harbour.PROPERTY_CODE, 1);
|
|
| 46 |
- Harbour harbour2 = dao.create(Harbour.PROPERTY_CODE, 2);
|
|
| 47 |
- |
|
| 48 |
- Trip trip = tx.getTripDao().create(
|
|
| 49 |
- Trip.PROPERTY_LANDING_HARBOUR, harbour
|
|
| 50 |
- );
|
|
| 43 |
+ Harbour harbour = T3PersistenceFixtures.newHarbour(tx, 1);
|
|
| 44 |
+ T3PersistenceFixtures.newHarbour(tx, 2);
|
|
| 45 |
+ T3PersistenceFixtures.newTrip(tx, harbour);
|
|
| 51 | 46 |
|
| 52 |
- Set<Harbour> result = dao.findAllUsedInLandingTrip();
|
|
| 47 |
+ Set<Harbour> result = tx.getHarbourDao().findAllUsedInLandingTrip();
|
|
| 53 | 48 |
Assert.assertNotNull(result);
|
| 54 | 49 |
Assert.assertEquals(1, result.size());
|
| 55 | 50 |
Assert.assertEquals(harbour, result.iterator().next());
|
| ... | ... | @@ -28,15 +28,16 @@ import com.google.common.collect.Sets; |
| 28 | 28 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 29 | 29 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 30 | 30 |
import fr.ird.t3.entities.type.T3Date;
|
| 31 |
-import java.util.Date;
|
|
| 32 |
-import java.util.List;
|
|
| 33 |
-import java.util.Map;
|
|
| 34 |
-import java.util.Set;
|
|
| 35 | 31 |
import org.junit.Assert;
|
| 36 | 32 |
import org.junit.Before;
|
| 37 | 33 |
import org.junit.Test;
|
| 38 | 34 |
import org.nuiton.topia.persistence.TopiaException;
|
| 39 | 35 |
|
| 36 |
+import java.util.Date;
|
|
| 37 |
+import java.util.List;
|
|
| 38 |
+import java.util.Map;
|
|
| 39 |
+import java.util.Set;
|
|
| 40 |
+ |
|
| 40 | 41 |
/**
|
| 41 | 42 |
* tests the {@link LengthWeightConversionHelper}.
|
| 42 | 43 |
*
|
| ... | ... | @@ -46,13 +47,13 @@ import org.nuiton.topia.persistence.TopiaException; |
| 46 | 47 |
public class LengthWeightConversionHelperTest extends AbstractDatabaseTest {
|
| 47 | 48 |
|
| 48 | 49 |
@Before
|
| 49 |
- public void setUp() throws Exception {
|
|
| 50 |
+ public void setUp() {
|
|
| 50 | 51 |
|
| 51 | 52 |
db.loadClassPathScript("/db/LengthWeightConversionHelperTest.sql");
|
| 52 | 53 |
}
|
| 53 | 54 |
|
| 54 | 55 |
@Test
|
| 55 |
- public void testGetConversionsAtlantique() throws Exception {
|
|
| 56 |
+ public void testGetConversionsAtlantique() {
|
|
| 56 | 57 |
|
| 57 | 58 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 58 | 59 |
|
| ... | ... | @@ -63,7 +64,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest { |
| 63 | 64 |
}
|
| 64 | 65 |
|
| 65 | 66 |
@Test
|
| 66 |
- public void testGetConversionsIndian() throws Exception {
|
|
| 67 |
+ public void testGetConversionsIndian() {
|
|
| 67 | 68 |
|
| 68 | 69 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 69 | 70 |
|
| ... | ... | @@ -73,8 +74,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest { |
| 73 | 74 |
|
| 74 | 75 |
}
|
| 75 | 76 |
|
| 76 |
- protected void testConversionForOcean(T3TopiaPersistenceContext tx,
|
|
| 77 |
- Ocean ocean) throws TopiaException {
|
|
| 77 |
+ private void testConversionForOcean(T3TopiaPersistenceContext tx, Ocean ocean) throws TopiaException {
|
|
| 78 | 78 |
Date date = T3Date.newDate(1, 2010).toBeginDate();
|
| 79 | 79 |
|
| 80 | 80 |
LengthWeightConversionHelper conversionHelper =
|
| ... | ... | @@ -130,10 +130,10 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest { |
| 130 | 130 |
}
|
| 131 | 131 |
|
| 132 | 132 |
Range<Integer> open = Range.open(0, 1000);
|
| 133 |
- List<Integer> lenghtClasses = Lists.newArrayList(ContiguousSet.create(open,DiscreteDomain.integers()));
|
|
| 133 |
+ List<Integer> lengthClasses = Lists.newArrayList(ContiguousSet.create(open,DiscreteDomain.integers()));
|
|
| 134 | 134 |
|
| 135 | 135 |
Map<Integer, WeightCategoryTreatment> distribution =
|
| 136 |
- conversionHelper.getWeightCategoriesDistribution(conversion, allCategories, lenghtClasses);
|
|
| 136 |
+ conversionHelper.getWeightCategoriesDistribution(conversion, allCategories, lengthClasses);
|
|
| 137 | 137 |
Assert.assertNotNull(distribution);
|
| 138 | 138 |
Set<WeightCategoryTreatment> usedweithCategories = Sets.newHashSet(distribution.values());
|
| 139 | 139 |
// all categories must be used (except the undefined one
|
| ... | ... | @@ -21,13 +21,15 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 | 26 |
import fr.ird.t3.entities.data.Activity;
|
| 26 | 27 |
import fr.ird.t3.entities.data.Trip;
|
| 27 |
-import java.util.Set;
|
|
| 28 | 28 |
import org.junit.Assert;
|
| 29 | 29 |
import org.junit.Test;
|
| 30 | 30 |
|
| 31 |
+import java.util.Set;
|
|
| 32 |
+ |
|
| 31 | 33 |
/**
|
| 32 | 34 |
* Test the user dao {@link AbstractOceanTopiaDao}.
|
| 33 | 35 |
*
|
| ... | ... | @@ -37,21 +39,18 @@ import org.junit.Test; |
| 37 | 39 |
public class OceanTopiaDaoTest extends AbstractDatabaseTest {
|
| 38 | 40 |
|
| 39 | 41 |
@Test
|
| 40 |
- public void findAllUsedInActivity() throws Exception {
|
|
| 42 |
+ public void findAllUsedInActivity() {
|
|
| 41 | 43 |
|
| 42 | 44 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 43 | 45 |
|
| 44 |
- OceanTopiaDao dao = tx.getOceanDao();
|
|
| 45 |
- Ocean ocean = dao.create(Ocean.PROPERTY_CODE, 0);
|
|
| 46 |
- Trip trip = tx.getTripDao().create();
|
|
| 47 |
- Activity activity = tx.getActivityDao().create(
|
|
| 48 |
- Activity.PROPERTY_OCEAN, ocean,
|
|
| 49 |
- Activity.PROPERTY_TRIP, trip
|
|
| 50 |
- );
|
|
| 46 |
+ Ocean ocean = T3PersistenceFixtures.newOcean(tx);
|
|
| 47 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx);
|
|
| 48 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
|
|
| 51 | 49 |
trip.addActivity(activity);
|
| 52 |
- Set<Ocean> result = dao.findAllUsedInActivity();
|
|
| 50 |
+ Set<Ocean> result = tx.getOceanDao().findAllUsedInActivity();
|
|
| 53 | 51 |
Assert.assertNotNull(result);
|
| 54 | 52 |
Assert.assertEquals(1, result.size());
|
| 55 | 53 |
Assert.assertEquals(ocean, result.iterator().next());
|
| 56 | 54 |
}
|
| 55 |
+ |
|
| 57 | 56 |
}
|
| ... | ... | @@ -21,14 +21,16 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 | 26 |
import fr.ird.t3.entities.data.Activity;
|
| 26 | 27 |
import fr.ird.t3.entities.data.CorrectedElementaryCatch;
|
| 27 | 28 |
import fr.ird.t3.entities.data.Trip;
|
| 28 |
-import java.util.Set;
|
|
| 29 | 29 |
import org.junit.Assert;
|
| 30 | 30 |
import org.junit.Test;
|
| 31 | 31 |
|
| 32 |
+import java.util.Set;
|
|
| 33 |
+ |
|
| 32 | 34 |
/**
|
| 33 | 35 |
* Test the user dao {@link AbstractSpeciesTopiaDao}.
|
| 34 | 36 |
*
|
| ... | ... | @@ -38,28 +40,23 @@ import org.junit.Test; |
| 38 | 40 |
public class SpecieDAOImplTest extends AbstractDatabaseTest {
|
| 39 | 41 |
|
| 40 | 42 |
@Test
|
| 41 |
- public void findAllSpecieUsedInCatch() throws Exception {
|
|
| 43 |
+ public void findAllSpecieUsedInCatch() {
|
|
| 42 | 44 |
|
| 43 | 45 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 44 | 46 |
|
| 45 | 47 |
SpeciesTopiaDao dao = tx.getSpeciesDao();
|
| 46 | 48 |
|
| 47 |
- Species species = dao.create(Species.PROPERTY_CODE, 0);
|
|
| 48 |
- Species species2 = dao.create(Species.PROPERTY_CODE, 1);
|
|
| 49 |
+ Species species = T3PersistenceFixtures.newSpecies(tx, 0);
|
|
| 50 |
+ T3PersistenceFixtures.newSpecies(tx, 1);
|
|
| 49 | 51 |
|
| 50 |
- Trip trip = tx.getTripDao().create();
|
|
| 52 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx);
|
|
| 51 | 53 |
|
| 52 |
- // create another trip without any activity (so withou also any corrected catches)
|
|
| 53 |
- Trip trip2 = tx.getTripDao().create();
|
|
| 54 |
+ // create another trip without any activity (so without also any corrected catches)
|
|
| 55 |
+ T3PersistenceFixtures.newTrip(tx, T3PersistenceFixtures.newVessel(tx, 0));
|
|
| 54 | 56 |
|
| 55 |
- Activity activity = tx.getActivityDao().create(
|
|
| 56 |
- Activity.PROPERTY_TRIP, trip
|
|
| 57 |
- );
|
|
| 57 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, T3PersistenceFixtures.newOcean(tx));
|
|
| 58 | 58 |
trip.addActivity(activity);
|
| 59 |
- |
|
| 60 |
- CorrectedElementaryCatch catche =
|
|
| 61 |
- tx.getCorrectedElementaryCatchDao().create(CorrectedElementaryCatch.PROPERTY_SPECIES, species);
|
|
| 62 |
- activity.addCorrectedElementaryCatch(catche);
|
|
| 59 |
+ activity.addCorrectedElementaryCatch(tx.getCorrectedElementaryCatchDao().create(CorrectedElementaryCatch.PROPERTY_SPECIES, species));
|
|
| 63 | 60 |
|
| 64 | 61 |
Set<Species> result = dao.findAllSpeciesUsedInCatch();
|
| 65 | 62 |
Assert.assertNotNull(result);
|
| ... | ... | @@ -21,12 +21,13 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 |
-import fr.ird.t3.entities.data.Trip;
|
|
| 26 |
-import java.util.Set;
|
|
| 27 | 26 |
import org.junit.Assert;
|
| 28 | 27 |
import org.junit.Test;
|
| 29 | 28 |
|
| 29 |
+import java.util.Set;
|
|
| 30 |
+ |
|
| 30 | 31 |
/**
|
| 31 | 32 |
* Test the user dao {@link AbstractVesselSimpleTypeTopiaDao}.
|
| 32 | 33 |
*
|
| ... | ... | @@ -36,26 +37,21 @@ import org.junit.Test; |
| 36 | 37 |
public class VesselSimpleTypeTopiaDaoTest extends AbstractDatabaseTest {
|
| 37 | 38 |
|
| 38 | 39 |
@Test
|
| 39 |
- public void findAllUsedInTrip() throws Exception {
|
|
| 40 |
+ public void findAllUsedInTrip() {
|
|
| 40 | 41 |
|
| 41 | 42 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 42 | 43 |
|
| 43 |
- VesselSimpleTypeTopiaDao dao = tx.getVesselSimpleTypeDao();
|
|
| 44 |
- VesselSimpleType vesselSimpleType = dao.create(VesselSimpleType.PROPERTY_CODE, 1);
|
|
| 45 |
- VesselSimpleType vesselSimpleType2 = dao.create(VesselSimpleType.PROPERTY_CODE, 2);
|
|
| 44 |
+ VesselSimpleType vesselSimpleType = T3PersistenceFixtures.newVesselSimpleType(tx, 1);
|
|
| 45 |
+ VesselSimpleType vesselSimpleType2 = T3PersistenceFixtures.newVesselSimpleType(tx, 2);
|
|
| 46 | 46 |
|
| 47 |
- VesselTypeTopiaDao vesselTypeDAO = tx.getVesselTypeDao();
|
|
| 48 |
- VesselType vesselType = vesselTypeDAO.create(VesselType.PROPERTY_CODE, 1, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType);
|
|
| 49 |
- VesselType vesselType2 = vesselTypeDAO.create(VesselType.PROPERTY_CODE, 2, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType2);
|
|
| 47 |
+ VesselType vesselType = T3PersistenceFixtures.newVesselType(tx, 1, vesselSimpleType);
|
|
| 48 |
+ VesselType vesselType2 = T3PersistenceFixtures.newVesselType(tx, 2, vesselSimpleType2);
|
|
| 50 | 49 |
|
| 51 |
- VesselTopiaDao vesselDAO = tx.getVesselDao();
|
|
| 52 |
- Vessel vessel = vesselDAO.create(Vessel.PROPERTY_CODE, 1, Vessel.PROPERTY_VESSEL_TYPE, vesselType);
|
|
| 53 |
- Vessel vessel2 = vesselDAO.create(Vessel.PROPERTY_CODE, 2, Vessel.PROPERTY_VESSEL_TYPE, vesselType2);
|
|
| 50 |
+ Vessel vessel = T3PersistenceFixtures.newVessel(tx, vesselType, 1);
|
|
| 51 |
+ T3PersistenceFixtures.newVessel(tx, vesselType2, 2);
|
|
| 54 | 52 |
|
| 55 |
- Trip trip = tx.getTripDao().create(
|
|
| 56 |
- Trip.PROPERTY_VESSEL, vessel
|
|
| 57 |
- );
|
|
| 58 |
- Set<VesselSimpleType> result = dao.findAllUsedInTrip(null);
|
|
| 53 |
+ T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 54 |
+ Set<VesselSimpleType> result = tx.getVesselSimpleTypeDao().findAllUsedInTrip(null);
|
|
| 59 | 55 |
Assert.assertNotNull(result);
|
| 60 | 56 |
Assert.assertEquals(1, result.size());
|
| 61 | 57 |
Assert.assertEquals(vesselSimpleType, result.iterator().next());
|
| ... | ... | @@ -21,13 +21,15 @@ |
| 21 | 21 |
package fr.ird.t3.entities.reference;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
+import fr.ird.t3.entities.T3PersistenceFixtures;
|
|
| 24 | 25 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 25 | 26 |
import fr.ird.t3.entities.data.Activity;
|
| 26 | 27 |
import fr.ird.t3.entities.data.Trip;
|
| 27 |
-import java.util.Set;
|
|
| 28 | 28 |
import org.junit.Assert;
|
| 29 | 29 |
import org.junit.Test;
|
| 30 | 30 |
|
| 31 |
+import java.util.Set;
|
|
| 32 |
+ |
|
| 31 | 33 |
/**
|
| 32 | 34 |
* Test the user dao {@link AbstractVesselTopiaDao}.
|
| 33 | 35 |
*
|
| ... | ... | @@ -37,22 +39,17 @@ import org.junit.Test; |
| 37 | 39 |
public class VesselTopiaDaoTest extends AbstractDatabaseTest {
|
| 38 | 40 |
|
| 39 | 41 |
@Test
|
| 40 |
- public void findAllUsedInTrip() throws Exception {
|
|
| 42 |
+ public void findAllUsedInTrip() {
|
|
| 41 | 43 |
|
| 42 | 44 |
T3TopiaPersistenceContext tx = beginTransaction();
|
| 43 | 45 |
|
| 44 |
- VesselTopiaDao dao = tx.getVesselDao();
|
|
| 45 |
- Vessel vessel = dao.create(Vessel.PROPERTY_CODE, 1);
|
|
| 46 |
- Vessel vessel2 = dao.create(Vessel.PROPERTY_CODE, 2);
|
|
| 46 |
+ Vessel vessel = T3PersistenceFixtures.newVessel(tx, 1);
|
|
| 47 |
+ T3PersistenceFixtures.newVessel(tx, 2);
|
|
| 47 | 48 |
|
| 48 |
- Trip trip = tx.getTripDao().create(
|
|
| 49 |
- Trip.PROPERTY_VESSEL, vessel
|
|
| 50 |
- );
|
|
| 51 |
- Activity activity = tx.getActivityDao().create(
|
|
| 52 |
- Activity.PROPERTY_TRIP, trip
|
|
| 53 |
- );
|
|
| 49 |
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
|
|
| 50 |
+ Activity activity = T3PersistenceFixtures.newActivity(tx, T3PersistenceFixtures.newOcean(tx));
|
|
| 54 | 51 |
trip.addActivity(activity);
|
| 55 |
- Set<Vessel> result = dao.findAllUsedInTrip();
|
|
| 52 |
+ Set<Vessel> result = tx.getVesselDao().findAllUsedInTrip();
|
|
| 56 | 53 |
Assert.assertNotNull(result);
|
| 57 | 54 |
Assert.assertEquals(1, result.size());
|
| 58 | 55 |
Assert.assertEquals(vessel, result.iterator().next());
|
| ... | ... | @@ -39,7 +39,7 @@ import org.junit.Test; |
| 39 | 39 |
public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
|
| 40 | 40 |
|
| 41 | 41 |
@Test
|
| 42 |
- public void testGetOldCategoryCode() throws Exception {
|
|
| 42 |
+ public void testGetOldCategoryCode() {
|
|
| 43 | 43 |
db.loadClassPathScript("/db/WeightCategoryTreatmentImplTest.sql");
|
| 44 | 44 |
|
| 45 | 45 |
try (T3TopiaPersistenceContext tx = beginTransaction()) {
|
| ... | ... | @@ -52,7 +52,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { |
| 52 | 52 |
}
|
| 53 | 53 |
|
| 54 | 54 |
@Test
|
| 55 |
- public void testWeightCategoryTreatmentComparator() throws Exception {
|
|
| 55 |
+ public void testWeightCategoryTreatmentComparator() {
|
|
| 56 | 56 |
|
| 57 | 57 |
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
|
| 58 | 58 |
|
| ... | ... | @@ -83,7 +83,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { |
| 83 | 83 |
}
|
| 84 | 84 |
|
| 85 | 85 |
@Test
|
| 86 |
- public void testWeightCategoryTreatmentComparator2() throws Exception {
|
|
| 86 |
+ public void testWeightCategoryTreatmentComparator2() {
|
|
| 87 | 87 |
|
| 88 | 88 |
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
|
| 89 | 89 |
|
| ... | ... | @@ -135,7 +135,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { |
| 135 | 135 |
}
|
| 136 | 136 |
|
| 137 | 137 |
@Test
|
| 138 |
- public void getWeightCategoryTreatment() throws Exception {
|
|
| 138 |
+ public void getWeightCategoryTreatment() {
|
|
| 139 | 139 |
|
| 140 | 140 |
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
|
| 141 | 141 |
|
| ... | ... | @@ -184,7 +184,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { |
| 184 | 184 |
}
|
| 185 | 185 |
|
| 186 | 186 |
@Test
|
| 187 |
- public void getWeightCategoryTreatment2() throws Exception {
|
|
| 187 |
+ public void getWeightCategoryTreatment2() {
|
|
| 188 | 188 |
|
| 189 | 189 |
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
|
| 190 | 190 |
|
| ... | ... | @@ -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",
|
| ... | ... | @@ -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",
|
| ... | ... | @@ -24,7 +24,7 @@ hibernate.show_sql=false |
| 24 | 24 |
|
| 25 | 25 |
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
| 26 | 26 |
hibernate.connection.username=sa
|
| 27 |
-hibernate.connection.password=
|
|
| 27 |
+hibernate.connection.password=sa
|
|
| 28 | 28 |
hibernate.connection.driver_class=org.h2.Driver
|
| 29 | 29 |
# tchemit 2010-11-28 : comment this line, each test must define his own db path
|
| 30 | 30 |
#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
|
| ... | ... | @@ -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",
|