T3-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
February 2018
- 1 participants
- 74 discussions
[Git][ultreiaio/ird-t3][develop] [N1][N2][N3] Permettre la sélection mutliple d'océans (See #260) N1 done
by Tony CHEMIT 21 Feb '18
by Tony CHEMIT 21 Feb '18
21 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
617f2075 by Tony CHEMIT at 2018-02-21T03:17:11+01:00
[N1][N2][N3] Permettre la sélection mutliple d'océans (See #260) N1 done
- - - - -
29 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/AbstractLevel1Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/Level1Configuration.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/StandardizeSampleMeasuresAction.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetActionResumeTest.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1ConfigureAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1RunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ComputeWeightOfCategoriesForSetRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSetSpeciesFrequencyToWeightRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleCountedAndMeasuredRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleWeightToSetRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/RedistributeSampleNumberToSetRunAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/StandardizeSampleMeasuresRunAction.java
- t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validateLevel1Configuration-validation.xml
- t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validation.xml
- t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1Configuration.jsp
- t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1ConfigurationResume.jsp
Changes:
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
@@ -59,9 +59,9 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A
@InjectDAO(entityType = SetDuration.class)
private SetDurationTopiaDao setDurationDAO;
/** Count of treated activities. */
- private int nbActivities;
+ int nbActivities;
/** Count of positive activities found. */
- private int nbPositiveActivities;
+ int nbPositiveActivities;
/** Count of set (sum(a.setCount) on each activity trip). */
private int nbSet;
/**
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/AbstractLevel1Action.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/AbstractLevel1Action.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/AbstractLevel1Action.java
@@ -28,20 +28,17 @@ import fr.ird.t3.entities.data.N1ResultState;
import fr.ird.t3.entities.data.Sample;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.TripTopiaDao;
-import fr.ird.t3.entities.reference.Ocean;
import fr.ird.t3.services.DecoratorService;
import fr.ird.t3.services.ioc.InjectDAO;
-import fr.ird.t3.services.ioc.InjectEntityById;
+import org.apache.commons.collections.CollectionUtils;
+import org.nuiton.topia.persistence.TopiaException;
+
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.commons.collections.CollectionUtils;
-import org.nuiton.topia.persistence.TopiaException;
-
-
import static org.nuiton.i18n.I18n.l;
/**
@@ -56,15 +53,12 @@ public abstract class AbstractLevel1Action extends T3Action<Level1Configuration>
.<Trip, Integer>comparing(t -> t.getVessel().getCode())
.thenComparing(Comparator.comparing(Trip::getLandingDate));
- protected final Level1Step step;
-
- protected final Set<Level1Step> higherSteps;
-
@InjectDAO(entityType = Trip.class)
protected TripTopiaDao tripDAO;
- @InjectEntityById(entityType = Ocean.class)
- protected Ocean ocean;
+ protected final Level1Step step;
+
+ protected final Set<Level1Step> higherSteps;
/** For a trip, selected samples to treat. */
protected Multimap<Trip, Sample> samplesByTrip;
@@ -77,10 +71,6 @@ public abstract class AbstractLevel1Action extends T3Action<Level1Configuration>
higherSteps = Level1Step.allAfter(step);
}
- public Ocean getOcean() {
- return ocean;
- }
-
public Multimap<Trip, Sample> getSamplesByTrip() {
return samplesByTrip;
}
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetAction.java
@@ -27,9 +27,9 @@ import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.WellSetAllSpecies;
import fr.ird.t3.entities.data.WellSetAllSpeciesTopiaDao;
import fr.ird.t3.services.ioc.InjectDAO;
-import java.util.Collection;
import org.nuiton.topia.persistence.TopiaException;
+import java.util.Collection;
import static org.nuiton.i18n.I18n.l;
@@ -127,9 +127,7 @@ public class ComputeWeightOfCategoriesForSetAction extends AbstractLevel1Action
// can not compute propMinus10Weight and propPlus10Weight
- String message =
- l(locale, "t3.level1.computeWeightOfCategoriesForSet.sample.noComputePropWeight"
- );
+ String message = l(locale, "t3.level1.computeWeightOfCategoriesForSet.sample.noComputePropWeight");
addInfoMessage(message);
} else {
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightAction.java
@@ -21,12 +21,10 @@ package fr.ird.t3.actions.data.level1;
* #L%
*/
-import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
import fr.ird.t3.T3IOUtil;
import fr.ird.t3.entities.CountAndWeight;
import fr.ird.t3.entities.T3Suppliers;
@@ -51,16 +49,17 @@ import fr.ird.t3.entities.reference.WeightCategorySample;
import fr.ird.t3.entities.reference.WeightCategorySampleTopiaDao;
import fr.ird.t3.services.DecoratorService;
import fr.ird.t3.services.ioc.InjectDAO;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.util.TimeLog;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
-import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.util.TimeLog;
-
import static org.nuiton.i18n.I18n.l;
@@ -72,38 +71,27 @@ import static org.nuiton.i18n.I18n.l;
*/
public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLevel1Action {
+ private final Map<String, List<WeightCategorySample>> weightCategoryCache;
@InjectDAO(entityType = LengthWeightConversion.class)
- protected LengthWeightConversionTopiaDao lengthWeightConversionDAO;
-
+ private LengthWeightConversionTopiaDao lengthWeightConversionDAO;
@InjectDAO(entityType = SampleSetSpeciesCatWeight.class)
- protected SampleSetSpeciesCatWeightTopiaDao sampleSetSpeciesCatWeightDAO;
-
+ private SampleSetSpeciesCatWeightTopiaDao sampleSetSpeciesCatWeightDAO;
@InjectDAO(entityType = WeightCategorySample.class)
- protected WeightCategorySampleTopiaDao weightCategorySampleDAO;
-
- protected LengthWeightConversionHelper conversionHelper;
-
- protected final Map<String, List<WeightCategorySample>> weightCategoryCache;
+ private WeightCategorySampleTopiaDao weightCategorySampleDAO;
+ private LengthWeightConversionHelper conversionHelper;
protected List<WeightCategorySample> getWeightCategories(SampleSet sampleSet) throws TopiaException {
-
Activity activity = sampleSet.getActivity();
- Ocean ocean1 = activity.getOcean();
+ Ocean ocean = activity.getOcean();
SchoolType schoolType = activity.getSchoolType();
- String key = ocean1.getTopiaId() + "-" + schoolType.getTopiaId();
+ String key = ocean.getTopiaId() + "-" + schoolType.getTopiaId();
List<WeightCategorySample> result = weightCategoryCache.get(key);
-
if (result == null) {
-
- result = weightCategorySampleDAO.forOceanEquals(ocean1).findAll();
+ result = weightCategorySampleDAO.forOceanEquals(ocean).findAll();
WeightCategories.sort(result);
weightCategoryCache.put(key, result);
}
-
- Preconditions.checkNotNull(
- result,
- "Could not find any weight categories for ocean " + ocean.getLabel1() );
- return result;
+ return Objects.requireNonNull(result, "Could not find any weight categories for ocean " + ocean.getLabel1());
}
public ConvertSampleSetSpeciesFrequencyToWeightAction() {
@@ -141,21 +129,18 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
String tripStr = decorate(trip, DecoratorService.WITH_ID);
- getTimeLog().log(s0, "treat trip " + tripStr);
+ getTimeLog().log(s0, String.format("treat trip %s", tripStr));
// flush transaction otherwise too much data in memory
- flushTransaction("Flush transaction for " + tripStr);
+ flushTransaction(String.format("Flush transaction for %s", tripStr));
}
return true;
}
- protected void doExecuteTrip(Trip trip,
- Collection<Sample> samples) throws TopiaException {
+ protected void doExecuteTrip(Trip trip, Collection<Sample> samples) throws TopiaException {
incrementsProgression();
- Set<Activity> tripActivities = Sets.newHashSet();
-
// extrapolate for each sample set number to set
for (Sample sample : samples) {
@@ -173,16 +158,14 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
// found a new activity to convert
convertFrequenciesToCatWeight(sampleSet);
- getTimeLog().log(s1,
- "convertSampleSetSpeciesFrequencyToWeight for " +
- tripActivities.size() + " sets.");
+ getTimeLog().log(s1, String.format("convertSampleSetSpeciesFrequencyToWeight for %d sets.", sample.sizeSampleSet()));
}
// mark sample as treated for this step of level 1 treatment
markAsTreated(sample);
- getTimeLog().log(s0, "treat sample " + sampleStr);
+ getTimeLog().log(s0, String.format("treat sample %s", sampleStr));
}
// mar trip as treated for this level 1 step
@@ -191,8 +174,7 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
protected void convertFrequenciesToCatWeight(SampleSet sampleSet) throws TopiaException {
- Collection<SampleSetSpeciesFrequency> frequencies =
- sampleSet.getSampleSetSpeciesFrequency();
+ Collection<SampleSetSpeciesFrequency> frequencies = sampleSet.getSampleSetSpeciesFrequency();
Activity activity = sampleSet.getActivity();
@@ -200,15 +182,12 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
Ocean activityOcean = activity.getOcean();
// group frequencies by species
- Multimap<Species, SampleSetSpeciesFrequency> frequenciesBySpecies =
- SpeciesTopiaDao.groupBySpecies(frequencies);
+ Multimap<Species, SampleSetSpeciesFrequency> frequenciesBySpecies = SpeciesTopiaDao.groupBySpecies(frequencies);
- Multimap<Species, Integer> lengthClassesBySpecies =
- ArrayListMultimap.create();
+ Multimap<Species, Integer> lengthClassesBySpecies = ArrayListMultimap.create();
// collect all length classes by species
- SampleSetSpeciesFrequencyTopiaDao.collectLengthClasses(
- frequenciesBySpecies, lengthClassesBySpecies);
+ SampleSetSpeciesFrequencyTopiaDao.collectLengthClasses(frequenciesBySpecies, lengthClassesBySpecies);
// get all available weight categories
List<WeightCategorySample> weightCategories = getWeightCategories(sampleSet);
@@ -216,19 +195,11 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
for (Species species : frequenciesBySpecies.keySet()) {
// get conversion for species
- LengthWeightConversion conversion =
- conversionHelper.getConversions(
- species,
- activityOcean,
- 0,
- date
- );
-
- Collection<SampleSetSpeciesFrequency> frequenciesForSpecies =
- frequenciesBySpecies.get(species);
-
- List<Integer> lengthClasses =
- Lists.newArrayList(lengthClassesBySpecies.get(species));
+ LengthWeightConversion conversion = conversionHelper.getConversions(species, activityOcean, 0, date);
+
+ Collection<SampleSetSpeciesFrequency> frequenciesForSpecies = frequenciesBySpecies.get(species);
+
+ List<Integer> lengthClasses = Lists.newArrayList(lengthClassesBySpecies.get(species));
Collections.sort(lengthClasses);
Map<WeightCategorySample, CountAndWeight> countAndWeightsByCategories =
@@ -238,9 +209,7 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
frequenciesForSpecies,
lengthClasses);
- // now we can build for the given activity and species the entries
- // in SetWeight
-
+ // now we can build for the given activity and species the entries in SetWeight
fill(sampleSet, species, countAndWeightsByCategories);
}
}
@@ -250,17 +219,12 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
Collection<SampleSetSpeciesFrequency> frequencies,
List<Integer> lengthClasses) throws TopiaException {
- Map<Integer, WeightCategorySample> weightCategorie =
- conversionHelper.getWeightCategoriesDistribution(
- conversion,
- weightCategories,
- lengthClasses);
+ Map<Integer, WeightCategorySample> weightCategoryMap =
+ conversionHelper.getWeightCategoriesDistribution(conversion, weightCategories, lengthClasses);
Map<WeightCategorySample, CountAndWeight> result = new HashMap<>();
- T3IOUtil.fillMapWithDefaultValue(result,
- weightCategorie.values(),
- T3Suppliers.COUNT_AND_WEIGHT_DEFAULT_VALUE);
+ T3IOUtil.fillMapWithDefaultValue(result, weightCategoryMap.values(), T3Suppliers.COUNT_AND_WEIGHT_DEFAULT_VALUE);
for (SampleSetSpeciesFrequency setSize : frequencies) {
@@ -268,7 +232,7 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
int lfLengthClass = setSize.getLfLengthClass();
// find the correct category for this length class
- WeightCategorySample weightCategory = weightCategorie.get(lfLengthClass);
+ WeightCategorySample weightCategory = weightCategoryMap.get(lfLengthClass);
CountAndWeight countAndWeight = result.get(weightCategory);
@@ -276,8 +240,7 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
countAndWeight.addCount(number);
// convert to weight from lf length class
- countAndWeight.addWeight(number *
- conversion.computeWeightFromLFLengthClass(lfLengthClass));
+ countAndWeight.addWeight(number * conversion.computeWeightFromLFLengthClass(lfLengthClass));
}
@@ -295,7 +258,7 @@ public class ConvertSampleSetSpeciesFrequencyToWeightAction extends AbstractLeve
CountAndWeight countAndWeight = e2.getValue();
float count = countAndWeight.getCount();
- // weight must be stored in tons but are in kilogramms
+ // weight must be stored in tons but are in kilograms
Float weight = countAndWeight.getWeight() / 1000;
SampleSetSpeciesCatWeight setSpeciesCatWeight = sampleSetSpeciesCatWeightDAO.create(
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightAction.java
@@ -8,19 +8,18 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package fr.ird.t3.actions.data.level1;
-import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@@ -49,16 +48,17 @@ import fr.ird.t3.entities.reference.WeightCategorySample;
import fr.ird.t3.entities.reference.WeightCategorySampleTopiaDao;
import fr.ird.t3.services.DecoratorService;
import fr.ird.t3.services.ioc.InjectDAO;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.util.TimeLog;
+
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
-import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.util.TimeLog;
-
import static org.nuiton.i18n.I18n.l;
@@ -70,48 +70,34 @@ import static org.nuiton.i18n.I18n.l;
*/
public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Action {
+ protected final Map<String, List<WeightCategorySample>> weightCategoryCache;
@InjectDAO(entityType = LengthWeightConversion.class)
protected LengthWeightConversionTopiaDao lengthWeightConversionDAO;
-
@InjectDAO(entityType = SetSpeciesCatWeight.class)
protected SetSpeciesCatWeightTopiaDao setSpeciesCatWeightDAO;
-
@InjectDAO(entityType = WeightCategorySample.class)
protected WeightCategorySampleTopiaDao weightCategorySampleDAO;
-
protected int nbTreatedSets;
-
protected float nbTreatedFishesInSamples;
-
protected float nbCreatedFishesInSetSpeciesFrequency;
-
protected LengthWeightConversionHelper conversionHelper;
- protected final Map<String, List<WeightCategorySample>> weightCategoryCache;
+ public ConvertSetSpeciesFrequencyToWeightAction() {
+ super(Level1Step.CONVERT_SET_SPECIES_FREQUENCY_TO_WEIGHT);
+ weightCategoryCache = Maps.newTreeMap();
+ }
protected List<WeightCategorySample> getWeightCategories(Activity activity) throws TopiaException {
-
- Ocean ocean1 = activity.getOcean();
+ Ocean ocean = activity.getOcean();
SchoolType schoolType = activity.getSchoolType();
- String key = ocean1.getTopiaId() + "-" + schoolType.getTopiaId();
+ String key = ocean.getTopiaId() + "-" + schoolType.getTopiaId();
List<WeightCategorySample> result = weightCategoryCache.get(key);
-
if (result == null) {
-
- result = weightCategorySampleDAO.findAllByOcean(ocean1);
+ result = weightCategorySampleDAO.forOceanEquals(ocean).findAll();
WeightCategories.sort(result);
weightCategoryCache.put(key, result);
}
-
- Preconditions.checkNotNull(
- result,
- "Could not find any weight categories for ocean " + ocean.getLabel1());
- return result;
- }
-
- public ConvertSetSpeciesFrequencyToWeightAction() {
- super(Level1Step.CONVERT_SET_SPECIES_FREQUENCY_TO_WEIGHT);
- weightCategoryCache = Maps.newTreeMap();
+ return Objects.requireNonNull(result, "Could not find any weight categories for ocean " + ocean.getLabel1());
}
public int getNbTreatedSets() {
@@ -140,7 +126,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
}
@Override
- protected boolean executeAction() throws Exception {
+ protected boolean executeAction() {
Set<Trip> trips = samplesByTrip.keySet();
setNbSteps(samplesByTrip.size() + trips.size());
@@ -164,8 +150,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
return true;
}
- protected void doExecuteTrip(Trip trip,
- Collection<Sample> samples) throws TopiaException {
+ protected void doExecuteTrip(Trip trip, Collection<Sample> samples) throws TopiaException {
incrementsProgression();
@@ -184,8 +169,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
float nb = sample.getTotalStandardiseSampleSpeciesFrequencyNumber();
addInfoMessage(
- l(locale, "t3.level1.convertSetSpeciesFrequencyToWeight.sample.nbFishes",
- sampleStr, nb));
+ l(locale, "t3.level1.convertSetSpeciesFrequencyToWeight.sample.nbFishes", sampleStr, nb));
nbTreatedFishesInSamples += nb;
for (SampleSet sampleSet : sample.getSampleSet()) {
@@ -200,17 +184,14 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
// found a new activity to convert
convertFrequenciesToCatWeight(activity);
- getTimeLog().log(
- s1,
- "convertSetSpeciesFrequencyToWeight for " +
- tripActivities.size() + " sets.");
+ getTimeLog().log(s1, String.format("convertSetSpeciesFrequencyToWeight for %d sets.", tripActivities.size()));
}
}
// mark sample as treated for this step of level 1 treatment
markAsTreated(sample);
- getTimeLog().log(s0, "treat sample " + sampleStr);
+ getTimeLog().log(s0, String.format("treat sample %s", sampleStr));
}
nbTreatedSets += tripActivities.size();
@@ -226,50 +207,32 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
Date date = activity.getDate();
Ocean activityOcean = activity.getOcean();
-
// group frequencies by species
Multimap<Species, SetSpeciesFrequency> setSpeciesFrequencyBySpecies =
SpeciesTopiaDao.groupBySpecies(frequencies);
- Multimap<Species, Integer> lengthClassesBySpecies =
- ArrayListMultimap.create();
+ Multimap<Species, Integer> lengthClassesBySpecies = ArrayListMultimap.create();
// collect all length classes by species
- SetSpeciesFrequencyTopiaDao.collectLengthClasses(
- setSpeciesFrequencyBySpecies, lengthClassesBySpecies);
+ SetSpeciesFrequencyTopiaDao.collectLengthClasses(setSpeciesFrequencyBySpecies, lengthClassesBySpecies);
// get all available weight categories
- List<WeightCategorySample> weightCategories =
- getWeightCategories(activity);
+ List<WeightCategorySample> weightCategories = getWeightCategories(activity);
for (Species species : setSpeciesFrequencyBySpecies.keySet()) {
// get conversion for species
- LengthWeightConversion conversion =
- conversionHelper.getConversions(
- species,
- activityOcean,
- 0,
- date
- );
-
- Collection<SetSpeciesFrequency> setSizes =
- setSpeciesFrequencyBySpecies.get(species);
-
- List<Integer> lengthClasses =
- Lists.newArrayList(lengthClassesBySpecies.get(species));
+ LengthWeightConversion conversion = conversionHelper.getConversions(species, activityOcean, 0, date);
+
+ Collection<SetSpeciesFrequency> setSizes = setSpeciesFrequencyBySpecies.get(species);
+
+ List<Integer> lengthClasses = Lists.newArrayList(lengthClassesBySpecies.get(species));
Collections.sort(lengthClasses);
Map<WeightCategorySample, CountAndWeight> countAndWeightsByCategories =
- convertForSpecies(
- weightCategories,
- conversion,
- setSizes,
- lengthClasses);
-
- // now we can build for the given activity and species the entries
- // in SetWeight
+ convertForSpecies(weightCategories, conversion, setSizes, lengthClasses);
+ // now we can build for the given activity and species the entries in SetWeight
fill(activity, species, countAndWeightsByCategories);
}
}
@@ -279,7 +242,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
Collection<SetSpeciesFrequency> setSizes,
List<Integer> lengthClasses) throws TopiaException {
- Map<Integer, WeightCategorySample> weightCategorie = conversionHelper.getWeightCategoriesDistribution(
+ Map<Integer, WeightCategorySample> weightCategoryMap = conversionHelper.getWeightCategoriesDistribution(
conversion,
weightCategories,
lengthClasses
@@ -287,9 +250,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
Map<WeightCategorySample, CountAndWeight> result = new HashMap<>();
- T3IOUtil.fillMapWithDefaultValue(result,
- weightCategorie.values(),
- T3Suppliers.COUNT_AND_WEIGHT_DEFAULT_VALUE);
+ T3IOUtil.fillMapWithDefaultValue(result, weightCategoryMap.values(), T3Suppliers.COUNT_AND_WEIGHT_DEFAULT_VALUE);
for (SetSpeciesFrequency setSize : setSizes) {
@@ -297,8 +258,7 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
int lfLengthClass = setSize.getLfLengthClass();
// find the correct category for this length class
- WeightCategorySample weightCategory =
- weightCategorie.get(lfLengthClass);
+ WeightCategorySample weightCategory = weightCategoryMap.get(lfLengthClass);
CountAndWeight countAndWeight = result.get(weightCategory);
@@ -313,12 +273,9 @@ public class ConvertSetSpeciesFrequencyToWeightAction extends AbstractLevel1Acti
return result;
}
- private void fill(Activity activity,
- Species species,
- Map<WeightCategorySample, CountAndWeight> countAndWeightsByCategories) throws TopiaException {
+ private void fill(Activity activity, Species species, Map<WeightCategorySample, CountAndWeight> countAndWeightsByCategories) throws TopiaException {
- for (Map.Entry<WeightCategorySample, CountAndWeight> e2 :
- countAndWeightsByCategories.entrySet()) {
+ for (Map.Entry<WeightCategorySample, CountAndWeight> e2 : countAndWeightsByCategories.entrySet()) {
WeightCategorySample categorySample = e2.getKey();
CountAndWeight countAndWeight = e2.getValue();
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredAction.java
@@ -28,11 +28,11 @@ import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.SpeciesTopiaDao;
+
import java.util.Collection;
import java.util.List;
import java.util.Map;
-
import static org.nuiton.i18n.I18n.l;
/**
@@ -50,9 +50,7 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
}
public List<SpeciesCountAndMeasuredModel> getResultSpeciesModel() {
- List<SpeciesCountAndMeasuredModel> result =
- getResultAsList(RESULT_SPECIES_MODEL, SpeciesCountAndMeasuredModel.class);
- return result;
+ return getResultAsList(RESULT_SPECIES_MODEL, SpeciesCountAndMeasuredModel.class);
}
public SpeciesCountAndMeasuredModel getTotalSpeciesModel() {
@@ -81,7 +79,7 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
}
@Override
- protected boolean executeAction() throws Exception {
+ protected boolean executeAction() {
Map<Species, SpeciesCountAndMeasuredModel> model = Maps.newHashMap();
@@ -110,8 +108,7 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
return true;
}
- protected void doExecuteSample(Sample sample,
- Map<Species, SpeciesCountAndMeasuredModel> model) {
+ protected void doExecuteSample(Sample sample, Map<Species, SpeciesCountAndMeasuredModel> model) {
incrementsProgression();
@@ -120,7 +117,6 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
sample.getSampleNumber()));
if (sample.isSampleSpeciesEmpty()) {
-
// no sample species, nothing to do...
return;
}
@@ -145,9 +141,7 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
float measuredCount = 0;
for (SampleSpecies aSampleSpecies : sampleSpecies) {
totalCount += aSampleSpecies.getTotalCount();
-
- measuredCount +=
- aSampleSpecies.getTotalSampleSpeciesFrequencyNumber();
+ measuredCount += aSampleSpecies.getTotalSampleSpeciesFrequencyNumber();
}
float rf0 = totalCount / measuredCount;
@@ -161,7 +155,6 @@ public class ExtrapolateSampleCountedAndMeasuredAction extends AbstractLevel1Act
// apply rf0 on each sample
for (SampleSpecies sampleSpecie : sampleSpecies) {
-
sampleSpecie.applyRf0(rf0);
}
}
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetAction.java
@@ -20,9 +20,7 @@
*/
package fr.ird.t3.actions.data.level1;
-import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.RfUsageStatus;
import fr.ird.t3.entities.data.Sample;
@@ -45,14 +43,16 @@ import fr.ird.t3.entities.reference.WeightCategoryWellPlan;
import fr.ird.t3.entities.reference.WeightCategoryWellPlanTopiaDao;
import fr.ird.t3.services.DecoratorService;
import fr.ird.t3.services.ioc.InjectDAO;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.persistence.TopiaException;
import org.nuiton.util.TimeLog;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import static org.nuiton.i18n.I18n.l;
@@ -125,7 +125,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
}
@Override
- protected boolean executeAction() throws Exception {
+ protected boolean executeAction() {
Set<Trip> trips = samplesByTrip.keySet();
setNbSteps(samplesByTrip.size() + trips.size());
@@ -153,11 +153,11 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
incrementsProgression();
+ //FIXME I replace ocean by trip.departureHarbour.ocean, check this is ok (See #260)
// get the length class +10kg limit
- Map<Species, Integer> limitLengthClassBySpecie =
- getThredHoldPlus10ForSpecies(trip, samples, ocean);
+ Map<Species, Integer> limitLengthClassBySpecie = getThredHoldPlus10ForSpecies(trip, samples, trip.getDepartureHarbour().getOcean());
- Set<Activity> tripActivities = Sets.newHashSet();
+ Set<Activity> tripActivities = new HashSet<>();
// extrapolate for each sample set number to set
for (Sample sample : samples) {
@@ -187,11 +187,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
activity.clearSetSpeciesCatWeight();
}
- doExecuteSampleWell(
- activity,
- sampleSet,
- sampleStr,
- limitLengthClassBySpecie);
+ doExecuteSampleWell(activity, sampleSet, sampleStr, limitLengthClassBySpecie);
}
@@ -244,11 +240,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
sampleSet.setRfTot(rfContext.getRfTot());
// fill the SetSpecieFrequency table
- fillSetSpeciesFrequency(
- activity,
- limitLengthClassBySpecie,
- sampleSet,
- rfContext);
+ fillSetSpeciesFrequency(activity, limitLengthClassBySpecie, sampleSet, rfContext);
}
@@ -330,9 +322,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
* @throws TopiaException if any pb while finding convertors
* @see SampleWellSampleWeight
*/
- protected SampleWellSetWeight computeSampleWellSetWeight(
- String sampleWellStr,
- SampleSet sampleSet) throws TopiaException {
+ protected SampleWellSetWeight computeSampleWellSetWeight(String sampleWellStr, SampleSet sampleSet) throws TopiaException {
float pondt = sampleSet.getWeightedWeight();
Float pondm = sampleSet.getWeightedWeightMinus10();
@@ -489,11 +479,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
return rfContext;
}
- public void fillSetSpeciesFrequency(
- Activity activity,
- Map<Species, Integer> limitLengthClassBySpecies,
- SampleSet sampleSet,
- RFContext rfContext) throws TopiaException {
+ public void fillSetSpeciesFrequency(Activity activity, Map<Species, Integer> limitLengthClassBySpecies, SampleSet sampleSet, RFContext rfContext) throws TopiaException {
// group sample set frequencies by species
Multimap<Species, SampleSetSpeciesFrequency> sampleSetSpeciesFrequencyBySpecies =
@@ -542,18 +528,15 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
* @param trip the trip where samples are done
* @param samples the sample to scan
* @param ocean ocean where trip happens
- * @return the universe of legnth class limits computed indexed by species
+ * @return the universe of length class limits computed indexed by species
* @throws TopiaException if any db problems while requesting
*/
- public Map<Species, Integer> getThredHoldPlus10ForSpecies(Trip trip,
- Collection<Sample> samples,
- Ocean ocean) throws TopiaException {
+ public Map<Species, Integer> getThredHoldPlus10ForSpecies(Trip trip, Collection<Sample> samples, Ocean ocean) throws TopiaException {
Set<Species> species = SpeciesTopiaDao.getAllSpeciesFromSampleSpecies(samples);
- // for each of those species, found the length class wich matches a
- // weight > 10Kg
- Map<Species, Integer> result = Maps.newHashMap();
+ // for each of those species, found the length class which matches a weight > 10Kg
+ Map<Species, Integer> result = new HashMap<>();
for (Species specie : species) {
LengthWeightConversion conversion = conversionHelper.getConversions(
@@ -577,8 +560,7 @@ public class ExtrapolateSampleWeightToSetAction extends AbstractLevel1Action {
if (log.isDebugEnabled()) {
for (Map.Entry<Species, Integer> entry : result.entrySet()) {
- log.debug("Species " + entry.getKey().getCode() +
- " - limit 10Kg length class : " + entry.getValue());
+ log.debug(String.format("Species %d - limit 10Kg length class : %d", entry.getKey().getCode(), entry.getValue()));
}
}
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/Level1Configuration.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/Level1Configuration.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/Level1Configuration.java
@@ -20,9 +20,7 @@
*/
package fr.ird.t3.actions.data.level1;
-import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
@@ -44,13 +42,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.decorator.Decorator;
-import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.nuiton.i18n.I18n.l;
@@ -84,11 +82,12 @@ public class Level1Configuration implements T3ActionConfiguration {
/** Ids of fleet countries to use. */
protected List<String> fleetIds;
+ /** Ids of ocean to use. */
+ protected List<String> oceanIds;
+
/** Ids of trips to use. */
protected Multimap<String, String> sampleIdsByTripId;
- /** Id of selected ocean. */
- protected String oceanId;
/** begin date to use. */
protected T3Date beginDate;
@@ -150,12 +149,12 @@ public class Level1Configuration implements T3ActionConfiguration {
getExecutedSteps().add(step);
}
- public String getOceanId() {
- return oceanId;
+ public List<String> getOceanIds() {
+ return oceanIds;
}
- public void setOceanId(String oceanId) {
- this.oceanId = oceanId;
+ public void setOceanIds(List<String> oceanIds) {
+ this.oceanIds = oceanIds;
}
public Multimap<String, String> getSampleIdsByTripId() {
@@ -306,32 +305,23 @@ public class Level1Configuration implements T3ActionConfiguration {
Multimap<String, String> result = TreeMultimap.create();
- if (oceanId == null) {
+ if (oceanIds == null) {
// no matching trips (so no matching trip
return result;
}
- Preconditions.checkNotNull(oceanId);
-
- Ocean ocean =
- Iterables.find(oceans, T3Predicates.equalsTopiaEntity(oceanId));
- Preconditions.checkNotNull(ocean);
+ Set<Ocean> usableOceans = oceans.stream().filter(o -> oceanIds.contains(o.getTopiaId())).collect(Collectors.toSet());
- Predicate<Trip> tripPredicate =
- T3Predicates.tripUsingOcean(Arrays.asList(ocean));
+ Predicate<Trip> tripPredicate = T3Predicates.tripUsingOcean(usableOceans);
- Decorator<Trip> tripDecorator =
- decoratorService.getDecorator(locale, Trip.class, DecoratorService.WITH_ID);
+ Decorator<Trip> tripDecorator = decoratorService.getDecorator(locale, Trip.class, DecoratorService.WITH_ID);
- Decorator<Sample> sampleDecorator =
- decoratorService.getDecorator(locale, Sample.class, DecoratorService.WITH_ID);
+ Decorator<Sample> sampleDecorator = decoratorService.getDecorator(locale, Sample.class, DecoratorService.WITH_ID);
- String sampleWellEmptyReason =
- l(locale, "t3.level1.notSelectedSample.sampleWellEmpty");
+ String sampleWellEmptyReason = l(locale, "t3.level1.notSelectedSample.sampleWellEmpty");
- String sampleNoMatchingActivityReason =
- l(locale, "t3.level1.notSelectedSample.sampleNoMatchingActivity");
+ String sampleNoMatchingActivityReason = l(locale, "t3.level1.notSelectedSample.sampleNoMatchingActivity");
Decorator<SampleQuality> sampleQualityDecorator = decoratorService.getDecorator(locale, SampleQuality.class, null);
Decorator<SampleType> sampleTypeDecorator = decoratorService.getDecorator(locale, SampleType.class, null);
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction.java
@@ -31,11 +31,11 @@ import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.SpeciesTopiaDao;
import fr.ird.t3.services.ioc.InjectDAO;
+import org.nuiton.topia.persistence.TopiaException;
+
import java.util.Collection;
import java.util.Map;
import java.util.Set;
-import org.nuiton.topia.persistence.TopiaException;
-
import static org.nuiton.i18n.I18n.l;
@@ -55,9 +55,7 @@ public class RedistributeSampleNumberToSetAction extends AbstractLevel1Action {
}
public Set<Species> getSpeciesOfSample(Sample sample) {
- Set<Species> result = SpeciesTopiaDao.getAllSpecies(
- sample.getStandardiseSampleSpecies());
- return result;
+ return SpeciesTopiaDao.getAllSpecies(sample.getStandardiseSampleSpecies());
}
public SpeciesModel getResultSpeciesModel(Sample sample, Species species) {
@@ -88,7 +86,7 @@ public class RedistributeSampleNumberToSetAction extends AbstractLevel1Action {
}
@Override
- protected boolean executeAction() throws Exception {
+ protected boolean executeAction() {
setNbSteps(2 * samplesByTrip.size());
@@ -125,8 +123,8 @@ public class RedistributeSampleNumberToSetAction extends AbstractLevel1Action {
}
incrementsProgression();
- long sampleTotalNumber = 0l;
- long sampleWellTotalNumber = 0l;
+ long sampleTotalNumber = 0L;
+ long sampleWellTotalNumber = 0L;
for (StandardiseSampleSpecies sampleSpecies :
sample.getStandardiseSampleSpecies()) {
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level1/StandardizeSampleMeasuresAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/StandardizeSampleMeasuresAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level1/StandardizeSampleMeasuresAction.java
@@ -8,12 +8,12 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
@@ -36,14 +36,15 @@ import fr.ird.t3.entities.reference.SpeciesLengthStep;
import fr.ird.t3.entities.reference.SpeciesLengthStepTopiaDao;
import fr.ird.t3.entities.reference.SpeciesTopiaDao;
import fr.ird.t3.services.ioc.InjectDAO;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.persistence.TopiaException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import static org.nuiton.i18n.I18n.l;
@@ -61,29 +62,22 @@ import static org.nuiton.i18n.I18n.l;
*/
public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
+ public static final String RESULT_SPECIES_MODEL = "speciesModel";
/** Logger. */
- private static final Log log =
- LogFactory.getLog(StandardizeSampleMeasuresAction.class);
-
+ private static final Log log = LogFactory.getLog(StandardizeSampleMeasuresAction.class);
@InjectDAO(entityType = StandardiseSampleSpecies.class)
- protected StandardiseSampleSpeciesTopiaDao standardiseSampleSpeciesDAO;
-
+ private StandardiseSampleSpeciesTopiaDao standardiseSampleSpeciesDAO;
@InjectDAO(entityType = StandardiseSampleSpeciesFrequency.class)
- protected StandardiseSampleSpeciesFrequencyTopiaDao standardiseSampleSpeciesFrequencyDAO;
-
+ private StandardiseSampleSpeciesFrequencyTopiaDao standardiseSampleSpeciesFrequencyDAO;
@InjectDAO(entityType = SpeciesLengthStep.class)
- protected SpeciesLengthStepTopiaDao speciesLengthStepDAO;
-
- public static final String RESULT_SPECIES_MODEL = "speciesModel";
+ private SpeciesLengthStepTopiaDao speciesLengthStepDAO;
public StandardizeSampleMeasuresAction() {
super(Level1Step.STANDARDIZE_SAMPLE_MEASURE);
}
public List<StandardizeSpeciesCountModel> getResultSpeciesModel() {
- List<StandardizeSpeciesCountModel> result =
- getResultAsList(RESULT_SPECIES_MODEL, StandardizeSpeciesCountModel.class);
- return result;
+ return getResultAsList(RESULT_SPECIES_MODEL, StandardizeSpeciesCountModel.class);
}
public StandardizeSpeciesCountModel getTotalSpeciesModel() {
@@ -101,7 +95,7 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
}
@Override
- protected boolean executeAction() throws Exception {
+ protected boolean executeAction() {
Map<Species, StandardizeSpeciesCountModel> model = Maps.newHashMap();
@@ -114,11 +108,7 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
for (Sample sample : samples) {
- doExecuteSample(
- trip,
- sample,
- model
- );
+ doExecuteSample(trip, sample, model);
// mark sample as treated for this step of level 1 treatment
markAsTreated(sample);
@@ -135,23 +125,20 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
return true;
}
- protected void doExecuteSample(Trip trip,
- Sample sample,
- Map<Species, StandardizeSpeciesCountModel> model) throws TopiaException {
+ private void doExecuteSample(Trip trip, Sample sample, Map<Species, StandardizeSpeciesCountModel> model) throws TopiaException {
incrementsProgression();
String tripStr = decorate(trip);
- addInfoMessage(l(locale, "t3.level1.standardizeSampleMeasures.treat.sample",
- tripStr, sample.getSampleNumber()));
+ addInfoMessage(l(locale, "t3.level1.standardizeSampleMeasures.treat.sample", tripStr, sample.getSampleNumber()));
if (!sample.isStandardiseSampleSpeciesEmpty()) {
// was already computed, remove previous data
addInfoMessage(
l(locale, "t3.level1.standardizeSampleMeasures.treat.remove.previously.treated.data",
- sample.sizeStandardiseSampleSpecies()));
+ sample.sizeStandardiseSampleSpecies()));
sample.clearStandardiseSampleSpecies();
}
@@ -162,8 +149,7 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
}
// split sample species by species
- Multimap<Species, SampleSpecies> sampleSpeciesBySpecies =
- SpeciesTopiaDao.groupBySpecies(sample.getSampleSpecies());
+ Multimap<Species, SampleSpecies> sampleSpeciesBySpecies = SpeciesTopiaDao.groupBySpecies(sample.getSampleSpecies());
for (Species species : sampleSpeciesBySpecies.keySet()) {
@@ -175,22 +161,14 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
}
// get sample species for this species
- Collection<SampleSpecies> sampleSpecies =
- sampleSpeciesBySpecies.get(species);
+ Collection<SampleSpecies> sampleSpecies = sampleSpeciesBySpecies.get(species);
- // obtain once for all the length classes for this species on
- // this ocean
+ //FIXME I replace ocean by trip.departureHarbour.ocean, check this is ok (See #260)
+ // obtain once for all the length classes for this species on this ocean
Multimap<Integer, SpeciesLengthStep> proportionsForSpecies =
- speciesLengthStepDAO.findAllByOceanAndSpeciesGroupByLd1Class(
- ocean,
- species);
-
- doExecuteSampleSpecies(species,
- sampleSpecies,
- sample,
- speciesCountModel,
- proportionsForSpecies
- );
+ speciesLengthStepDAO.findAllByOceanAndSpeciesGroupByLd1Class(trip.getDepartureHarbour().getOcean(), species);
+
+ doExecuteSampleSpecies(species, sampleSpecies, sample, speciesCountModel, proportionsForSpecies);
}
}
@@ -204,23 +182,16 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
// each species will give exactly one entry in StandardiseSampleSpecies table
StandardiseSampleSpecies standardiseSampleSpecies =
- standardiseSampleSpeciesDAO.create(
- StandardiseSampleSpecies.PROPERTY_SPECIES, species
- );
+ standardiseSampleSpeciesDAO.create(StandardiseSampleSpecies.PROPERTY_SPECIES, species);
- // contains for each lflengthclass, the number of fishes
+ // contains for each lfLengthClass, the number of fishes
Map<Integer, Float> frequencies = Maps.newTreeMap();
float measuredCount = 0;
float totalCount = 0;
for (SampleSpecies sampleSpecie : sampleSpecies) {
measuredCount += sampleSpecie.getMeasuredCount();
totalCount += sampleSpecie.getTotalCount();
-
- collectSampleSpeciesFrequencies(
- proportionsForSpecies,
- sampleSpecie,
- frequencies
- );
+ collectSampleSpeciesFrequencies(proportionsForSpecies, sampleSpecie, frequencies);
}
// set the total measured count computed
@@ -238,13 +209,12 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
// must recode length classes
- finalFrequencies = Maps.newTreeMap();
+ finalFrequencies = new TreeMap<>();
for (Map.Entry<Integer, Float> ee : frequencies.entrySet()) {
Integer lfLengthClass = ee.getKey();
Float numberExtrapolated = ee.getValue();
- int finalLengthClass = lfLengthClass -
- lfLengthClass % lfLengthClassStep;
+ int finalLengthClass = lfLengthClass - lfLengthClass % lfLengthClassStep;
Float finalNumber = finalFrequencies.get(finalLengthClass);
if (finalNumber == null) {
@@ -277,10 +247,7 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
// attach to sample new data
sample.addStandardiseSampleSpecies(standardiseSampleSpecies);
addInfoMessage(l(locale, "t3.level1.standardizeSampleMeasures.treat.resume.for.species",
- decorate(species),
- oldCOunt,
- newCount
- ));
+ decorate(species), oldCOunt, newCount));
}
protected void collectSampleSpeciesFrequencies(Multimap<Integer, SpeciesLengthStep> proportionsForSpecies,
@@ -304,16 +271,15 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
// ld1 length class is in cm in sample, but in milimeter in SpeciesLengthStep table
int ld1LengthClass = sampleSpeciesFrequency.getLengthClass() * 10;
- Collection<SpeciesLengthStep> proportions =
- proportionsForSpecies.get(ld1LengthClass);
+ Collection<SpeciesLengthStep> proportions = proportionsForSpecies.get(ld1LengthClass);
if (CollectionUtils.isEmpty(proportions)) {
//TODO This should be an error ?
String message = l(locale, "t3.level1.standardizeSampleMeasures.warning.lfConversion.not.found",
- decorate(ocean),
- decorate(species),
- ld1LengthClass);
+ decorate(getConfiguration().getOceans()),
+ decorate(species),
+ ld1LengthClass);
if (log.isWarnEnabled()) {
log.warn(message);
}
@@ -336,14 +302,8 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
// just add lf frequencies
- for (SampleSpeciesFrequency sampleSpecyFrequency :
- sampleSpecies.getSampleSpeciesFrequency()) {
-
- addLFFrequency(
- sampleSpecyFrequency.getLengthClass(),
- sampleSpecyFrequency.getNumberExtrapolated(),
- frequencies
- );
+ for (SampleSpeciesFrequency sampleSpecyFrequency : sampleSpecies.getSampleSpeciesFrequency()) {
+ addLFFrequency(sampleSpecyFrequency.getLengthClass(), sampleSpecyFrequency.getNumberExtrapolated(), frequencies);
}
}
}
@@ -352,12 +312,7 @@ public class StandardizeSampleMeasuresAction extends AbstractLevel1Action {
float number,
Map<Integer, Float> frequencies) throws TopiaException {
- Float standardiseSampleSpecieFrequency = frequencies.get(lengthClass);
- if (standardiseSampleSpecieFrequency == null) {
-
- standardiseSampleSpecieFrequency = 0.f;
- frequencies.put(lengthClass, standardiseSampleSpecieFrequency);
- }
+ Float standardiseSampleSpecieFrequency = frequencies.computeIfAbsent(lengthClass, k -> 0.f);
standardiseSampleSpecieFrequency += number;
=====================================
t3-actions/src/test/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountActionResumeTest.java
=====================================
--- a/t3-actions/src/test/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountActionResumeTest.java
+++ b/t3-actions/src/test/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountActionResumeTest.java
@@ -60,13 +60,11 @@ public class ComputeSetDurationAndPositiveSetCountActionResumeTest extends Abstr
Map<String, Object> parameters = super.createTemplateParameters();
- Map<String, String> vesselSimpleTypes = new TreeMap<String, String>();
- putInMap(vesselSimpleTypes,
- fixtures.vesselSimpleTypeCanneur(),
- fixtures.vesselSimpleTypeSenneur());
+ Map<String, String> vesselSimpleTypes = new TreeMap<>();
+ putInMap(vesselSimpleTypes, fixtures.vesselSimpleTypeCanneur(), fixtures.vesselSimpleTypeSenneur());
parameters.put("vesselSimpleTypes", vesselSimpleTypes);
- Map<String, String> fleets = new TreeMap<String, String>();
+ Map<String, String> fleets = new TreeMap<>();
putInMap(fleets, fixtures.frenchCountry());
parameters.put("fleets", fleets);
=====================================
t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetActionResumeTest.java
=====================================
--- a/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetActionResumeTest.java
+++ b/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ComputeWeightOfCategoriesForSetActionResumeTest.java
@@ -23,7 +23,6 @@ package fr.ird.t3.actions.data.level1;
import org.junit.Test;
import java.util.Locale;
-import java.util.Map;
/**
* To test the resume generation of action
@@ -44,13 +43,13 @@ public class ComputeWeightOfCategoriesForSetActionResumeTest extends AbstractLev
action.nbSampleWithoutWell = 1;
}
- @Override
- protected Map<String, Object> createTemplateParameters() {
-
- Map<String, Object> parameters = super.createTemplateParameters();
-
- return parameters;
- }
+// @Override
+// protected Map<String, Object> createTemplateParameters() {
+//
+// Map<String, Object> parameters = super.createTemplateParameters();
+//
+// return parameters;
+// }
@Test
public void testRender() throws Exception {
=====================================
t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightActionResumeTest.java
=====================================
--- a/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightActionResumeTest.java
+++ b/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightActionResumeTest.java
@@ -24,7 +24,6 @@ package fr.ird.t3.actions.data.level1;
import org.junit.Test;
import java.util.Locale;
-import java.util.Map;
/**
* Tests the {@link ConvertSampleSetSpeciesFrequencyToWeightAction}.
@@ -43,13 +42,13 @@ public class ConvertSampleSetSpeciesFrequencyToWeightActionResumeTest extends Ab
super.prepareAction(action, locale);
}
- @Override
- protected Map<String, Object> createTemplateParameters() {
-
- Map<String, Object> parameters = super.createTemplateParameters();
-
- return parameters;
- }
+// @Override
+// protected Map<String, Object> createTemplateParameters() {
+//
+// Map<String, Object> parameters = super.createTemplateParameters();
+//
+// return parameters;
+// }
@Test
public void testRender() throws Exception {
=====================================
t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightActionResumeTest.java
=====================================
--- a/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightActionResumeTest.java
+++ b/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightActionResumeTest.java
@@ -23,7 +23,6 @@ package fr.ird.t3.actions.data.level1;
import org.junit.Test;
import java.util.Locale;
-import java.util.Map;
/**
* Tests the {@link ConvertSetSpeciesFrequencyToWeightAction}.
@@ -45,13 +44,13 @@ public class ConvertSetSpeciesFrequencyToWeightActionResumeTest extends Abstract
action.nbCreatedFishesInSetSpeciesFrequency = 102;
}
- @Override
- protected Map<String, Object> createTemplateParameters() {
-
- Map<String, Object> parameters = super.createTemplateParameters();
-
- return parameters;
- }
+// @Override
+// protected Map<String, Object> createTemplateParameters() {
+//
+// Map<String, Object> parameters = super.createTemplateParameters();
+//
+// return parameters;
+// }
@Test
public void testRender() throws Exception {
=====================================
t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetActionResumeTest.java
=====================================
--- a/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetActionResumeTest.java
+++ b/t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleWeightToSetActionResumeTest.java
@@ -23,7 +23,6 @@ package fr.ird.t3.actions.data.level1;
import org.junit.Test;
import java.util.Locale;
-import java.util.Map;
/**
* To test the resume generation of action
@@ -46,13 +45,13 @@ public class ExtrapolateSampleWeightToSetActionResumeTest extends AbstractLevel1
action.nbCreatedFishesInSetSpeciesFrequency = 102;
}
- @Override
- protected Map<String, Object> createTemplateParameters() {
-
- Map<String, Object> parameters = super.createTemplateParameters();
-
- return parameters;
- }
+// @Override
+// protected Map<String, Object> createTemplateParameters() {
+//
+// Map<String, Object> parameters = super.createTemplateParameters();
+//
+// return parameters;
+// }
@Test
public void testRender() throws Exception {
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1ConfigureAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1ConfigureAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1ConfigureAction.java
@@ -33,15 +33,16 @@ import fr.ird.t3.entities.reference.SampleType;
import fr.ird.t3.services.ioc.InjectDAO;
import fr.ird.t3.services.ioc.InjectDecoratedBeans;
import fr.ird.t3.web.actions.AbstractConfigureAction;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.collections.MapUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Abstract run action for all level1 actions.
@@ -57,26 +58,26 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
private static final long serialVersionUID = 1L;
- protected final Level1Step[] requiredSteps;
+ private final Level1Step[] requiredSteps;
- protected final Level1Step currentStep;
+ private final Level1Step currentStep;
@InjectDAO(entityType = Sample.class)
- protected transient SampleTopiaDao sampleDAO;
+ private transient SampleTopiaDao sampleDAO;
@InjectDecoratedBeans(beanType = SampleQuality.class, filterById = true, pathIds = "sampleQualityIds")
- protected Map<String, String> sampleQualities;
+ private Map<String, String> sampleQualities;
@InjectDecoratedBeans(beanType = SampleType.class, filterById = true)
- protected Map<String, String> sampleTypes;
+ private Map<String, String> sampleTypes;
@InjectDecoratedBeans(beanType = Country.class)
- protected Map<String, String> fleets;
+ private Map<String, String> fleets;
- @InjectDecoratedBeans(beanType = Ocean.class)
- protected Map<String, String> oceans;
+ @InjectDecoratedBeans(beanType = Ocean.class, filterById = true)
+ private Map<String, String> oceans;
- protected Map<String, String> useRfMinus10AndRfPlus10OrNot;
+ private Map<String, String> useRfMinus10AndRfPlus10OrNot;
public AbstractLevel1ConfigureAction(Level1Step currentStep) {
super(Level1Configuration.class);
@@ -110,7 +111,7 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
log.info("Selected fleet countries : " + configuration.getFleetIds());
log.info("Selected sample qualities : " + configuration.getSampleQualityIds());
log.info("Selected sample types : " + configuration.getSampleTypeIds());
- log.info("Selected ocean : " + configuration.getOceanId());
+ log.info("Selected oceans : " + configuration.getOceanIds());
log.info("Selected begin date : " + configuration.getBeginDate());
log.info("Selected end date : " + configuration.getEndDate());
log.info("Executed steps : " + configuration.getExecutedSteps());
@@ -118,12 +119,12 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
}
@Override
- public String input() throws Exception {
+ public String input() {
return INPUT;
}
@Override
- public String execute() throws Exception {
+ public String execute() {
prepareActionContext();
return SUCCESS;
@@ -136,14 +137,12 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
// all required step already executed with this configuration
if (log.isInfoEnabled()) {
- log.info("Current configuration already treats all required step " +
- Arrays.toString(requiredSteps));
+ log.info(String.format("Current configuration already treats all required step %s", Arrays.toString(requiredSteps)));
}
} else {
- // check on each selected sample of the configuration which steps
- // are missing
+ // check on each selected sample of the configuration which steps are missing
Multimap<Level1Step, Sample> missingSteps =
getMissingRequiredStepsExecutedOnSample();
@@ -152,10 +151,7 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
// ok every steps were previously executed on selected sample
if (log.isInfoEnabled()) {
- log.info("All required steps " +
- Arrays.toString(requiredSteps) +
- "were already executed on selected samples " +
- "of current configuration.");
+ log.info(String.format("All required steps %s were already executed on selected samples of current configuration.", Arrays.toString(requiredSteps)));
}
} else {
@@ -209,8 +205,7 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
}
public Multimap<String, String> getTripIds() {
- Multimap<String, String> ids = getConfiguration().getSampleIdsByTripId();
- return ids;
+ return getConfiguration().getSampleIdsByTripId();
}
/**
@@ -228,7 +223,7 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
if (!executedSteps.contains(requiredStep)) {
if (log.isWarnEnabled()) {
- log.warn("A required step [" + requiredStep + "] was still not executed with this configuration ");
+ log.warn(String.format("A required step [%s] was still not executed with this configuration ", requiredStep));
}
return false;
}
@@ -249,19 +244,17 @@ public class AbstractLevel1ConfigureAction extends AbstractConfigureAction<Level
Collection<String> sampleIds = getTripIds().values();
- Multimap<Level1Step, Sample> missingStates =
- HashMultimap.create();
+ Multimap<Level1Step, Sample> missingStates = HashMultimap.create();
for (String sampleId : sampleIds) {
- Sample sample = sampleDAO.findByTopiaId(sampleId);
+ Sample sample = sampleDAO.forTopiaIdEquals(sampleId).findUnique();
for (Level1Step requiredStep : requiredSteps) {
boolean sampleState = requiredStep.getState(sample);
if (!sampleState) {
if (log.isWarnEnabled()) {
- log.warn("Required step " + requiredStep +
- " is missing for sample " + sampleId);
+ log.warn(String.format("Required step %s is missing for sample %s", requiredStep, sampleId));
}
missingStates.put(requiredStep, sample);
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1RunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1RunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/AbstractLevel1RunAction.java
@@ -34,7 +34,6 @@ import org.apache.commons.collections.MapUtils;
import java.util.Collection;
import java.util.Date;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -48,24 +47,18 @@ public abstract class AbstractLevel1RunAction<A extends AbstractLevel1Action> ex
private static final long serialVersionUID = 1L;
- protected final Level1Step currentStep;
-
+ private final Level1Step currentStep;
@InjectDecoratedBeans(beanType = SampleQuality.class, filterById = true, pathIds = "sampleQualityIds")
- protected Map<String, String> sampleQualities;
-
+ private Map<String, String> sampleQualities;
@InjectDecoratedBeans(beanType = SampleType.class, filterById = true)
- protected Map<String, String> sampleTypes;
-
+ private Map<String, String> sampleTypes;
@InjectDecoratedBeans(beanType = Country.class, filterById = true)
- protected Map<String, String> fleets;
+ private Map<String, String> fleets;
+ @InjectDecoratedBeans(beanType = Ocean.class, filterById = true)
+ private Map<String, String> oceans;
+ private Map<String, String> useRfMinus10AndRfPlus10OrNot;
- @InjectDecoratedBeans(beanType = Ocean.class, filterById = true, filterBySingleId = true)
- protected Map<String, String> oceans;
-
- protected Map<String, String> useRfMinus10AndRfPlus10OrNot;
-
- protected AbstractLevel1RunAction(Class<A> actionType,
- Level1Step currentStep) {
+ AbstractLevel1RunAction(Class<A> actionType, Level1Step currentStep) {
super(actionType);
this.currentStep = currentStep;
}
@@ -73,21 +66,13 @@ public abstract class AbstractLevel1RunAction<A extends AbstractLevel1Action> ex
@Override
protected void executeAction(A action) throws Exception {
- // when beginning a step, remove from executed one all the step with
- // higher ranks...
+ // when beginning a step, remove from executed one all the step with higher ranks...
Level1Configuration configuration = getConfiguration();
- Set<Level1Step> executedSteps =
- configuration.getExecutedSteps();
+ Set<Level1Step> executedSteps = configuration.getExecutedSteps();
int ordinal = currentStep.ordinal();
- Iterator<Level1Step> itr = executedSteps.iterator();
- while (itr.hasNext()) {
- Level1Step step = itr.next();
- if (step.ordinal() >= ordinal) {
- itr.remove();
- }
- }
+ executedSteps.removeIf(step -> step.ordinal() >= ordinal);
super.executeAction(action);
@@ -134,8 +119,7 @@ public abstract class AbstractLevel1RunAction<A extends AbstractLevel1Action> ex
}
public Multimap<String, String> getTripIds() {
- Multimap<String, String> ids = getConfiguration().getSampleIdsByTripId();
- return ids;
+ return getConfiguration().getSampleIdsByTripId();
}
public Map<String, String> getUseRfMinus10AndRfPlus10OrNot() {
@@ -143,14 +127,8 @@ public abstract class AbstractLevel1RunAction<A extends AbstractLevel1Action> ex
}
@Override
- protected Map<String, Object> prepareResumeParameters(A action,
- Exception error,
- Date startDate,
- Date endDate) {
- Map<String, Object> map = super.prepareResumeParameters(action,
- error,
- startDate,
- endDate);
+ protected Map<String, Object> prepareResumeParameters(A action, Exception error, Date startDate, Date endDate) {
+ Map<String, Object> map = super.prepareResumeParameters(action, error, startDate, endDate);
map.put("oceans", oceans);
map.put("sampleQualities", sampleQualities);
map.put("sampleTypes", sampleTypes);
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ComputeWeightOfCategoriesForSetRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ComputeWeightOfCategoriesForSetRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ComputeWeightOfCategoriesForSetRunAction.java
@@ -34,7 +34,6 @@ public class ComputeWeightOfCategoriesForSetRunAction extends AbstractLevel1RunA
private static final long serialVersionUID = 1L;
public ComputeWeightOfCategoriesForSetRunAction() {
- super(ComputeWeightOfCategoriesForSetAction.class,
- Level1Step.COMPUTE_WEIGHT_OF_CATEGORIES_FOR_SET);
+ super(ComputeWeightOfCategoriesForSetAction.class, Level1Step.COMPUTE_WEIGHT_OF_CATEGORIES_FOR_SET);
}
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightRunAction.java
@@ -35,7 +35,6 @@ public class ConvertSampleSetSpeciesFrequencyToWeightRunAction extends AbstractL
private static final long serialVersionUID = 1L;
public ConvertSampleSetSpeciesFrequencyToWeightRunAction() {
- super(ConvertSampleSetSpeciesFrequencyToWeightAction.class,
- Level1Step.CONVERT_SAMPLE_SET_SPECIES_FREQUENCY_TO_WEIGHT);
+ super(ConvertSampleSetSpeciesFrequencyToWeightAction.class, Level1Step.CONVERT_SAMPLE_SET_SPECIES_FREQUENCY_TO_WEIGHT);
}
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSetSpeciesFrequencyToWeightRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSetSpeciesFrequencyToWeightRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ConvertSetSpeciesFrequencyToWeightRunAction.java
@@ -34,7 +34,6 @@ public class ConvertSetSpeciesFrequencyToWeightRunAction extends AbstractLevel1R
private static final long serialVersionUID = 1L;
public ConvertSetSpeciesFrequencyToWeightRunAction() {
- super(ConvertSetSpeciesFrequencyToWeightAction.class,
- Level1Step.CONVERT_SET_SPECIES_FREQUENCY_TO_WEIGHT);
+ super(ConvertSetSpeciesFrequencyToWeightAction.class, Level1Step.CONVERT_SET_SPECIES_FREQUENCY_TO_WEIGHT);
}
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleCountedAndMeasuredRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleCountedAndMeasuredRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleCountedAndMeasuredRunAction.java
@@ -38,24 +38,13 @@ public class ExtrapolateSampleCountedAndMeasuredRunAction extends AbstractLevel1
private static final long serialVersionUID = 1L;
public ExtrapolateSampleCountedAndMeasuredRunAction() {
- super(ExtrapolateSampleCountedAndMeasuredAction.class,
- Level1Step.EXTRAPOLATE_SAMPLE_COUNTED_AND_MEASURED);
+ super(ExtrapolateSampleCountedAndMeasuredAction.class, Level1Step.EXTRAPOLATE_SAMPLE_COUNTED_AND_MEASURED);
}
@Override
- protected Map<String, Object> prepareResumeParameters(
- ExtrapolateSampleCountedAndMeasuredAction action,
- Exception error,
- Date startDate,
- Date endDate) {
- Map<String, Object> parameters =
- super.prepareResumeParameters(action,
- error,
- startDate,
- endDate
- );
+ protected Map<String, Object> prepareResumeParameters(ExtrapolateSampleCountedAndMeasuredAction action, Exception error, Date startDate, Date endDate) {
+ Map<String, Object> parameters = super.prepareResumeParameters(action, error, startDate, endDate);
parameters.put("speciesDecorator", getDecorator(Species.class));
-
return parameters;
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleWeightToSetRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleWeightToSetRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ExtrapolateSampleWeightToSetRunAction.java
@@ -34,7 +34,6 @@ public class ExtrapolateSampleWeightToSetRunAction extends AbstractLevel1RunActi
private static final long serialVersionUID = 1L;
public ExtrapolateSampleWeightToSetRunAction() {
- super(ExtrapolateSampleWeightToSetAction.class,
- Level1Step.EXTRAPOLATE_SAMPLE_WEIGHT_TO_SET);
+ super(ExtrapolateSampleWeightToSetAction.class, Level1Step.EXTRAPOLATE_SAMPLE_WEIGHT_TO_SET);
}
}
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction.java
@@ -35,22 +35,21 @@ import fr.ird.t3.entities.reference.SampleType;
import fr.ird.t3.entities.reference.SampleTypeTopiaDao;
import fr.ird.t3.entities.type.T3Date;
import fr.ird.t3.services.DecoratorService;
-import fr.ird.t3.services.ioc.InjectDAO;
import fr.ird.t3.services.ioc.InjectDecoratedBeans;
import fr.ird.t3.services.ioc.InjectFromDAO;
import fr.ird.t3.web.actions.AbstractConfigureAction;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.nuiton.decorator.Decorator;
import org.nuiton.topia.persistence.util.TopiaEntityHelper;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
/**
* Action to manage the configuration of level 1.
*
@@ -62,26 +61,23 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
private static final long serialVersionUID = 1L;
@InjectDecoratedBeans(beanType = SampleQuality.class)
- protected Map<String, String> sampleQualities;
+ private Map<String, String> sampleQualities;
@InjectDecoratedBeans(beanType = SampleType.class)
- protected Map<String, String> sampleTypes;
+ private Map<String, String> sampleTypes;
@InjectDecoratedBeans(beanType = Country.class)
- protected Map<String, String> fleets;
+ private Map<String, String> fleets;
@InjectDecoratedBeans(beanType = Ocean.class)
- protected Map<String, String> oceans;
+ private Map<String, String> oceans;
@InjectFromDAO(entityType = Trip.class, method = "findAllForLevel1")
- protected Collection<Trip> trips;
+ private Collection<Trip> trips;
- @InjectDAO(entityType = Ocean.class)
- protected transient OceanTopiaDao oceanDAO;
+ private Map<String, Trip> tripByTopiaIds;
- protected Map<String, Trip> tripByTopiaIds;
-
- protected Map<String, String> useRfMinus10AndRfPlus10OrNot;
+ private Map<String, String> useRfMinus10AndRfPlus10OrNot;
public ManageLevel1ConfigurationAction() {
super(Level1Configuration.class);
@@ -124,18 +120,17 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
conf.setSampleTypes(sortToList(SampleTypeTopiaDao.getAllSampleTypes(trips)));
conf.setFleets(sortToList(CountryTopiaDao.getAllFleetCountries(trips)));
conf.setOceans(sortToList(OceanTopiaDao.getAllOcean(trips)));
- if (StringUtils.isEmpty(conf.getOceanId()) &&
- CollectionUtils.isNotEmpty(conf.getOceans())) {
- conf.setOceanId(conf.getOceans().get(0).getTopiaId());
- }
+// if (StringUtils.isEmpty(conf.getOceanId()) &&
+// CollectionUtils.isNotEmpty(conf.getOceans())) {
+// conf.setOceanId(conf.getOceans().get(0).getTopiaId());
+// }
// set ids list to empty lists
List<String> ids;
// use default sample qualities
ids = T3EntityHelper.selectIdsByCodes(conf.getSampleQualities(), 1, 2, 3, 9);
- conf.setSampleQualityIds(
- ids);
+ conf.setSampleQualityIds(ids);
// use default sample types
ids = T3EntityHelper.selectIdsByCodes(conf.getSampleTypes(), 1, 2, 3, 9);
@@ -165,8 +160,7 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
injectOnly(InjectDecoratedBeans.class);
DecoratorService decoratorService = newService(DecoratorService.class);
- Multimap<String, String> matchingTrips = conf.getMatchingTrips(
- trips, getLocale(), decoratorService);
+ Multimap<String, String> matchingTrips = conf.getMatchingTrips(trips, getLocale(), decoratorService);
conf.setSampleIdsByTripId(matchingTrips);
}
@@ -179,7 +173,7 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
}
}
- public final String prepareConfiguration() throws Exception {
+ public final String prepareConfiguration() {
if (!isConfigurationInSession() && !hasFieldErrors()) {
@@ -189,7 +183,7 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
return INPUT;
}
- public String saveConfiguration() throws Exception {
+ public String saveConfiguration() {
Level1Configuration config = getConfiguration();
// each time configuration is modified, reset executed steps for
@@ -205,7 +199,7 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
}
@SkipValidation
- public String removeConfiguration() throws Exception {
+ public String removeConfiguration() {
boolean saved = isConfigurationInSession();
if (saved) {
@@ -238,9 +232,7 @@ public class ManageLevel1ConfigurationAction extends AbstractConfigureAction<Lev
}
public Map<String, Collection<String>> getTripIds() {
- Map<String, Collection<String>> ids =
- getConfiguration().getSampleIdsByTripId().asMap();
- return ids;
+ return getConfiguration().getSampleIdsByTripId().asMap();
}
public Map<String, String> getSampleQualities() {
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/RedistributeSampleNumberToSetRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/RedistributeSampleNumberToSetRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/RedistributeSampleNumberToSetRunAction.java
@@ -41,23 +41,12 @@ public class RedistributeSampleNumberToSetRunAction extends AbstractLevel1RunAct
private static final long serialVersionUID = 1L;
public RedistributeSampleNumberToSetRunAction() {
- super(RedistributeSampleNumberToSetAction.class,
- Level1Step.REDISTRIBUTE_SAMPLE_SET_TO_SET);
+ super(RedistributeSampleNumberToSetAction.class, Level1Step.REDISTRIBUTE_SAMPLE_SET_TO_SET);
}
@Override
- protected Map<String, Object> prepareResumeParameters(
- RedistributeSampleNumberToSetAction action,
- Exception error,
- Date startDate,
- Date endDate) {
- Map<String, Object> parameters = super.prepareResumeParameters(
- action,
- error,
- startDate,
- endDate
- );
-
+ protected Map<String, Object> prepareResumeParameters(RedistributeSampleNumberToSetAction action, Exception error, Date startDate, Date endDate) {
+ Map<String, Object> parameters = super.prepareResumeParameters(action, error, startDate, endDate);
parameters.put("speciesDecorator", getDecorator(Species.class));
parameters.put("tripDecorator", getDecorator(Trip.class, DecoratorService.WITH_ID));
parameters.put("activityDecorator", getDecorator(Activity.class));
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/StandardizeSampleMeasuresRunAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/StandardizeSampleMeasuresRunAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level1/StandardizeSampleMeasuresRunAction.java
@@ -38,24 +38,13 @@ public class StandardizeSampleMeasuresRunAction extends AbstractLevel1RunAction<
private static final long serialVersionUID = 1L;
public StandardizeSampleMeasuresRunAction() {
- super(StandardizeSampleMeasuresAction.class,
- Level1Step.STANDARDIZE_SAMPLE_MEASURE);
+ super(StandardizeSampleMeasuresAction.class, Level1Step.STANDARDIZE_SAMPLE_MEASURE);
}
@Override
- protected Map<String, Object> prepareResumeParameters(
- StandardizeSampleMeasuresAction action,
- Exception error,
- Date startDate,
- Date endDate) {
- Map<String, Object> parameters =
- super.prepareResumeParameters(action,
- error,
- startDate,
- endDate
- );
+ protected Map<String, Object> prepareResumeParameters(StandardizeSampleMeasuresAction action, Exception error, Date startDate, Date endDate) {
+ Map<String, Object> parameters = super.prepareResumeParameters(action, error, startDate, endDate);
parameters.put("speciesDecorator", getDecorator(Species.class));
-
return parameters;
}
}
=====================================
t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validateLevel1Configuration-validation.xml
=====================================
--- a/t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validateLevel1Configuration-validation.xml
+++ b/t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validateLevel1Configuration-validation.xml
@@ -48,9 +48,10 @@
</field>
- <field name="configuration.oceanId">
+ <field name="configuration.oceanIds">
- <field-validator type="requiredstring">
+ <field-validator type="fieldexpression">
+ <param name="expression">!configuration.oceanIds.empty</param>
<message key="t3.error.no.ocean.selected"/>
</field-validator>
=====================================
t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validation.xml
=====================================
--- a/t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validation.xml
+++ b/t3-web/src/main/resources/fr/ird/t3/web/actions/data/level1/ManageLevel1ConfigurationAction-validation.xml
@@ -48,7 +48,7 @@
</field>
- <field name="configuration.oceanId">
+ <field name="configuration.oceanIds">
<field-validator type="fieldexpression">
<param name="expression">!configuration.oceans.empty</param>
=====================================
t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1Configuration.jsp
=====================================
--- a/t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1Configuration.jsp
+++ b/t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1Configuration.jsp
@@ -56,8 +56,9 @@
list="fleets" template="mycheckboxlist"/>
<%-- selected ocean --%>
- <s:select key="configuration.oceanId" list="oceans" requiredLabel="true"
- label='%{getText("t3.common.ocean")}'/>
+ <s:checkboxlist key="configuration.oceanIds" requiredLabel="true"
+ label='%{getText("t3.common.ocean")}'
+ list="oceans" template="mycheckboxlist"/>
<%-- selected begin date --%>
<sj:datepicker key="configuration.beginDate" requiredLabel="true"
=====================================
t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1ConfigurationResume.jsp
=====================================
--- a/t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1ConfigurationResume.jsp
+++ b/t3-web/src/main/webapp/WEB-INF/jsp/data/level1/level1ConfigurationResume.jsp
@@ -45,8 +45,9 @@
label='%{getText("t3.common.fleetCountry")}'/>
<%-- selected ocean --%>
- <s:select key="configuration.oceanId" disabled="true" list="oceans"
- label='%{getText("t3.common.ocean")}'/>
+ <s:checkboxlist key="configuration.oceanIds" disabled="true"
+ list="fleets" template="mycheckboxlist"
+ label='%{getText("t3.common.ocean")}'/>
<%-- selected begin date --%>
<s:textfield key="configuration.beginDate" disabled="true"
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/617f20756a9d8882034db2ed98e28a51…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/617f20756a9d8882034db2ed98e28a51…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0.4] Calcul des durées de calées pour les activités avec setcount > 1 (Closes #241)
by Tony CHEMIT 21 Feb '18
by Tony CHEMIT 21 Feb '18
21 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
4072de7b by Tony CHEMIT at 2018-02-21T02:09:42+01:00
[N0.4] Calcul des durées de calées pour les activités avec setcount > 1 (Closes #241)
- - - - -
3 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
- t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
- t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
Changes:
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
@@ -20,7 +20,6 @@
*/
package fr.ird.t3.actions.data.level0;
-import com.google.common.collect.Maps;
import fr.ird.t3.entities.T3Functions;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.Trip;
@@ -41,14 +40,14 @@ import org.nuiton.util.TimeLog;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import static org.nuiton.i18n.I18n.l;
/**
- * Compute for the all activities of selected trips, the set duration and the
- * positive set count.
+ * Compute for the all activities of selected trips, the set duration and the positive set count.
* <p/>
- * <strong>Note:</strong> The rf2 msut have been computed on each trip.
+ * <strong>Note:</strong> The rf2 must have been computed on each trip.
*
* @author Tony Chemit - dev(a)tchemit.fr
* @since 1.0
@@ -56,24 +55,21 @@ import static org.nuiton.i18n.I18n.l;
public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0Action<ComputeSetDurationAndPositiveSetCountConfiguration> {
/** Logger. */
- private static final Log log = LogFactory.getLog(
- ComputeSetDurationAndPositiveSetCountAction.class);
-
+ private static final Log log = LogFactory.getLog(ComputeSetDurationAndPositiveSetCountAction.class);
@InjectDAO(entityType = SetDuration.class)
- protected SetDurationTopiaDao setDurationDAO;
-
- /** Count of treated activites. */
- protected int nbActivities;
+ private SetDurationTopiaDao setDurationDAO;
+ /** Count of treated activities. */
+ private int nbActivities;
+ /** Count of positive activities found. */
+ private int nbPositiveActivities;
/** Count of set (sum(a.setCount) on each activity trip). */
- protected int nbSet;
- /** Count of positive activites found. */
- protected int nbPositiveActivities;
+ private int nbSet;
/**
* Cache of setDuration (improve a lot performance!).
*
* @since 1.3
*/
- protected Map<String, SetDuration> setDurations;
+ private Map<String, SetDuration> setDurations;
public ComputeSetDurationAndPositiveSetCountAction() {
super(Level0Step.COMPUTE_SET_DURATION_AND_POSITIVE_SET_COUNT);
@@ -98,8 +94,7 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A
for (Trip trip : tripList) {
nbActivities += trip.sizeActivity();
}
-
- setDurations = Maps.newTreeMap();
+ setDurations = new TreeMap<>();
}
@Override
@@ -108,177 +103,112 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A
}
@Override
- protected boolean executeAction() throws Exception {
-
+ protected boolean executeAction() {
boolean result = false;
-
if (CollectionUtils.isNotEmpty(trips)) {
-
setNbSteps(2 * nbActivities);
-
- // do action for each data using the prepared action context
-
for (Trip trip : trips) {
-
result |= executeForTrip(trip);
}
}
-
return result;
}
- protected boolean executeForTrip(Trip trip) throws TopiaException {
-
+ private boolean executeForTrip(Trip trip) throws TopiaException {
long s0 = TimeLog.getTime();
-
String tripStr = decorate(trip, DecoratorService.WITH_ID);
-
- if (!trip.isActivityEmpty()) {
-
+ if (trip.isActivityNotEmpty()) {
int year = T3Functions.TRIP_TO_LANDING_YEAR.apply(trip);
-
Set<Species> species = trip.getElementaryCatchSpecies();
-
for (Activity activity : trip.getActivity()) {
+ String activityStr = String.format("Activity %s - %s", tripStr, decorate(activity));
+ int setCount = activity.getSetCount();
+ nbSet += setCount;
- String activityStr = "Activity " + tripStr + " - " +
- decorate(activity);
-
- nbSet += activity.getSetCount();
- incrementsProgression();
-
- float totalCatchesWeight =
- activity.getElementaryCatchTotalWeightRf2(species);
-
+ float totalCatchesWeight = activity.getElementaryCatchTotalWeightRf2(species);
if (log.isDebugEnabled()) {
- log.debug("Total catches " + totalCatchesWeight +
- " for " + activityStr);
+ log.debug(String.format("Total catches %s for %s", totalCatchesWeight, activityStr));
}
+ int positiveSetCount = computePositiveSetCount(totalCatchesWeight > 0, activity);
+ activity.setPositiveSetCount(positiveSetCount);
+ if (positiveSetCount > 0) {
+ nbPositiveActivities++;
+ }
+ incrementsProgression();
- computePositiveSetCount(activityStr, totalCatchesWeight, activity);
-
+ float subCatch = totalCatchesWeight;
+ if (positiveSetCount > 0) {
+ subCatch = subCatch / activity.getPositiveSetCount();
+ }
+ int negativeSetCount = setCount - positiveSetCount;
+ Float setDuration = computeSetDuration(year, subCatch, activity, negativeSetCount);
+ activity.setSetDuration(setDuration);
incrementsProgression();
- computeSetDuration(year,
- totalCatchesWeight, activity);
String message = l(locale, "t3.level0.computeActivitySetDurationAndPositiveSetCount",
- activityStr,
- activity.getSetDuration(),
- activity.getPositiveSetCount()
- );
+ activityStr, setDuration, positiveSetCount, negativeSetCount);
addInfoMessage(message);
if (log.isDebugEnabled()) {
log.debug(message);
}
}
}
-
markTripAsTreated(trip);
-
getTimeLog().log(s0, "executeForTrip for " + tripStr);
-
// always commit since trip is always modified
return true;
}
- protected void computePositiveSetCount(String activityStr,
- float totalCatchesWeight,
- Activity activity) {
-
- int positiveSetCount = 0;
-
- if (totalCatchesWeight > 0) {
-
- // ok some catches found on activity, it means
- // positive set
-
- positiveSetCount = activity.getSetCount();
-
- } else {
- if (log.isDebugEnabled()) {
- log.debug("Catches with no catches! for " + activityStr);
- }
- }
-
- if (log.isDebugEnabled()) {
- String message = "Computed positive Set Count = " +
- positiveSetCount + " for " + activityStr;
- log.debug(message);
- }
- activity.setPositiveSetCount(positiveSetCount);
-
- if (positiveSetCount > 0) {
- nbPositiveActivities++;
+ private int computePositiveSetCount(boolean withCatches, Activity activity) {
+ if (withCatches) {
+ // ok some catches found on activity, it means positive set
+ return activity.getSetCount();
}
+ return 0;
}
- protected void computeSetDuration(int year,
- float totalCatchesWeight,
- Activity activity) throws TopiaException {
-
+ private Float computeSetDuration(int year, float subCatch, Activity activity, int negativeSetCount) throws TopiaException {
// get the correct setDuration
SetDuration setDuration = getSetDuration(activity, year);
-
if (setDuration == null) {
-
- activity.setSetDuration(0f);
-
- } else {
-
- Float setTime;
-
- if (activity.isSetNull()) {
-
- // use setDuration nullSetValue
- setTime = setDuration.getNullSetValue();
- if (log.isDebugEnabled()) {
- log.debug("Computed set duration (set is null) = " +
- setTime);
- }
- } else if (activity.isWithSetDuration()) {
-
- // use setDuration computedValue
- setTime = setDuration.getParameterB() +
- setDuration.getParameterA() * totalCatchesWeight;
- if (log.isDebugEnabled()) {
- log.debug("Computed set duration = " + setTime);
- }
- } else {
-
- // no setDuration
- setTime = null;
- if (log.isDebugEnabled()) {
- log.debug("Use null set duration (set is null) ");
- }
+ if (log.isDebugEnabled()) {
+ log.debug("No setDuration found, use 0 value.");
}
-
- activity.setSetDuration(setTime);
+ return 0f;
+ }
+ float nullSetDuration = negativeSetCount * setDuration.getNullSetValue();
+ if (activity.isSetNull()) {
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Use nullValue of set duration = %s", nullSetDuration));
+ }
+ return nullSetDuration;
+ }
+ if (activity.isWithSetDuration()) {
+ float subDuration = (setDuration.getParameterB() + setDuration.getParameterA() * subCatch);
+ float positiveSetDuration = activity.getPositiveSetCount() * subDuration;
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Computed positive set duration = %s", positiveSetDuration));
+ }
+ return nullSetDuration + positiveSetDuration;
+ }
+ // no setDuration
+ if (log.isDebugEnabled()) {
+ log.debug("Use null set duration (set is null) ");
}
+ return null;
}
- protected SetDuration getSetDuration(Activity activity, int year) throws TopiaException {
+ private SetDuration getSetDuration(Activity activity, int year) throws TopiaException {
Ocean ocean = activity.getOcean();
Country fleetCountry = activity.getTrip().getVessel().getFleetCountry();
SchoolType schoolType = activity.getSchoolType();
- String key = ocean.getCode() + ":" +
- fleetCountry.getCode() + ":" +
- schoolType.getCode() + ":" +
- year;
-
+ String key = ocean.getCode() + ":" + fleetCountry.getCode() + ":" + schoolType.getCode() + ":" + year;
SetDuration result = setDurations.get(key);
if (result == null) {
-
// no result found in cache
-
if (!setDurations.containsKey(key)) {
-
// try to load it
-
- result = setDurationDAO.findByActivityAndYear(
- activity,
- year
- );
-
+ result = setDurationDAO.findByActivityAndYear(activity, year);
if (result == null) {
addWarningMessage(
l(getLocale(), "t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound",
@@ -288,11 +218,9 @@ public class ComputeSetDurationAndPositiveSetCountAction extends AbstractLevel0A
year));
}
}
-
// store it once for all (even if result is null)
setDurations.put(key, result);
}
-
return result;
}
=====================================
t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
@@ -18,7 +18,7 @@ t3.import.warning.on.analyze=%s warnings detected on analyze import db
t3.input.AnalyzeInputSource=Data Import\: Analyze
t3.input.ImportInputSource=Input Data Import
t3.level0.action=Level 0 Operation\: %s
-t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, set duration\: %s, positiveSetCount\: %s
+t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, set duration\: %s, positiveSetCount\: %s, negativeSetCount \: %s
t3.level0.computeRF1.complete.trips.to.use.for.vessel=Found %s complete trip(s) for vessel %s
t3.level0.computeRF1.resume.for.complete.trip=Total catches weight %s / Total landing weight %s / Total local market weight %s / Detailled total local market weight %s / RF1 \= %s
t3.level0.computeRF1.resume.for.trip=Trip %s, Total catches weight %s / Total landing weight %s / Total local market weight %s / Detailled total local market weight %s
=====================================
t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
@@ -18,7 +18,7 @@ t3.import.warning.on.analyze=%s avertissements détectées lors de l'analyse de
t3.input.AnalyzeInputSource=Import de données \: Analyse des données
t3.input.ImportInputSource=Import de données
t3.level0.action=Opération du niveau 0 \: %s
-t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, durée de calée \: %s, positiveSetCount \: %s
+t3.level0.computeActivitySetDurationAndPositiveSetCount=%s, durée de calée \: %s, positiveSetCount \: %s, negativeSetCount \: %s
t3.level0.computeRF1.complete.trips.to.use.for.vessel=%s marée(s) complète(s) trouvées pour le navire %s
t3.level0.computeRF1.resume.for.complete.trip=Poids total capturé %s / Poids total vendu %s / Poids marché local résumé %s / Poids marché local détaillé %s / RF1 \= %s
t3.level0.computeRF1.resume.for.trip=Marée %s, Poids total capturé %s / Poids total vendu %s / Poids marché local résumé %s / Poids marché local détaillé %s
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/4072de7b084af636430951ea39172719…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/4072de7b084af636430951ea39172719…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] 26 commits: [REFERENTIEL] Rajouter des champs de traduction (See #245)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
7768109b by Tony CHEMIT at 2018-02-21T00:23:45+01:00
[REFERENTIEL] Rajouter des champs de traduction (See #245)
- - - - -
739d78af by Tony CHEMIT at 2018-02-21T00:23:47+01:00
L'importeur plante si les coordonnées d'un port sont à NULL (See #258)
- - - - -
d85f0d93 by Tony CHEMIT at 2018-02-21T00:23:47+01:00
generate bundle for main application
- - - - -
7d705348 by Tony CHEMIT at 2018-02-21T00:23:47+01:00
move some pom conf
- - - - -
ef991d25 by Tony CHEMIT at 2018-02-21T00:23:47+01:00
Améliorations dans la gestion des profils utilisateurs (See #251)
- - - - -
db020e61 by Tony CHEMIT at 2018-02-21T00:23:47+01:00
[LOGS] Erreur d'affichage sur le log du RF1 (See #246)
- - - - -
0d6eedfa by Tony CHEMIT at 2018-02-21T00:23:48+01:00
[N0.4][LOG] Calcul du nombre de calées et durée des calées - Petite erreur dans le log (See #160)
- - - - -
87ba2424 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
[LOGS] Inversion de libellé dans le log d'import AVDTH (See #247)
- - - - -
98f0052d by Tony CHEMIT at 2018-02-21T00:23:48+01:00
Ordonnacement du traitement de marées au 1.4 (distribution des échantillons sur les calées de l'échantillon) (See #259)
- - - - -
b1f3d41d by Tony CHEMIT at 2018-02-21T00:23:48+01:00
Erreur de libellé dans le log N0.1 (calcul des RF1) (See #270)
- - - - -
389c4eb7 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
Amélioration du log du RF1 (N0.1) (See #2171)
- - - - -
15bc0636 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
reformat code
- - - - -
14ce5598 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
Probleme de calcul de rf1 (See #283)
- - - - -
318b2b93 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
[WIN] Windows/Mauvais affichage des caractères accentués dans le navigateur (See #154)
- - - - -
780318bf by Tony CHEMIT at 2018-02-21T00:23:48+01:00
use auto-service
- - - - -
aa86a809 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
Améliorations dans la gestion des profils utilisateurs (Pour la création on deamdne aussi une confirmation du mot de passe) (See #251)
- - - - -
8c1d0a5e by Tony CHEMIT at 2018-02-21T00:23:48+01:00
improve configurations (for migration purpose)
- - - - -
6f6dcf51 by Tony CHEMIT at 2018-02-21T00:23:48+01:00
fix migrations + add a test for migraiton
- - - - -
6e537254 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
Let's go to version 2.1
- - - - -
893ac656 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
Use ird-t3-data 1.2
- - - - -
1266f890 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
[N0] Marée Echantillons seulement et gestion de l'UI du N0 (Closes #85)
- - - - -
8f5d5139 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
let's use a password, otherwise can't open test db in IDEA, what a shame...
- - - - -
cafd70e9 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
Improve persistences tests
- - - - -
8cea3365 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
9a005089 by Tony CHEMIT at 2018-02-21T00:23:49+01:00
[N0] Marée Echantillons seulement et gestion de l'UI du N0 (See #85)
- - - - -
e35842a5 by Tony CHEMIT at 2018-02-21T00:57:02+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
30 changed files:
- CONTRIBUTING.md
- pom.xml
- t3-actions/pom.xml
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeRF1Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeRF2Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeWellPlanWeightCategoriesProportionsAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/AbstractLevel1Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSampleSetSpeciesFrequencyToWeightAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ConvertSetSpeciesFrequencyToWeightAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredAction.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level3/L3SampleStratumLoader.java
- t3-actions/src/main/java/fr/ird/t3/actions/io/input/ImportInputSourceAction.java
- t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction.ftl
- t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level0/ComputeSetDurationAndPositiveSetCountAction_en.ftl
- t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction.ftl
- t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level1/RedistributeSampleNumberToSetAction_en.ftl
- t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
- t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
- t3-actions/src/test/java/fr/ird/t3/actions/AbstractActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level0/ConvertCatchesWeightCategoriesActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/AbstractLevel1ActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/ExtrapolateSampleCountedAndMeasuredActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level1/StandardizeSampleMeasuresActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level2/Level2ActionResumeTest.java
- t3-actions/src/test/java/fr/ird/t3/actions/data/level3/Level3ActionResumeTest.java
- t3-domain/pom.xml
The diff was not included because it is too large.
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/0c634be4613a78a9b21ebc1b8b53e5b…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/0c634be4613a78a9b21ebc1b8b53e5b…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0] Calcul des temps de pêche (See #240)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
0c634be4 by Tony CHEMIT at 2018-02-21T00:11:54+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
7 changed files:
- t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
- t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.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/resources/db/migration/V2_1_07_add-Route-table.sql
- t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql → t3-domain/src/main/resources/db/migration/V2_1_08_remove-Trip-fields.sql
- t3-domain/src/main/xmi/t3-persistence.properties
- t3-domain/src/main/xmi/t3-persistence.zargo
Changes:
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -59,6 +59,17 @@ public class ActivityImpl extends ActivityAbstract {
);
protected Integer quadrant;
+ private transient Date date;
+
+ @Override
+ public Date getDate() {
+ return date != null ? date : getRoute().getDate();
+ }
+
+ @Override
+ public void setDate(Date date) {
+ this.date = date;
+ }
@Override
public Trip getTrip() {
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_1.java
@@ -22,12 +22,24 @@ package fr.ird.t3.services.migration;
*/
import com.google.auto.service.AutoService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
import org.nuiton.topia.persistence.support.TopiaSqlSupport;
+import org.nuiton.util.DateUtil;
import org.nuiton.version.Versions;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Set;
/**
* Created by tchemit on 18/02/2018.
@@ -37,6 +49,8 @@ import java.util.List;
@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
public class T3MigrationCallbackV2_1 extends T3MigrationCallbackSupport {
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_1.class);
+
public T3MigrationCallbackV2_1() {
super(Versions.valueOf("2.1"));
}
@@ -49,6 +63,76 @@ public class T3MigrationCallbackV2_1 extends T3MigrationCallbackSupport {
addScript("04", "rename-SampleWell-table", queries);
addScript("05", "rename-SampleSpecies-fields", queries);
addScript("06", "referential-i18n", queries);
+ addScript("07", "add-Route-table", queries);
+
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
+ }
+
+ @Override
+ public String prepareResult(ResultSet set) throws SQLException {
+ return set.getString(1);
+ }
+ });
+
+ for (String tripId : tripList) {
+
+ int i = tripId.indexOf('#');
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1).replace(".", "").replace("#", "") + "#";
+
+ log.info("Route prefix: " + routeIdPrefix);
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ? ORDER BY date");
+ preparedStatement.setString(1, tripId);
+ return preparedStatement;
+ }
+
+ @Override
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
+ return new TripActivity(set.getString(1), set.getDate(2));
+ }
+ });
+
+ int activityIndex = 0;
+ Set<Date> days = new LinkedHashSet<>();
+ for (TripActivity activity : activityList) {
+
+ String dayDateStr = df.format(activity.date);
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
+
+ if (days.add(activity.date)) {
+
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
+ activityIndex = 0;
+ 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));
+ }
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activityIndex++, activity.activity));
+ }
+
+ if (!activityList.isEmpty()) {
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
+ }
+ }
+
+ addScript("08", "remove-Trip-fields", queries);
}
+
+ private static class TripActivity {
+
+ private final String activity;
+ private final Date date;
+
+ private TripActivity(String activity, Date date) {
+ this.activity = activity;
+ this.date = DateUtil.getDay(date);
+ }
+ }
}
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java deleted
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package fr.ird.t3.services.migration;
-
-/*
- * #%L
- * T3 :: Domain
- * %%
- * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-
-import com.google.auto.service.AutoService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
-import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
-import org.nuiton.topia.persistence.support.TopiaSqlSupport;
-import org.nuiton.util.DateUtil;
-import org.nuiton.version.Versions;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Created by tchemit on 18/02/2018.
- *
- * @author Tony Chemit - dev(a)tchemit.fr
- */
-@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
-public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
-
- private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
-
- public T3MigrationCallbackV2_2() {
- super(Versions.valueOf("2.2"));
- }
-
- @Override
- protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
- addScript("07", "add-Route-table", queries);
-
-
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
-
- List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
- @Override
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
- return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
- }
-
- @Override
- public String prepareResult(ResultSet set) throws SQLException {
- return set.getString(1);
- }
- });
-
- for (String tripId : tripList) {
-
- int i = tripId.indexOf('#');
- String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
-
- log.info("Route prefix: " + routeIdPrefix);
- List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
- @Override
- public PreparedStatement prepareQuery(Connection connection) throws SQLException {
- PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
- preparedStatement.setString(1, tripId);
- return preparedStatement;
- }
-
- @Override
- public TripActivity prepareResult(ResultSet set) throws SQLException {
- return new TripActivity(set.getString(1), set.getDate(2));
- }
- });
-
-
- Set<Date> days = new LinkedHashSet<>();
- int activityIndex = 0;
- for (TripActivity activity : activityList) {
-
- String dayDateStr = df.format(activity.date);
- String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
-
- if (days.add(activity.date)) {
-
- log.info(String.format("[%s] new Route: %s", tripId, routeId));
- // create new route
- 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));
- }
- queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
- }
-
- if (!activityList.isEmpty()) {
- queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
- }
- }
-
- addScript("08", "remove-Trip-fields", queries);
- }
-
- private static class TripActivity {
-
- private final String activity;
- private final Date date;
-
- private TripActivity(String activity, Date date) {
- this.activity = activity;
- this.date = DateUtil.getDay(date);
- }
- }
-
-}
=====================================
t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql → t3-domain/src/main/resources/db/migration/V2_1_07_add-Route-table.sql
=====================================
=====================================
t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql → t3-domain/src/main/resources/db/migration/V2_1_08_remove-Trip-fields.sql
=====================================
=====================================
t3-domain/src/main/xmi/t3-persistence.properties
=====================================
--- a/t3-domain/src/main/xmi/t3-persistence.properties
+++ b/t3-domain/src/main/xmi/t3-persistence.properties
@@ -22,7 +22,7 @@
model.tagValue.notGenerateToString=true
model.tagValue.generateOperatorForDAOHelper=true
model.tagValue.constantPrefix=PROPERTY_
-model.tagValue.version=2.2
+model.tagValue.version=2.1
model.tagValue.indexForeignKeys=true
fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/0c634be4613a78a9b21ebc1b8b53e5b5…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/0c634be4613a78a9b21ebc1b8b53e5b5…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0] Calcul des temps de pêche (See #240)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
ef5344b6 by Tony CHEMIT at 2018-02-21T00:05:08+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
3 changed files:
- t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
- t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
- t3-domain/src/main/xmi/t3-persistence.zargo
Changes:
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -59,6 +59,17 @@ public class ActivityImpl extends ActivityAbstract {
);
protected Integer quadrant;
+ private transient Date date;
+
+ @Override
+ public Date getDate() {
+ return date != null ? date : getRoute().getDate();
+ }
+
+ @Override
+ public void setDate(Date date) {
+ this.date = date;
+ }
@Override
public Trip getTrip() {
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -77,13 +77,13 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
for (String tripId : tripList) {
int i = tripId.indexOf('#');
- String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1).replace(".", "").replace("#", "") + "#";
log.info("Route prefix: " + routeIdPrefix);
List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
@Override
public PreparedStatement prepareQuery(Connection connection) throws SQLException {
- PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ? ORDER BY date");
preparedStatement.setString(1, tripId);
return preparedStatement;
}
@@ -94,9 +94,8 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
}
});
-
- Set<Date> days = new LinkedHashSet<>();
int activityIndex = 0;
+ Set<Date> days = new LinkedHashSet<>();
for (TripActivity activity : activityList) {
String dayDateStr = df.format(activity.date);
@@ -105,10 +104,10 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
if (days.add(activity.date)) {
log.info(String.format("[%s] new Route: %s", tripId, routeId));
- // create new route
+ activityIndex = 0;
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));
}
- queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activityIndex++, activity.activity));
}
if (!activityList.isEmpty()) {
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ef5344b6cf1d59efc1ca7e6d4a748231…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ef5344b6cf1d59efc1ca7e6d4a748231…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] 2 commits: [N0] Marée Echantillons seulement et gestion de l'UI du N0 (See #85)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
08a664fc by Tony CHEMIT at 2018-02-20T23:38:41+01:00
[N0] Marée Echantillons seulement et gestion de l'UI du N0 (See #85)
- - - - -
5b736ba8 by Tony CHEMIT at 2018-02-21T00:03:08+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
12 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/ComputedDataHelper.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/xmi/t3-persistence.zargo
- 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-web/src/main/java/fr/ird/t3/web/actions/data/level0/AbstractLevel0ConfigureAction.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level2/ConfigureLevel2Step1Action.java
- t3-web/src/main/java/fr/ird/t3/web/actions/data/level3/ConfigureLevel3Step1Action.java
- t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java
Changes:
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
@@ -42,6 +42,13 @@ import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.type.T3Date;
import fr.ird.t3.entities.type.T3Point;
import fr.ird.t3.entities.type.T3PointImpl;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -53,12 +60,6 @@ import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Set;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.tuple.MutablePair;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.topia.persistence.support.TopiaSqlQuery;
/**
* Client implementation of the Trip dao.
@@ -214,8 +215,8 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
}
public List<Integer> findAllYearsUsedInTrip() throws TopiaException {
- T3Date minDate = getFirstLandingDate();
- T3Date maxDate = getLastLandingDate();
+ T3Date minDate = getFirstLandingDate(null);
+ T3Date maxDate = getLastLandingDate(null);
int minYear = minDate.getYear();
int maxYear = maxDate.getYear();
Set<Integer> years = Sets.newHashSet();
@@ -227,9 +228,10 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
return result;
}
- public T3Date getFirstLandingDate() throws TopiaException {
+ public T3Date getFirstLandingDate(Boolean samplesOnly) throws TopiaException {
- String hql = " SELECT min(t.landingDate) FROM TripImpl t";
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" WHERE t.samplesOnly = " + samplesOnly);
+ String hql = " SELECT min(t.landingDate) FROM TripImpl t" + samplesOnlyFilter;
Date date = findAnyOrNull(hql);
// Date date = (Date) createQuery().
// executeToObject(getContext(),
@@ -243,9 +245,10 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
return result;
}
- public T3Date getLastLandingDate() throws TopiaException {
+ public T3Date getLastLandingDate(Boolean samplesOnly) throws TopiaException {
- String hql = " SELECT max(t.landingDate) FROM TripImpl t";
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" WHERE t.samplesOnly = " + samplesOnly);
+ String hql = " SELECT max(t.landingDate) FROM TripImpl t" + samplesOnlyFilter;
Date date = findAnyOrNull(hql);
// Date date = (Date) createQuery().
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -59,6 +59,17 @@ public class ActivityImpl extends ActivityAbstract {
);
protected Integer quadrant;
+ private transient Date date;
+
+ @Override
+ public Date getDate() {
+ return date != null ? date : getRoute().getDate();
+ }
+
+ @Override
+ public void setDate(Date date) {
+ this.date = date;
+ }
@Override
public Trip getTrip() {
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ComputedDataHelper.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ComputedDataHelper.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ComputedDataHelper.java
@@ -53,6 +53,9 @@ public class ComputedDataHelper {
public static <E extends ComputedDataAware> void deleteComputedDataLevel0(Collection<E> entities) {
if (CollectionUtils.isNotEmpty(entities)) {
for (E entity : entities) {
+ if (entity==null) {
+ continue;
+ }
entity.deleteComputedDataLevel0();
}
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
@@ -25,10 +25,11 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import fr.ird.t3.entities.T3Functions;
import fr.ird.t3.entities.data.Trip;
+import org.nuiton.topia.persistence.TopiaException;
+
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.nuiton.topia.persistence.TopiaException;
/**
* {@link Country} user dao operations.
@@ -41,14 +42,14 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
/**
* Obtains all countries used as fleet for any trip in the database.
*
+ * @param samplesOnly if null no filter else filter on value
* @return the set of fleet countries used by any trip in the database
* @throws TopiaException if any problem while querying the database
*/
- public Set<E> findAllFleetUsedInTrip() throws TopiaException {
+ public Set<E> findAllFleetUsedInTrip(Boolean samplesOnly) throws TopiaException {
- String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t " +
- "WHERE t.vessel.fleetCountry = c.id";
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
+ String hql = "SELECT DISTINCT(c) FROM CountryImpl c, TripImpl t WHERE t.vessel.fleetCountry = c.id" + samplesOnlyFilter;
// TopiaQuery query = createQuery("c")
// .addFrom(Trip.class, "t")
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -77,13 +77,13 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
for (String tripId : tripList) {
int i = tripId.indexOf('#');
- String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1).replace(".", "").replace("#", "") + "#";
log.info("Route prefix: " + routeIdPrefix);
List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
@Override
public PreparedStatement prepareQuery(Connection connection) throws SQLException {
- PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ? ORDER BY date");
preparedStatement.setString(1, tripId);
return preparedStatement;
}
@@ -94,9 +94,8 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
}
});
-
- Set<Date> days = new LinkedHashSet<>();
int activityIndex = 0;
+ Set<Date> days = new LinkedHashSet<>();
for (TripActivity activity : activityList) {
String dayDateStr = df.format(activity.date);
@@ -105,10 +104,10 @@ public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
if (days.add(activity.date)) {
log.info(String.format("[%s] new Route: %s", tripId, routeId));
- // create new route
+ activityIndex = 0;
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));
}
- queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activityIndex++, activity.activity));
}
if (!activityList.isEmpty()) {
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
@@ -101,13 +101,13 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
- result = dao.getFirstLandingDate();
+ result = dao.getFirstLandingDate(null);
Assert.assertNotNull(result);
Assert.assertEquals(endDate, result);
T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
- result = dao.getFirstLandingDate();
+ result = dao.getFirstLandingDate(null);
Assert.assertNotNull(result);
Assert.assertEquals(startDate, result);
}
@@ -122,13 +122,13 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
- result = dao.getLastLandingDate();
+ result = dao.getLastLandingDate(null);
Assert.assertNotNull(result);
Assert.assertEquals(startDate, result);
T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
- result = dao.getLastLandingDate();
+ result = dao.getLastLandingDate(null);
Assert.assertNotNull(result);
Assert.assertEquals(endDate, result);
}
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
@@ -63,7 +63,7 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest {
T3PersistenceFixtures.newTrip(tx, vessel);
- Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip();
+ Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip(null);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(country, result.iterator().next());
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level0/AbstractLevel0ConfigureAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level0/AbstractLevel0ConfigureAction.java
+++ b/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
@InjectDecoratedBeans(beanType = VesselSimpleType.class)
protected Map<String, String> vesselSimpleTypes;
- @InjectDecoratedBeans(beanType = Country.class, pathIds = "configuration.")
+ @InjectDecoratedBeans(beanType = Country.class)
protected Map<String, String> fleets;
protected AbstractLevel0ConfigureAction(Class<C> configurationType) {
@@ -99,7 +99,7 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
injectOnly(InjectDecoratedBeans.class);
}
- public final String prepareConfiguration() throws Exception {
+ public final String prepareConfiguration() {
if (!isConfigurationInSession() && !hasFieldErrors()) {
@@ -110,7 +110,7 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
}
@Override
- public final String execute() throws Exception {
+ public final String execute() {
// init action context in session
prepareActionContext();
@@ -136,14 +136,14 @@ public abstract class AbstractLevel0ConfigureAction<C extends AbstractLevel0Conf
*/
protected void loadDefaultConfiguration(C config) throws TopiaException {
- T3Date minDate = tripDAO.getFirstLandingDate();
+ T3Date minDate = tripDAO.getFirstLandingDate(false);
config.setMinDate(minDate);
config.setBeginDate(minDate);
- T3Date maxDate = tripDAO.getLastLandingDate();
+ T3Date maxDate = tripDAO.getLastLandingDate(false);
config.setMaxDate(maxDate);
config.setEndDate(maxDate);
config.setVesselSimpleTypes(sortToList(vesselSimpleTypeDAO.findAllUsedInTrip(false)));
- config.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip()));
+ config.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip(false)));
if (log.isInfoEnabled()) {
log.info("beginDate : " + config.getBeginDate());
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level2/ConfigureLevel2Step1Action.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level2/ConfigureLevel2Step1Action.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level2/ConfigureLevel2Step1Action.java
@@ -201,8 +201,8 @@ public class ConfigureLevel2Step1Action extends AbstractConfigureAction<Level2Co
conf.setTimeStep(3);
// use first and last landing date
- T3Date firstLandingDate = tripDAO.getFirstLandingDate();
- T3Date lastLandingDate = tripDAO.getLastLandingDate();
+ T3Date firstLandingDate = tripDAO.getFirstLandingDate(null);
+ T3Date lastLandingDate = tripDAO.getLastLandingDate(null);
conf.setMinDate(firstLandingDate);
conf.setBeginDate(firstLandingDate);
conf.setMaxDate(lastLandingDate);
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/data/level3/ConfigureLevel3Step1Action.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/data/level3/ConfigureLevel3Step1Action.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/data/level3/ConfigureLevel3Step1Action.java
@@ -196,8 +196,8 @@ public class ConfigureLevel3Step1Action extends AbstractConfigureAction<Level3Co
conf.setTimeStep(3);
// use first and last landing date
- T3Date firstLandingDate = tripDAO.getFirstLandingDate();
- T3Date lastLandingDate = tripDAO.getLastLandingDate();
+ T3Date firstLandingDate = tripDAO.getFirstLandingDate(null);
+ T3Date lastLandingDate = tripDAO.getLastLandingDate(null);
conf.setMinDate(firstLandingDate);
conf.setBeginDate(firstLandingDate);
conf.setMaxDate(lastLandingDate);
=====================================
t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java
=====================================
--- a/t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java
+++ b/t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java
@@ -135,15 +135,15 @@ public class ExportConfigureAction extends AbstractConfigureAction<ExportConfigu
// grab data and store once for all in configuration
- T3Date beginDate = tripDAO.getFirstLandingDate();
+ T3Date beginDate = tripDAO.getFirstLandingDate(null);
conf.setMinDate(beginDate);
conf.setBeginDate(beginDate);
- T3Date endDate = tripDAO.getLastLandingDate();
+ T3Date endDate = tripDAO.getLastLandingDate(null);
conf.setMaxDate(endDate);
conf.setEndDate(endDate);
- conf.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip()));
+ conf.setFleets(sortToList(countryDAO.findAllFleetUsedInTrip(null)));
conf.setOceans(sortToList(oceanDAO.findAllUsedInActivity()));
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/26e69f3c92f5a91d63b77a44b57598b…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/26e69f3c92f5a91d63b77a44b57598b…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0] Calcul des temps de pêche (See #240)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
26e69f3c by Tony CHEMIT at 2018-02-20T22:56:38+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
27 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
- t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
- t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
- + t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
- 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/RouteImpl.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/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
- t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.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/resources/db/migration/V2_2_08_remove-Trip-fields.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-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
- t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
- t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
Changes:
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
@@ -21,6 +21,8 @@
package fr.ird.t3.actions.data.level0;
import fr.ird.t3.actions.T3Action;
+import fr.ird.t3.entities.data.Route;
+import fr.ird.t3.entities.data.RouteTopiaDao;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.TripTopiaDao;
import fr.ird.t3.entities.reference.Country;
@@ -54,6 +56,9 @@ public abstract class AbstractLevel0Action<C extends AbstractLevel0Configuration
@InjectDAO(entityType = Trip.class)
protected TripTopiaDao tripDAO;
+ @InjectDAO(entityType = Route.class)
+ protected RouteTopiaDao routeDAO;
+
@InjectEntitiesById(entityType = Country.class)
protected List<Country> fleets;
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
@@ -8,12 +8,12 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
@@ -22,26 +22,21 @@ package fr.ird.t3.actions.data.level0;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import com.web_tomorrow.utils.suntimes.SunTimes;
import fr.ird.t3.entities.data.Activity;
-import fr.ird.t3.entities.data.ActivityTopiaDao;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.util.DateUtil;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
import static org.nuiton.i18n.I18n.l;
@@ -56,22 +51,20 @@ import static org.nuiton.i18n.I18n.l;
*/
public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEffortsConfiguration> {
- /** Logger. */
- private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
-
/**
* Les codes des activités surlequel on ne calcule pas d'effort de pêche.
*
* @since 2.0
*/
- protected static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
+ private static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
4, // route sans veille
7, // avarie
8, // à la cape
10, // en attente
15 // au port
);
-
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
protected float totalTimeAtSeaN0;
protected float totalFishingTimeN0;
@@ -127,146 +120,110 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
return result;
}
- protected boolean executeForTrip(Trip trip) throws TopiaException {
+ private boolean executeForTrip(Trip trip) throws TopiaException {
// compute time at sea
- float timeAtSea = computeTimeAtSea(trip);
- totalTimeAtSeaN0 += timeAtSea;
-
- trip.setComputedTimeAtSeaN0(timeAtSea);
- incrementsProgression();
-
- // compute fishing time
- float fishingTime = computeFishingTime(trip);
- totalFishingTimeN0 += fishingTime;
- trip.setComputedFishingTimeN0(fishingTime);
- incrementsProgression();
-
- // compute search time
- float searchTime = computeTripSearchTime(trip, fishingTime);
- totalSearchTimeN0 += searchTime;
- trip.setComputedSearchTimeN0(searchTime);
-
- incrementsProgression();
-
- String message = l(locale, "t3.level0.computeTripEffort",
- decorate(trip),
- trip.getComputedTimeAtSeaN0(),
- trip.getComputedFishingTimeN0(),
- trip.getComputedSearchTimeN0()
- );
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
- markTripAsTreated(trip);
- return true;
- }
-
- protected float computeTimeAtSea(Trip trip) {
- float setTimeAtSea;
+ Route firstRoute = Objects.requireNonNull(trip.getRoute().get(0));
+ Route lastRoute = Objects.requireNonNull(Iterables.getLast(trip.getRoute()));
- // date depart - date dpq = nb jours
- // result = nb heures entre le départ et l'arrivée
- Calendar calendarDep = DateUtils.toCalendar(trip.getDepartureDate());
- calendarDep.set(Calendar.MINUTE, 0);
- calendarDep.set(Calendar.SECOND, 0);
- calendarDep.set(Calendar.MILLISECOND, 0);
- Calendar calendarLanding = DateUtils.toCalendar(trip.getLandingDate());
- calendarLanding.set(Calendar.MINUTE, 0);
- calendarLanding.set(Calendar.SECOND, 0);
- calendarLanding.set(Calendar.MILLISECOND, 0);
+ for (Route route : trip.getRoute()) {
- int months = DateUtil.getDifferenceInHours(calendarDep.getTime(), calendarLanding.getTime());
- setTimeAtSea = months;
+// float timeAtSea = computeTimeAtSea(route);
+// totalTimeAtSeaN0 += timeAtSea;
+ totalTimeAtSeaN0 += 24;
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " : time at sea = " + setTimeAtSea);
- }
- return setTimeAtSea;
- }
-
- protected float computeFishingTime(Trip trip) throws TopiaException {
-
- float setFishingTime = 0;
+// route.setComputedTimeAtSeaN0(timeAtSea);
+// incrementsProgression();
- if (!trip.isActivityEmpty()) {
+ // compute fishing time
+ Float fishingTime = computeFishingTime(firstRoute, lastRoute, route);
+ route.setComputedFishingTimeN0(fishingTime);
+ incrementsProgression();
- Multimap<Long, Activity> activitiesByDay = ActivityTopiaDao.groupActivitiesByDay(trip.getActivity());
+ if (fishingTime == null) {
- List<Long> daysIds = Lists.newArrayList(activitiesByDay.keySet());
- Collections.sort(daysIds);
-
- long firstDay = daysIds.get(0);
- long lastDay = Iterables.getLast(daysIds);
+ route.setComputedSearchTimeN0(null);
+ incrementsProgression();
+ continue;
+ }
- for (Long dayId : daysIds) {
+ totalFishingTimeN0 += fishingTime;
+ // compute search time
+ float searchTime = computeTripSearchTime(route, fishingTime);
+ totalSearchTimeN0 += searchTime;
+ route.setComputedSearchTimeN0(searchTime);
- Collection<Activity> activities = activitiesByDay.get(dayId);
+ incrementsProgression();
- if (dayId == firstDay || lastDay == dayId) {
- float currentFishingTime = computeSetFishingTimeForFirstOrLayDay(activities);
- setFishingTime += currentFishingTime;
- continue;
- }
+ String message = l(locale, "t3.level0.computeTripEffort",
+ decorate(route),
+ route.getComputedFishingTimeN0(),
+ route.getComputedSearchTimeN0()
+ );
- Date date = new Date(dayId);
- if (!canComputeSetFishingTime(activities)) {
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ }
+ markTripAsTreated(trip);
+ return true;
+ }
- String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(trip), date);
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
+ private Float computeFishingTime(Route firstRoute, Route lastRoute, Route route) throws TopiaException {
- continue;
- }
+ Collection<Activity> activities = route.getActivity();
+ if (Objects.equals(firstRoute, route) || Objects.equals(lastRoute, route)) {
+ return computeSetFishingTimeForFirstOrLayDay(activities);
+ }
- T3Point point;
+ Date date = route.getDate();
+ if (!canComputeSetFishingTime(activities)) {
- if (activities.size() == 1) {
+ String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(route));
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ return null;
+ }
- // only one activity for this day,
- Activity activity = activities.iterator().next();
- point = activity.toPoint();
+ T3Point point;
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] , single activity, point : " + point);
- }
- } else {
+ if (activities.size() == 1) {
- // compute barycenter for all activities of the day
- point = tripDAO.getBarycenterForActivitiesOfADay(trip, date);
+ // only one activity for this day,
+ Activity activity = activities.iterator().next();
+ point = activity.toPoint();
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] Computed barycenter point " + point);
- }
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] , single activity, point : " + point);
+ }
+ } else {
- // compute day duration for this point and day (in minutes)
- double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
+ // compute barycenter for all activities of the day
+ point = routeDAO.getBarycenterForActivitiesOfADay(route, date);
- if (log.isInfoEnabled()) {
- log.info("Day [" + date + "] duration = " + duration);
- }
- // add it to setTime
- setFishingTime += duration;
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] Computed barycenter point " + point);
}
}
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - fishing time = " + setFishingTime);
- }
+ // compute day duration for this point and day (in minutes)
+ double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
- return setFishingTime;
+ if (log.isInfoEnabled()) {
+ log.info("Day [" + date + "] duration = " + duration);
+ }
+ return (float) duration;
}
- protected float computeTripSearchTime(Trip trip, float fishingTime) {
+ private float computeTripSearchTime(Route route, float fishingTime) {
// compute sum of catches time
- float catchesTime = trip.getTotalSetsDuration();
+ float catchesTime = route.getTotalSetsDuration();
if (log.isDebugEnabled()) {
log.debug("Total catches time = " + catchesTime);
@@ -274,12 +231,12 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
float result = fishingTime - catchesTime;
if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - trip search time = " + result);
+ log.debug(decorate(route) + " - trip search time = " + result);
}
return result;
}
- protected float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
+ private float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
float result = 0f;
for (Activity activity : activities) {
@@ -289,7 +246,7 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
}
- protected boolean canComputeSetFishingTime(Collection<Activity> activities) {
+ private boolean canComputeSetFishingTime(Collection<Activity> activities) {
boolean result = false;
for (Activity activity : activities) {
VesselActivity vesselActivity = activity.getVesselActivity();
=====================================
t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Trip %s total rf1 catches weight %s / t
t3.level0.computeRF2.resume.skip.for.trip=Trip %s has not elementary landing (trip not used to compute rf2)
t3.level0.computeRF2.resume.total.rf1=Sum total rf1 catches weight %s / Sum total landing weight %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=SetDuration data not found (ocean %s, fleet %s, school type %s, year %s)
-t3.level0.computeTripEffort=Trip efforts %s (sea %s, fishing%s, search%s)
-t3.level0.computeTripEffortSkipForDay=Trip %s, Day (%s) without fihsing time (only activities of type « at harbour » or « under way without prospection »)
+t3.level0.computeTripEffort=Trip efforts %s (fishing %s, search %s)
+t3.level0.computeTripEffortSkipForDay=Trip %s, day without fishing time (only activities of type « at harbour » or « under way without prospection »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Weight category %s, weight \= %s, propWeight \= %s (activity %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Well (%s) with well plan filled %s wellSetAllSpecies, total weight %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Species %s < logBook total weight \= %s , converted total weight \= %s>
=====================================
t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Marée %s Poids total des captures rf1i
t3.level0.computeRF2.resume.skip.for.trip=La marée %s ne possède pas de lots commerciaux (non prise en compte dans le calcul du rf2)
t3.level0.computeRF2.resume.total.rf1=Poids cumulé des captures rf1isées %s / Poids cumulé des ventes %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=Donnée SetDuration non trouvée (ocean %s, flotte %s, type de banc %s, année %s)
-t3.level0.computeTripEffort=Efforts de la marée %s (mer %s, pêche %s, recherche %s)
-t3.level0.computeTripEffortSkipForDay=Marée %s, Journée (%s) sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
+t3.level0.computeTripEffort=Efforts de la marée %s (pêche %s, recherche %s)
+t3.level0.computeTripEffortSkipForDay=Marée %s, jour sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Catégorie de poids %s, poids \= %s, poids pondéré\= %s (activité %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Cuve avec plan de cuve (%s) avec %s wellSetAllSpecies, poids total %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Espèce %s < poids total des captures du livre de bord \= %s , poids total converti \= %s>
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
@@ -0,0 +1,55 @@
+package fr.ird.t3.entities.data;
+
+import fr.ird.t3.entities.type.T3Point;
+import fr.ird.t3.entities.type.T3PointImpl;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+public class AbstractRouteTopiaDao<E extends Route> extends GeneratedRouteTopiaDao<E> {
+
+ public T3Point getBarycenterForActivitiesOfADay(E route, Date day) throws TopiaException {
+
+ TopiaSqlQuery<T3Point> query = new GetT3PointQuery<E>(route, day);
+ return topiaSqlSupport.findSingleResult(query);
+ }
+
+ private static class GetT3PointQuery<E extends Route> extends TopiaSqlQuery<T3Point> {
+ private final E route;
+
+ private final Date day;
+
+ public GetT3PointQuery(E route, Date day) {
+ this.route = route;
+ this.day = day;
+ }
+
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT ST_X(record.point), ST_Y(record.point) FROM " +
+ "(" +
+ " SELECT ST_Centroid(ST_Collect(a.the_geom)) AS point" +
+ " FROM activity a " +
+ " WHERE a.route = ? AND a.date::DATE = ?" +
+ ") AS record;");
+ ps.setString(1, route.getTopiaId());
+ ps.setDate(2, new java.sql.Date(day.getTime()));
+ return ps;
+ }
+
+ @Override
+ public T3Point prepareResult(ResultSet set) throws SQLException {
+ float x = set.getFloat(1);
+ float y = set.getFloat(2);
+ return new T3PointImpl(x, y);
+ }
+ }
+
+}
+
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
@@ -128,13 +128,13 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
// query = createQuery("t")
// .setSelect("t.id")
// .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
- hql = "SELECT t.id FROM TripImpl t WHERE size(t.activity) = 0";
+ hql = "SELECT t.id FROM TripImpl as t WHERE size(t.route) = 0";
// params = Collections.emptyList();
} else {
// query = new TopiaQuery(Activity.class, "a")
// .setSelect("distinct(a.trip.id)")
// .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
- hql = "SELECT DISTINCT(a.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
+ hql = "SELECT DISTINCT(a.route.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
paramsBuilder.put("ocean", ocean);
// params = Lists.<Object>newArrayList("ocean", ocean);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -26,12 +26,13 @@ import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
import fr.ird.t3.entities.type.T3PointImpl;
import fr.ird.type.CoordinateHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Implementation of {@link Activity} with manual quadrant
@@ -60,6 +61,11 @@ public class ActivityImpl extends ActivityAbstract {
protected Integer quadrant;
@Override
+ public Trip getTrip() {
+ return getRoute().getTrip();
+ }
+
+ @Override
public Integer getQuadrant() {
if (quadrant == null) {
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
@@ -0,0 +1,49 @@
+package fr.ird.t3.entities.data;
+
+public class RouteImpl extends RouteAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ /** @return the sum of all activities set duration in hours. */
+ @Override
+ public float getTotalSetsDuration() {
+ float result = 0;
+ if (!isActivityEmpty()) {
+ for (Activity activity : getActivity()) {
+
+ // get the setDuration
+ Float setTime = activity.getSetDuration();
+
+ result += setTime == null ? 0f : setTime;
+ }
+ }
+ return result / 60;
+ }
+
+ @Override
+ public void deleteComputedDataLevel0() {
+ setComputedFishingTimeN0(null);
+ setComputedSearchTimeN0(null);
+ ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ }
+
+ @Override
+ public void deleteComputedData() {
+ ComputedDataHelper.deleteComputedDatas(this);
+ }
+
+ @Override
+ public void deleteComputedDataLevel1() {
+ ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel2() {
+ ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel3() {
+ ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ }
+}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
@@ -30,9 +30,17 @@ import fr.ird.t3.entities.reference.Ocean;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.reference.VesselImpl;
+import org.nuiton.util.DateUtil;
import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.nuiton.i18n.I18n.n;
@@ -119,21 +127,21 @@ public class TripImpl extends TripAbstract {
return result;
}
- /** @return the sum of all activities set duration in hours. */
- @Override
- public float getTotalSetsDuration() {
- float result = 0;
- if (!isActivityEmpty()) {
- for (Activity activity : getActivity()) {
-
- // get the setDuration
- Float setTime = activity.getSetDuration();
-
- result += setTime == null ? 0f : setTime;
- }
- }
- return result / 60;
- }
+// /** @return the sum of all activities set duration in hours. */
+// @Override
+// public float getTotalSetsDuration() {
+// float result = 0;
+// if (!isActivityEmpty()) {
+// for (Activity activity : getActivity()) {
+//
+// // get the setDuration
+// Float setTime = activity.getSetDuration();
+//
+// result += setTime == null ? 0f : setTime;
+// }
+// }
+// return result / 60;
+// }
@Override
public float getElementaryCatchTotalWeight(Collection<Species> species) {
@@ -436,19 +444,17 @@ public class TripImpl extends TripAbstract {
setCompletionStatus(null);
setRf1(null);
setRf2(null);
- setComputedFishingTimeN0(null);
- setComputedSearchTimeN0(null);
- setComputedTimeAtSeaN0(null);
+// setComputedFishingTimeN0(null);
+// setComputedSearchTimeN0(null);
+// setComputedTimeAtSeaN0(null);
- ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel0(getRoute());
ComputedDataHelper.deleteComputedDataLevel0(getSample());
ComputedDataHelper.deleteComputedDataLevel0(getWell());
}
@Override
public void deleteComputedDataLevel1() {
-
- // level 1 flags
setExtrapolateSampleCountedAndMeasured(false);
setStandardizeSampleMeasures(false);
setComputeWeightOfCategoriesForSet(false);
@@ -457,27 +463,97 @@ public class TripImpl extends TripAbstract {
setConvertSetSpeciesFrequencyToWeight(false);
setConvertSampleSetSpeciesFrequencyToWeight(false);
- ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel1(getRoute());
ComputedDataHelper.deleteComputedDataLevel1(getSample());
ComputedDataHelper.deleteComputedDataLevel1(getWell());
}
@Override
public void deleteComputedDataLevel2() {
- // level 2 flags
-
- ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel2(getRoute());
ComputedDataHelper.deleteComputedDataLevel2(getSample());
ComputedDataHelper.deleteComputedDataLevel2(getWell());
}
@Override
public void deleteComputedDataLevel3() {
- // level 3 flags
-
- ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel3(getRoute());
ComputedDataHelper.deleteComputedDataLevel3(getSample());
ComputedDataHelper.deleteComputedDataLevel3(getWell());
}
+ @Override
+ public int getComputedTimeAtSeaN0() {
+ return 24 * sizeRoute();
+ }
+
+ @Override
+ public int sizeActivity() {
+ return (int) activityStream().count();
+ }
+
+ @Override
+ public boolean isActivityEmpty() {
+ return isRouteEmpty() || activityStream().count() == 0;
+ }
+
+ @Override
+ public boolean isActivityNotEmpty() {
+ return isRouteNotEmpty() && activityStream().count() > 0;
+ }
+
+ @Override
+ public List<Activity> getActivity() {
+ return activityStream().collect(Collectors.toList());
+ }
+
+ @Override
+ public void setActivity(List<Activity> activities) {
+ clearRoute();
+ for (Activity activity : activities) {
+ addActivity(activity);
+ }
+ }
+
+ @Override
+ public Activity getActivityByTopiaId(String topiaId) {
+ return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
+ }
+
+ @Override
+ public Collection<String> getActivityTopiaIds() {
+ return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
+ }
+
+ @Override
+ public void addActivity(Activity activity) {
+ Date date = DateUtil.getDay(activity.getDate());
+ Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
+ Route route;
+ if (optionalRoute.isPresent()) {
+ route = optionalRoute.get();
+ } else {
+ route = new RouteImpl();
+ route.setDate(date);
+ addRoute(route);
+ }
+ route.addActivity(activity);
+ }
+
+ @Override
+ public List<Route> getRoute() {
+ List<Route> route = super.getRoute();
+ if (route == null) {
+ setRoute(route = new LinkedList<>());
+ }
+ return route;
+ }
+
+ private Stream<Route> routeStream() {
+ return getRoute().stream();
+ }
+
+ private Stream<Activity> activityStream() {
+ return routeStream().flatMap(r -> r.getActivity().stream());
+ }
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
@@ -126,7 +126,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.fleetCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .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
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.flagCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) >0")
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
@@ -37,11 +37,11 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
/**
* Obtains all vessel simple types used by all trips in the database.
*
- * @param sampleOnly if null no filter else filter on value
+ * @param samplesOnly if null no filter else filter on value
* @return the set of used vessel simple types in trips in the database
* @throws TopiaException if any problem while querying the database
*/
- public Set<E> findAllUsedInTrip(Boolean sampleOnly) throws TopiaException {
+ public Set<E> findAllUsedInTrip(Boolean samplesOnly) throws TopiaException {
// TopiaQuery query = createQuery("vst")
// .addFrom(Trip.class, "t")
@@ -50,8 +50,8 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
// Vessel.PROPERTY_VESSEL_TYPE + "." +
// VesselType.PROPERTY_VESSEL_SIMPLE_TYPE + " = vst.id");
- String sampleOnlyFilter = sampleOnly == null ? "" : (" AND t.sampleOnly = " + sampleOnly);
- String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + sampleOnlyFilter;
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
+ String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + samplesOnlyFilter;
return new HashSet<>(findAll(hql));
// return T3EntityHelper.querytoSet(hql, this);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
@@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.CompleteTrip;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Sample;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
@@ -167,6 +168,9 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
// trip decorator
registerJXPathDecorator(locale, Trip.class, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY");
+ // route decorator
+ registerJXPathDecorator(locale, Route.class, "${trip.vesselLabel}$s - ${trip.landingDate}$td/%2$tm/%2$tY - ${date}$td/%3$tm/%3$tY");
+
// trip (with topiaid) decorator
registerJXPathDecorator(locale, Trip.class, WITH_ID, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY [${topiaId}$s]");
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -0,0 +1,133 @@
+package fr.ird.t3.services.migration;
+
+/*
+ * #%L
+ * T3 :: Domain
+ * %%
+ * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+import org.nuiton.topia.persistence.support.TopiaSqlSupport;
+import org.nuiton.util.DateUtil;
+import org.nuiton.version.Versions;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by tchemit on 18/02/2018.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ */
+@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
+public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
+
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
+
+ public T3MigrationCallbackV2_2() {
+ super(Versions.valueOf("2.2"));
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
+ addScript("07", "add-Route-table", queries);
+
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
+ }
+
+ @Override
+ public String prepareResult(ResultSet set) throws SQLException {
+ return set.getString(1);
+ }
+ });
+
+ for (String tripId : tripList) {
+
+ int i = tripId.indexOf('#');
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+
+ log.info("Route prefix: " + routeIdPrefix);
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ preparedStatement.setString(1, tripId);
+ return preparedStatement;
+ }
+
+ @Override
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
+ return new TripActivity(set.getString(1), set.getDate(2));
+ }
+ });
+
+
+ Set<Date> days = new LinkedHashSet<>();
+ int activityIndex = 0;
+ for (TripActivity activity : activityList) {
+
+ String dayDateStr = df.format(activity.date);
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
+
+ if (days.add(activity.date)) {
+
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
+ // create new route
+ 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));
+ }
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
+ }
+
+ if (!activityList.isEmpty()) {
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
+ }
+ }
+
+ addScript("08", "remove-Trip-fields", queries);
+ }
+
+ private static class TripActivity {
+
+ private final String activity;
+ private final Date date;
+
+ private TripActivity(String activity, Date date) {
+ this.activity = activity;
+ this.date = DateUtil.getDay(date);
+ }
+ }
+
+}
=====================================
t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
@@ -0,0 +1,29 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+CREATE TABLE Route( topiaid VARCHAR(255) PRIMARY KEY NOT NULL, topiaversion BIGINT NOT NULL, topiacreatedate TIMESTAMP NOT NULL, trip VARCHAR(255) NOT NULL, trip_idx INTEGER NOT NULL, date DATE NOT NULL, computedFishingTimeN0 REAL, computedSearchTimeN0 REAL);
+CREATE UNIQUE INDEX uk_route ON Route(trip, date);
+ALTER TABLE Route ADD CONSTRAINT fk_route_trip FOREIGN KEY (trip) REFERENCES Trip(topiaid);
+CREATE INDEX idx_route_trip ON Route(trip);
+
+ALTER TABLE Activity ADD COLUMN route VARCHAR(255);
+ALTER TABLE Activity ADD COLUMN route_idx INTEGER;
+ALTER TABLE Activity ADD CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
+CREATE INDEX idx_activity_route ON Activity(route);
=====================================
t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
@@ -0,0 +1,28 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+
+ALTER TABLE Activity DROP COLUMN trip;
+ALTER TABLE Activity DROP COLUMN trip_idx;
+ALTER TABLE Activity DROP COLUMN date;
+ALTER TABLE Trip DROP COLUMN computedfishingtimen0;
+ALTER TABLE Trip DROP COLUMN computedsearchtimen0;
+ALTER TABLE Trip DROP COLUMN computedtimeatsean0;
+ALTER TABLE Activity ALTER COLUMN route_idx SET NOT NULL;
\ No newline at end of file
=====================================
t3-domain/src/main/xmi/t3-persistence.properties
=====================================
--- a/t3-domain/src/main/xmi/t3-persistence.properties
+++ b/t3-domain/src/main/xmi/t3-persistence.properties
@@ -22,11 +22,17 @@
model.tagValue.notGenerateToString=true
model.tagValue.generateOperatorForDAOHelper=true
model.tagValue.constantPrefix=PROPERTY_
-model.tagValue.version=2.1
+model.tagValue.version=2.2
model.tagValue.indexForeignKeys=true
-fr.ird.t3.entities.data.Trip.attribute.activity.stereotype=ordered
-fr.ird.t3.entities.data.Trip.attribute.activity.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
+fr.ird.t3.entities.data.Route.attribute.activity.stereotype=ordered
+
+fr.ird.t3.entities.data.Trip.attribute.route.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date
+
+fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date
+fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time
fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text
fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
@@ -56,8 +56,8 @@ public class T3PersistenceFixtures {
return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
}
- public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean sampleOnly) {
- return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, sampleOnly);
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean samplesOnly) {
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, samplesOnly);
}
public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
=====================================
t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
=====================================
--- a/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
+++ b/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
@@ -55,11 +55,12 @@ import fr.ird.t3.io.input.access.T3AccessEntityMeta;
import fr.ird.t3.io.input.access.T3AccessEntityMetaProvider;
import fr.ird.t3.io.input.access.T3AccessReferentielEntityMeta;
import fr.ird.t3.io.input.access.type.IntToBoolean;
-import java.util.Date;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.Date;
+import java.util.Set;
+
/**
* Provider of {@link T3AccessEntityMeta}.
*
@@ -86,9 +87,7 @@ public class T3AccessEntityMetaProviderAvdth33 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
@@ -163,7 +163,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -172,7 +172,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
@@ -115,14 +115,14 @@ public class ImportInputSourceActionIT implements T3AVDTHV33Test {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
=====================================
--- a/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
+++ b/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -98,9 +98,7 @@ public class T3AccessEntityMetaProviderAvdth35 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{/* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -165,7 +165,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -174,7 +174,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
=====================================
--- a/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
+++ b/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -100,9 +100,7 @@ public class T3AccessEntityMetaProviderAvdth36 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -168,7 +168,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -177,7 +177,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/26e69f3c92f5a91d63b77a44b57598b3…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/26e69f3c92f5a91d63b77a44b57598b3…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0] Calcul des temps de pêche (See #240)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
ef7c73b1 by Tony CHEMIT at 2018-02-20T22:41:48+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
27 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
- t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
- t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
- + t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
- 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/RouteImpl.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/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
- t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.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/resources/db/migration/V2_2_08_remove-Trip-fields.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-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
- t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
- t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
Changes:
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
@@ -21,6 +21,8 @@
package fr.ird.t3.actions.data.level0;
import fr.ird.t3.actions.T3Action;
+import fr.ird.t3.entities.data.Route;
+import fr.ird.t3.entities.data.RouteTopiaDao;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.TripTopiaDao;
import fr.ird.t3.entities.reference.Country;
@@ -54,6 +56,9 @@ public abstract class AbstractLevel0Action<C extends AbstractLevel0Configuration
@InjectDAO(entityType = Trip.class)
protected TripTopiaDao tripDAO;
+ @InjectDAO(entityType = Route.class)
+ protected RouteTopiaDao routeDAO;
+
@InjectEntitiesById(entityType = Country.class)
protected List<Country> fleets;
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
@@ -8,12 +8,12 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
@@ -22,26 +22,21 @@ package fr.ird.t3.actions.data.level0;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import com.web_tomorrow.utils.suntimes.SunTimes;
import fr.ird.t3.entities.data.Activity;
-import fr.ird.t3.entities.data.ActivityTopiaDao;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.util.DateUtil;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
import static org.nuiton.i18n.I18n.l;
@@ -56,22 +51,20 @@ import static org.nuiton.i18n.I18n.l;
*/
public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEffortsConfiguration> {
- /** Logger. */
- private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
-
/**
* Les codes des activités surlequel on ne calcule pas d'effort de pêche.
*
* @since 2.0
*/
- protected static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
+ private static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
4, // route sans veille
7, // avarie
8, // à la cape
10, // en attente
15 // au port
);
-
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
protected float totalTimeAtSeaN0;
protected float totalFishingTimeN0;
@@ -127,146 +120,110 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
return result;
}
- protected boolean executeForTrip(Trip trip) throws TopiaException {
+ private boolean executeForTrip(Trip trip) throws TopiaException {
// compute time at sea
- float timeAtSea = computeTimeAtSea(trip);
- totalTimeAtSeaN0 += timeAtSea;
-
- trip.setComputedTimeAtSeaN0(timeAtSea);
- incrementsProgression();
-
- // compute fishing time
- float fishingTime = computeFishingTime(trip);
- totalFishingTimeN0 += fishingTime;
- trip.setComputedFishingTimeN0(fishingTime);
- incrementsProgression();
-
- // compute search time
- float searchTime = computeTripSearchTime(trip, fishingTime);
- totalSearchTimeN0 += searchTime;
- trip.setComputedSearchTimeN0(searchTime);
-
- incrementsProgression();
-
- String message = l(locale, "t3.level0.computeTripEffort",
- decorate(trip),
- trip.getComputedTimeAtSeaN0(),
- trip.getComputedFishingTimeN0(),
- trip.getComputedSearchTimeN0()
- );
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
- markTripAsTreated(trip);
- return true;
- }
-
- protected float computeTimeAtSea(Trip trip) {
- float setTimeAtSea;
+ Route firstRoute = Objects.requireNonNull(trip.getRoute().get(0));
+ Route lastRoute = Objects.requireNonNull(Iterables.getLast(trip.getRoute()));
- // date depart - date dpq = nb jours
- // result = nb heures entre le départ et l'arrivée
- Calendar calendarDep = DateUtils.toCalendar(trip.getDepartureDate());
- calendarDep.set(Calendar.MINUTE, 0);
- calendarDep.set(Calendar.SECOND, 0);
- calendarDep.set(Calendar.MILLISECOND, 0);
- Calendar calendarLanding = DateUtils.toCalendar(trip.getLandingDate());
- calendarLanding.set(Calendar.MINUTE, 0);
- calendarLanding.set(Calendar.SECOND, 0);
- calendarLanding.set(Calendar.MILLISECOND, 0);
+ for (Route route : trip.getRoute()) {
- int months = DateUtil.getDifferenceInHours(calendarDep.getTime(), calendarLanding.getTime());
- setTimeAtSea = months;
+// float timeAtSea = computeTimeAtSea(route);
+// totalTimeAtSeaN0 += timeAtSea;
+ totalTimeAtSeaN0 += 24;
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " : time at sea = " + setTimeAtSea);
- }
- return setTimeAtSea;
- }
-
- protected float computeFishingTime(Trip trip) throws TopiaException {
-
- float setFishingTime = 0;
+// route.setComputedTimeAtSeaN0(timeAtSea);
+// incrementsProgression();
- if (!trip.isActivityEmpty()) {
+ // compute fishing time
+ Float fishingTime = computeFishingTime(firstRoute, lastRoute, route);
+ route.setComputedFishingTimeN0(fishingTime);
+ incrementsProgression();
- Multimap<Long, Activity> activitiesByDay = ActivityTopiaDao.groupActivitiesByDay(trip.getActivity());
+ if (fishingTime == null) {
- List<Long> daysIds = Lists.newArrayList(activitiesByDay.keySet());
- Collections.sort(daysIds);
-
- long firstDay = daysIds.get(0);
- long lastDay = Iterables.getLast(daysIds);
+ route.setComputedSearchTimeN0(null);
+ incrementsProgression();
+ continue;
+ }
- for (Long dayId : daysIds) {
+ totalFishingTimeN0 += fishingTime;
+ // compute search time
+ float searchTime = computeTripSearchTime(route, fishingTime);
+ totalSearchTimeN0 += searchTime;
+ route.setComputedSearchTimeN0(searchTime);
- Collection<Activity> activities = activitiesByDay.get(dayId);
+ incrementsProgression();
- if (dayId == firstDay || lastDay == dayId) {
- float currentFishingTime = computeSetFishingTimeForFirstOrLayDay(activities);
- setFishingTime += currentFishingTime;
- continue;
- }
+ String message = l(locale, "t3.level0.computeTripEffort",
+ decorate(route),
+ route.getComputedFishingTimeN0(),
+ route.getComputedSearchTimeN0()
+ );
- Date date = new Date(dayId);
- if (!canComputeSetFishingTime(activities)) {
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ }
+ markTripAsTreated(trip);
+ return true;
+ }
- String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(trip), date);
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
+ private Float computeFishingTime(Route firstRoute, Route lastRoute, Route route) throws TopiaException {
- continue;
- }
+ Collection<Activity> activities = route.getActivity();
+ if (Objects.equals(firstRoute, route) || Objects.equals(lastRoute, route)) {
+ return computeSetFishingTimeForFirstOrLayDay(activities);
+ }
- T3Point point;
+ Date date = route.getDate();
+ if (!canComputeSetFishingTime(activities)) {
- if (activities.size() == 1) {
+ String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(route));
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ return null;
+ }
- // only one activity for this day,
- Activity activity = activities.iterator().next();
- point = activity.toPoint();
+ T3Point point;
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] , single activity, point : " + point);
- }
- } else {
+ if (activities.size() == 1) {
- // compute barycenter for all activities of the day
- point = tripDAO.getBarycenterForActivitiesOfADay(trip, date);
+ // only one activity for this day,
+ Activity activity = activities.iterator().next();
+ point = activity.toPoint();
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] Computed barycenter point " + point);
- }
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] , single activity, point : " + point);
+ }
+ } else {
- // compute day duration for this point and day (in minutes)
- double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
+ // compute barycenter for all activities of the day
+ point = routeDAO.getBarycenterForActivitiesOfADay(route, date);
- if (log.isInfoEnabled()) {
- log.info("Day [" + date + "] duration = " + duration);
- }
- // add it to setTime
- setFishingTime += duration;
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] Computed barycenter point " + point);
}
}
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - fishing time = " + setFishingTime);
- }
+ // compute day duration for this point and day (in minutes)
+ double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
- return setFishingTime;
+ if (log.isInfoEnabled()) {
+ log.info("Day [" + date + "] duration = " + duration);
+ }
+ return (float) duration;
}
- protected float computeTripSearchTime(Trip trip, float fishingTime) {
+ private float computeTripSearchTime(Route route, float fishingTime) {
// compute sum of catches time
- float catchesTime = trip.getTotalSetsDuration();
+ float catchesTime = route.getTotalSetsDuration();
if (log.isDebugEnabled()) {
log.debug("Total catches time = " + catchesTime);
@@ -274,12 +231,12 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
float result = fishingTime - catchesTime;
if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - trip search time = " + result);
+ log.debug(decorate(route) + " - trip search time = " + result);
}
return result;
}
- protected float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
+ private float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
float result = 0f;
for (Activity activity : activities) {
@@ -289,7 +246,7 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
}
- protected boolean canComputeSetFishingTime(Collection<Activity> activities) {
+ private boolean canComputeSetFishingTime(Collection<Activity> activities) {
boolean result = false;
for (Activity activity : activities) {
VesselActivity vesselActivity = activity.getVesselActivity();
=====================================
t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Trip %s total rf1 catches weight %s / t
t3.level0.computeRF2.resume.skip.for.trip=Trip %s has not elementary landing (trip not used to compute rf2)
t3.level0.computeRF2.resume.total.rf1=Sum total rf1 catches weight %s / Sum total landing weight %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=SetDuration data not found (ocean %s, fleet %s, school type %s, year %s)
-t3.level0.computeTripEffort=Trip efforts %s (sea %s, fishing%s, search%s)
-t3.level0.computeTripEffortSkipForDay=Trip %s, Day (%s) without fihsing time (only activities of type « at harbour » or « under way without prospection »)
+t3.level0.computeTripEffort=Trip efforts %s (fishing %s, search %s)
+t3.level0.computeTripEffortSkipForDay=Trip %s, day without fishing time (only activities of type « at harbour » or « under way without prospection »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Weight category %s, weight \= %s, propWeight \= %s (activity %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Well (%s) with well plan filled %s wellSetAllSpecies, total weight %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Species %s < logBook total weight \= %s , converted total weight \= %s>
=====================================
t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Marée %s Poids total des captures rf1i
t3.level0.computeRF2.resume.skip.for.trip=La marée %s ne possède pas de lots commerciaux (non prise en compte dans le calcul du rf2)
t3.level0.computeRF2.resume.total.rf1=Poids cumulé des captures rf1isées %s / Poids cumulé des ventes %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=Donnée SetDuration non trouvée (ocean %s, flotte %s, type de banc %s, année %s)
-t3.level0.computeTripEffort=Efforts de la marée %s (mer %s, pêche %s, recherche %s)
-t3.level0.computeTripEffortSkipForDay=Marée %s, Journée (%s) sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
+t3.level0.computeTripEffort=Efforts de la marée %s (pêche %s, recherche %s)
+t3.level0.computeTripEffortSkipForDay=Marée %s, jour sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Catégorie de poids %s, poids \= %s, poids pondéré\= %s (activité %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Cuve avec plan de cuve (%s) avec %s wellSetAllSpecies, poids total %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Espèce %s < poids total des captures du livre de bord \= %s , poids total converti \= %s>
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
@@ -0,0 +1,55 @@
+package fr.ird.t3.entities.data;
+
+import fr.ird.t3.entities.type.T3Point;
+import fr.ird.t3.entities.type.T3PointImpl;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+public class AbstractRouteTopiaDao<E extends Route> extends GeneratedRouteTopiaDao<E> {
+
+ public T3Point getBarycenterForActivitiesOfADay(E route, Date day) throws TopiaException {
+
+ TopiaSqlQuery<T3Point> query = new GetT3PointQuery<E>(route, day);
+ return topiaSqlSupport.findSingleResult(query);
+ }
+
+ private static class GetT3PointQuery<E extends Route> extends TopiaSqlQuery<T3Point> {
+ private final E route;
+
+ private final Date day;
+
+ public GetT3PointQuery(E route, Date day) {
+ this.route = route;
+ this.day = day;
+ }
+
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT ST_X(record.point), ST_Y(record.point) FROM " +
+ "(" +
+ " SELECT ST_Centroid(ST_Collect(a.the_geom)) AS point" +
+ " FROM activity a " +
+ " WHERE a.route = ? AND a.date::DATE = ?" +
+ ") AS record;");
+ ps.setString(1, route.getTopiaId());
+ ps.setDate(2, new java.sql.Date(day.getTime()));
+ return ps;
+ }
+
+ @Override
+ public T3Point prepareResult(ResultSet set) throws SQLException {
+ float x = set.getFloat(1);
+ float y = set.getFloat(2);
+ return new T3PointImpl(x, y);
+ }
+ }
+
+}
+
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
@@ -128,13 +128,13 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
// query = createQuery("t")
// .setSelect("t.id")
// .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
- hql = "SELECT t.id FROM TripImpl t WHERE size(t.activity) = 0";
+ hql = "SELECT t.id FROM TripImpl as t WHERE size(t.route) = 0";
// params = Collections.emptyList();
} else {
// query = new TopiaQuery(Activity.class, "a")
// .setSelect("distinct(a.trip.id)")
// .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
- hql = "SELECT DISTINCT(a.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
+ hql = "SELECT DISTINCT(a.route.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
paramsBuilder.put("ocean", ocean);
// params = Lists.<Object>newArrayList("ocean", ocean);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -26,12 +26,13 @@ import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
import fr.ird.t3.entities.type.T3PointImpl;
import fr.ird.type.CoordinateHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Implementation of {@link Activity} with manual quadrant
@@ -60,6 +61,11 @@ public class ActivityImpl extends ActivityAbstract {
protected Integer quadrant;
@Override
+ public Trip getTrip() {
+ return getRoute().getTrip();
+ }
+
+ @Override
public Integer getQuadrant() {
if (quadrant == null) {
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
@@ -0,0 +1,49 @@
+package fr.ird.t3.entities.data;
+
+public class RouteImpl extends RouteAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ /** @return the sum of all activities set duration in hours. */
+ @Override
+ public float getTotalSetsDuration() {
+ float result = 0;
+ if (!isActivityEmpty()) {
+ for (Activity activity : getActivity()) {
+
+ // get the setDuration
+ Float setTime = activity.getSetDuration();
+
+ result += setTime == null ? 0f : setTime;
+ }
+ }
+ return result / 60;
+ }
+
+ @Override
+ public void deleteComputedDataLevel0() {
+ setComputedFishingTimeN0(null);
+ setComputedSearchTimeN0(null);
+ ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ }
+
+ @Override
+ public void deleteComputedData() {
+ ComputedDataHelper.deleteComputedDatas(this);
+ }
+
+ @Override
+ public void deleteComputedDataLevel1() {
+ ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel2() {
+ ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel3() {
+ ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ }
+}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
@@ -30,9 +30,17 @@ import fr.ird.t3.entities.reference.Ocean;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.reference.VesselImpl;
+import org.nuiton.util.DateUtil;
import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.nuiton.i18n.I18n.n;
@@ -119,21 +127,21 @@ public class TripImpl extends TripAbstract {
return result;
}
- /** @return the sum of all activities set duration in hours. */
- @Override
- public float getTotalSetsDuration() {
- float result = 0;
- if (!isActivityEmpty()) {
- for (Activity activity : getActivity()) {
-
- // get the setDuration
- Float setTime = activity.getSetDuration();
-
- result += setTime == null ? 0f : setTime;
- }
- }
- return result / 60;
- }
+// /** @return the sum of all activities set duration in hours. */
+// @Override
+// public float getTotalSetsDuration() {
+// float result = 0;
+// if (!isActivityEmpty()) {
+// for (Activity activity : getActivity()) {
+//
+// // get the setDuration
+// Float setTime = activity.getSetDuration();
+//
+// result += setTime == null ? 0f : setTime;
+// }
+// }
+// return result / 60;
+// }
@Override
public float getElementaryCatchTotalWeight(Collection<Species> species) {
@@ -436,19 +444,17 @@ public class TripImpl extends TripAbstract {
setCompletionStatus(null);
setRf1(null);
setRf2(null);
- setComputedFishingTimeN0(null);
- setComputedSearchTimeN0(null);
- setComputedTimeAtSeaN0(null);
+// setComputedFishingTimeN0(null);
+// setComputedSearchTimeN0(null);
+// setComputedTimeAtSeaN0(null);
- ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel0(getRoute());
ComputedDataHelper.deleteComputedDataLevel0(getSample());
ComputedDataHelper.deleteComputedDataLevel0(getWell());
}
@Override
public void deleteComputedDataLevel1() {
-
- // level 1 flags
setExtrapolateSampleCountedAndMeasured(false);
setStandardizeSampleMeasures(false);
setComputeWeightOfCategoriesForSet(false);
@@ -457,27 +463,97 @@ public class TripImpl extends TripAbstract {
setConvertSetSpeciesFrequencyToWeight(false);
setConvertSampleSetSpeciesFrequencyToWeight(false);
- ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel1(getRoute());
ComputedDataHelper.deleteComputedDataLevel1(getSample());
ComputedDataHelper.deleteComputedDataLevel1(getWell());
}
@Override
public void deleteComputedDataLevel2() {
- // level 2 flags
-
- ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel2(getRoute());
ComputedDataHelper.deleteComputedDataLevel2(getSample());
ComputedDataHelper.deleteComputedDataLevel2(getWell());
}
@Override
public void deleteComputedDataLevel3() {
- // level 3 flags
-
- ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel3(getRoute());
ComputedDataHelper.deleteComputedDataLevel3(getSample());
ComputedDataHelper.deleteComputedDataLevel3(getWell());
}
+ @Override
+ public int getComputedTimeAtSeaN0() {
+ return 24 * sizeRoute();
+ }
+
+ @Override
+ public int sizeActivity() {
+ return (int) activityStream().count();
+ }
+
+ @Override
+ public boolean isActivityEmpty() {
+ return isRouteEmpty() || activityStream().count() == 0;
+ }
+
+ @Override
+ public boolean isActivityNotEmpty() {
+ return isRouteNotEmpty() && activityStream().count() > 0;
+ }
+
+ @Override
+ public List<Activity> getActivity() {
+ return activityStream().collect(Collectors.toList());
+ }
+
+ @Override
+ public void setActivity(List<Activity> activities) {
+ clearRoute();
+ for (Activity activity : activities) {
+ addActivity(activity);
+ }
+ }
+
+ @Override
+ public Activity getActivityByTopiaId(String topiaId) {
+ return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
+ }
+
+ @Override
+ public Collection<String> getActivityTopiaIds() {
+ return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
+ }
+
+ @Override
+ public void addActivity(Activity activity) {
+ Date date = DateUtil.getDay(activity.getDate());
+ Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
+ Route route;
+ if (optionalRoute.isPresent()) {
+ route = optionalRoute.get();
+ } else {
+ route = new RouteImpl();
+ route.setDate(date);
+ addRoute(route);
+ }
+ route.addActivity(activity);
+ }
+
+ @Override
+ public List<Route> getRoute() {
+ List<Route> route = super.getRoute();
+ if (route == null) {
+ setRoute(route = new LinkedList<>());
+ }
+ return route;
+ }
+
+ private Stream<Route> routeStream() {
+ return getRoute().stream();
+ }
+
+ private Stream<Activity> activityStream() {
+ return routeStream().flatMap(r -> r.getActivity().stream());
+ }
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
@@ -126,7 +126,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.fleetCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .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
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.flagCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) >0")
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
@@ -37,11 +37,11 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
/**
* Obtains all vessel simple types used by all trips in the database.
*
- * @param sampleOnly if null no filter else filter on value
+ * @param samplesOnly if null no filter else filter on value
* @return the set of used vessel simple types in trips in the database
* @throws TopiaException if any problem while querying the database
*/
- public Set<E> findAllUsedInTrip(Boolean sampleOnly) throws TopiaException {
+ public Set<E> findAllUsedInTrip(Boolean samplesOnly) throws TopiaException {
// TopiaQuery query = createQuery("vst")
// .addFrom(Trip.class, "t")
@@ -50,8 +50,8 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
// Vessel.PROPERTY_VESSEL_TYPE + "." +
// VesselType.PROPERTY_VESSEL_SIMPLE_TYPE + " = vst.id");
- String sampleOnlyFilter = sampleOnly == null ? "" : (" AND t.sampleOnly = " + sampleOnly);
- String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + sampleOnlyFilter;
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
+ String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + samplesOnlyFilter;
return new HashSet<>(findAll(hql));
// return T3EntityHelper.querytoSet(hql, this);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
@@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.CompleteTrip;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Sample;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
@@ -167,6 +168,9 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
// trip decorator
registerJXPathDecorator(locale, Trip.class, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY");
+ // route decorator
+ registerJXPathDecorator(locale, Route.class, "${trip.vesselLabel}$s - ${trip.landingDate}$td/%2$tm/%2$tY - ${date}$td/%3$tm/%3$tY");
+
// trip (with topiaid) decorator
registerJXPathDecorator(locale, Trip.class, WITH_ID, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY [${topiaId}$s]");
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -0,0 +1,133 @@
+package fr.ird.t3.services.migration;
+
+/*
+ * #%L
+ * T3 :: Domain
+ * %%
+ * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+import org.nuiton.topia.persistence.support.TopiaSqlSupport;
+import org.nuiton.util.DateUtil;
+import org.nuiton.version.Versions;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by tchemit on 18/02/2018.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ */
+@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
+public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
+
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
+
+ public T3MigrationCallbackV2_2() {
+ super(Versions.valueOf("2.2"));
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
+ addScript("07", "add-Route-table", queries);
+
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
+ }
+
+ @Override
+ public String prepareResult(ResultSet set) throws SQLException {
+ return set.getString(1);
+ }
+ });
+
+ for (String tripId : tripList) {
+
+ int i = tripId.indexOf('#');
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+
+ log.info("Route prefix: " + routeIdPrefix);
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ preparedStatement.setString(1, tripId);
+ return preparedStatement;
+ }
+
+ @Override
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
+ return new TripActivity(set.getString(1), set.getDate(2));
+ }
+ });
+
+
+ Set<Date> days = new LinkedHashSet<>();
+ int activityIndex = 0;
+ for (TripActivity activity : activityList) {
+
+ String dayDateStr = df.format(activity.date);
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
+
+ if (days.add(activity.date)) {
+
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
+ // create new route
+ 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(), dayDateStr));
+ }
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
+ }
+
+ if (!activityList.isEmpty()) {
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
+ }
+ }
+
+ addScript("08", "remove-Trip-fields", queries);
+ }
+
+ private static class TripActivity {
+
+ private final String activity;
+ private final Date date;
+
+ private TripActivity(String activity, Date date) {
+ this.activity = activity;
+ this.date = DateUtil.getDay(date);
+ }
+ }
+
+}
=====================================
t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
@@ -0,0 +1,29 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+CREATE TABLE Route( topiaid VARCHAR(255) PRIMARY KEY NOT NULL, topiaversion BIGINT NOT NULL, topiacreatedate TIMESTAMP NOT NULL, trip VARCHAR(255) NOT NULL, trip_idx INTEGER NOT NULL, date DATE NOT NULL, computedFishingTimeN0 REAL, computedSearchTimeN0 REAL);
+CREATE UNIQUE INDEX uk_route ON Route(trip, date);
+ALTER TABLE Route ADD CONSTRAINT fk_route_trip FOREIGN KEY (trip) REFERENCES Trip(topiaid);
+CREATE INDEX idx_route_trip ON Route(trip);
+
+ALTER TABLE Activity ADD COLUMN route VARCHAR(255);
+ALTER TABLE Activity ADD COLUMN route_idx INTEGER;
+ALTER TABLE Activity ADD CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
+CREATE INDEX idx_activity_route ON Activity(route);
=====================================
t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
@@ -0,0 +1,28 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+
+ALTER TABLE Activity DROP COLUMN trip;
+ALTER TABLE Activity DROP COLUMN trip_idx;
+ALTER TABLE Activity DROP COLUMN date;
+ALTER TABLE Trip DROP COLUMN computedfishingtimen0;
+ALTER TABLE Trip DROP COLUMN computedsearchtimen0;
+ALTER TABLE Trip DROP COLUMN computedtimeatsean0;
+ALTER TABLE Activity ALTER COLUMN route_idx SET NOT NULL;
\ No newline at end of file
=====================================
t3-domain/src/main/xmi/t3-persistence.properties
=====================================
--- a/t3-domain/src/main/xmi/t3-persistence.properties
+++ b/t3-domain/src/main/xmi/t3-persistence.properties
@@ -22,11 +22,17 @@
model.tagValue.notGenerateToString=true
model.tagValue.generateOperatorForDAOHelper=true
model.tagValue.constantPrefix=PROPERTY_
-model.tagValue.version=2.1
+model.tagValue.version=2.2
model.tagValue.indexForeignKeys=true
-fr.ird.t3.entities.data.Trip.attribute.activity.stereotype=ordered
-fr.ird.t3.entities.data.Trip.attribute.activity.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
+fr.ird.t3.entities.data.Route.attribute.activity.stereotype=ordered
+
+fr.ird.t3.entities.data.Trip.attribute.route.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date
+
+fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date
+fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time
fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text
fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
@@ -56,8 +56,8 @@ public class T3PersistenceFixtures {
return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
}
- public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean sampleOnly) {
- return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, sampleOnly);
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean samplesOnly) {
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, samplesOnly);
}
public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
=====================================
t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
=====================================
--- a/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
+++ b/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
@@ -55,11 +55,12 @@ import fr.ird.t3.io.input.access.T3AccessEntityMeta;
import fr.ird.t3.io.input.access.T3AccessEntityMetaProvider;
import fr.ird.t3.io.input.access.T3AccessReferentielEntityMeta;
import fr.ird.t3.io.input.access.type.IntToBoolean;
-import java.util.Date;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.Date;
+import java.util.Set;
+
/**
* Provider of {@link T3AccessEntityMeta}.
*
@@ -86,9 +87,7 @@ public class T3AccessEntityMetaProviderAvdth33 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
@@ -163,7 +163,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -172,7 +172,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
@@ -115,14 +115,14 @@ public class ImportInputSourceActionIT implements T3AVDTHV33Test {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
=====================================
--- a/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
+++ b/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -98,9 +98,7 @@ public class T3AccessEntityMetaProviderAvdth35 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{/* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -165,7 +165,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -174,7 +174,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
=====================================
--- a/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
+++ b/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -100,9 +100,7 @@ public class T3AccessEntityMetaProviderAvdth36 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -168,7 +168,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -177,7 +177,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ef7c73b147b73da7e7c2888852019d1b…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/ef7c73b147b73da7e7c2888852019d1b…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] [N0] Calcul des temps de pêche (See #240)
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
774f886a by Tony CHEMIT at 2018-02-20T22:08:33+01:00
[N0] Calcul des temps de pêche (See #240)
- - - - -
27 changed files:
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
- t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
- t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
- t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
- + t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
- 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/RouteImpl.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/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
- t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.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/resources/db/migration/V2_2_08_remove-Trip-fields.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-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
- t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
- t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
- t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
- t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
Changes:
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/AbstractLevel0Action.java
@@ -21,6 +21,8 @@
package fr.ird.t3.actions.data.level0;
import fr.ird.t3.actions.T3Action;
+import fr.ird.t3.entities.data.Route;
+import fr.ird.t3.entities.data.RouteTopiaDao;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.TripTopiaDao;
import fr.ird.t3.entities.reference.Country;
@@ -54,6 +56,9 @@ public abstract class AbstractLevel0Action<C extends AbstractLevel0Configuration
@InjectDAO(entityType = Trip.class)
protected TripTopiaDao tripDAO;
+ @InjectDAO(entityType = Route.class)
+ protected RouteTopiaDao routeDAO;
+
@InjectEntitiesById(entityType = Country.class)
protected List<Country> fleets;
=====================================
t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
=====================================
--- a/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
+++ b/t3-actions/src/main/java/fr/ird/t3/actions/data/level0/ComputeTripEffortsAction.java
@@ -8,12 +8,12 @@
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
@@ -22,26 +22,21 @@ package fr.ird.t3.actions.data.level0;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
import com.web_tomorrow.utils.suntimes.SunTimes;
import fr.ird.t3.entities.data.Activity;
-import fr.ird.t3.entities.data.ActivityTopiaDao;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.persistence.TopiaException;
-import org.nuiton.util.DateUtil;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
import static org.nuiton.i18n.I18n.l;
@@ -56,22 +51,20 @@ import static org.nuiton.i18n.I18n.l;
*/
public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEffortsConfiguration> {
- /** Logger. */
- private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
-
/**
* Les codes des activités surlequel on ne calcule pas d'effort de pêche.
*
* @since 2.0
*/
- protected static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
+ private static final ImmutableSet<Integer> VESSEL_ACTIVITY_CODES_TO_SKIP = ImmutableSet.of(
4, // route sans veille
7, // avarie
8, // à la cape
10, // en attente
15 // au port
);
-
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ComputeTripEffortsAction.class);
protected float totalTimeAtSeaN0;
protected float totalFishingTimeN0;
@@ -127,146 +120,110 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
return result;
}
- protected boolean executeForTrip(Trip trip) throws TopiaException {
+ private boolean executeForTrip(Trip trip) throws TopiaException {
// compute time at sea
- float timeAtSea = computeTimeAtSea(trip);
- totalTimeAtSeaN0 += timeAtSea;
-
- trip.setComputedTimeAtSeaN0(timeAtSea);
- incrementsProgression();
-
- // compute fishing time
- float fishingTime = computeFishingTime(trip);
- totalFishingTimeN0 += fishingTime;
- trip.setComputedFishingTimeN0(fishingTime);
- incrementsProgression();
-
- // compute search time
- float searchTime = computeTripSearchTime(trip, fishingTime);
- totalSearchTimeN0 += searchTime;
- trip.setComputedSearchTimeN0(searchTime);
-
- incrementsProgression();
-
- String message = l(locale, "t3.level0.computeTripEffort",
- decorate(trip),
- trip.getComputedTimeAtSeaN0(),
- trip.getComputedFishingTimeN0(),
- trip.getComputedSearchTimeN0()
- );
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
- markTripAsTreated(trip);
- return true;
- }
-
- protected float computeTimeAtSea(Trip trip) {
- float setTimeAtSea;
+ Route firstRoute = Objects.requireNonNull(trip.getRoute().get(0));
+ Route lastRoute = Objects.requireNonNull(Iterables.getLast(trip.getRoute()));
- // date depart - date dpq = nb jours
- // result = nb heures entre le départ et l'arrivée
- Calendar calendarDep = DateUtils.toCalendar(trip.getDepartureDate());
- calendarDep.set(Calendar.MINUTE, 0);
- calendarDep.set(Calendar.SECOND, 0);
- calendarDep.set(Calendar.MILLISECOND, 0);
- Calendar calendarLanding = DateUtils.toCalendar(trip.getLandingDate());
- calendarLanding.set(Calendar.MINUTE, 0);
- calendarLanding.set(Calendar.SECOND, 0);
- calendarLanding.set(Calendar.MILLISECOND, 0);
+ for (Route route : trip.getRoute()) {
- int months = DateUtil.getDifferenceInHours(calendarDep.getTime(), calendarLanding.getTime());
- setTimeAtSea = months;
+// float timeAtSea = computeTimeAtSea(route);
+// totalTimeAtSeaN0 += timeAtSea;
+ totalTimeAtSeaN0 += 24;
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " : time at sea = " + setTimeAtSea);
- }
- return setTimeAtSea;
- }
-
- protected float computeFishingTime(Trip trip) throws TopiaException {
-
- float setFishingTime = 0;
+// route.setComputedTimeAtSeaN0(timeAtSea);
+// incrementsProgression();
- if (!trip.isActivityEmpty()) {
+ // compute fishing time
+ Float fishingTime = computeFishingTime(firstRoute, lastRoute, route);
+ route.setComputedFishingTimeN0(fishingTime);
+ incrementsProgression();
- Multimap<Long, Activity> activitiesByDay = ActivityTopiaDao.groupActivitiesByDay(trip.getActivity());
+ if (fishingTime == null) {
- List<Long> daysIds = Lists.newArrayList(activitiesByDay.keySet());
- Collections.sort(daysIds);
-
- long firstDay = daysIds.get(0);
- long lastDay = Iterables.getLast(daysIds);
+ route.setComputedSearchTimeN0(null);
+ incrementsProgression();
+ continue;
+ }
- for (Long dayId : daysIds) {
+ totalFishingTimeN0 += fishingTime;
+ // compute search time
+ float searchTime = computeTripSearchTime(route, fishingTime);
+ totalSearchTimeN0 += searchTime;
+ route.setComputedSearchTimeN0(searchTime);
- Collection<Activity> activities = activitiesByDay.get(dayId);
+ incrementsProgression();
- if (dayId == firstDay || lastDay == dayId) {
- float currentFishingTime = computeSetFishingTimeForFirstOrLayDay(activities);
- setFishingTime += currentFishingTime;
- continue;
- }
+ String message = l(locale, "t3.level0.computeTripEffort",
+ decorate(route),
+ route.getComputedFishingTimeN0(),
+ route.getComputedSearchTimeN0()
+ );
- Date date = new Date(dayId);
- if (!canComputeSetFishingTime(activities)) {
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ }
+ markTripAsTreated(trip);
+ return true;
+ }
- String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(trip), date);
- addInfoMessage(message);
- if (log.isInfoEnabled()) {
- log.info(message);
- }
+ private Float computeFishingTime(Route firstRoute, Route lastRoute, Route route) throws TopiaException {
- continue;
- }
+ Collection<Activity> activities = route.getActivity();
+ if (Objects.equals(firstRoute, route) || Objects.equals(lastRoute, route)) {
+ return computeSetFishingTimeForFirstOrLayDay(activities);
+ }
- T3Point point;
+ Date date = route.getDate();
+ if (!canComputeSetFishingTime(activities)) {
- if (activities.size() == 1) {
+ String message = l(locale, "t3.level0.computeTripEffortSkipForDay", decorate(route));
+ addInfoMessage(message);
+ if (log.isInfoEnabled()) {
+ log.info(message);
+ }
+ return null;
+ }
- // only one activity for this day,
- Activity activity = activities.iterator().next();
- point = activity.toPoint();
+ T3Point point;
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] , single activity, point : " + point);
- }
- } else {
+ if (activities.size() == 1) {
- // compute barycenter for all activities of the day
- point = tripDAO.getBarycenterForActivitiesOfADay(trip, date);
+ // only one activity for this day,
+ Activity activity = activities.iterator().next();
+ point = activity.toPoint();
- if (log.isDebugEnabled()) {
- log.debug("Day [" + date + "] Computed barycenter point " + point);
- }
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] , single activity, point : " + point);
+ }
+ } else {
- // compute day duration for this point and day (in minutes)
- double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
+ // compute barycenter for all activities of the day
+ point = routeDAO.getBarycenterForActivitiesOfADay(route, date);
- if (log.isInfoEnabled()) {
- log.info("Day [" + date + "] duration = " + duration);
- }
- // add it to setTime
- setFishingTime += duration;
+ if (log.isDebugEnabled()) {
+ log.debug("Day [" + date + "] Computed barycenter point " + point);
}
}
- if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - fishing time = " + setFishingTime);
- }
+ // compute day duration for this point and day (in minutes)
+ double duration = SunTimes.getDayDurationInMonths(date, point.getX(), point.getY());
- return setFishingTime;
+ if (log.isInfoEnabled()) {
+ log.info("Day [" + date + "] duration = " + duration);
+ }
+ return (float) duration;
}
- protected float computeTripSearchTime(Trip trip, float fishingTime) {
+ private float computeTripSearchTime(Route route, float fishingTime) {
// compute sum of catches time
- float catchesTime = trip.getTotalSetsDuration();
+ float catchesTime = route.getTotalSetsDuration();
if (log.isDebugEnabled()) {
log.debug("Total catches time = " + catchesTime);
@@ -274,12 +231,12 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
float result = fishingTime - catchesTime;
if (log.isDebugEnabled()) {
- log.debug(decorate(trip) + " - trip search time = " + result);
+ log.debug(decorate(route) + " - trip search time = " + result);
}
return result;
}
- protected float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
+ private float computeSetFishingTimeForFirstOrLayDay(Collection<Activity> activities) {
float result = 0f;
for (Activity activity : activities) {
@@ -289,7 +246,7 @@ public class ComputeTripEffortsAction extends AbstractLevel0Action<ComputeTripEf
}
- protected boolean canComputeSetFishingTime(Collection<Activity> activities) {
+ private boolean canComputeSetFishingTime(Collection<Activity> activities) {
boolean result = false;
for (Activity activity : activities) {
VesselActivity vesselActivity = activity.getVesselActivity();
=====================================
t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_en_GB.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Trip %s total rf1 catches weight %s / t
t3.level0.computeRF2.resume.skip.for.trip=Trip %s has not elementary landing (trip not used to compute rf2)
t3.level0.computeRF2.resume.total.rf1=Sum total rf1 catches weight %s / Sum total landing weight %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=SetDuration data not found (ocean %s, fleet %s, school type %s, year %s)
-t3.level0.computeTripEffort=Trip efforts %s (sea %s, fishing%s, search%s)
-t3.level0.computeTripEffortSkipForDay=Trip %s, Day (%s) without fihsing time (only activities of type « at harbour » or « under way without prospection »)
+t3.level0.computeTripEffort=Trip efforts %s (fishing %s, search %s)
+t3.level0.computeTripEffortSkipForDay=Trip %s, day without fishing time (only activities of type « at harbour » or « under way without prospection »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Weight category %s, weight \= %s, propWeight \= %s (activity %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Well (%s) with well plan filled %s wellSetAllSpecies, total weight %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Species %s < logBook total weight \= %s , converted total weight \= %s>
=====================================
t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
=====================================
--- a/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
+++ b/t3-actions/src/main/resources/i18n/t3-actions_fr_FR.properties
@@ -42,8 +42,8 @@ t3.level0.computeRF2.resume.rf1.for.trip=Marée %s Poids total des captures rf1i
t3.level0.computeRF2.resume.skip.for.trip=La marée %s ne possède pas de lots commerciaux (non prise en compte dans le calcul du rf2)
t3.level0.computeRF2.resume.total.rf1=Poids cumulé des captures rf1isées %s / Poids cumulé des ventes %s
t3.level0.computeSetDurationAndPositiveSetCount.error.noSetDurationFound=Donnée SetDuration non trouvée (ocean %s, flotte %s, type de banc %s, année %s)
-t3.level0.computeTripEffort=Efforts de la marée %s (mer %s, pêche %s, recherche %s)
-t3.level0.computeTripEffortSkipForDay=Marée %s, Journée (%s) sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
+t3.level0.computeTripEffort=Efforts de la marée %s (pêche %s, recherche %s)
+t3.level0.computeTripEffortSkipForDay=Marée %s, jour sans temps de pêche (uniquement des activités « au port » ou « route sans veille »)
t3.level0.computeWellPlanWeightCategoriesProportions.resume.for.weightCategory=Catégorie de poids %s, poids \= %s, poids pondéré\= %s (activité %s)
t3.level0.computeWellPlanWeightCategoriesProportions.well.withWellPlan=Cuve avec plan de cuve (%s) avec %s wellSetAllSpecies, poids total %s
t3.level0.convertCatchesWeightCategories.resume.for.species=Espèce %s < poids total des captures du livre de bord \= %s , poids total converti \= %s>
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractRouteTopiaDao.java
@@ -0,0 +1,55 @@
+package fr.ird.t3.entities.data;
+
+import fr.ird.t3.entities.type.T3Point;
+import fr.ird.t3.entities.type.T3PointImpl;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+public class AbstractRouteTopiaDao<E extends Route> extends GeneratedRouteTopiaDao<E> {
+
+ public T3Point getBarycenterForActivitiesOfADay(E route, Date day) throws TopiaException {
+
+ TopiaSqlQuery<T3Point> query = new GetT3PointQuery<E>(route, day);
+ return topiaSqlSupport.findSingleResult(query);
+ }
+
+ private static class GetT3PointQuery<E extends Route> extends TopiaSqlQuery<T3Point> {
+ private final E route;
+
+ private final Date day;
+
+ public GetT3PointQuery(E route, Date day) {
+ this.route = route;
+ this.day = day;
+ }
+
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement ps = connection.prepareStatement(
+ "SELECT ST_X(record.point), ST_Y(record.point) FROM " +
+ "(" +
+ " SELECT ST_Centroid(ST_Collect(a.the_geom)) AS point" +
+ " FROM activity a " +
+ " WHERE a.route = ? AND a.date::DATE = ?" +
+ ") AS record;");
+ ps.setString(1, route.getTopiaId());
+ ps.setDate(2, new java.sql.Date(day.getTime()));
+ return ps;
+ }
+
+ @Override
+ public T3Point prepareResult(ResultSet set) throws SQLException {
+ float x = set.getFloat(1);
+ float y = set.getFloat(2);
+ return new T3PointImpl(x, y);
+ }
+ }
+
+}
+
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
@@ -128,13 +128,13 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
// query = createQuery("t")
// .setSelect("t.id")
// .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
- hql = "SELECT t.id FROM TripImpl t WHERE size(t.activity) = 0";
+ hql = "SELECT t.id FROM TripImpl as t WHERE size(t.route) = 0";
// params = Collections.emptyList();
} else {
// query = new TopiaQuery(Activity.class, "a")
// .setSelect("distinct(a.trip.id)")
// .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
- hql = "SELECT DISTINCT(a.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
+ hql = "SELECT DISTINCT(a.route.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
paramsBuilder.put("ocean", ocean);
// params = Lists.<Object>newArrayList("ocean", ocean);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -26,12 +26,13 @@ import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
import fr.ird.t3.entities.type.T3PointImpl;
import fr.ird.type.CoordinateHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Implementation of {@link Activity} with manual quadrant
@@ -60,6 +61,11 @@ public class ActivityImpl extends ActivityAbstract {
protected Integer quadrant;
@Override
+ public Trip getTrip() {
+ return getRoute().getTrip();
+ }
+
+ @Override
public Integer getQuadrant() {
if (quadrant == null) {
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/RouteImpl.java
@@ -0,0 +1,49 @@
+package fr.ird.t3.entities.data;
+
+public class RouteImpl extends RouteAbstract {
+
+ private static final long serialVersionUID = 1L;
+
+ /** @return the sum of all activities set duration in hours. */
+ @Override
+ public float getTotalSetsDuration() {
+ float result = 0;
+ if (!isActivityEmpty()) {
+ for (Activity activity : getActivity()) {
+
+ // get the setDuration
+ Float setTime = activity.getSetDuration();
+
+ result += setTime == null ? 0f : setTime;
+ }
+ }
+ return result / 60;
+ }
+
+ @Override
+ public void deleteComputedDataLevel0() {
+ setComputedFishingTimeN0(null);
+ setComputedSearchTimeN0(null);
+ ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ }
+
+ @Override
+ public void deleteComputedData() {
+ ComputedDataHelper.deleteComputedDatas(this);
+ }
+
+ @Override
+ public void deleteComputedDataLevel1() {
+ ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel2() {
+ ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ }
+
+ @Override
+ public void deleteComputedDataLevel3() {
+ ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ }
+}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
@@ -30,9 +30,17 @@ import fr.ird.t3.entities.reference.Ocean;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.reference.VesselImpl;
+import org.nuiton.util.DateUtil;
import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.nuiton.i18n.I18n.n;
@@ -119,21 +127,21 @@ public class TripImpl extends TripAbstract {
return result;
}
- /** @return the sum of all activities set duration in hours. */
- @Override
- public float getTotalSetsDuration() {
- float result = 0;
- if (!isActivityEmpty()) {
- for (Activity activity : getActivity()) {
-
- // get the setDuration
- Float setTime = activity.getSetDuration();
-
- result += setTime == null ? 0f : setTime;
- }
- }
- return result / 60;
- }
+// /** @return the sum of all activities set duration in hours. */
+// @Override
+// public float getTotalSetsDuration() {
+// float result = 0;
+// if (!isActivityEmpty()) {
+// for (Activity activity : getActivity()) {
+//
+// // get the setDuration
+// Float setTime = activity.getSetDuration();
+//
+// result += setTime == null ? 0f : setTime;
+// }
+// }
+// return result / 60;
+// }
@Override
public float getElementaryCatchTotalWeight(Collection<Species> species) {
@@ -436,19 +444,17 @@ public class TripImpl extends TripAbstract {
setCompletionStatus(null);
setRf1(null);
setRf2(null);
- setComputedFishingTimeN0(null);
- setComputedSearchTimeN0(null);
- setComputedTimeAtSeaN0(null);
+// setComputedFishingTimeN0(null);
+// setComputedSearchTimeN0(null);
+// setComputedTimeAtSeaN0(null);
- ComputedDataHelper.deleteComputedDataLevel0(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel0(getRoute());
ComputedDataHelper.deleteComputedDataLevel0(getSample());
ComputedDataHelper.deleteComputedDataLevel0(getWell());
}
@Override
public void deleteComputedDataLevel1() {
-
- // level 1 flags
setExtrapolateSampleCountedAndMeasured(false);
setStandardizeSampleMeasures(false);
setComputeWeightOfCategoriesForSet(false);
@@ -457,27 +463,97 @@ public class TripImpl extends TripAbstract {
setConvertSetSpeciesFrequencyToWeight(false);
setConvertSampleSetSpeciesFrequencyToWeight(false);
- ComputedDataHelper.deleteComputedDataLevel1(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel1(getRoute());
ComputedDataHelper.deleteComputedDataLevel1(getSample());
ComputedDataHelper.deleteComputedDataLevel1(getWell());
}
@Override
public void deleteComputedDataLevel2() {
- // level 2 flags
-
- ComputedDataHelper.deleteComputedDataLevel2(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel2(getRoute());
ComputedDataHelper.deleteComputedDataLevel2(getSample());
ComputedDataHelper.deleteComputedDataLevel2(getWell());
}
@Override
public void deleteComputedDataLevel3() {
- // level 3 flags
-
- ComputedDataHelper.deleteComputedDataLevel3(getActivity());
+ ComputedDataHelper.deleteComputedDataLevel3(getRoute());
ComputedDataHelper.deleteComputedDataLevel3(getSample());
ComputedDataHelper.deleteComputedDataLevel3(getWell());
}
+ @Override
+ public int getComputedTimeAtSeaN0() {
+ return 24 * sizeRoute();
+ }
+
+ @Override
+ public int sizeActivity() {
+ return (int) activityStream().count();
+ }
+
+ @Override
+ public boolean isActivityEmpty() {
+ return isRouteEmpty() || activityStream().count() == 0;
+ }
+
+ @Override
+ public boolean isActivityNotEmpty() {
+ return isRouteNotEmpty() && activityStream().count() > 0;
+ }
+
+ @Override
+ public List<Activity> getActivity() {
+ return activityStream().collect(Collectors.toList());
+ }
+
+ @Override
+ public void setActivity(List<Activity> activities) {
+ clearRoute();
+ for (Activity activity : activities) {
+ addActivity(activity);
+ }
+ }
+
+ @Override
+ public Activity getActivityByTopiaId(String topiaId) {
+ return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
+ }
+
+ @Override
+ public Collection<String> getActivityTopiaIds() {
+ return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
+ }
+
+ @Override
+ public void addActivity(Activity activity) {
+ Date date = DateUtil.getDay(activity.getDate());
+ Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
+ Route route;
+ if (optionalRoute.isPresent()) {
+ route = optionalRoute.get();
+ } else {
+ route = new RouteImpl();
+ route.setDate(date);
+ addRoute(route);
+ }
+ route.addActivity(activity);
+ }
+
+ @Override
+ public List<Route> getRoute() {
+ List<Route> route = super.getRoute();
+ if (route == null) {
+ setRoute(route = new LinkedList<>());
+ }
+ return route;
+ }
+
+ private Stream<Route> routeStream() {
+ return getRoute().stream();
+ }
+
+ private Stream<Activity> activityStream() {
+ return routeStream().flatMap(r -> r.getActivity().stream());
+ }
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
@@ -126,7 +126,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.fleetCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .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
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.flagCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) >0")
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractVesselSimpleTypeTopiaDao.java
@@ -37,11 +37,11 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
/**
* Obtains all vessel simple types used by all trips in the database.
*
- * @param sampleOnly if null no filter else filter on value
+ * @param samplesOnly if null no filter else filter on value
* @return the set of used vessel simple types in trips in the database
* @throws TopiaException if any problem while querying the database
*/
- public Set<E> findAllUsedInTrip(Boolean sampleOnly) throws TopiaException {
+ public Set<E> findAllUsedInTrip(Boolean samplesOnly) throws TopiaException {
// TopiaQuery query = createQuery("vst")
// .addFrom(Trip.class, "t")
@@ -50,8 +50,8 @@ public class AbstractVesselSimpleTypeTopiaDao<E extends VesselSimpleType> extend
// Vessel.PROPERTY_VESSEL_TYPE + "." +
// VesselType.PROPERTY_VESSEL_SIMPLE_TYPE + " = vst.id");
- String sampleOnlyFilter = sampleOnly == null ? "" : (" AND t.sampleOnly = " + sampleOnly);
- String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + sampleOnlyFilter;
+ String samplesOnlyFilter = samplesOnly == null ? "" : (" AND t.samplesOnly = " + samplesOnly);
+ String hql = "SELECT DISTINCT(vst) FROM VesselSimpleTypeImpl vst, TripImpl t WHERE t.vessel.vesselType.vesselSimpleType = vst.id" + samplesOnlyFilter;
return new HashSet<>(findAll(hql));
// return T3EntityHelper.querytoSet(hql, this);
}
=====================================
t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
+++ b/t3-domain/src/main/java/fr/ird/t3/services/DecoratorService.java
@@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.CompleteTrip;
+import fr.ird.t3.entities.data.Route;
import fr.ird.t3.entities.data.Sample;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
@@ -167,6 +168,9 @@ public class DecoratorService extends T3ServiceSupport implements T3ServiceSingl
// trip decorator
registerJXPathDecorator(locale, Trip.class, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY");
+ // route decorator
+ registerJXPathDecorator(locale, Route.class, "${trip.vesselLabel}$s - ${trip.landingDate}$td/%2$tm/%2$tY - ${date}$td/%3$tm/%3$tY");
+
// trip (with topiaid) decorator
registerJXPathDecorator(locale, Trip.class, WITH_ID, "${vesselLabel}$s - ${landingDate}$td/%2$tm/%2$tY [${topiaId}$s]");
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -0,0 +1,133 @@
+package fr.ird.t3.services.migration;
+
+/*
+ * #%L
+ * T3 :: Domain
+ * %%
+ * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+import org.nuiton.topia.persistence.support.TopiaSqlSupport;
+import org.nuiton.util.DateUtil;
+import org.nuiton.version.Versions;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by tchemit on 18/02/2018.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ */
+@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
+public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
+
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
+
+ public T3MigrationCallbackV2_2() {
+ super(Versions.valueOf("2.2"));
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
+ addScript("07", "add-Route-table", queries);
+
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
+ }
+
+ @Override
+ public String prepareResult(ResultSet set) throws SQLException {
+ return set.getString(1);
+ }
+ });
+
+ for (String tripId : tripList) {
+
+ int i = tripId.indexOf('#');
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+
+ log.info("Route prefix: " + routeIdPrefix);
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ preparedStatement.setString(1, tripId);
+ return preparedStatement;
+ }
+
+ @Override
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
+ return new TripActivity(set.getString(1), set.getDate(2));
+ }
+ });
+
+
+ Set<Date> days = new LinkedHashSet<>();
+ int activityIndex = 0;
+ for (TripActivity activity : activityList) {
+
+ String dayDateStr = df.format(activity.date);
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
+
+ if (days.add(activity.date)) {
+
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
+ // create new route
+ queries.add(String.format("INSERT INTO Route(topiaId, topiaVersion, topiaCreateDate, trip, date, trip_idx) VALUES('%s', 0, CURRENT_TIMESTAMP, '%s', to_date('%s', 'YYY-MM-DD'), %d);", routeId, tripId, dayDateStr, days.size()));
+ }
+ queries.add(String.format("UPDATE Activity SET route = '%s', route_idx = %d , topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, (activityIndex++), activity.activity));
+ }
+
+ if (!activityList.isEmpty()) {
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
+ }
+ }
+
+ addScript("08", "remove-trip-fields", queries);
+ }
+
+ private static class TripActivity {
+
+ private final String activity;
+ private final Date date;
+
+ private TripActivity(String activity, Date date) {
+ this.activity = activity;
+ this.date = DateUtil.getDay(date);
+ }
+ }
+
+}
=====================================
t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
@@ -0,0 +1,29 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+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, trip_id INTEGER);
+CREATE UNIQUE INDEX uk_route ON Route(trip, date);
+ALTER TABLE Route ADD CONSTRAINT fk_route_trip FOREIGN KEY (trip) REFERENCES Trip(topiaid);
+CREATE INDEX idx_route_trip ON Route(trip);
+
+ALTER TABLE Activity ADD COLUMN route VARCHAR(255);
+ALTER TABLE Activity ADD COLUMN route_idx INTEGER;
+ALTER TABLE Activity ADD CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
+CREATE INDEX idx_activity_route ON Activity(route);
=====================================
t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_08_remove-Trip-fields.sql
@@ -0,0 +1,27 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+
+ALTER TABLE Activity DROP COLUMN trip;
+ALTER TABLE Activity DROP COLUMN trip_idx;
+ALTER TABLE Activity DROP COLUMN date;
+ALTER TABLE Trip DROP COLUMN computedfishingtimen0;
+ALTER TABLE Trip DROP COLUMN computedsearchtimen0;
+ALTER TABLE Trip DROP COLUMN computedtimeatsean0;
=====================================
t3-domain/src/main/xmi/t3-persistence.properties
=====================================
--- a/t3-domain/src/main/xmi/t3-persistence.properties
+++ b/t3-domain/src/main/xmi/t3-persistence.properties
@@ -22,11 +22,17 @@
model.tagValue.notGenerateToString=true
model.tagValue.generateOperatorForDAOHelper=true
model.tagValue.constantPrefix=PROPERTY_
-model.tagValue.version=2.1
+model.tagValue.version=2.2
model.tagValue.indexForeignKeys=true
-fr.ird.t3.entities.data.Trip.attribute.activity.stereotype=ordered
-fr.ird.t3.entities.data.Trip.attribute.activity.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
+fr.ird.t3.entities.data.Route.attribute.activity.stereotype=ordered
+
+fr.ird.t3.entities.data.Trip.attribute.route.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date
+
+fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date
+fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time
fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text
fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
@@ -56,8 +56,8 @@ public class T3PersistenceFixtures {
return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
}
- public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean sampleOnly) {
- return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, sampleOnly);
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean samplesOnly) {
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, samplesOnly);
}
public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
=====================================
t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
=====================================
--- a/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
+++ b/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
@@ -55,11 +55,12 @@ import fr.ird.t3.io.input.access.T3AccessEntityMeta;
import fr.ird.t3.io.input.access.T3AccessEntityMetaProvider;
import fr.ird.t3.io.input.access.T3AccessReferentielEntityMeta;
import fr.ird.t3.io.input.access.type.IntToBoolean;
-import java.util.Date;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.Date;
+import java.util.Set;
+
/**
* Provider of {@link T3AccessEntityMeta}.
*
@@ -86,9 +87,7 @@ public class T3AccessEntityMetaProviderAvdth33 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionIT.java
@@ -163,7 +163,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -172,7 +172,7 @@ public class AnalyzeInputSourceActionIT implements T3AVDTHV33Test {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
=====================================
--- a/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
+++ b/t3-input-avdthv33/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionIT.java
@@ -115,14 +115,14 @@ public class ImportInputSourceActionIT implements T3AVDTHV33Test {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
=====================================
--- a/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
+++ b/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -98,9 +98,7 @@ public class T3AccessEntityMetaProviderAvdth35 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{/* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -165,7 +165,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -174,7 +174,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv35/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
=====================================
t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
=====================================
--- a/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
+++ b/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -100,9 +100,7 @@ public class T3AccessEntityMetaProviderAvdth36 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/AnalyzeInputSourceActionITSupport.java
@@ -168,7 +168,7 @@ public class AnalyzeInputSourceActionITSupport {
int nbUnsafe,
int nbSafeWithoutwell,
int nbUnsafeWithoutWell,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
@@ -177,7 +177,7 @@ public class AnalyzeInputSourceActionITSupport {
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
AnalyzeInputSourceConfiguration actionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, useWells, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, useWells, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ActionContext<AnalyzeInputSourceConfiguration> context =
serviceFactory.newT3ActionContext(actionConfiguration, serviceContext);
=====================================
t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
=====================================
--- a/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
+++ b/t3-input-avdthv36/src/test/java/fr/ird/t3/actions/io/input/ImportInputSourceActionITSupport.java
@@ -116,14 +116,14 @@ public abstract class ImportInputSourceActionITSupport {
}
public void testExecute(int nbSafe, int nbUnsafe,
- boolean sampleOnly,
+ boolean samplesOnly,
boolean canCreateVessel,
boolean createVirtualVessel) throws Exception {
if (msConfig.doTest(serviceContext.getTestName())) {
AnalyzeInputSourceConfiguration analyzeActionConfiguration = AnalyzeInputSourceConfiguration.newConfiguration(
- inputProvider, target, true, sampleOnly, canCreateVessel, createVirtualVessel
+ inputProvider, target, true, samplesOnly, canCreateVessel, createVirtualVessel
);
T3ServiceFactory serviceFactory = serviceContext.getServiceFactory();
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/774f886a4dea29332f9c4af01b2766c7…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/774f886a4dea29332f9c4af01b2766c7…
You're receiving this email because of your account on gitlab.com.
1
0
[Git][ultreiaio/ird-t3][develop] 3 commits: let's use a password, otherwise can't open test db in IDEA, what a shame...
by Tony CHEMIT 20 Feb '18
by Tony CHEMIT 20 Feb '18
20 Feb '18
Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
9d608f1e by Tony CHEMIT at 2018-02-20T19:29:19+01:00
let's use a password, otherwise can't open test db in IDEA, what a shame...
- - - - -
92556d11 by Tony CHEMIT at 2018-02-20T20:40:10+01:00
Improve persistences tests
- - - - -
9c95acac by Tony CHEMIT at 2018-02-20T20:40:17+01:00
[N0] Calcul des temps de pêche (Closes #240)
- - - - -
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:
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java
@@ -36,6 +36,7 @@ import fr.ird.t3.entities.T3Functions;
import fr.ird.t3.entities.T3Predicates;
import fr.ird.t3.entities.reference.Harbour;
import fr.ird.t3.entities.reference.Ocean;
+import fr.ird.t3.entities.reference.OceanImpl;
import fr.ird.t3.entities.reference.OceanTopiaDao;
import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.type.T3Date;
@@ -127,19 +128,21 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
// query = createQuery("t")
// .setSelect("t.id")
// .addWhere("size(t." + Trip.PROPERTY_ACTIVITY + ") = 0");
- hql = "SELECT t.id FROM TripImpl t WHERE size(t.activity) = 0";
+ hql = "SELECT t.id FROM TripImpl as t WHERE size(t.route) = 0";
// params = Collections.emptyList();
} else {
// query = new TopiaQuery(Activity.class, "a")
// .setSelect("distinct(a.trip.id)")
// .addWhere("a.ocean", TopiaQuery.Op.EQ, ocean);
- hql = "SELECT DISTINCT(a.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
+ hql = "SELECT DISTINCT(a.route.trip.id) FROM ActivityImpl a WHERE a.ocean = :ocean";
paramsBuilder.put("ocean", ocean);
// params = Lists.<Object>newArrayList("ocean", ocean);
}
return findAll(hql, paramsBuilder.build());
}
+ public static final Ocean EMPTY_OCEAN = new OceanImpl();
+
public Multimap<Ocean, String> findAllIdsByOcean() throws TopiaException {
Set<Ocean> oceans = topiaDaoSupplier.getDao(Ocean.class, OceanTopiaDao.class).findAllUsedInActivity();
@@ -154,7 +157,7 @@ public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<
// add trips with no ocean (http://forge.codelutin.com/issues/1134)
List<String> tripsWithNoOcean = findAllIdsByOcean(null);
if (CollectionUtils.isNotEmpty(tripsWithNoOcean)) {
- result.putAll(null, tripsWithNoOcean);
+ result.putAll(EMPTY_OCEAN, tripsWithNoOcean);
}
return result;
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/ActivityImpl.java
@@ -26,12 +26,13 @@ import fr.ird.t3.entities.reference.VesselActivity;
import fr.ird.t3.entities.type.T3Point;
import fr.ird.t3.entities.type.T3PointImpl;
import fr.ird.type.CoordinateHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
/**
* Implementation of {@link Activity} with manual quadrant
@@ -60,6 +61,11 @@ public class ActivityImpl extends ActivityAbstract {
protected Integer quadrant;
@Override
+ public Trip getTrip() {
+ return getRoute().getTrip();
+ }
+
+ @Override
public Integer getQuadrant() {
if (quadrant == null) {
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/data/TripImpl.java
@@ -30,9 +30,17 @@ import fr.ird.t3.entities.reference.Ocean;
import fr.ird.t3.entities.reference.Species;
import fr.ird.t3.entities.reference.Vessel;
import fr.ird.t3.entities.reference.VesselImpl;
+import org.nuiton.util.DateUtil;
import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static org.nuiton.i18n.I18n.n;
@@ -480,4 +488,73 @@ public class TripImpl extends TripAbstract {
ComputedDataHelper.deleteComputedDataLevel3(getWell());
}
+ @Override
+ public int sizeActivity() {
+ return (int) activityStream().count();
+ }
+
+ @Override
+ public boolean isActivityEmpty() {
+ return isRouteEmpty() || activityStream().count() == 0;
+ }
+
+ @Override
+ public boolean isActivityNotEmpty() {
+ return isRouteNotEmpty() && activityStream().count() > 0;
+ }
+
+ @Override
+ public List<Activity> getActivity() {
+ return activityStream().collect(Collectors.toList());
+ }
+
+ @Override
+ public void setActivity(List<Activity> activities) {
+ clearRoute();
+ for (Activity activity : activities) {
+ addActivity(activity);
+ }
+ }
+
+ @Override
+ public Activity getActivityByTopiaId(String topiaId) {
+ return activityStream().filter(a -> topiaId.equals(a.getTopiaId())).findFirst().orElse(null);
+ }
+
+ @Override
+ public Collection<String> getActivityTopiaIds() {
+ return activityStream().map(Activity::getTopiaId).collect(Collectors.toList());
+ }
+
+ @Override
+ public void addActivity(Activity activity) {
+ Date date = DateUtil.getDay(activity.getDate());
+ Optional<Route> optionalRoute = routeStream().filter(r -> Objects.equals(r.getDate(), date)).findFirst();
+ Route route;
+ if (optionalRoute.isPresent()) {
+ route = optionalRoute.get();
+ } else {
+ route = new RouteImpl();
+ route.setDate(date);
+ addRoute(route);
+ }
+ route.addActivity(activity);
+ }
+
+ @Override
+ public List<Route> getRoute() {
+ List<Route> route = super.getRoute();
+ if (route == null) {
+ setRoute(route = new LinkedList<>());
+ }
+ return route;
+ }
+
+ private Stream<Route> routeStream() {
+ return getRoute().stream();
+ }
+
+ private Stream<Activity> activityStream() {
+ return routeStream().flatMap(r -> r.getActivity().stream());
+ }
}
=====================================
t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
=====================================
--- a/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
+++ b/t3-domain/src/main/java/fr/ird/t3/entities/reference/AbstractCountryTopiaDao.java
@@ -126,7 +126,7 @@ public class AbstractCountryTopiaDao<E extends Country> extends GeneratedCountry
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.fleetCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .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
// .addParam("oceanId", oceanId);
String hql = "SELECT DISTINCT(c) " +
- "FROM CountryImpl c, TripImpl t LEFT JOIN t.activity as a " +
+ "FROM CountryImpl c, TripImpl t LEFT JOIN t.route as r LEFT JOIN r.activity as a " +
"WHERE t.vessel.flagCountry = c.id AND a.ocean.id = :oceanId";
// FIXME : trouvé pk cela est aussi long...
// .addWhere("(SELECT count(*) FROM " + SetSpeciesFrequencyImpl.class.getSimpleName() + " s WHERE s." + SetSpeciesFrequency.PROPERTY_ACTIVITY + " = a.id) >0")
=====================================
t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
=====================================
--- /dev/null
+++ b/t3-domain/src/main/java/fr/ird/t3/services/migration/T3MigrationCallbackV2_2.java
@@ -0,0 +1,133 @@
+package fr.ird.t3.services.migration;
+
+/*
+ * #%L
+ * T3 :: Domain
+ * %%
+ * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+import com.google.auto.service.AutoService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.migration.TopiaMigrationCallbackByClassNG;
+import org.nuiton.topia.persistence.TopiaException;
+import org.nuiton.topia.persistence.support.TopiaSqlQuery;
+import org.nuiton.topia.persistence.support.TopiaSqlSupport;
+import org.nuiton.util.DateUtil;
+import org.nuiton.version.Versions;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by tchemit on 18/02/2018.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ */
+@AutoService(TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion.class)
+public class T3MigrationCallbackV2_2 extends T3MigrationCallbackSupport {
+
+ private static final Log log = LogFactory.getLog(T3MigrationCallbackV2_2.class);
+
+ public T3MigrationCallbackV2_2() {
+ super(Versions.valueOf("2.2"));
+ }
+
+ @Override
+ protected void prepareMigrationScript(TopiaSqlSupport sqlSupport, List<String> queries, boolean showSql, boolean showProgression) throws TopiaException {
+ addScript("07", "add-Route-table", queries);
+
+
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+
+ List<String> tripList = sqlSupport.findMultipleResult(new TopiaSqlQuery<String>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ return connection.prepareStatement("SELECT DISTINCT(a.trip) FROM activity a");
+ }
+
+ @Override
+ public String prepareResult(ResultSet set) throws SQLException {
+ return set.getString(1);
+ }
+ });
+
+ for (String tripId : tripList) {
+
+ int i = tripId.indexOf('#');
+ String routeIdPrefix = "fr.ird.t3.entities.data.Route#" + tripId.substring(i + 1, tripId.lastIndexOf('#') + 1);
+
+ log.info("Route prefix: " + routeIdPrefix);
+ List<TripActivity> activityList = sqlSupport.findMultipleResult(new TopiaSqlQuery<TripActivity>() {
+ @Override
+ public PreparedStatement prepareQuery(Connection connection) throws SQLException {
+ PreparedStatement preparedStatement = connection.prepareStatement("SELECT a.topiaId, a.date FROM activity a WHERE a.trip = ?");
+ preparedStatement.setString(1, tripId);
+ return preparedStatement;
+ }
+
+ @Override
+ public TripActivity prepareResult(ResultSet set) throws SQLException {
+ return new TripActivity(set.getString(1), set.getDate(2));
+ }
+ });
+
+
+ Set<Date> days = new LinkedHashSet<>();
+ for (TripActivity activity : activityList) {
+
+ String dayDateStr = df.format(activity.date);
+ String routeId = routeIdPrefix + dayDateStr.replaceAll("-", "");
+
+ if (days.add(activity.date)) {
+
+ log.info(String.format("[%s] new Route: %s", tripId, routeId));
+ // create new route
+ 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));
+ }
+ queries.add(String.format("UPDATE Activity SET route = '%s', topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", routeId, activity.activity));
+ }
+
+ if (!activityList.isEmpty()) {
+ queries.add(String.format("UPDATE Trip SET effortComputed = false, topiaVersion = topiaVersion + 1 WHERE topiaId = '%s';", tripId));
+ }
+ }
+
+ queries.add("ALTER TABLE Activity DROP COLUMN trip;");
+ queries.add("ALTER TABLE Activity DROP COLUMN date;");
+ }
+
+ private static class TripActivity {
+
+ private final String activity;
+ private final Date date;
+
+ private TripActivity(String activity, Date date) {
+ this.activity = activity;
+ this.date = DateUtil.getDay(date);
+ }
+ }
+
+}
=====================================
t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
=====================================
--- /dev/null
+++ b/t3-domain/src/main/resources/db/migration/V2_2_07_add-Route-table.sql
@@ -0,0 +1,28 @@
+---
+-- #%L
+-- T3 :: Domain
+-- %%
+-- Copyright (C) 2010 - 2018 IRD, Code Lutin, Ultreia.io
+-- %%
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU Affero General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+-- #L%
+---
+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);
+CREATE UNIQUE INDEX uk_route ON Route(trip, date);
+ALTER TABLE Route ADD CONSTRAINT fk_route_trip FOREIGN KEY (trip) REFERENCES Trip(topiaid);
+CREATE INDEX idx_route_trip ON Route(trip);
+
+ALTER TABLE Activity ADD COLUMN route VARCHAR(255);
+ALTER TABLE Activity ADD CONSTRAINT fk_activity_route FOREIGN KEY (route) REFERENCES Route(topiaid);
+CREATE INDEX idx_activity_route ON Activity(route);
=====================================
t3-domain/src/main/xmi/t3-persistence.properties
=====================================
--- a/t3-domain/src/main/xmi/t3-persistence.properties
+++ b/t3-domain/src/main/xmi/t3-persistence.properties
@@ -22,11 +22,17 @@
model.tagValue.notGenerateToString=true
model.tagValue.generateOperatorForDAOHelper=true
model.tagValue.constantPrefix=PROPERTY_
-model.tagValue.version=2.1
+model.tagValue.version=2.2
model.tagValue.indexForeignKeys=true
-fr.ird.t3.entities.data.Trip.attribute.activity.stereotype=ordered
-fr.ird.t3.entities.data.Trip.attribute.activity.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Trip.attribute.route.stereotype=ordered
+fr.ird.t3.entities.data.Route.attribute.activity.stereotype=ordered
+
+fr.ird.t3.entities.data.Trip.attribute.route.tagvalue.orderBy=date
+fr.ird.t3.entities.data.Route.attribute.activity.tagvalue.orderBy=date
+
+fr.ird.t3.entities.data.Route.attribute.date.tagvalue.hibernateAttributeType.java.util.Date=date
+fr.ird.t3.entities.data.Activity.attribute.time.tagvalue.hibernateAttributeType.java.util.Date=time
fr.ird.t3.entities.data.Activity.attribute.comment.tagvalue.sqlType=text
fr.ird.t3.entities.data.LocalMarketBatch.attribute.origin.tagvalue.sqlType=text
=====================================
t3-domain/src/main/xmi/t3-persistence.zargo
=====================================
Binary files a/t3-domain/src/main/xmi/t3-persistence.zargo and b/t3-domain/src/main/xmi/t3-persistence.zargo differ
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
=====================================
--- /dev/null
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/T3PersistenceFixtures.java
@@ -0,0 +1,90 @@
+package fr.ird.t3.entities;
+
+import fr.ird.t3.entities.data.Activity;
+import fr.ird.t3.entities.data.Trip;
+import fr.ird.t3.entities.reference.Country;
+import fr.ird.t3.entities.reference.Harbour;
+import fr.ird.t3.entities.reference.Ocean;
+import fr.ird.t3.entities.reference.Species;
+import fr.ird.t3.entities.reference.Vessel;
+import fr.ird.t3.entities.reference.VesselSimpleType;
+import fr.ird.t3.entities.reference.VesselType;
+
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * Created by tchemit on 20/02/2018.
+ *
+ * @author Tony Chemit - dev(a)tchemit.fr
+ */
+public class T3PersistenceFixtures {
+
+ public static Activity newActivity(T3TopiaPersistenceContext tx, Ocean ocean) {
+ return newActivity(tx, ocean, new Date());
+ }
+
+ public static Ocean newOcean(T3TopiaPersistenceContext tx) {
+ return newOcean(tx, 0);
+ }
+
+ public static Ocean newOcean(T3TopiaPersistenceContext tx, int code) {
+ return tx.getOceanDao().create(Ocean.PROPERTY_CODE, code);
+ }
+
+ public static Country newCountry(T3TopiaPersistenceContext tx, int code) {
+ return tx.getCountryDao().create(Country.PROPERTY_CODE, code);
+ }
+
+ public static Activity newActivity(T3TopiaPersistenceContext tx, Ocean ocean, Date date) {
+ return Objects.requireNonNull(tx.getActivityDao()).create(Activity.PROPERTY_OCEAN, Objects.requireNonNull(ocean), Activity.PROPERTY_DATE, Objects.requireNonNull(date));
+ }
+
+ public static Trip newTrip(T3TopiaPersistenceContext tx) {
+ return tx.getTripDao().create();
+ }
+
+ public static Trip newTrip(T3TopiaPersistenceContext tx, Vessel vessel) {
+ return tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
+ }
+
+ public static Trip newTrip(T3TopiaPersistenceContext tx, Harbour harbour) {
+ return tx.getTripDao().create(Trip.PROPERTY_LANDING_HARBOUR, harbour);
+ }
+
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date) {
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date);
+ }
+
+ public static Trip newTrip(T3TopiaPersistenceContext tx, int code, Date date, boolean sampleOnly) {
+ return tx.getTripDao().create(Trip.PROPERTY_CODE, code, Trip.PROPERTY_LANDING_DATE, date, Trip.PROPERTY_SAMPLES_ONLY, sampleOnly);
+ }
+
+ public static Harbour newHarbour(T3TopiaPersistenceContext tx, int code) {
+ return tx.getHarbourDao().create(Harbour.PROPERTY_CODE, code);
+ }
+
+ public static Species newSpecies(T3TopiaPersistenceContext tx, int code) {
+ return tx.getSpeciesDao().create(Species.PROPERTY_CODE, code);
+ }
+
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, int code) {
+ return tx.getVesselDao().create(Vessel.PROPERTY_CODE, code);
+ }
+
+ public static VesselType newVesselType(T3TopiaPersistenceContext tx, int code, VesselSimpleType vesselSimpleType) {
+ return tx.getVesselTypeDao().create(VesselType.PROPERTY_CODE, code, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType);
+ }
+
+ public static VesselSimpleType newVesselSimpleType(T3TopiaPersistenceContext tx, int code) {
+ return tx.getVesselSimpleTypeDao().create(VesselSimpleType.PROPERTY_CODE, code);
+ }
+
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, Country country, int code) {
+ return tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country, Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, code);
+ }
+
+ public static Vessel newVessel(T3TopiaPersistenceContext tx, VesselType vesselType, int code) {
+ return tx.getVesselDao().create(Vessel.PROPERTY_VESSEL_TYPE, vesselType, Vessel.PROPERTY_CODE, code);
+ }
+}
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/data/TripTopiaDaoTest.java
@@ -22,17 +22,19 @@ package fr.ird.t3.entities.data;
import com.google.common.collect.Multimap;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.reference.Ocean;
-import fr.ird.t3.entities.reference.OceanTopiaDao;
import fr.ird.t3.entities.type.T3Date;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
/**
* Tests the trip dao {@link TripTopiaDao}.
@@ -42,36 +44,23 @@ import org.junit.Test;
*/
public class TripTopiaDaoTest extends AbstractDatabaseTest {
- T3TopiaPersistenceContext tx;
-
- TripTopiaDao dao;
-
- OceanTopiaDao oceanDAO;
-
- ActivityTopiaDao activitDAO;
+ private T3TopiaPersistenceContext tx;
+ private TripTopiaDao dao;
@Before
- public void setUp() throws Exception {
-
+ public void setUp() {
tx = beginTransaction();
dao = tx.getTripDao();
- oceanDAO = tx.getOceanDao();
- activitDAO = tx.getActivityDao();
}
@Test
- public void findAllBetweenLandingDate() throws Exception {
+ public void findAllBetweenLandingDate() {
T3Date startDate = T3Date.newDate(1, 2010);
T3Date endDate = T3Date.newDate(1, 2011);
- Trip trip = dao.create(Trip.PROPERTY_CODE, 0,
- Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate(),
- Trip.PROPERTY_SAMPLES_ONLY, false
- );
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1,
- Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate(),
- Trip.PROPERTY_SAMPLES_ONLY, true);
+ Trip trip = T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate(), false);
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate(), true);
List<Trip> result;
@@ -103,20 +92,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void getFirstLandingDate() throws Exception {
+ public void getFirstLandingDate() {
T3Date startDate = T3Date.newDate(1, 2010);
T3Date endDate = T3Date.newDate(1, 2011);
T3Date result;
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
result = dao.getFirstLandingDate();
Assert.assertNotNull(result);
Assert.assertEquals(endDate, result);
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
result = dao.getFirstLandingDate();
Assert.assertNotNull(result);
@@ -124,20 +113,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void getLastLandingDate() throws Exception {
+ public void getLastLandingDate() {
T3Date startDate = T3Date.newDate(1, 2010);
T3Date endDate = T3Date.newDate(1, 2011);
T3Date result;
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
result = dao.getLastLandingDate();
Assert.assertNotNull(result);
Assert.assertEquals(startDate, result);
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
result = dao.getLastLandingDate();
Assert.assertNotNull(result);
@@ -145,20 +134,20 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void findAllYearsUsedInTrip() throws Exception {
+ public void findAllYearsUsedInTrip() {
T3Date startDate = T3Date.newDate(1, 2010);
T3Date endDate = T3Date.newDate(1, 2011);
List<Integer> result;
- dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, endDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 1, endDate.toBeginDate());
result = dao.findAllYearsUsedInTrip();
Assert.assertNotNull(result);
- Assert.assertEquals(Arrays.asList(2011), result);
+ Assert.assertEquals(Collections.singletonList(2011), result);
- dao.create(Trip.PROPERTY_CODE, 0, Trip.PROPERTY_LANDING_DATE, startDate.toBeginDate());
+ T3PersistenceFixtures.newTrip(tx, 0, startDate.toBeginDate());
result = dao.findAllYearsUsedInTrip();
Assert.assertNotNull(result);
@@ -230,22 +219,22 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
// }
@Test
- public void findAllIdsByOcean() throws Exception {
+ public void findAllIdsByOcean() {
- Ocean ocean1 = oceanDAO.create(Ocean.PROPERTY_CODE, 1);
- Ocean ocean2 = oceanDAO.create(Ocean.PROPERTY_CODE, 2);
+ Ocean ocean1 = T3PersistenceFixtures.newOcean(tx, 1);
+ Ocean ocean2 = T3PersistenceFixtures.newOcean(tx, 2);
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, new Date());
- Activity activity1 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean1);
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, new Date());
+ Activity activity1 = T3PersistenceFixtures.newActivity(tx, ocean1);
trip1.addActivity(activity1);
- Activity activity11 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
+ Activity activity11 = T3PersistenceFixtures.newActivity(tx, ocean2);
trip1.addActivity(activity11);
- Trip trip2 = dao.create(Trip.PROPERTY_CODE, 2, Trip.PROPERTY_LANDING_DATE, new Date());
- Activity activity2 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
+ Trip trip2 = T3PersistenceFixtures.newTrip(tx, 2, new Date());
+ Activity activity2 = T3PersistenceFixtures.newActivity(tx, ocean2);
trip2.addActivity(activity2);
- Trip trip3 = dao.create(Trip.PROPERTY_CODE, 3, Trip.PROPERTY_LANDING_DATE, new Date());
+ Trip trip3 = T3PersistenceFixtures.newTrip(tx, 3, new Date());
Multimap<Ocean, String> result = dao.findAllIdsByOcean();
@@ -263,7 +252,7 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
Assert.assertTrue(trips.contains(trip1.getTopiaId()));
Assert.assertTrue(trips.contains(trip2.getTopiaId()));
- trips = result.get(null);
+ trips = result.get(TripTopiaDao.EMPTY_OCEAN);
Assert.assertNotNull(trips);
Assert.assertEquals(1, trips.size());
Assert.assertTrue(trips.contains(trip3.getTopiaId()));
@@ -283,25 +272,24 @@ public class TripTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void findAllByIds() throws Exception {
-
- Ocean ocean1 = oceanDAO.create(Ocean.PROPERTY_CODE, 1);
- Ocean ocean2 = oceanDAO.create(Ocean.PROPERTY_CODE, 2);
+ public void findAllByIds() {
+ Ocean ocean1 = T3PersistenceFixtures.newOcean(tx, 1);
+ Ocean ocean2 = T3PersistenceFixtures.newOcean(tx, 2);
- Trip trip1 = dao.create(Trip.PROPERTY_CODE, 1, Trip.PROPERTY_LANDING_DATE, new Date());
- Activity activity1 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean1);
+ Trip trip1 = T3PersistenceFixtures.newTrip(tx, 1, new Date());
+ Activity activity1 = T3PersistenceFixtures.newActivity(tx, ocean1);
trip1.addActivity(activity1);
- Activity activity11 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
+ Activity activity11 = T3PersistenceFixtures.newActivity(tx, ocean2);
trip1.addActivity(activity11);
- Trip trip2 = dao.create(Trip.PROPERTY_CODE, 2, Trip.PROPERTY_LANDING_DATE, new Date());
- Activity activity2 = activitDAO.create(Activity.PROPERTY_OCEAN, ocean2);
+ Trip trip2 = T3PersistenceFixtures.newTrip(tx, 2, new Date());
+ Activity activity2 = T3PersistenceFixtures.newActivity(tx, ocean2);
trip2.addActivity(activity2);
List<Trip> result;
- result = dao.findAllByIds(Arrays.asList(trip1.getTopiaId()));
+ result = dao.findAllByIds(Collections.singletonList(trip1.getTopiaId()));
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/CountryTopiaDaoTest.java
@@ -21,14 +21,17 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.CorrectedElementaryCatch;
import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractCountryTopiaDao}.
*
@@ -37,44 +40,44 @@ import org.junit.Test;
*/
public class CountryTopiaDaoTest extends AbstractDatabaseTest {
- @Test
- public void findAllFleetUsedInTrip() throws Exception {
-
- T3TopiaPersistenceContext tx = beginTransaction();
+ private Country country;
+ private Vessel vessel;
+ private Vessel vessel2;
+ private Ocean ocean;
+ private T3TopiaPersistenceContext tx;
+ private CountryTopiaDao dao;
+
+ @Before
+ public void setUp() {
+ tx = beginTransaction();
+ dao = tx.getCountryDao();
+ country = T3PersistenceFixtures.newCountry(tx, 0);
+ Country country2 = T3PersistenceFixtures.newCountry(tx, 1);
+ vessel = T3PersistenceFixtures.newVessel(tx, country, 0);
+ vessel2 = T3PersistenceFixtures.newVessel(tx, country2, 1);
+ ocean = T3PersistenceFixtures.newOcean(tx, 0);
+ }
- CountryTopiaDao dao = tx.getCountryDao();
+ @Test
+ public void findAllFleetUsedInTrip() {
- Country country = dao.create(Country.PROPERTY_CODE, 0);
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
+ T3PersistenceFixtures.newTrip(tx, vessel);
- Set<Country> result = dao.findAllFleetUsedInTrip();
+ Set<Country> result = tx.getCountryDao().findAllFleetUsedInTrip();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(country, result.iterator().next());
}
@Test
- public void findAllFleetUsedInCatch() throws Exception {
-
- T3TopiaPersistenceContext tx = beginTransaction();
-
- CountryTopiaDao dao = tx.getCountryDao();
+ public void findAllFleetUsedInCatch() {
- Country country = dao.create(Country.PROPERTY_CODE, 0);
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
- // create another trip without any activity (so withou also any corrected catches)
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
+ // create another trip without any activity (so without also any corrected catches)
+ T3PersistenceFixtures.newTrip(tx, vessel2);
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_TRIP, trip
- );
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
trip.addActivity(activity);
CorrectedElementaryCatch catche = tx.getCorrectedElementaryCatchDao().create();
@@ -89,27 +92,15 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void findAllFleetUsedInSample() throws Exception {
-
- T3TopiaPersistenceContext tx = beginTransaction();
+ public void findAllFleetUsedInSample() {
- Ocean ocean = tx.getOceanDao().create();
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
- CountryTopiaDao dao = tx.getCountryDao();
- Country country = dao.create(Country.PROPERTY_CODE, 0);
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLEET_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
+ // create another trip without any activity (so without also any corrected catches)
+ T3PersistenceFixtures.newTrip(tx, vessel2);
- // create another trip without any activity (so withou also any corrected catches)
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
-
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_TRIP, trip,
- Activity.PROPERTY_OCEAN, ocean
- );
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
trip.addActivity(activity);
Set<Country> result;
@@ -132,32 +123,17 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest {
}
@Test
- public void findAllFlagUsedInSample() throws Exception {
-
- T3TopiaPersistenceContext tx = beginTransaction();
-
- Ocean ocean = tx.getOceanDao().create();
+ public void findAllFlagUsedInSample() {
- CountryTopiaDao dao = tx.getCountryDao();
-
- Country country = dao.create(Country.PROPERTY_CODE, 0);
- Country country2 = dao.create(Country.PROPERTY_CODE, 1);
- Vessel vessel = tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country, Vessel.PROPERTY_CODE, 0);
- Vessel vessel2 = tx.getVesselDao().create(Vessel.PROPERTY_FLAG_COUNTRY, country2, Vessel.PROPERTY_CODE, 1);
- Trip trip = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel);
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
// create another trip without any activity (so withou also any corrected catches)
- Trip trip2 = tx.getTripDao().create(Trip.PROPERTY_VESSEL, vessel2);
+ T3PersistenceFixtures.newTrip(tx, vessel2);
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_TRIP, trip,
- Activity.PROPERTY_OCEAN, ocean
- );
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
trip.addActivity(activity);
- Set<Country> result;
-
- result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
+ Set<Country> result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
Assert.assertNotNull(result);
//FIXME Should be zero when we will fix the request...
// Assert.assertEquals(0, result.size());
@@ -166,10 +142,10 @@ public class CountryTopiaDaoTest extends AbstractDatabaseTest {
// SetSpeciesFrequency f =
// tx.getSetSpeciesFrequencyDAO(tx).create(SetSpeciesFrequency.PROPERTY_ACTIVITY, activity);
- result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
- Assert.assertNotNull(result);
- Assert.assertEquals(1, result.size());
- Assert.assertEquals(country, result.iterator().next());
+// result = dao.findAllFlagUsedInSample(ocean.getTopiaId());
+// Assert.assertNotNull(result);
+// Assert.assertEquals(1, result.size());
+// Assert.assertEquals(country, result.iterator().next());
}
}
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/HarbourTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/HarbourTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/HarbourTopiaDaoTest.java
@@ -21,12 +21,13 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
-import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractHarbourTopiaDao}.
*
@@ -36,20 +37,14 @@ import org.junit.Test;
public class HarbourTopiaDaoTest extends AbstractDatabaseTest {
@Test
- public void findAllUsedInLandingTrip() throws Exception {
-
+ public void findAllUsedInLandingTrip() {
T3TopiaPersistenceContext tx = beginTransaction();
- HarbourTopiaDao dao = tx.getHarbourDao();
-
- Harbour harbour = dao.create(Harbour.PROPERTY_CODE, 1);
- Harbour harbour2 = dao.create(Harbour.PROPERTY_CODE, 2);
-
- Trip trip = tx.getTripDao().create(
- Trip.PROPERTY_LANDING_HARBOUR, harbour
- );
+ Harbour harbour = T3PersistenceFixtures.newHarbour(tx, 1);
+ T3PersistenceFixtures.newHarbour(tx, 2);
+ T3PersistenceFixtures.newTrip(tx, harbour);
- Set<Harbour> result = dao.findAllUsedInLandingTrip();
+ Set<Harbour> result = tx.getHarbourDao().findAllUsedInLandingTrip();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(harbour, result.iterator().next());
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
@@ -28,15 +28,16 @@ import com.google.common.collect.Sets;
import fr.ird.t3.entities.AbstractDatabaseTest;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.type.T3Date;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.nuiton.topia.persistence.TopiaException;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* tests the {@link LengthWeightConversionHelper}.
*
@@ -46,13 +47,13 @@ import org.nuiton.topia.persistence.TopiaException;
public class LengthWeightConversionHelperTest extends AbstractDatabaseTest {
@Before
- public void setUp() throws Exception {
+ public void setUp() {
db.loadClassPathScript("/db/LengthWeightConversionHelperTest.sql");
}
@Test
- public void testGetConversionsAtlantique() throws Exception {
+ public void testGetConversionsAtlantique() {
T3TopiaPersistenceContext tx = beginTransaction();
@@ -63,7 +64,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest {
}
@Test
- public void testGetConversionsIndian() throws Exception {
+ public void testGetConversionsIndian() {
T3TopiaPersistenceContext tx = beginTransaction();
@@ -73,8 +74,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest {
}
- protected void testConversionForOcean(T3TopiaPersistenceContext tx,
- Ocean ocean) throws TopiaException {
+ private void testConversionForOcean(T3TopiaPersistenceContext tx, Ocean ocean) throws TopiaException {
Date date = T3Date.newDate(1, 2010).toBeginDate();
LengthWeightConversionHelper conversionHelper =
@@ -130,10 +130,10 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest {
}
Range<Integer> open = Range.open(0, 1000);
- List<Integer> lenghtClasses = Lists.newArrayList(ContiguousSet.create(open,DiscreteDomain.integers()));
+ List<Integer> lengthClasses = Lists.newArrayList(ContiguousSet.create(open,DiscreteDomain.integers()));
Map<Integer, WeightCategoryTreatment> distribution =
- conversionHelper.getWeightCategoriesDistribution(conversion, allCategories, lenghtClasses);
+ conversionHelper.getWeightCategoriesDistribution(conversion, allCategories, lengthClasses);
Assert.assertNotNull(distribution);
Set<WeightCategoryTreatment> usedweithCategories = Sets.newHashSet(distribution.values());
// all categories must be used (except the undefined one
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/OceanTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/OceanTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/OceanTopiaDaoTest.java
@@ -21,13 +21,15 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractOceanTopiaDao}.
*
@@ -37,21 +39,18 @@ import org.junit.Test;
public class OceanTopiaDaoTest extends AbstractDatabaseTest {
@Test
- public void findAllUsedInActivity() throws Exception {
+ public void findAllUsedInActivity() {
T3TopiaPersistenceContext tx = beginTransaction();
- OceanTopiaDao dao = tx.getOceanDao();
- Ocean ocean = dao.create(Ocean.PROPERTY_CODE, 0);
- Trip trip = tx.getTripDao().create();
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_OCEAN, ocean,
- Activity.PROPERTY_TRIP, trip
- );
+ Ocean ocean = T3PersistenceFixtures.newOcean(tx);
+ Trip trip = T3PersistenceFixtures.newTrip(tx);
+ Activity activity = T3PersistenceFixtures.newActivity(tx, ocean);
trip.addActivity(activity);
- Set<Ocean> result = dao.findAllUsedInActivity();
+ Set<Ocean> result = tx.getOceanDao().findAllUsedInActivity();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(ocean, result.iterator().next());
}
+
}
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/SpecieDAOImplTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/SpecieDAOImplTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/SpecieDAOImplTest.java
@@ -21,14 +21,16 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.CorrectedElementaryCatch;
import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractSpeciesTopiaDao}.
*
@@ -38,28 +40,23 @@ import org.junit.Test;
public class SpecieDAOImplTest extends AbstractDatabaseTest {
@Test
- public void findAllSpecieUsedInCatch() throws Exception {
+ public void findAllSpecieUsedInCatch() {
T3TopiaPersistenceContext tx = beginTransaction();
SpeciesTopiaDao dao = tx.getSpeciesDao();
- Species species = dao.create(Species.PROPERTY_CODE, 0);
- Species species2 = dao.create(Species.PROPERTY_CODE, 1);
+ Species species = T3PersistenceFixtures.newSpecies(tx, 0);
+ T3PersistenceFixtures.newSpecies(tx, 1);
- Trip trip = tx.getTripDao().create();
+ Trip trip = T3PersistenceFixtures.newTrip(tx);
- // create another trip without any activity (so withou also any corrected catches)
- Trip trip2 = tx.getTripDao().create();
+ // create another trip without any activity (so without also any corrected catches)
+ T3PersistenceFixtures.newTrip(tx, T3PersistenceFixtures.newVessel(tx, 0));
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_TRIP, trip
- );
+ Activity activity = T3PersistenceFixtures.newActivity(tx, T3PersistenceFixtures.newOcean(tx));
trip.addActivity(activity);
-
- CorrectedElementaryCatch catche =
- tx.getCorrectedElementaryCatchDao().create(CorrectedElementaryCatch.PROPERTY_SPECIES, species);
- activity.addCorrectedElementaryCatch(catche);
+ activity.addCorrectedElementaryCatch(tx.getCorrectedElementaryCatchDao().create(CorrectedElementaryCatch.PROPERTY_SPECIES, species));
Set<Species> result = dao.findAllSpeciesUsedInCatch();
Assert.assertNotNull(result);
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselSimpleTypeTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselSimpleTypeTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselSimpleTypeTopiaDaoTest.java
@@ -21,12 +21,13 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
-import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractVesselSimpleTypeTopiaDao}.
*
@@ -36,26 +37,21 @@ import org.junit.Test;
public class VesselSimpleTypeTopiaDaoTest extends AbstractDatabaseTest {
@Test
- public void findAllUsedInTrip() throws Exception {
+ public void findAllUsedInTrip() {
T3TopiaPersistenceContext tx = beginTransaction();
- VesselSimpleTypeTopiaDao dao = tx.getVesselSimpleTypeDao();
- VesselSimpleType vesselSimpleType = dao.create(VesselSimpleType.PROPERTY_CODE, 1);
- VesselSimpleType vesselSimpleType2 = dao.create(VesselSimpleType.PROPERTY_CODE, 2);
+ VesselSimpleType vesselSimpleType = T3PersistenceFixtures.newVesselSimpleType(tx, 1);
+ VesselSimpleType vesselSimpleType2 = T3PersistenceFixtures.newVesselSimpleType(tx, 2);
- VesselTypeTopiaDao vesselTypeDAO = tx.getVesselTypeDao();
- VesselType vesselType = vesselTypeDAO.create(VesselType.PROPERTY_CODE, 1, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType);
- VesselType vesselType2 = vesselTypeDAO.create(VesselType.PROPERTY_CODE, 2, VesselType.PROPERTY_VESSEL_SIMPLE_TYPE, vesselSimpleType2);
+ VesselType vesselType = T3PersistenceFixtures.newVesselType(tx, 1, vesselSimpleType);
+ VesselType vesselType2 = T3PersistenceFixtures.newVesselType(tx, 2, vesselSimpleType2);
- VesselTopiaDao vesselDAO = tx.getVesselDao();
- Vessel vessel = vesselDAO.create(Vessel.PROPERTY_CODE, 1, Vessel.PROPERTY_VESSEL_TYPE, vesselType);
- Vessel vessel2 = vesselDAO.create(Vessel.PROPERTY_CODE, 2, Vessel.PROPERTY_VESSEL_TYPE, vesselType2);
+ Vessel vessel = T3PersistenceFixtures.newVessel(tx, vesselType, 1);
+ T3PersistenceFixtures.newVessel(tx, vesselType2, 2);
- Trip trip = tx.getTripDao().create(
- Trip.PROPERTY_VESSEL, vessel
- );
- Set<VesselSimpleType> result = dao.findAllUsedInTrip(null);
+ T3PersistenceFixtures.newTrip(tx, vessel);
+ Set<VesselSimpleType> result = tx.getVesselSimpleTypeDao().findAllUsedInTrip(null);
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(vesselSimpleType, result.iterator().next());
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselTopiaDaoTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselTopiaDaoTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/VesselTopiaDaoTest.java
@@ -21,13 +21,15 @@
package fr.ird.t3.entities.reference;
import fr.ird.t3.entities.AbstractDatabaseTest;
+import fr.ird.t3.entities.T3PersistenceFixtures;
import fr.ird.t3.entities.T3TopiaPersistenceContext;
import fr.ird.t3.entities.data.Activity;
import fr.ird.t3.entities.data.Trip;
-import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
+import java.util.Set;
+
/**
* Test the user dao {@link AbstractVesselTopiaDao}.
*
@@ -37,22 +39,17 @@ import org.junit.Test;
public class VesselTopiaDaoTest extends AbstractDatabaseTest {
@Test
- public void findAllUsedInTrip() throws Exception {
+ public void findAllUsedInTrip() {
T3TopiaPersistenceContext tx = beginTransaction();
- VesselTopiaDao dao = tx.getVesselDao();
- Vessel vessel = dao.create(Vessel.PROPERTY_CODE, 1);
- Vessel vessel2 = dao.create(Vessel.PROPERTY_CODE, 2);
+ Vessel vessel = T3PersistenceFixtures.newVessel(tx, 1);
+ T3PersistenceFixtures.newVessel(tx, 2);
- Trip trip = tx.getTripDao().create(
- Trip.PROPERTY_VESSEL, vessel
- );
- Activity activity = tx.getActivityDao().create(
- Activity.PROPERTY_TRIP, trip
- );
+ Trip trip = T3PersistenceFixtures.newTrip(tx, vessel);
+ Activity activity = T3PersistenceFixtures.newActivity(tx, T3PersistenceFixtures.newOcean(tx));
trip.addActivity(activity);
- Set<Vessel> result = dao.findAllUsedInTrip();
+ Set<Vessel> result = tx.getVesselDao().findAllUsedInTrip();
Assert.assertNotNull(result);
Assert.assertEquals(1, result.size());
Assert.assertEquals(vessel, result.iterator().next());
=====================================
t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
=====================================
--- a/t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
+++ b/t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
@@ -39,7 +39,7 @@ import org.junit.Test;
public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
@Test
- public void testGetOldCategoryCode() throws Exception {
+ public void testGetOldCategoryCode() {
db.loadClassPathScript("/db/WeightCategoryTreatmentImplTest.sql");
try (T3TopiaPersistenceContext tx = beginTransaction()) {
@@ -52,7 +52,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
}
@Test
- public void testWeightCategoryTreatmentComparator() throws Exception {
+ public void testWeightCategoryTreatmentComparator() {
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
@@ -83,7 +83,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
}
@Test
- public void testWeightCategoryTreatmentComparator2() throws Exception {
+ public void testWeightCategoryTreatmentComparator2() {
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
@@ -135,7 +135,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
}
@Test
- public void getWeightCategoryTreatment() throws Exception {
+ public void getWeightCategoryTreatment() {
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
@@ -184,7 +184,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest {
}
@Test
- public void getWeightCategoryTreatment2() throws Exception {
+ public void getWeightCategoryTreatment2() {
WeightCategoryTreatment catInconnu = new WeightCategoryTreatmentImpl();
=====================================
t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
=====================================
--- a/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
+++ b/t3-input-avdthv33/src/main/java/fr/ird/t3/io/input/avdth/v33/T3AccessEntityMetaProviderAvdth33.java
@@ -55,11 +55,12 @@ import fr.ird.t3.io.input.access.T3AccessEntityMeta;
import fr.ird.t3.io.input.access.T3AccessEntityMetaProvider;
import fr.ird.t3.io.input.access.T3AccessReferentielEntityMeta;
import fr.ird.t3.io.input.access.type.IntToBoolean;
-import java.util.Date;
-import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.Date;
+import java.util.Set;
+
/**
* Provider of {@link T3AccessEntityMeta}.
*
@@ -86,9 +87,7 @@ public class T3AccessEntityMetaProviderAvdth33 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
=====================================
--- a/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
+++ b/t3-input-avdthv35/src/main/java/fr/ird/t3/io/input/avdth/v35/T3AccessEntityMetaProviderAvdth35.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -98,9 +98,7 @@ public class T3AccessEntityMetaProviderAvdth35 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{/* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
=====================================
t3-input-avdthv35/src/test/resources/t3-TopiaContextImpl.properties
=====================================
--- a/t3-input-avdthv35/src/test/resources/t3-TopiaContextImpl.properties
+++ b/t3-input-avdthv35/src/test/resources/t3-TopiaContextImpl.properties
@@ -24,7 +24,7 @@ hibernate.show_sql=false
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.connection.username=sa
-hibernate.connection.password=
+hibernate.connection.password=sa
hibernate.connection.driver_class=org.h2.Driver
# tchemit 2010-11-28 : comment this line, each test must define his own db path
#hibernate.connection.url=jdbc:h2:file:target/surefire-workdir/h2data
=====================================
t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
=====================================
--- a/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
+++ b/t3-input-avdthv36/src/main/java/fr/ird/t3/io/input/avdth/v36/T3AccessEntityMetaProviderAvdth36.java
@@ -34,9 +34,9 @@ import fr.ird.t3.entities.data.LocalMarketSampleSpeciesFrequency;
import fr.ird.t3.entities.data.LocalMarketSampleWell;
import fr.ird.t3.entities.data.LocalMarketSurvey;
import fr.ird.t3.entities.data.Sample;
+import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.SampleSpecies;
import fr.ird.t3.entities.data.SampleSpeciesFrequency;
-import fr.ird.t3.entities.data.SampleSet;
import fr.ird.t3.entities.data.Trip;
import fr.ird.t3.entities.data.Well;
import fr.ird.t3.entities.data.WellPlan;
@@ -100,9 +100,7 @@ public class T3AccessEntityMetaProviderAvdth36 implements T3AccessEntityMetaProv
Activity.PROPERTY_ACTIVITY_FISHING_CONTEXT, ActivityFishingContext.class,
Activity.PROPERTY_ELEMENTARY_CATCH, ElementaryCatch.class
},
- new Object[]{
- Activity.PROPERTY_TRIP, Trip.class
- },
+ new Object[]{ /* Nothing to do any longer */},
Activity.PROPERTY_DATE, Date.class, "D_ACT",
Activity.PROPERTY_NUMBER, Integer.class, "N_ACT",
Activity.PROPERTY_OCEAN, Ocean.class, "C_OCEA",
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/896731cf2ee1936293340e4c2e25c73…
---
View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/compare/896731cf2ee1936293340e4c2e25c73…
You're receiving this email because of your account on gitlab.com.
1
0