This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit f742ba87cbe7e01af617911670dbfcb49d2d30bb Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Nov 21 18:00:02 2014 +0100 - ajout du commentaire de melag - ajout règle metier lors de l'import du melag pour changer en poids petit si aussi un poid G trouve --- .../tutti/service/pupitri/PupitriCatch.java | 25 +++++- .../tutti/service/pupitri/PupitriImportResult.java | 90 ++++++++++++++++++---- .../service/pupitri/PupitriImportService.java | 36 ++++++--- .../resources/i18n/tutti-service_fr_FR.properties | 3 + 4 files changed, 124 insertions(+), 30 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java index 10f4781..26238c2 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriCatch.java @@ -52,11 +52,26 @@ public class PupitriCatch implements Serializable { private static final Set<String> MELAG_SPECIES = ImmutableSet.copyOf( new String[]{MELAG_META_SPECIES, MELAG_2_META_SPECIES}); - + /** + * Espece du lot. + */ protected Species species; + /** + * Is the species is a sorted (VRAC) or unsorted (HORS-VRAC)? + */ protected boolean sorted; + /** + * If the species was involved in the melag, fill this flag. + * + * If species has also a {@link Signs#BIG} weight, then the melga weight is imported as a {@link Signs#SMALL} batch. + * Otherwise using the {@link Signs#DEFAULT} sign. + * + * We will look after this sign while crzating species batch to import. + */ + protected Signs addMelagCommentForSign; + protected Map<Signs, MutableFloat> weightBySign = Maps.newHashMap(); public PupitriCatch(Species species, boolean sorted) { @@ -72,6 +87,10 @@ public class PupitriCatch implements Serializable { return sorted; } + public boolean isAddMelagComment(Signs sign) { + return addMelagCommentForSign != null && addMelagCommentForSign.equals(sign); + } + public boolean isForMelag() { return weightBySign.containsKey(Signs.MELAG); } @@ -107,6 +126,10 @@ public class PupitriCatch implements Serializable { weightBySign.remove(sign); } + public void setAddMelagCommentForSign(Signs addMelagCommentForSign) { + this.addMelagCommentForSign = addMelagCommentForSign; + } + @Override public int hashCode() { int speciesHashCode = species != null ? species.hashCode() : 0; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java index a88fe84..e5f864b 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java @@ -24,19 +24,22 @@ package fr.ifremer.tutti.service.pupitri; import com.google.common.collect.ImmutableSet; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.util.Weights; import org.apache.commons.lang3.mutable.MutableFloat; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; import java.io.File; import java.util.ArrayList; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import static org.nuiton.i18n.I18n.t; + /** * Result of a pupitri import. * <p/> @@ -83,19 +86,23 @@ public class PupitriImportResult { private MutableFloat melagSortedWeight; /** - * Set of all species in the melag (sign = {@code T}). + * Set of species that were not imported from the carrousel file. * - * @since 3.4.2 + * @since 3.10 */ - private final Set<Species> melagSpecies; - private final Set<String> notImportedSpeciesIds; + /** + * Comment to add on each melag batch to import. + * + * @since 3.10 + */ + private String melagComment; + public PupitriImportResult(File trunkFile, File carrousselFile) { this.trunkFile = trunkFile; this.carrousselFile = carrousselFile; - catches = new ArrayList<>(); - melagSpecies = new HashSet<>(); + this.catches = new ArrayList<>(); notImportedSpeciesIds = new LinkedHashSet<>(); } @@ -151,6 +158,10 @@ public class PupitriImportResult { return melagSortedWeight == null ? null : melagSortedWeight.floatValue(); } + public String getMelagComment() { + return melagComment; + } + public Set<String> getNotImportedSpeciesIds() { return ImmutableSet.copyOf(notImportedSpeciesIds); } @@ -197,11 +208,14 @@ public class PupitriImportResult { this.notImportedSpeciesIds.addAll(carrouselImportRequestResult.getNotImportedSpeciesIds()); List<PupitriCatch> incomingCatches = carrouselImportRequestResult.getCatches(); - setCatches(incomingCatches); + + for (PupitriCatch aCatch : incomingCatches) { + addCatch(aCatch); + } } - void prepareMelag() { + void prepareMelag(Decorator<Species> speciesDecorator) { boolean useMelag = isFoundTotalMelag() && isFoundSortedMelag(); @@ -209,8 +223,17 @@ public class PupitriImportResult { if (useMelag) { melagRatio = melagSortedWeight.floatValue() / melagTotalWeight.floatValue(); + + if (log.isInfoEnabled()) { + log.info("Use Melag (sorted weight: " + melagSortedWeight.floatValue() + " / total weight: " + melagTotalWeight.floatValue() + ")"); + } } + + String unitLabel = WeightUnit.KG.getShortLabel(); + + StringBuilder melagCommentBuilder = new StringBuilder(t("tutti.service.pupitri.import.createMelag.comment.part1") + "\n"); + Iterator<PupitriCatch> iterator = catches.iterator(); while (iterator.hasNext()) { PupitriCatch aCatch = iterator.next(); @@ -231,9 +254,37 @@ public class PupitriImportResult { Float sampleWeight = aCatch.getWeight(Signs.MELAG); Float weight = Weights.roundKiloGram(sampleWeight / melagRatio); - aCatch.addToSign(Signs.DEFAULT, weight); + + if (aCatch.getWeight(Signs.BIG) == null) { + + // No BIG batch associated with this melag species + // use default batch + // see https://forge.codelutin.com/issues/5742 + aCatch.addToSign(Signs.DEFAULT, weight); + aCatch.setAddMelagCommentForSign(Signs.DEFAULT); + + if (log.isInfoEnabled()) { + log.info("Add melag batch for " + aCatch + " as default (no G found) : " + weight); + } + + } else { + + // also found a big batch associated with this melga species + // transform it as a small batch instead of default + // see https://forge.codelutin.com/issues/5742 + aCatch.addToSign(Signs.SMALL, weight); + aCatch.setAddMelagCommentForSign(Signs.SMALL); + + if (log.isInfoEnabled()) { + log.info("Add melag batch for " + aCatch + " as small (G found) : " + weight); + } + + } + aCatch.removeSign(Signs.MELAG); + melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part2", sampleWeight, unitLabel, speciesDecorator.toString(aCatch.getSpecies()))).append("\n"); + } else { // move the melag weight as a default weight @@ -247,12 +298,17 @@ public class PupitriImportResult { } - } + if (useMelag) { + + melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part3", melagTotalWeight, unitLabel)); + + melagComment = melagCommentBuilder.toString(); + if (log.isInfoEnabled()) { + log.info("Melag comment:\n" + melagComment); + } - private void setCatches(List<PupitriCatch> catches) { - for (PupitriCatch aCatch : catches) { - addCatch(aCatch); } + } private void addCatch(PupitriCatch aCatch) { @@ -271,10 +327,10 @@ public class PupitriImportResult { if (aCatch.isForMelag()) { - // add species as a melag one - melagSpecies.add(aCatch.getSpecies()); - // add weight to sorted melag + if (log.isInfoEnabled()) { + log.info("Found a catch used in MELAG: " + aCatch); + } addMelagSortedWeight(aCatch.getWeight(Signs.MELAG)); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java index 117c4b2..45aa3e3 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java @@ -148,7 +148,8 @@ public class PupitriImportService extends AbstractTuttiService { // there is some matching rows to import - result.prepareMelag(); + Decorator<Species> decorator = getService(DecoratorService.class).getDecoratorByType(Species.class); + result.prepareMelag(decorator); savePupitriImportResult(result, operation, catchBatch); @@ -243,10 +244,6 @@ public class PupitriImportService extends AbstractTuttiService { protected CarrouselImportRequestResult processCarrouselImportFile(File carrouselFile, FishingOperation operation) { - if (log.isInfoEnabled()) { - log.info("Will import pupitri operation [" + operation.toString() + "] carrousel from file: " + carrouselFile); - } - // get the map of species by survey code or reftax code ListMultimap<String, Species> speciesBySurveyCode = ArrayListMultimap.create(); speciesBySurveyCode.putAll(Speciess.splitBySurveyCode(dataContext.getReferentSpeciesWithSurveyCode())); @@ -446,6 +443,8 @@ public class PupitriImportService extends AbstractTuttiService { // insert all imported species batches + String melagComment = result.getMelagComment(); + Decorator<Species> speciesDecorator = decoratorService.getDecoratorByType(Species.class); for (PupitriCatch pupitriCatch : result.getCatches()) { @@ -463,6 +462,7 @@ public class PupitriImportService extends AbstractTuttiService { if (log.isDebugEnabled()) { log.debug("Create a categorized batches for species " + speciesDecorator.toString(species)); } + SpeciesBatch batch = createSpeciesBatch(operation, species, null, @@ -476,6 +476,7 @@ public class PupitriImportService extends AbstractTuttiService { for (Map.Entry<Signs, MutableFloat> entry : weightBySign.entrySet()) { Signs signs = entry.getKey(); + boolean addMelagComment = pupitriCatch.isAddMelagComment(signs); float catchWeight = entry.getValue().floatValue(); Integer categoryId = signs.getCategory(); @@ -485,9 +486,14 @@ public class PupitriImportService extends AbstractTuttiService { species, catchWeight, categoryId, - splitCqv - ); + splitCqv); + if (addMelagComment) { + childBatch.setComment(melagComment); + if (log.isInfoEnabled()) { + log.info("Add melag comment for sign " + signs + "on " + speciesDecorator.toString(species)); + } + } persistenceService.createSpeciesBatch(childBatch, parentBatchId); } @@ -509,6 +515,14 @@ public class PupitriImportService extends AbstractTuttiService { PmfmId.SORTED_UNSORTED.getValue(), cqv); + boolean addMelagComment = pupitriCatch.isAddMelagComment(Signs.DEFAULT); + if (addMelagComment) { + if (log.isInfoEnabled()) { + log.info("Add melag comment for simple batch " + speciesDecorator.toString(species)); + } + batch.setComment(melagComment); + } + persistenceService.createSpeciesBatch(batch, null); } } @@ -546,16 +560,14 @@ public class PupitriImportService extends AbstractTuttiService { * </ul> * See http://forge.codelutin.com/issues/3898 * - * @param speciesCatch catch to cehck + * @param speciesCatch catch to check * @return {@code true} if species catch is safe, {@code false} otherwise. * @since 3.0-rc-2 */ private boolean isSplitSpecies(PupitriCatch speciesCatch) { boolean result; - Map<Signs, MutableFloat> weightBySign = - speciesCatch.getWeightBySign(); - Set<Signs> signs = - Sets.newHashSet(weightBySign.keySet()); + Map<Signs, MutableFloat> weightBySign = speciesCatch.getWeightBySign(); + Set<Signs> signs = Sets.newHashSet(weightBySign.keySet()); if (DEFAULT_SIGNS.equals(signs)) { diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index 4d638cd..1e4416b 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -197,6 +197,9 @@ tutti.service.referential.export.person.error=Erreur lors de l'export des person tutti.service.referential.export.species.error=Erreur lors de l'export des espèces dans le fichier %s tutti.service.referential.export.vessel.error=Erreur lors de l'export des navires dans le fichier %s tutti.service.referential.import.gear.add.noName.error=Le nom de l'engin est obligatoire +tutti.service.pupitri.import.createMelag.comment.part1=Traitement issu d'un mélange composé de \: +tutti.service.pupitri.import.createMelag.comment.part2=- %s%s de %s +tutti.service.pupitri.import.createMelag.comment.part3=avec un poids d'élévation de %s%s tutti.service.referential.import.gear.cannotDeleteNotExisting.error=L'engin temporaire d'identifiant %s n'extsite pas, impossible de la supprimer tutti.service.referential.import.gear.cannotDeleteWithoutId.error=L'identifiant est obligatoire pour la suppression tutti.service.referential.import.gear.existingName.error=L'engin '%s' n'a pas été ajouté au référentiel car il est déjà présent -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.