Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe Commits: 34f5d1f4 by Tony Chemit at 2020-05-10T23:36:39+02:00 Comportement sidérant d'H2 - Closes #1463 - - - - - 16 changed files: - dto/src/main/java/fr/ird/observe/dto/decoration/DecoratorService.java - observe-i18n/src/main/i18n/translations/observe_en_GB.properties - observe-i18n/src/main/i18n/translations/observe_es_ES.properties - observe-i18n/src/main/i18n/translations/observe_fr_FR.properties - + persistence/.mvn/i18n/parse-java - persistence/pom.xml - + persistence/src/main/i18n/getters/java.getter - persistence/src/main/java/fr/ird/observe/entities/referential/DuplicateLengthLengthParameterException.java - persistence/src/main/java/fr/ird/observe/entities/referential/DuplicateLengthWeightParameterException.java - persistence/src/main/java/fr/ird/observe/entities/referential/LengthLengthParameterNotFoundException.java - persistence/src/main/java/fr/ird/observe/entities/referential/LengthWeightParameterNotFoundException.java - persistence/src/main/java/fr/ird/observe/entities/referential/common/LengthLengthParameters.java - persistence/src/main/java/fr/ird/observe/entities/referential/common/LengthWeightParameters.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java - services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidationActivitySeineDataContext.java - services-local/src/test/java/fr/ird/observe/services/local/entity/LengthWeightParemetersTest.java Changes: ===================================== dto/src/main/java/fr/ird/observe/dto/decoration/DecoratorService.java ===================================== @@ -23,6 +23,7 @@ package fr.ird.observe.dto.decoration; */ import fr.ird.observe.dto.DtoToReference; +import fr.ird.observe.dto.reference.DataDtoReference; import fr.ird.observe.dto.reference.ReferentialDtoReference; import fr.ird.observe.dto.referential.ReferentialDto; import fr.ird.observe.spi.DtoModelHelper; @@ -67,4 +68,17 @@ public class DecoratorService extends DecoratorServiceSupport<DecoratorServiceIn protected void init(DecoratorServiceInitializer initializer) { ObserveGlobalModelInitializer.run(initializer); } + + public String toString(Object o) { + if (o==null) { + return null; + } + if (o instanceof ReferentialDtoReference) { + return getReferentialReferenceDecorator(((ReferentialDtoReference<?,?>) o).getReferenceType()).toString(o); + } + if (o instanceof DataDtoReference) { + return getDataReferenceDecorator(((DataDtoReference<?,?>) o).getReferenceType()).toString(o); + } + return getDecoratorByType(o.getClass()).toString(o); + } } ===================================== observe-i18n/src/main/i18n/translations/observe_en_GB.properties ===================================== @@ -2293,6 +2293,10 @@ observe.data.ps.observation.TransmittingBuoy.types=Transmitting buoys observe.entity.message.creating=Creating object '%1$s'. observe.entity.message.reading=Object '%1$s' is not open, no modification allowed. observe.entity.message.updating=Updating object '%1$s'. +observe.error.DuplicateLengthLengthParameterException=Found multiple length length relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s +observe.error.DuplicateLengthWeightParameterException=Found multiple length weight paramters for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s +observe.error.LengthLengthParameterNotFoundException=No length length relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s +observe.error.LengthWeightParameterNotFoundException=No length weight relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s observe.error.can.not.create.directory=Can't create directory %&$s\! observe.error.storage.could.not.backup.unsane.local.db=Can not save an borken database observe.error.storage.could.not.load.local.db=Could not open local database for reason\: %s ===================================== observe-i18n/src/main/i18n/translations/observe_es_ES.properties ===================================== @@ -2293,6 +2293,10 @@ observe.data.ps.observation.TransmittingBuoy.types=Balizas leidas observe.entity.message.creating=Se está crear el objeto actual '%1$s'. observe.entity.message.reading=Object '%1$s' is not open, no modification allowed. observe.entity.message.updating=Se está modificando el objeto actual '%1$s'. +observe.error.DuplicateLengthLengthParameterException=Found multiple length length relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s \#TODO +observe.error.DuplicateLengthWeightParameterException=Found multiple length weight relation for species\: %s, ocean\: %s, sex\: %s, date\: %s \:\n * %s \#TODO +observe.error.LengthLengthParameterNotFoundException=No length length relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s \#TODO +observe.error.LengthWeightParameterNotFoundException=No length weight relation found for species\: %s, ocean\: %s, sex\: %s, date\: %s \: %s \#TODO observe.error.can.not.create.directory=¡Imposible crear el directorio %1$s\! observe.error.storage.could.not.backup.unsane.local.db=Impossible grabar una base dañada observe.error.storage.could.not.load.local.db=Impossible grabar la base local por la razón siguiente \: %s ===================================== observe-i18n/src/main/i18n/translations/observe_fr_FR.properties ===================================== @@ -2293,6 +2293,10 @@ observe.data.ps.observation.TransmittingBuoy.types=Balises lues observe.entity.message.creating=L'objet '%1$s' est en cours de création. observe.entity.message.reading=L'objet '%1$s' n'est pas ouvert, aucune modification possible. observe.entity.message.updating=L'objet '%1$s' est en cours de modification. +observe.error.DuplicateLengthLengthParameterException=Plusieurs relations taille-taille ont été trouvées pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s \:\n * %s +observe.error.DuplicateLengthWeightParameterException=Plusieurs relations taille-poids ont été trouvées pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s \:\n * %s +observe.error.LengthLengthParameterNotFoundException=Aucune relation taille-taille trouvée pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s +observe.error.LengthWeightParameterNotFoundException=Aucune relation taille-poids trouvée pour l'espèce\: %s, l'ocean\: %s, le sexe\: %s et la date\: %s observe.error.can.not.create.directory=Création du répertoire %1$s impossible\! observe.error.storage.could.not.backup.unsane.local.db=Impossible d'enregistrer une base non endommagée observe.error.storage.could.not.load.local.db=Impossible d'ouvrir la base locale pour la raison suivante \: %s ===================================== persistence/.mvn/i18n/parse-java ===================================== ===================================== persistence/pom.xml ===================================== @@ -97,7 +97,10 @@ <artifactId>nuiton-csv</artifactId> <scope>test</scope> </dependency> - + <dependency> + <groupId>io.ultreia.java4all.i18n</groupId> + <artifactId>i18n-runtime</artifactId> + </dependency> <dependency> <groupId>io.ultreia.java4all.http</groupId> <artifactId>http-api</artifactId> ===================================== persistence/src/main/i18n/getters/java.getter ===================================== @@ -0,0 +1,3 @@ +observe.error.DuplicateLengthWeightParameterException +observe.error.LengthLengthParameterNotFoundException +observe.error.LengthWeightParameterNotFoundException ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/DuplicateLengthLengthParameterException.java ===================================== @@ -22,13 +22,21 @@ package fr.ird.observe.entities.referential; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.referential.ReferentialLocale; +import fr.ird.observe.dto.referential.common.LengthLengthParameterDto; +import fr.ird.observe.dto.referential.common.LengthLengthParameterReference; import fr.ird.observe.entities.referential.common.LengthLengthParameter; import fr.ird.observe.entities.referential.common.Ocean; import fr.ird.observe.entities.referential.common.Sex; import fr.ird.observe.entities.referential.common.Species; +import fr.ird.observe.spi.DbModelHelper; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 28/08/15. @@ -49,7 +57,8 @@ public class DuplicateLengthLengthParameterException extends RuntimeException { protected final List<LengthLengthParameter> foundLengthLengthParameters; - public DuplicateLengthLengthParameterException(Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + public DuplicateLengthLengthParameterException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + super(buildMessage(decoratorService, species, ocean, sex, date, foundLengthLengthParameters)); this.species = species; this.ocean = ocean; this.sex = sex; @@ -57,6 +66,18 @@ public class DuplicateLengthLengthParameterException extends RuntimeException { this.foundLengthLengthParameters = foundLengthLengthParameters; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthLengthParameter> foundLengthLengthParameters) { + ReferentialLocale referentialLocale = decoratorService.getReferentialLocale(); + return t("observe.error.DuplicateLengthWeightParameterException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date, + foundLengthLengthParameters.stream().map(e -> e.toReference(referentialLocale)).map(decoratorService::toString).collect(Collectors.joining("\n * ")) + ); + } + + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/DuplicateLengthWeightParameterException.java ===================================== @@ -22,13 +22,21 @@ package fr.ird.observe.entities.referential; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.referential.ReferentialLocale; +import fr.ird.observe.dto.referential.common.LengthWeightParameterDto; +import fr.ird.observe.dto.referential.common.LengthWeightParameterReference; import fr.ird.observe.entities.referential.common.LengthWeightParameter; import fr.ird.observe.entities.referential.common.Ocean; import fr.ird.observe.entities.referential.common.Sex; import fr.ird.observe.entities.referential.common.Species; +import fr.ird.observe.spi.DbModelHelper; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; + +import static io.ultreia.java4all.i18n.I18n.t; /** * Created on 28/08/15. @@ -49,7 +57,8 @@ public class DuplicateLengthWeightParameterException extends RuntimeException { protected final List<LengthWeightParameter> foundLengthWeightParameters; - public DuplicateLengthWeightParameterException(Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + public DuplicateLengthWeightParameterException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + super(buildMessage(decoratorService, species, ocean, sex, date, foundLengthWeightParameters)); this.species = species; this.ocean = ocean; this.sex = sex; @@ -57,6 +66,17 @@ public class DuplicateLengthWeightParameterException extends RuntimeException { this.foundLengthWeightParameters = foundLengthWeightParameters; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date, List<LengthWeightParameter> foundLengthWeightParameters) { + ReferentialLocale referentialLocale = decoratorService.getReferentialLocale(); + return t("observe.error.DuplicateLengthWeightParameterException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date, + foundLengthWeightParameters.stream().map(e -> e.toReference(referentialLocale)).map(decoratorService::toString).collect(Collectors.joining("\n * ")) + ); + } + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/LengthLengthParameterNotFoundException.java ===================================== @@ -22,12 +22,16 @@ package fr.ird.observe.entities.referential; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.entities.referential.common.Ocean; import fr.ird.observe.entities.referential.common.Sex; import fr.ird.observe.entities.referential.common.Species; +import fr.ird.observe.spi.DbModelHelper; import java.util.Date; +import static io.ultreia.java4all.i18n.I18n.t; + /** * Created on 29/08/15. * @@ -45,13 +49,23 @@ public class LengthLengthParameterNotFoundException extends RuntimeException { protected final Date date; - public LengthLengthParameterNotFoundException(Species species, Ocean ocean, Sex sex, Date date) { + public LengthLengthParameterNotFoundException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + super(buildMessage(decoratorService, species, ocean, sex, date)); this.species = species; this.ocean = ocean; this.sex = sex; this.date = date; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + + return t("observe.error.LengthLengthParameterNotFoundException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date); + } + public Species getSpecies() { return species; } @@ -68,4 +82,11 @@ public class LengthLengthParameterNotFoundException extends RuntimeException { return date; } + + static <E extends ReferentialEntity<?, ?>> String toString(DecoratorService decoratorService, E entity) { + if (entity == null) { + return null; + } + return decoratorService.toString(entity.toReference(decoratorService.getReferentialLocale())); + } } ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/LengthWeightParameterNotFoundException.java ===================================== @@ -22,12 +22,16 @@ package fr.ird.observe.entities.referential; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.entities.referential.LengthLengthParameterNotFoundException; import fr.ird.observe.entities.referential.common.Ocean; import fr.ird.observe.entities.referential.common.Sex; import fr.ird.observe.entities.referential.common.Species; import java.util.Date; +import static io.ultreia.java4all.i18n.I18n.t; + /** * Created on 29/08/15. * @@ -45,13 +49,23 @@ public class LengthWeightParameterNotFoundException extends RuntimeException { protected final Date date; - public LengthWeightParameterNotFoundException(Species species, Ocean ocean, Sex sex, Date date) { + public LengthWeightParameterNotFoundException(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + super(buildMessage(decoratorService, species, ocean, sex, date)); this.species = species; this.ocean = ocean; this.sex = sex; this.date = date; } + private static String buildMessage(DecoratorService decoratorService, Species species, Ocean ocean, Sex sex, Date date) { + + return t("observe.error.LengthWeightParameterNotFoundException", + LengthLengthParameterNotFoundException.toString(decoratorService, species), + LengthLengthParameterNotFoundException.toString(decoratorService, ocean), + LengthLengthParameterNotFoundException.toString(decoratorService, sex), + date); + } + public Species getSpecies() { return species; } ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/common/LengthLengthParameters.java ===================================== @@ -22,6 +22,7 @@ package fr.ird.observe.entities.referential.common; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.entities.referential.DuplicateLengthLengthParameterException; import fr.ird.observe.entities.referential.LengthLengthParameterNotFoundException; import fr.ird.observe.entities.ObserveTopiaDaoSupplier; @@ -50,6 +51,7 @@ public class LengthLengthParameters { * <p> * Si non trouvé sur le sexe (et que le sexe n'est pas indéterminé) , alors on recherche avec le sexe indéterminé (sexe=0). * + * @param decoratorService le service de décoration * @param daoSupplier la transaction en cours d'utilisation * @param species l'espèce sur lequel on recherche le paramétrage * @param ocean l'ocean recherché (peut être null) @@ -60,7 +62,8 @@ public class LengthLengthParameters { * @return le paramétrage adéquate * @since 1.5 */ - public static Optional<LengthLengthParameter> findLengthLengthParameter(ObserveTopiaDaoSupplier daoSupplier, + public static Optional<LengthLengthParameter> findLengthLengthParameter(DecoratorService decoratorService, + ObserveTopiaDaoSupplier daoSupplier, Species species, Ocean ocean, Sex sex, @@ -85,7 +88,7 @@ public class LengthLengthParameters { } if (CollectionUtils.isEmpty(list)) { - throw new LengthLengthParameterNotFoundException(species, ocean, sex, date); + throw new LengthLengthParameterNotFoundException(decoratorService, species, ocean, sex, date); } // if (inputSizeMeasureType != null) { @@ -116,192 +119,14 @@ public class LengthLengthParameters { // au final il ne devrait en rester qu'un if (list.size() > 1) { - throw new DuplicateLengthLengthParameterException(species, ocean, sex, date, list); + throw new DuplicateLengthLengthParameterException(decoratorService, species, ocean, sex, date, list); } return Optional.of(list.get(0)); } -// -// /** -// * Recherche de la liste des {@link LengthLengthParameter} à partir des paramètres donnés. -// * <p> -// * La recherche peut ne peut être aussi exacte que les paramètres donnés : -// * <p> -// * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son -// * speciesGroup d'espèce. -// * <p> -// * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on -// * recherche avec un ocean vide. -// * -// * @param daoSupplier la transaction en cours d'utilisation -// * @param species l'espèce sur lequel on recherche le paramétrage -// * @param ocean l'ocean recherché (peut être null) -// * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) -// * @param date le jour recherché -// * @return le paramétrage adéquate -// * @since 1.5 -// */ -// public static List<LengthLengthParameter> findLengthLengthParameter0(ObserveTopiaDaoSupplier daoSupplier, -// Species species, -// Ocean ocean, -// Sex sex, -// Date date) { -// -// Objects.requireNonNull(daoSupplier, "daoSupplier parameter can't be null"); -// Objects.requireNonNull(species, "species parameter can't be null"); -// Objects.requireNonNull(sex, "sex parameter can't be null"); -// -// List<LengthLengthParameter> list = findBySpecies(daoSupplier, species); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // aucun parametrage pour le type donne -// return null; -// } -// -// // filtrage par ocean -// List<LengthLengthParameter> filterByOcean = filterByOcean(list, ocean); -// -// if (CollectionUtils.isEmpty(filterByOcean) && ocean != null) { -// -// // filtre par ocean null -// filterByOcean = filterByOcean(list, null); -// } -// list = filterByOcean; -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas d'ocean adequate -// return null; -// } -// -// // filtrage par sexe -// list = filterBySexe(list, sex); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de sexe adequate -// return null; -// } -// -// // filtrage par startDate de validite -// list = filterByDateDebutValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de debut adequate -// return null; -// } -// -// // filtrage par endDate de validite -// list = filterByDateFinValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de fin adequate -// return null; -// } -// -// return list; -// -// } private static Sex getUnknownSex(ObserveTopiaDaoSupplier daoSupplier) { return daoSupplier.getCommonSexDao().forCodeEquals("0").findUnique(); } - -// public static List<LengthLengthParameter> findBySpecies(ObserveTopiaDaoSupplier daoSupplier, Species species) { -// -// LengthLengthParameterTopiaDao dao = daoSupplier.getCommonLengthLengthParameterDao(); -// -// List<LengthLengthParameter> list = dao.forSpeciesEquals(species).findAll(); -// -// // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null -// Iterator<LengthLengthParameter> itr = list.iterator(); -// while (itr.hasNext()) { -// LengthLengthParameter p = itr.next(); -// Double a = p.getCoefficientValue(FormulaHelper.COEFFICIENT_A); -// if (a == null || a == 0) { -// itr.remove(); -// continue; -// } -// -// Double b = p.getCoefficientValue(FormulaHelper.COEFFICIENT_B); -// // on autorise d'avoir b à 0 (mais cela ne permet plus de calculer la taille à partir du poids) -//// if (b == null || b == 0) { -// if (b == null) { -// itr.remove(); -// } -// } -// return list; -// -// } - -// public static List<LengthLengthParameter> filterByOcean(List<LengthLengthParameter> list, Ocean ocean) { -// List<LengthLengthParameter> result = new ArrayList<>(); -// if (ocean == null) { -// -// // on n'accepte que les parametrage sans ocean -// for (LengthLengthParameter parametrageLengthWeight : list) { -// if (parametrageLengthWeight.getOcean() == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// for (LengthLengthParameter parametrageLengthWeight : list) { -// if (ocean.equals(parametrageLengthWeight.getOcean())) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } -// -// public static List<LengthLengthParameter> filterBySexe(List<LengthLengthParameter> list, Sex sex) { -// return list.stream().filter(l -> l.getSex() == sex).collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByInputSizeMeasureType(List<LengthLengthParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getInputSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -//public static List<LengthLengthParameter> filterByOutputSizeMeasureType(List<LengthLengthParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getOutputSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByDateDebutValidite(List<LengthLengthParameter> list, Date startDate) { -// return list.stream() -// .filter(l -> l.getStartDate() == null || l.getStartDate().before(startDate) || l.getStartDate().equals(startDate)) -// .collect(Collectors.toList()); -// } -// -// public static List<LengthLengthParameter> filterByDateFinValidite(List<LengthLengthParameter> list, Date endDate) { -// List<LengthLengthParameter> result = new ArrayList<>(); -// -// if (endDate == null) { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// for (LengthLengthParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// // - ceux dont la date de fin est avant la date de fin donnée -// for (LengthLengthParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null || -// date.after(endDate) || -// date.equals(endDate)) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } } ===================================== persistence/src/main/java/fr/ird/observe/entities/referential/common/LengthWeightParameters.java ===================================== @@ -22,6 +22,7 @@ package fr.ird.observe.entities.referential.common; * #L% */ +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.entities.referential.DuplicateLengthWeightParameterException; import fr.ird.observe.entities.referential.LengthWeightParameterNotFoundException; import fr.ird.observe.entities.ObserveTopiaDaoSupplier; @@ -49,16 +50,18 @@ public class LengthWeightParameters { * <p> * Si non trouvé sur le sexe (et que le sexe n'est pas indéterminé) , alors on recherche avec le sexe indéterminé (sexe=0). * - * @param daoSupplier la transaction en cours d'utilisation - * @param species l'espèce sur lequel on recherche le paramétrage - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param ocean l'ocean recherché (peut être null) - * @param date le jour recherché - * @param sizeMeasureType le type de mensuration recherché + * @param decoratorService le service de décoration + * @param daoSupplier la transaction en cours d'utilisation + * @param species l'espèce sur lequel on recherche le paramétrage + * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) + * @param ocean l'ocean recherché (peut être null) + * @param date le jour recherché + * @param sizeMeasureType le type de mensuration recherché * @return le paramétrage adéquate * @since 1.5 */ - public static LengthWeightParameter findLengthWeightParameter(ObserveTopiaDaoSupplier daoSupplier, + public static LengthWeightParameter findLengthWeightParameter(DecoratorService decoratorService, + ObserveTopiaDaoSupplier daoSupplier, Species species, Sex sex, Ocean ocean, Date date, SizeMeasureType sizeMeasureType) { // Sex unknownSex = getUnknownSex(daoSupplier); @@ -79,7 +82,7 @@ public class LengthWeightParameters { // } if (CollectionUtils.isEmpty(list)) { - throw new LengthWeightParameterNotFoundException(species, ocean, sex, date); + throw new LengthWeightParameterNotFoundException(decoratorService, species, ocean, sex, date); } // if (sizeMeasureType != null) { @@ -98,190 +101,11 @@ public class LengthWeightParameters { // au final il ne devrait en rester qu'un if (list.size() > 1) { - throw new DuplicateLengthWeightParameterException(species, ocean, sex, date, list); + throw new DuplicateLengthWeightParameterException(decoratorService, species, ocean, sex, date, list); } return Objects.requireNonNull(list.get(0)); } -// /** -// * Recherche de la liste des {@link LengthWeightParameter} à partir des paramètres donnés. -// * <p> -// * La recherche peut ne peut être aussi exacte que les paramètres donnés : -// * <p> -// * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son -// * speciesGroup d'espèce. -// * <p> -// * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on -// * recherche avec un ocean vide. -// * -// * @param daoSupplier la transaction en cours d'utilisation -// * @param species l'espèce sur lequel on recherche le paramétrage -// * @param ocean l'ocean recherché (peut être null) -// * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) -// * @param date le jour recherché -// * @return le paramétrage adéquate -// * @since 1.5 -// */ -// public static List<LengthWeightParameter> findLengthWeightParameter0(ObserveTopiaDaoSupplier daoSupplier, -// Species species, -// Ocean ocean, -// Sex sex, -// Date date) { -// -// Objects.requireNonNull(daoSupplier, "daoSupplier parameter can't be null"); -// Objects.requireNonNull(species, "species parameter can't be null"); -// Objects.requireNonNull(sex, "sex parameter can't be null"); -// -// List<LengthWeightParameter> list = findBySpecies(daoSupplier, species); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // aucun parametrage pour le type donne -// return null; -// } -// -// // filtrage par ocean -// List<LengthWeightParameter> filterByOcean = filterByOcean(list, ocean); -// -// if (CollectionUtils.isEmpty(filterByOcean) && ocean != null) { -// -// // filtre par ocean null -// filterByOcean = filterByOcean(list, null); -// } -// list = filterByOcean; -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas d'ocean adequate -// return null; -// } -// -// // filtrage par sexe -// list = filterBySexe(list, sex); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de sexe adequate -// return null; -// } -// -// // filtrage par startDate de validite -// list = filterByDateDebutValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de debut adequate -// return null; -// } -// -// // filtrage par endDate de validite -// list = filterByDateFinValidite(list, date); -// -// if (CollectionUtils.isEmpty(list)) { -// -// // pas de date de fin adequate -// return null; -// } -// -// return list; -// -// } - -// private static Sex getUnknownSex(ObserveTopiaDaoSupplier daoSupplier) { -// return daoSupplier.getCommonSexDao().forCodeEquals("0").findUnique(); -// } - -// public static List<LengthWeightParameter> findBySpecies(ObserveTopiaDaoSupplier daoSupplier, Species species) { -// -// LengthWeightParameterTopiaDao dao = daoSupplier.getCommonLengthWeightParameterDao(); -// -// List<LengthWeightParameter> list = dao.forSpeciesEquals(species).findAll(); -// -// // on supprime les paramétrages qui ont a=0 ou a=null ou b=0 ou b = null -// Iterator<LengthWeightParameter> itr = list.iterator(); -// while (itr.hasNext()) { -// LengthWeightParameter p = itr.next(); -// Double a = p.getCoefficientValue(FormulaHelper.COEFFICIENT_A); -// if (a == null || a == 0) { -// itr.remove(); -// continue; -// } -// -// Double b = p.getCoefficientValue(FormulaHelper.COEFFICIENT_B); -// // on autorise d'avoir b à 0 (mais cela ne permet plus de calculer la taille à partir du poids) -//// if (b == null || b == 0) { -// if (b == null) { -// itr.remove(); -// } -// } -// return list; -// -// } -// -// public static List<LengthWeightParameter> filterByOcean(List<LengthWeightParameter> list, Ocean ocean) { -// List<LengthWeightParameter> result = new ArrayList<>(); -// if (ocean == null) { -// -// // on n'accepte que les parametrage sans ocean -// for (LengthWeightParameter parametrageLengthWeight : list) { -// if (parametrageLengthWeight.getOcean() == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// for (LengthWeightParameter parametrageLengthWeight : list) { -// if (ocean.equals(parametrageLengthWeight.getOcean())) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } -// -// public static List<LengthWeightParameter> filterBySexe(List<LengthWeightParameter> list, Sex sex) { -// return list.stream().filter(l -> l.getSex() == sex).collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterBySizeMeasureType(List<LengthWeightParameter> list, SizeMeasureType sizeMeasureType) { -// return list.stream().filter(l -> l.getSizeMeasureType() == sizeMeasureType).collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterByDateDebutValidite(List<LengthWeightParameter> list, Date startDate) { -// return list.stream() -// .filter(l -> l.getStartDate() == null || l.getStartDate().before(startDate) || l.getStartDate().equals(startDate)) -// .collect(Collectors.toList()); -// } -// -// public static List<LengthWeightParameter> filterByDateFinValidite(List<LengthWeightParameter> list, Date endDate) { -// List<LengthWeightParameter> result = new ArrayList<>(); -// -// if (endDate == null) { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// for (LengthWeightParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null) { -// result.add(parametrageLengthWeight); -// } -// } -// } else { -// // on n'accepte que les parametrages selon les critères suivants : -// // - sans date de fin (i.e en cours de validite) -// // - ceux dont la date de fin est avant la date de fin donnée -// for (LengthWeightParameter parametrageLengthWeight : list) { -// -// Date date = parametrageLengthWeight.getEndDate(); -// if (date == null || -// date.after(endDate) || -// date.equals(endDate)) { -// result.add(parametrageLengthWeight); -// } -// } -// } -// return result; -// } - } ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidateDataServiceLocal.java ===================================== @@ -27,6 +27,8 @@ import com.google.common.collect.ImmutableSet; import fr.ird.observe.dto.data.ps.NonTargetCatchComputedValueSource; import fr.ird.observe.dto.data.ps.observation.FloatingObjectDto; import fr.ird.observe.dto.data.ps.observation.FloatingObjectPartDto; +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.decoration.DecoratorServiceApplicationComponent; import fr.ird.observe.dto.referential.I18nReferentialHelper; import fr.ird.observe.dto.referential.ReferentialLocale; import fr.ird.observe.entities.EntityHelper; @@ -152,8 +154,8 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements SimplifiedObjectTypeManager simplifiedObjectTypeManager = newSimplifiedObjectTypeManager(simplifiedObjectTypeSpecializedRules); FloatingObjectConsolidateEngine floatingObjectConsolidateEngine = new FloatingObjectConsolidateEngine(simplifiedObjectTypeManager); - - Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(referenceLocale, floatingObjectConsolidateEngine, request.getTripSeineId(), failIfLengthWeightParameterNotFound, failIfLengthLengthParameterNotFound); + DecoratorService decoratorService = DecoratorServiceApplicationComponent.value(); + Optional<ConsolidateTripSeineDataResult> consolidateTripSeineDataResult = consolidateTripSeine(decoratorService,referenceLocale, floatingObjectConsolidateEngine, request.getTripSeineId(), failIfLengthWeightParameterNotFound, failIfLengthLengthParameterNotFound); return consolidateTripSeineDataResult.orElse(null); } @@ -174,7 +176,7 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements return new SimplifiedObjectTypeManager(materialMapping, simplifiedObjectTypeSpecializedRules); } - private Optional<ConsolidateTripSeineDataResult> consolidateTripSeine(ReferentialLocale referenceLocale, FloatingObjectConsolidateEngine floatingObjectConsolidateEngine, String tripSeineId, boolean failIfLengthWeightParameterNotFound, boolean failIfLengthLengthParameterNotFound) { + private Optional<ConsolidateTripSeineDataResult> consolidateTripSeine(DecoratorService decoratorService, ReferentialLocale referenceLocale, FloatingObjectConsolidateEngine floatingObjectConsolidateEngine, String tripSeineId, boolean failIfLengthWeightParameterNotFound, boolean failIfLengthLengthParameterNotFound) { log.info(String.format("Start consolidate trip: %s", tripSeineId)); @@ -235,6 +237,7 @@ public class ConsolidateDataServiceLocal extends ObserveServiceLocal implements ConsolidationActivitySeineDataContext activityContext = new ConsolidationActivitySeineDataContext(); activityContext.locale = applicationLocale; + activityContext.decoratorService = decoratorService; activityContext.failIfLengthWeightParameterNotFound = failIfLengthWeightParameterNotFound; activityContext.failIfLengthLengthParameterNotFound = failIfLengthLengthParameterNotFound; activityContext.daoSupplier = persistenceContext; ===================================== services-local/src/main/java/fr/ird/observe/services/local/service/actions/consolidate/ConsolidationActivitySeineDataContext.java ===================================== @@ -24,6 +24,7 @@ package fr.ird.observe.services.local.service.actions.consolidate; import fr.ird.observe.dto.data.ps.DcpComputedValue; import fr.ird.observe.dto.data.ps.observation.FloatingObjectDto; +import fr.ird.observe.dto.decoration.DecoratorService; import fr.ird.observe.entities.ObserveTopiaDaoSupplier; import fr.ird.observe.entities.data.ps.common.Trip; import fr.ird.observe.entities.data.ps.observation.Activity; @@ -67,6 +68,7 @@ class ConsolidationActivitySeineDataContext { boolean failIfLengthWeightParameterNotFound; boolean failIfLengthLengthParameterNotFound; BeanMonitor targetLengthMonitor; + DecoratorService decoratorService; String activityPrefix; BeanMonitor nonTargetLengthMonitor; @@ -93,7 +95,7 @@ class ConsolidationActivitySeineDataContext { Ocean ocean = getOcean(); Date routeDate = getRouteDate(); try { - return Optional.ofNullable(LengthWeightParameters.findLengthWeightParameter(daoSupplier, species, sex, ocean, routeDate, sizeMeasureType)); + return Optional.ofNullable(LengthWeightParameters.findLengthWeightParameter(decoratorService, daoSupplier, species, sex, ocean, routeDate, sizeMeasureType)); } catch (LengthWeightParameterNotFoundException e) { if (failIfLengthWeightParameterNotFound) { throw e; @@ -107,7 +109,7 @@ class ConsolidationActivitySeineDataContext { Ocean ocean = getOcean(); Date routeDate = getRouteDate(); try { - return LengthLengthParameters.findLengthLengthParameter(daoSupplier, species, ocean, sex, routeDate, inputSizeMeasureType, outputSizeMeasureType); + return LengthLengthParameters.findLengthLengthParameter(decoratorService, daoSupplier, species, ocean, sex, routeDate, inputSizeMeasureType, outputSizeMeasureType); } catch (LengthLengthParameterNotFoundException e) { if (failIfLengthLengthParameterNotFound) { throw e; ===================================== services-local/src/test/java/fr/ird/observe/services/local/entity/LengthWeightParemetersTest.java ===================================== @@ -22,6 +22,8 @@ package fr.ird.observe.services.local.entity; import com.opensymphony.xwork2.interceptor.annotations.After; +import fr.ird.observe.dto.decoration.DecoratorService; +import fr.ird.observe.dto.decoration.DecoratorServiceApplicationComponent; import fr.ird.observe.dto.referential.ReferenceStatus; import fr.ird.observe.entities.ObserveTopiaDaoSupplier; import fr.ird.observe.entities.ObserveTopiaPersistenceContext; @@ -61,6 +63,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { private static final Logger log = LogManager.getLogger(LengthWeightParemetersTest.class); private ObserveTopiaPersistenceContext persistenceContext; + private DecoratorService decoratorService; protected static void createLengthWeightParameter(LengthWeightParameterTopiaDao lengthWeightParameterDao, Species species, @@ -93,6 +96,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { persistenceContext = localTestMethodResource.newPersistenceContext(); + decoratorService = DecoratorServiceApplicationComponent.value(); SpeciesTopiaDao speciesDAO = persistenceContext.getCommonSpeciesDao(); OceanTopiaDao oceanDAO = persistenceContext.getCommonOceanDao(); SexTopiaDao sexDao = persistenceContext.getCommonSexDao(); @@ -239,7 +243,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { if (log.isInfoEnabled()) { log.info("Try to find length weith parameter for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date); } - LengthWeightParameter lengthWeightParameter = LengthWeightParameters.findLengthWeightParameter(supplier, species, sex, ocean, date, expectedSizeMeasureType); + LengthWeightParameter lengthWeightParameter = LengthWeightParameters.findLengthWeightParameter(decoratorService, supplier, species, sex, ocean, date, expectedSizeMeasureType); Assert.assertNotNull("length weith parameter not found for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date, lengthWeightParameter); Assert.assertEquals("Expected sex is " + expectedSex.getLabel1() + " but the one found was " + lengthWeightParameter.getSex().getLabel1(), expectedSex, lengthWeightParameter.getSex()); @@ -255,7 +259,7 @@ public class LengthWeightParemetersTest extends ServiceLocalTestSupport { log.info("Try to find length weith parameter for species " + species.getFaoCode() + " - ocean " + ocean.getLabel1() + " - sex " + (sex == null ? "null" : sex.getLabel1()) + " at " + date); } try { - LengthWeightParameters.findLengthWeightParameter(supplier, species, sex, ocean, date, expectedSizeMeasureType); + LengthWeightParameters.findLengthWeightParameter(decoratorService, supplier, species, sex, ocean, date, expectedSizeMeasureType); Assert.fail(); } catch (LengthWeightParameterNotFoundException e) { View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/34f5d1f4b7799ad6f4eb6f0aec... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/-/commit/34f5d1f4b7799ad6f4eb6f0aec... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT