Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3 Commits: 70318fcc by Tony CHEMIT at 2018-03-08T12:55:59Z Marées sans logbooks : gestion de leurs échantillons - ajout de check de cohérence sur Trip.logbookAvaibility (See #116) + fix typo - - - - - 11 changed files: - t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level3/Level3Action_en.ftl - t3-domain/src/main/java/fr/ird/t3/entities/data/AbstractTripTopiaDao.java - t3-domain/src/main/java/fr/ird/t3/io/input/access/AbstractT3InputMSAccess.java - t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AccessDataSource.java - t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AvdthDataEntityVisitor.java - t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java - t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java - t3-web/src/main/java/fr/ird/t3/web/actions/io/output/ExportConfigureAction.java - t3-web/src/main/java/fr/ird/t3/web/actions/json/GetOutputProviderOperationsAction.java - t3-web/src/main/java/fr/ird/t3/web/actions/json/GetZoneVersionsAction.java - t3-web/src/main/resources/i18n/t3-web_en_GB.properties Changes: ===================================== t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level3/Level3Action_en.ftl ===================================== --- a/t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level3/Level3Action_en.ftl +++ b/t3-actions/src/main/resources/ftl/fr/ird/t3/actions/data/level3/Level3Action_en.ftl @@ -30,7 +30,7 @@ Time step: ${configuration.timeStep} Treatment to apply to catches with samples: <#if configuration.useAllSamplesOfStratum> -Apply length structures from the sample statrum +Apply length structures from the sample stratum <#else> Keep their own samples (do nothing) </#if> ===================================== 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 @@ -49,6 +49,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -69,12 +70,43 @@ import java.util.stream.StreamSupport; public class AbstractTripTopiaDao<E extends Trip> extends GeneratedTripTopiaDao<E> { public static final Ocean EMPTY_OCEAN = new OceanImpl(); + private static final int TRIP_WITHOUT_LOGBOOK = 0; + private static final int TRIP_WITH_LOGBOOK = 1; private static final Log log = LogFactory.getLog(AbstractTripTopiaDao.class); static { EMPTY_OCEAN.setTopiaId("fr.ird.t3.entities.reference.Ocean#EMPTY#EMPTY"); } + /** + * Check that a standard trip ({@link TripType#STANDARD}) is consistent around {@link Trip#getLogBookAvailability()}. + * + * @param trip trip to check + * @param pKey primary key of this trip + */ + public static void checkStandardTrip(Trip trip, Object[] pKey) { + int logBookAvailability = trip.getLogBookAvailability(); + if (AbstractTripTopiaDao.TRIP_WITHOUT_LOGBOOK == logBookAvailability && trip.isActivityNotEmpty()) { + throw new IllegalStateException(String.format("Trip [%s] has some logBook but logBookAvailability says the opposite, please fix this trip..", Arrays.toString(pKey))); + } + if (AbstractTripTopiaDao.TRIP_WITH_LOGBOOK == logBookAvailability && trip.isActivityEmpty()) { + throw new IllegalStateException(String.format("Trip [%s] has some logBook but logBookAvailability says the opposite, please fix this trip..", Arrays.toString(pKey))); + } + } + + /** + * Check that a standard trip ({@link TripType#LOGBOOKMISSING}) is consistent around {@link Trip#getLogBookAvailability()}. + * + * @param trip trip to check + * @param pKey primary key of this trip + */ + public static void checkLogbookMissingTrip(Trip trip, Object[] pKey) { + int logBookAvailability = trip.getLogBookAvailability(); + if (AbstractTripTopiaDao.TRIP_WITH_LOGBOOK == logBookAvailability) { + throw new IllegalStateException(String.format("Trip [%s] has no logBook but logBookAvailability says the opposite, please fix this trip.", Arrays.toString(pKey))); + } + } + public static String getSamplesOnlyFilter(String prefix, Boolean samplesOnly) { if (samplesOnly == null) { return ""; ===================================== t3-domain/src/main/java/fr/ird/t3/io/input/access/AbstractT3InputMSAccess.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/io/input/access/AbstractT3InputMSAccess.java +++ b/t3-domain/src/main/java/fr/ird/t3/io/input/access/AbstractT3InputMSAccess.java @@ -25,6 +25,7 @@ import fr.ird.t3.entities.ReferenceEntityMap; import fr.ird.t3.entities.T3EntityEnum; import fr.ird.t3.entities.T3EntityMap; import fr.ird.t3.entities.data.Trip; +import fr.ird.t3.entities.data.TripTopiaDao; import fr.ird.t3.entities.data.TripType; import fr.ird.t3.entities.reference.Vessel; import fr.ird.t3.io.input.MissingForeignKey; @@ -42,6 +43,7 @@ import java.io.File; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -91,11 +93,7 @@ public abstract class AbstractT3InputMSAccess implements T3Input { T3AccessHitModel hitModel = new T3AccessHitModel(); hitModel.addPropertyChangeListener(new LoadDbPropertyChangeListener(t3DataTypes)); // analyse data source - if (configuration.getTripType() == TripType.LOGBOOKMISSING) { - dataSource.analyzeDb(TripType.LOGBOOKMISSING, hitModel); - } else { - dataSource.analyzeDb(hitModel); - } + dataSource.analyzeDb(hitModel); if (dataSource.hasError()) { errors = dataSource.getErrors(); } @@ -168,7 +166,7 @@ public abstract class AbstractT3InputMSAccess implements T3Input { T3EntityEnum constant = T3EntityEnum.valueOf(Trip.class); T3AccessEntityMeta meta = dataSource.getMeta(constant); List<Trip> entities = dataSource.loadEntities(meta); - Map<Trip, T3EntityMap> result = Maps.newLinkedHashMap(); + Map<Trip, T3EntityMap> result = new LinkedHashMap<>(); missingFK = new HashMap<>(); T3DataEntityVisitor dataVisitor = newDataVisitor(dataSource, safeReferences); try { @@ -242,7 +240,29 @@ public abstract class AbstractT3InputMSAccess implements T3Input { // remove proxy on data Trip loadedTrip = visitor.doVisit(trip); // set tripType flag - loadedTrip.setTripType(tripType); + T3AccessEntity a = (T3AccessEntity) trip; + int logBookAvailability = loadedTrip.getLogBookAvailability(); + Object[] pKey = a.getPKey(); + switch (tripType) { + case STANDARD: + TripTopiaDao.checkStandardTrip(loadedTrip, pKey); + loadedTrip.setTripType(TripType.STANDARD); + break; + case SAMPLEONLY: + // no check + loadedTrip.setTripType(TripType.SAMPLEONLY); + break; + case LOGBOOKMISSING: + if (TripType.LOGBOOKMISSING == loadedTrip.getTripType()) { + // That trip was marked to be without logbook, check that + TripTopiaDao.checkLogbookMissingTrip(loadedTrip, pKey); + } else { + // standard trip, just check logBookAvailability value is correct + TripTopiaDao.checkStandardTrip(loadedTrip, pKey); + loadedTrip.setTripType(TripType.STANDARD); + } + break; + } if (trip.getVessel() == null && canCreateVessel) { // use new created vessel Vessel vessel = getNewVessels().get(vesselCode); ===================================== t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AccessDataSource.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AccessDataSource.java +++ b/t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AccessDataSource.java @@ -22,7 +22,6 @@ package fr.ird.t3.io.input.access; import fr.ird.msaccess.importer.AbstractAccessDataSource; import fr.ird.t3.entities.T3EntityEnum; -import fr.ird.t3.entities.data.TripType; import fr.ird.t3.entities.reference.T3ReferenceEntity; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -99,10 +98,6 @@ public class T3AccessDataSource extends AbstractAccessDataSource<T3EntityEnum, T } public void analyzeDb(T3AccessHitModel hits) throws Exception { - analyzeDb(null, hits); - } - - public void analyzeDb(TripType tripType, T3AccessHitModel hits) throws Exception { // always init the data source init(); Set<String> tables = getTableNames(); ===================================== t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AvdthDataEntityVisitor.java ===================================== --- a/t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AvdthDataEntityVisitor.java +++ b/t3-domain/src/main/java/fr/ird/t3/io/input/access/T3AvdthDataEntityVisitor.java @@ -78,6 +78,7 @@ public abstract class T3AvdthDataEntityVisitor extends T3DataEntityVisitor { activity.setSchoolType(Objects.requireNonNull(sampleSet.getActivitySchoolType())); sampleSet.setActivity(endActivity(activity)); parent.addActivity(activity); + parent.setTripType(TripType.LOGBOOKMISSING); } }; } else { ===================================== 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 @@ -20,7 +20,6 @@ */ package fr.ird.t3.entities.reference; -import com.google.common.collect.Maps; import fr.ird.t3.entities.AbstractDatabaseTest; import fr.ird.t3.entities.T3TopiaPersistenceContext; import org.junit.Assert; @@ -28,6 +27,7 @@ import org.junit.Test; import java.util.ArrayList; import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -154,7 +154,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { catUnbound.setMax(null); Map<WeightCategoryTreatment, Integer> weightCategories = - Maps.newLinkedHashMap(); + new LinkedHashMap<>(); weightCategories.put(catBound, 20); weightCategories.put(catUnbound, Integer.MAX_VALUE); @@ -208,7 +208,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { catUnbound.setMax(null); Map<WeightCategoryTreatment, Integer> weightCategories = - Maps.newLinkedHashMap(); + new LinkedHashMap<>(); weightCategories.put(catBound, 20); weightCategories.put(catBound2, 40); ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/T3ActionSupport.java @@ -21,7 +21,6 @@ package fr.ird.t3.web.actions; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; @@ -63,6 +62,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -261,7 +261,7 @@ public class T3ActionSupport extends ActionSupport implements T3TopiaPersistence } protected Map<String, String> createTimeSteps() { - Map<String, String> timeSteps = Maps.newLinkedHashMap(); + Map<String, String> timeSteps = new LinkedHashMap<>(); for (int i = 1; i < 13; i++) { timeSteps.put("" + i, "" + i); } ===================================== 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 @@ -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.web.actions.io.output; -import com.google.common.collect.Maps; import fr.ird.t3.actions.io.output.ExportConfiguration; import fr.ird.t3.entities.T3EntityHelper; import fr.ird.t3.entities.data.Trip; @@ -49,6 +48,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -116,14 +116,13 @@ public class ExportConfigureAction extends AbstractConfigureAction<ExportConfigu // make sur configuration is inited before all getConfiguration(); - operations = Maps.newLinkedHashMap(); + operations = new LinkedHashMap<>(); - for (T3OutputOperation operation : - getT3OutputService().getOperations(configuration.getOutputProviderId())) { + for (T3OutputOperation operation : getT3OutputService().getOperations(configuration.getOutputProviderId())) { operations.put(operation.getId(), operation.getLibelle(getLocale())); } - // inject everything needed (daos, ...) + // inject everything needed (dao, ...) injectExcept(InjectDecoratedBeans.class); boolean configurationInSession = isConfigurationInSession(); ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/json/GetOutputProviderOperationsAction.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetOutputProviderOperationsAction.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetOutputProviderOperationsAction.java @@ -8,24 +8,24 @@ * 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.web.actions.json; -import com.google.common.collect.Maps; import fr.ird.t3.io.output.T3OutputOperation; import fr.ird.t3.web.actions.T3ActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.LinkedHashMap; import java.util.Map; @@ -39,13 +39,10 @@ public class GetOutputProviderOperationsAction extends T3ActionSupport { private static final long serialVersionUID = 1L; - /** Logger. */ - private static final Log log = - LogFactory.getLog(GetOutputProviderOperationsAction.class); + private static final Log log = LogFactory.getLog(GetOutputProviderOperationsAction.class); - protected String outputProviderId; - - protected Map<String, String> operations; + private String outputProviderId; + private Map<String, String> operations; public void setOutputProviderId(String outputProviderId) { this.outputProviderId = outputProviderId; @@ -57,18 +54,11 @@ public class GetOutputProviderOperationsAction extends T3ActionSupport { @Override public String execute() { - - if (log.isInfoEnabled()) { - log.info("outputProviderId = " + outputProviderId); - } - - operations = Maps.newLinkedHashMap(); - - for (T3OutputOperation operation : - getT3OutputService().getOperations(outputProviderId)) { + log.info(String.format("outputProviderId = %s", outputProviderId)); + operations = new LinkedHashMap<>(); + for (T3OutputOperation operation : getT3OutputService().getOperations(outputProviderId)) { operations.put(operation.getId(), operation.getLibelle(getLocale())); } - return SUCCESS; } } ===================================== t3-web/src/main/java/fr/ird/t3/web/actions/json/GetZoneVersionsAction.java ===================================== --- a/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetZoneVersionsAction.java +++ b/t3-web/src/main/java/fr/ird/t3/web/actions/json/GetZoneVersionsAction.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.web.actions.json; -import com.google.common.collect.Maps; import fr.ird.t3.entities.reference.zone.ZoneStratumAwareMeta; import fr.ird.t3.entities.reference.zone.ZoneVersion; import fr.ird.t3.web.actions.T3ActionSupport; @@ -28,6 +27,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -41,14 +41,11 @@ public class GetZoneVersionsAction extends T3ActionSupport { private static final long serialVersionUID = 1L; - /** Logger. */ - private static final Log log = - LogFactory.getLog(GetZoneVersionsAction.class); + private static final Log log = LogFactory.getLog(GetZoneVersionsAction.class); /** Selected zoneTypeId. */ - protected String zoneTypeId; - - protected Map<String, String> zoneVersions; + private String zoneTypeId; + private Map<String, String> zoneVersions; public void setZoneTypeId(String zoneTypeId) { this.zoneTypeId = zoneTypeId; @@ -60,23 +57,12 @@ public class GetZoneVersionsAction extends T3ActionSupport { @Override public String execute() { - - if (log.isInfoEnabled()) { - log.info("zoneTypeId = " + zoneTypeId); - } - - zoneVersions = Maps.newLinkedHashMap(); - + log.info(String.format("zoneTypeId = %s", zoneTypeId)); + zoneVersions = new LinkedHashMap<>(); if (!StringUtils.isEmpty(zoneTypeId)) { - - ZoneStratumAwareMeta zoneType = - getZoneStratumService().getZoneMetaById(zoneTypeId); - - List<ZoneVersion> allVersions = - zoneType.getAllZoneVersions(getT3TopiaPersistenceContext().get()); - + ZoneStratumAwareMeta zoneType = getZoneStratumService().getZoneMetaById(zoneTypeId); + List<ZoneVersion> allVersions = zoneType.getAllZoneVersions(getT3TopiaPersistenceContext().get()); zoneVersions = sortAndDecorateIdAbles(allVersions); - } return SUCCESS; } ===================================== t3-web/src/main/resources/i18n/t3-web_en_GB.properties ===================================== --- a/t3-web/src/main/resources/i18n/t3-web_en_GB.properties +++ b/t3-web/src/main/resources/i18n/t3-web_en_GB.properties @@ -267,7 +267,7 @@ t3.label.data.level3.configuration.samplesToUse=Treatment to apply to catches wi t3.label.data.level3.configuration.step1=Level 3 configuration step 1 t3.label.data.level3.configuration.step2=Level 3 configuration step 2 t3.label.data.level3.configuration.useAllSamples=Keep their own sample (do nothing) -t3.label.data.level3.configuration.useCatchSamples=Apply length structures from the sample statrum +t3.label.data.level3.configuration.useCatchSamples=Apply length structures from the sample stratum t3.label.data.level3.configuration.useWeightCategories=Use weight categories t3.label.data.level3.configuration.useWeightCategoriesOrNot=Extrapolation method t3.label.data.treatment.level0=Level 0 treatment View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/70318fcc05b803dca6f92b7b2361af599... --- View it on GitLab: https://gitlab.com/ultreiaio/ird-t3/commit/70318fcc05b803dca6f92b7b2361af599... You're receiving this email because of your account on gitlab.com.