branch feature/6150 created (now 1f0b7a1)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6150 in repository tutti. See http://git.codelutin.com/tutti.git at 1f0b7a1 Propose a l'utilisateur de consulter le rapport pupitri genere This branch includes the following new commits: new b9613b5 refs #6149 rename test new 9fcf63e - ajout d'un service de generation de pdf (utilisation pour le raport des captures) - debut de generation du rapport pupitri new 1f0b7a1 Propose a l'utilisateur de consulter le rapport pupitri genere The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 1f0b7a10317739248f03f9739e9a4762c0959252 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Nov 22 15:51:08 2014 +0100 Propose a l'utilisateur de consulter le rapport pupitri genere commit 9fcf63e92d9090471b84c6d2a3ae9ce803cb0b0f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Nov 22 15:04:02 2014 +0100 - ajout d'un service de generation de pdf (utilisation pour le raport des captures) - debut de generation du rapport pupitri commit b9613b5781bdf7fcc553dfccfaf11a8eee07aeb6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Nov 22 14:50:46 2014 +0100 refs #6149 rename test -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6150 in repository tutti. See http://git.codelutin.com/tutti.git commit 9fcf63e92d9090471b84c6d2a3ae9ce803cb0b0f Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Nov 22 15:04:02 2014 +0100 - ajout d'un service de generation de pdf (utilisation pour le raport des captures) - debut de generation du rapport pupitri --- .../ifremer/tutti/service/PdfGeneratorService.java | 82 +++++++++++ .../export/pdf/CatchesPdfExportService.java | 90 +++++------- .../pupitri/CarrouselImportRequestResult.java | 48 ++++++- .../tutti/service/pupitri/PupitriCatch.java | 2 +- .../service/pupitri/PupitriImportReportModel.java | 158 +++++++++++++++++++++ .../tutti/service/pupitri/PupitriImportResult.java | 78 ++++++---- .../service/pupitri/PupitriImportService.java | 106 ++++++++++++-- .../src/main/resources/ftl/pupitriReport_fr.ftl | 118 +++++++++++++++ 8 files changed, 582 insertions(+), 100 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PdfGeneratorService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PdfGeneratorService.java new file mode 100644 index 0000000..ab1d6f1 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PdfGeneratorService.java @@ -0,0 +1,82 @@ +package fr.ifremer.tutti.service; + +import freemarker.cache.ClassTemplateLoader; +import freemarker.ext.beans.BeansWrapper; +import freemarker.template.Configuration; +import freemarker.template.Template; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.ApplicationTechnicalException; +import org.xhtmlrenderer.pdf.ITextRenderer; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.io.Writer; +import java.util.Locale; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 11/22/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.10 + */ +public class PdfGeneratorService extends AbstractTuttiService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(PdfGeneratorService.class); + + protected Configuration freemarkerConfiguration; + + @Override + public void setServiceContext(TuttiServiceContext context) { + super.setServiceContext(context); + + freemarkerConfiguration = new Configuration(); + + // needed to overwrite "Defaults to default system encoding." + // fix encoding issue on some systems + freemarkerConfiguration.setEncoding(Locale.getDefault(), "UTF-8"); + + // specific template loader to get template from jars (classpath) + ClassTemplateLoader templateLoader = new ClassTemplateLoader(getClass(), "/ftl"); + freemarkerConfiguration.setTemplateLoader(templateLoader); + + // pour les maps dans les template (entre autre) + freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); + + } + + public void generatePdf(File targetFile, Locale locale, String templateName, Object model) { + + if (log.isInfoEnabled()) { + log.info("Will generate pdf from template " + templateName + " at " + targetFile); + } + try { + + // Get freemarker template + Template mapTemplate = freemarkerConfiguration.getTemplate(templateName, locale); + + Writer out = new StringWriter(); + mapTemplate.process(model, out); + out.flush(); + + // render template output as pdf + try (OutputStream os = new FileOutputStream(targetFile)) { + + ITextRenderer renderer = new ITextRenderer(); + renderer.setDocumentFromString(out.toString()); + renderer.layout(); + renderer.createPDF(os); + + os.close(); + } + + } catch (Exception ex) { + throw new ApplicationTechnicalException(t("tutti.service.exportPdf.error"), ex); + } + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java index f82c2c4..ce31737 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java @@ -29,28 +29,18 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.AbstractTuttiService; +import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.export.ExportBatchEntry; import fr.ifremer.tutti.service.export.ExportCatchContext; -import freemarker.cache.ClassTemplateLoader; -import freemarker.ext.beans.BeansWrapper; -import freemarker.template.Configuration; -import freemarker.template.Template; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationBusinessException; -import org.nuiton.jaxx.application.ApplicationTechnicalException; -import org.xhtmlrenderer.pdf.ITextRenderer; import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.StringWriter; -import java.io.Writer; import java.util.List; import java.util.Locale; import java.util.Map; @@ -64,30 +54,17 @@ import static org.nuiton.i18n.I18n.t; public class CatchesPdfExportService extends AbstractTuttiService { /** Logger. */ - private static final Log log = - LogFactory.getLog(CatchesPdfExportService.class); - - protected Configuration freemarkerConfiguration; + private static final Log log = LogFactory.getLog(CatchesPdfExportService.class); protected PersistenceService persistenceService; protected WeightComputingService weightComputingService; + protected PdfGeneratorService pdfGeneratorService; + public CatchesPdfExportService() { super(); - freemarkerConfiguration = new Configuration(); - - // needed to overwrite "Defaults to default system encoding." - // fix encoding issue on some systems - freemarkerConfiguration.setEncoding(Locale.getDefault(), "UTF-8"); - - // specific template loader to get template from jars (classpath) - ClassTemplateLoader templateLoader = new ClassTemplateLoader(CatchesPdfExportService.class, "/ftl"); - freemarkerConfiguration.setTemplateLoader(templateLoader); - - // pour les maps dans les template (entre autre) - freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); } @Override @@ -95,6 +72,7 @@ public class CatchesPdfExportService extends AbstractTuttiService { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); weightComputingService = getService(WeightComputingService.class); + pdfGeneratorService = getService(PdfGeneratorService.class); } /** @@ -292,34 +270,44 @@ public class CatchesPdfExportService extends AbstractTuttiService { Map<String, Object> data = Maps.newHashMap(); data.put("operations", operations); - // generate the report - OutputStream os = null; - try { - - // render freemarker template - Template mapTemplate = freemarkerConfiguration.getTemplate("catchesReport.ftl", locale); - Writer out = new StringWriter(); - mapTemplate.process(data, out); - out.flush(); + pdfGeneratorService.generatePdf(targetFile, locale, "catchesReport.ftl", data); - // render template output as pdf - os = new FileOutputStream(targetFile); - - ITextRenderer renderer = new ITextRenderer(); - renderer.setDocumentFromString(out.toString()); - renderer.layout(); - renderer.createPDF(os); - - os.close(); - - } catch (Exception ex) { - throw new ApplicationTechnicalException(t("tutti.service.operations.exportCatchesReport.error"), ex); - } finally { - IOUtils.closeQuietly(os); - } } + + // protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { +// +// Map<String, Object> data = Maps.newHashMap(); +// data.put("operations", operations); +// // generate the report +// OutputStream os = null; +// try { +// +// // render freemarker template +// Template mapTemplate = freemarkerConfiguration.getTemplate("catchesReport.ftl", locale); +// +// Writer out = new StringWriter(); +// mapTemplate.process(data, out); +// out.flush(); +// +// // render template output as pdf +// os = new FileOutputStream(targetFile); +// +// ITextRenderer renderer = new ITextRenderer(); +// renderer.setDocumentFromString(out.toString()); +// renderer.layout(); +// renderer.createPDF(os); +// +// os.close(); +// +// } catch (Exception ex) { +// throw new ApplicationTechnicalException(t("tutti.service.operations.exportCatchesReport.error"), ex); +// } finally { +// IOUtils.closeQuietly(os); +// } +// } +// protected Map<String, Object> createOperation(FishingOperation fishingOperation) { Map<String, Object> op = Maps.newHashMap(); op.put("number", fishingOperation.getFishingOperationNumber()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselImportRequestResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselImportRequestResult.java index 4adcbec..456aec2 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselImportRequestResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/CarrouselImportRequestResult.java @@ -3,6 +3,7 @@ package fr.ifremer.tutti.service.pupitri; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.apache.commons.lang3.mutable.MutableFloat; import java.util.LinkedHashSet; import java.util.List; @@ -18,12 +19,29 @@ public class CarrouselImportRequestResult { private final ListMultimap<String, Species> speciesByCode; - int nbCarrousselImported; + /** + * Nombre d'espèces importées depuis le fichier carrousel. + */ + private int nbCarrousselImported; - float carrouselSortedWeight; + /** + * Poids total du VRAC cumulé depuis le fichier carrousel. + */ + private MutableFloat carrouselSortedWeight; + /** + * Poids total du HORS-VRAC cumulé depuis le fichier carrousel. + */ + private MutableFloat carrouselUnsortedWeight; + + /** + * Ensemble de identifiants d'espèces non importés depuis el fichier carrousel. + */ private final Set<String> notImportedSpeciesIds; + /** + * Liste des lots lus depuis le fichier carrousel. Chaque lot est un tuple (espece,trie). + */ private final List<PupitriCatch> catches; public CarrouselImportRequestResult(ListMultimap<String, Species> speciesByCode) { @@ -38,7 +56,23 @@ public class CarrouselImportRequestResult { } public void addCarrouselSortedWeight(Float beanWeight) { - carrouselSortedWeight += beanWeight; + if (carrouselSortedWeight == null) { + carrouselSortedWeight = new MutableFloat(); + } + if (beanWeight != null) { + + carrouselSortedWeight.add(beanWeight); + } + } + + public void addCarrouselUnsortedWeight(Float beanWeight) { + if (carrouselUnsortedWeight == null) { + carrouselUnsortedWeight = new MutableFloat(); + } + if (beanWeight != null) { + + carrouselUnsortedWeight.add(beanWeight); + } } public List<Species> getSpecies(String speciesId) { @@ -51,7 +85,7 @@ public class CarrouselImportRequestResult { public PupitriCatch getExistingCatchOrAdd(List<Species> speciesList, boolean sorted) { - // on utilise la première espèce trouvée dans la liste des candidate + // on utilise la première espèce trouvée dans la liste des candidates //FIXME Bien s'assurer que cela est ok Species species = speciesList.get(0); PupitriCatch pupitriCatch = new PupitriCatch(species, sorted); @@ -66,7 +100,11 @@ public class CarrouselImportRequestResult { } public float getCarrouselSortedWeight() { - return carrouselSortedWeight; + return carrouselSortedWeight == null ? 0f : carrouselSortedWeight.floatValue(); + } + + public float getCarrouselUnsortedWeight() { + return carrouselUnsortedWeight == null ? 0f : carrouselUnsortedWeight.floatValue(); } public int getNbCarrousselImported() { 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 5112ceb..91b3c01 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 @@ -49,7 +49,7 @@ public class PupitriCatch implements Serializable { * * @since 3.7 */ - private static final Set<String> MELAG_SPECIES = ImmutableSet.copyOf( + static final Set<String> MELAG_SPECIES = ImmutableSet.copyOf( new String[]{MELAG_META_SPECIES, MELAG_2_META_SPECIES}); /** diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportReportModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportReportModel.java new file mode 100644 index 0000000..80f633b --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportReportModel.java @@ -0,0 +1,158 @@ +package fr.ifremer.tutti.service.pupitri; + +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.util.Numbers; +import fr.ifremer.tutti.util.Weights; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Modèle du rapport d'import Pupitri. + * + * Created on 11/22/14. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.11 + */ +public class PupitriImportReportModel { + + public static class PupitriImportReportCatch { + + String speciesCode; + + String speciesName; + + String speciesVernucalCode; + + String sortedWeight; + + String sign; + + String nbBox; + + String nbSmall; + + String nbBig; + + public String getSpeciesCode() { + return speciesCode; + } + + public String getSpeciesName() { + return speciesName; + } + + public String getSpeciesVernucalCode() { + return speciesVernucalCode; + } + + public String getSortedWeight() { + return sortedWeight; + } + + public String getSign() { + return sign; + } + + public String getNbBox() { + return nbBox; + } + + public String getNbSmall() { + return nbSmall; + } + + public String getNbBig() { + return nbBig; + } + } + + public static PupitriImportReportCatch newCatch(String code, + String name, + String vernacularCode, + PupitriCatch pupitriCatch) { + PupitriImportReportCatch result = new PupitriImportReportCatch(); + result.speciesCode = code; + result.speciesName = name; + result.speciesVernucalCode = vernacularCode; + return result; + } + + private final FishingOperation operation; + + private final PupitriImportResult importResult; + + private final List<PupitriImportReportCatch> catches; + + public PupitriImportReportModel(FishingOperation operation, PupitriImportResult importResult) { + this.operation = operation; + this.importResult = importResult; + this.catches = new ArrayList<>(); + } + + public String getStationNumber() { + return operation.getStationNumber(); + } + + public Integer getFishingOperationNumber() { + return operation.getFishingOperationNumber(); + } + + public String getMultirigAggregation() { + return operation.getMultirigAggregation(); + } + + public Date getGearShootingStartDate() { + return operation.getGearShootingStartDate(); + } + + public Date getGearShootingEndDate() { + return operation.getGearShootingEndDate(); + } + + public Float getTrunkSortedWeight() { + Float sortedWeight = importResult.getSortedWeight(); + return sortedWeight == null ? null : Weights.roundKiloGram(sortedWeight); + } + + public Float getTrunkRejectedWeight() { + Float rejectedWeight = importResult.getRejectedWeight(); + return rejectedWeight == null ? null : Weights.roundKiloGram(rejectedWeight); + } + + public Float getTrunkTotalWeight() { + float trunkSortedWeight = Numbers.getValueOrComputedValue(importResult.getSortedWeight(), 0f); + float trunkRejectedWeight = Numbers.getValueOrComputedValue(importResult.getRejectedWeight(), 0f); + + float totalWeight = Weights.roundKiloGram(trunkSortedWeight + trunkRejectedWeight); + return totalWeight; + } + + public Float getCarrouselSortedWeight() { + Float carrouselSortedWeight = importResult.getCarrouselSortedWeight(); + return carrouselSortedWeight == null ? null : Weights.roundKiloGram(carrouselSortedWeight); + } + + public Float getCarrouselUnsortedWeight() { + Float carrouselUnsortedWeight = importResult.getCarrouselUnsortedWeight(); + return carrouselUnsortedWeight == null ? null : Weights.roundKiloGram(carrouselUnsortedWeight); + } + + public Float getCarrouselTotalWeight() { + float trunkSortedWeight = Numbers.getValueOrComputedValue(importResult.getCarrouselSortedWeight(), 0f); + float trunkRejectedWeight = Numbers.getValueOrComputedValue(importResult.getCarrouselUnsortedWeight(), 0f); + + float totalWeight = Weights.roundKiloGram(trunkSortedWeight + trunkRejectedWeight); + return totalWeight; + } + + public List<PupitriImportReportCatch> getCatches() { + return catches; + } + + void addPupitriImportReportCatch(PupitriImportReportCatch aCatch) { + catches.add(aCatch); + } +} 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 7acb4ed..320c99a 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 @@ -31,7 +31,6 @@ 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.Iterator; import java.util.LinkedHashSet; @@ -53,71 +52,85 @@ public class PupitriImportResult { /** Logger. */ private static final Log log = LogFactory.getLog(PupitriImportResult.class); - final File trunkFile; - - final File carrousselFile; - - int nbTrunkImported; + /** + * Nombre de lignes importes depuis le fichier tremie. + */ + private int nbTrunkImported; - int nbTrunkNotImported; + /** + * Nombre de lignes rejetes depuis le fichier tremie. + */ + private int nbTrunkNotImported; - int nbCarrousselImported; + /** + * Nombre d'espèces importées depuis le fichier carrousel. + */ + private int nbCarrousselImported; + /** + * Poids total trié cumulé depuis le fichier tremie. + */ private Float sortedWeight; + /** + * Poids total rejeté cumulé depuis le fichier tremie. + */ private Float rejectedWeight; + /** + * Poids total du VRAC cumulé depuis le fichier carrousel. + */ private Float carrouselSortedWeight; + /** + * Poids total du HORS-VRAC cumulé depuis le fichier carrousel. + */ + private Float carrouselUnsortedWeight; + + /** + * Liste des lots lus depuis le fichier carrousel. Chaque lot est un tuple (espece,trie). + */ private final List<PupitriCatch> catches; /** - * Total weight of all entries of species {@code MELA-GNE}. + * Ensemble de identifiants d'espèces non importés depuis el fichier carrousel. * - * @since 3.4.2 + * @since 3.10 */ - private MutableFloat melagTotalWeight; + private final Set<String> notImportedSpeciesIds; /** - * Total weight of all entries of sorted species of melag (sign = {@code T}). + * Poids total des espèces du mélange cumulé depuis le fichier carrousel, i.e de toutes les lignes dont + * l'espèce appartient à l'ensemble {@link PupitriCatch#MELAG_SPECIES}. * * @since 3.4.2 */ - private MutableFloat melagSortedWeight; + private MutableFloat melagTotalWeight; /** - * Set of species that were not imported from the carrousel file. + * Poids total des lots echantillone cumulé depuis le fichier carrousel, i.e toutes les lignes dont le signe de + * l'espèce est {@code T}. * - * @since 3.10 + * @since 3.4.2 */ - private final Set<String> notImportedSpeciesIds; + private MutableFloat melagSortedWeight; /** - * Comment to add on each melag batch to import. + * Commentaire à ajouter sur tous les lots importés en tant que MELAG. * * @since 3.10 */ private String melagComment; - public PupitriImportResult(File trunkFile, File carrousselFile) { - this.trunkFile = trunkFile; - this.carrousselFile = carrousselFile; + public PupitriImportResult() { this.catches = new ArrayList<>(); - notImportedSpeciesIds = new LinkedHashSet<>(); + this.notImportedSpeciesIds = new LinkedHashSet<>(); } public boolean isFishingOperationFound() { return nbTrunkImported + nbCarrousselImported > 0; } - public File getTrunkFile() { - return trunkFile; - } - - public File getCarrousselFile() { - return carrousselFile; - } - public int getNbTrunkImported() { return nbTrunkImported; } @@ -146,6 +159,10 @@ public class PupitriImportResult { return carrouselSortedWeight; } + public Float getCarrouselUnsortedWeight() { + return carrouselUnsortedWeight; + } + public List<PupitriCatch> getCatches() { return catches; } @@ -202,6 +219,7 @@ public class PupitriImportResult { // set carrousel sorted weight this.carrouselSortedWeight = Weights.roundKiloGram(carrouselImportRequestResult.getCarrouselSortedWeight()); + this.carrouselUnsortedWeight = Weights.roundKiloGram(carrouselImportRequestResult.getCarrouselUnsortedWeight()); // set nb carrousel imported batches this.nbCarrousselImported = carrouselImportRequestResult.getNbCarrousselImported(); @@ -278,7 +296,7 @@ public class PupitriImportResult { } } - + melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part2", sampleWeight, unitLabel, speciesDecorator.toString(aCatch.getSpecies()))).append("\n"); } else { 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 09a8ae1..2f40334 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 @@ -36,6 +36,7 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; +import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; @@ -43,6 +44,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; +import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiCsvUtil; import fr.ifremer.tutti.service.TuttiDataContext; @@ -56,6 +58,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; import org.nuiton.decorator.Decorator; +import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; @@ -66,6 +69,7 @@ import java.io.Serializable; import java.text.DateFormat; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -85,6 +89,8 @@ public class PupitriImportService extends AbstractTuttiService { protected PersistenceService persistenceService; + protected PdfGeneratorService pdfGeneratorService; + protected TuttiDataContext dataContext; protected CaracteristicQualitativeValue sortedCaracteristic; @@ -98,6 +104,7 @@ public class PupitriImportService extends AbstractTuttiService { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); decoratorService = getService(DecoratorService.class); + pdfGeneratorService = getService(PdfGeneratorService.class); dataContext = context.getDataContext(); signsToCaracteristicValue = Maps.newEnumMap(Signs.class); @@ -138,26 +145,100 @@ public class PupitriImportService extends AbstractTuttiService { FishingOperation operation, CatchBatch catchBatch) { - PupitriImportResult result = new PupitriImportResult(trunkFile, - carrouselFile); + PupitriImportResult result = new PupitriImportResult(); importPupitriTrunk(result, trunkFile, operation); importPupitriCarrousel(result, carrouselFile, operation); if (result.isFishingOperationFound()) { - // there is some matching rows to import - + // gestion du melange Decorator<Species> decorator = getService(DecoratorService.class).getDecoratorByType(Species.class); result.prepareMelag(decorator); + // generation du rapport + File reportFile = generatePupitriReport(operation, result); + + // persistence des lots savePupitriImportResult(result, operation, catchBatch); + // ajout des pièces-jointes + addFileAsAttachment(trunkFile, catchBatch); + addFileAsAttachment(carrouselFile, catchBatch); + addFileAsAttachment(reportFile, catchBatch); + } return result; } + protected File generatePupitriReport(FishingOperation operation, PupitriImportResult result) { + + boolean protocolFilled = context.getDataContext().isProtocolFilled(); + + Map<Integer, SpeciesProtocol> speciesProtocolMap = null; + + if (protocolFilled) { + + speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); + + } + + PupitriImportReportModel reportModel = new PupitriImportReportModel(operation, result); + + for (PupitriCatch aCatch : result.getCatches()) { + + Species species = aCatch.getSpecies(); + + Species speciesWithVerncularCode = + persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); + + String code; + + // if the protocol is set and the species is in the protocol + if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { + + // use surveyCode from protocol + SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); + + code = speciesProtocol.getSpeciesSurveyCode(); + + } else { + + // use refTaxCode + code = species.getRefTaxCode(); + + } + + String name = species.getName(); + if (StringUtils.isEmpty(code)) { + + + throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), name)); + } + + String vernacularCode = speciesWithVerncularCode.getVernacularCode(); + + //FIXME Pour Voir si on doit ajouter une ligne par signe ? + PupitriImportReportModel.PupitriImportReportCatch reportCatch = PupitriImportReportModel.newCatch(code, + name, + vernacularCode, + aCatch); + + + reportModel.addPupitriImportReportCatch(reportCatch); + + } + + File reportFile = context.getConfig().newTempFile("puputri-report"); + Locale locale = context.getConfig().getI18nLocale(); + + pdfGeneratorService.generatePdf(reportFile, locale, "pupitriReport.ftl", reportModel); + + return reportFile; + + } + protected void addFileAsAttachment(File f, CatchBatch catchBatch) { Attachment attachment = Attachments.newAttachment(); attachment.setObjectType(ObjectTypeCode.CATCH_BATCH); @@ -223,9 +304,7 @@ public class PupitriImportService extends AbstractTuttiService { } - protected void importPupitriCarrousel(PupitriImportResult result, - File carrouselFile, - FishingOperation operation) { + protected void importPupitriCarrousel(PupitriImportResult result, File carrouselFile, FishingOperation operation) { if (log.isInfoEnabled()) { log.info("Will import pupitri operation [" + operation.toString() + @@ -235,8 +314,6 @@ public class PupitriImportService extends AbstractTuttiService { // process import file CarrouselImportRequestResult carrouselImportRequestResult = processCarrouselImportFile(carrouselFile, operation); - // adjust result (deal with melag for example) - // save it to global result result.flushCarrouselResult(carrouselImportRequestResult); @@ -306,9 +383,15 @@ public class PupitriImportService extends AbstractTuttiService { if (sorted) { // ajout au total des poids trie du carrousel - // meme si ensuite l'espèce peut-être rejeté + // meme si ensuite l'espèce peut-être rejetée result.addCarrouselSortedWeight(beanWeight); + } else { + + // ajout au total des poids non trié du carrousel + // meme si ensuite l'espèce peut-être rejetée + result.addCarrouselUnsortedWeight(beanWeight); + } String speciesId = bean.getSpeciesId(); @@ -426,9 +509,6 @@ public class PupitriImportService extends AbstractTuttiService { FishingOperation operation, CatchBatch catchBatch) { - addFileAsAttachment(result.getTrunkFile(), catchBatch); - addFileAsAttachment(result.getCarrousselFile(), catchBatch); - catchBatch.setCatchTotalSortedTremisWeight(result.getSortedWeight()); catchBatch.setCatchTotalRejectedWeight(result.getRejectedWeight()); diff --git a/tutti-service/src/main/resources/ftl/pupitriReport_fr.ftl b/tutti-service/src/main/resources/ftl/pupitriReport_fr.ftl new file mode 100644 index 0000000..9480cc6 --- /dev/null +++ b/tutti-service/src/main/resources/ftl/pupitriReport_fr.ftl @@ -0,0 +1,118 @@ +<#-- + #%L + Tutti :: Service + %% + Copyright (C) 2012 - 2014 Ifremer + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU 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 General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% +--> +<html> +<head> + <style type="text/css"> + + <#assign blueColor="#000080"> + + h1, h4 { + color: ${blueColor}; + font-weight: bold; + font-style: italic; + } + + th { + color: ${blueColor}; + font-weight: bold; + } + + td, th { + padding-right: 10pt; + } + + td.number { + text-align: right; + } + + .operationInfo { + font-weight: bold; + } + + .label { + color: ${blueColor}; + } + + .value { + margin-right: 50pt; + } + + </style> +</head> +<body> + +<h1>Rapport détaillé du tri des chalutages</h1> + +<p class='operationInfo'> + <span class="label">Station :</span> <span class="value">${stationNumber} - ${fishingOperationNumber}</span> + <span class="label">Poche :</span> <span class="value">${multirigAggregation}</span> + <span class="label"> + du ${gearShootingStartDate?date?string.full} ${gearShootingStartDate?time?string.short} + <#if gearShootingEndDate??>au ${gearShootingEndDate?date?string.full} ${gearShootingEndDate?time?string.short}</#if> + </span> +</p> + +<p class='operationInfo'> + Balance Trunk + <span class="label">Trié :</span> <span class="value"><#if trunkSortedWeight??>${trunkSortedWeight?string("0.00")}</#if></span> + <span class="label">Rejet :</span> <#if trunkRejectedWeight??>${trunkRejectedWeight?string("")}</#if> + <span class="label">Total :</span> <#if trunkTotalWeight??>${trunkTotalWeight?string("0.00")}</#if> +</p> +<p class='operationInfo'> + Balance Caroussel + <span class="label">Vrac :</span> <span class="value"><#if carrouselSortedWeight??>${carrouselSortedWeight?string("0.00")}</#if></span> + <span class="label">Hors Vrac :</span> <#if carrouselUnsortedWeight??>${carrouselUnsortedWeight?string("")}</#if> + <span class="label">Total :</span> <#if carrouselTotalWeight??>${carrouselTotalWeight?string("0.00")}</#if> +</p> + +<h4>Liste du tri "Vrac à trier"</h4> +<table> + <tr> + <th></th> + <th>Espèce</th> + <th>Nom scientifique</th> + <th>Nom commun</th> + <th>Poids trié (kg)</th> + <th>Signe</th> + <th>Nb de caisses</th> + <th>Petite</th> + <th>Grande</th> + </tr> + + <#--<#list catches?sort_by("sortedWeight")?reverse as catch>--> + <#list catches as catch> + <tr> + <td></td> + <td>${catch.speciesCode}</td> + <td><em>${catch.speciesName}</em></td> + <td><#if catch.speciesVernucalCode??>${catch.speciesVernucalCode}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.sortedWeight?string("0.00")}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.sign?string("0")}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.nbBoxs?string("0")}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.nbSmall?string("0")}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.nbBig?string("0")}</#if></td> + </tr> + </#list> +</table> + +</body> +</html> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm