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 b9613b5781bdf7fcc553dfccfaf11a8eee07aeb6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Nov 22 14:50:46 2014 +0100 refs #6149 rename test --- ...riImportServiceEvo6149.java => PupitriImportServiceEvo6149Test.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java similarity index 98% rename from tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java rename to tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java index 3ebe58b..d4cba18 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/PupitriImportServiceEvo6149Test.java @@ -29,7 +29,7 @@ import java.util.Set; * @author Tony Chemit - chemit@codelutin.com * @since 3.10 */ -public class PupitriImportServiceEvo6149 extends PupitryImportServiceTestSupport { +public class PupitriImportServiceEvo6149Test extends PupitryImportServiceTestSupport { /** Logger. */ private static final Log log = LogFactory.getLog(PupitriImportServiceEvo5062Test.class); -- 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>.
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 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 --- .../tutti/service/pupitri/PupitriImportResult.java | 30 ++++++++++++++++ .../service/pupitri/PupitriImportService.java | 40 ++++++++++++++++------ .../resources/i18n/tutti-service_en_GB.properties | 3 ++ .../resources/i18n/tutti-service_fr_FR.properties | 6 ++-- .../tutti/ui/swing/action/ImportPupitriAction.java | 37 ++++++++++++++++++++ .../ifremer/tutti/ui/swing/util/TuttiUIUtil.java | 14 ++++++++ .../util/attachment/AttachmentEditorUIHandler.java | 10 +----- .../resources/i18n/tutti-ui-swing_en_GB.properties | 4 +++ .../resources/i18n/tutti-ui-swing_fr_FR.properties | 4 +++ 9 files changed, 126 insertions(+), 22 deletions(-) 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 320c99a..3045791 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 @@ -122,6 +122,20 @@ public class PupitriImportResult { */ private String melagComment; + /** + * L'identifiant de la pièce-jointe du rapport généré suite à l'import. + * + * @since 3.11 + */ + private String reportAttachmentId; + + /** + * Le nom du rapport généré suite à l'import. + * + * @since 3.11 + */ + private String reportAttachmentFilename; + public PupitriImportResult() { this.catches = new ArrayList<>(); this.notImportedSpeciesIds = new LinkedHashSet<>(); @@ -183,6 +197,14 @@ public class PupitriImportResult { return ImmutableSet.copyOf(notImportedSpeciesIds); } + public String getReportAttachmentId() { + return reportAttachmentId; + } + + public String getReportAttachmentFilename() { + return reportAttachmentFilename; + } + /** * @return {@code true} if there is a total melag weight defined (at least one species MELA-GNE found). * @since 3.4.2 @@ -215,6 +237,14 @@ public class PupitriImportResult { this.rejectedWeight = rejectedWeight; } + void setReportAttachmentId(String reportAttachmentId) { + this.reportAttachmentId = reportAttachmentId; + } + + void setReportAttachmentFilename(String reportAttachmentFilename) { + this.reportAttachmentFilename = reportAttachmentFilename; + } + void flushCarrouselResult(CarrouselImportRequestResult carrouselImportRequestResult) { // set carrousel sorted weight 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 2f40334..b06b349 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 @@ -67,6 +67,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Serializable; import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Collections; import java.util.List; import java.util.Locale; @@ -159,13 +160,27 @@ public class PupitriImportService extends AbstractTuttiService { // generation du rapport File reportFile = generatePupitriReport(operation, result); - // persistence des lots - savePupitriImportResult(result, operation, catchBatch); + try { - // ajout des pièces-jointes - addFileAsAttachment(trunkFile, catchBatch); - addFileAsAttachment(carrouselFile, catchBatch); - addFileAsAttachment(reportFile, catchBatch); + // persistence des lots + savePupitriImportResult(result, operation, catchBatch); + + // ajout des pièces-jointes + addFileAsAttachment(trunkFile, catchBatch); + addFileAsAttachment(carrouselFile, catchBatch); + + DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd__HH_mm"); + String reportAttachmentFilename = "rapport-pupitri-" + simpleDateFormat.format(context.currentDate()) + ".pdf"; + if (log.isInfoEnabled()) { + log.info("Save report with attachment filename: " + reportAttachmentFilename); + } + String reportId = addFileAsAttachment(reportFile, reportAttachmentFilename, catchBatch); + result.setReportAttachmentId(reportId); + result.setReportAttachmentFilename(reportAttachmentFilename); + + } finally { + FileUtils.deleteQuietly(reportFile); + } } @@ -194,7 +209,7 @@ public class PupitriImportService extends AbstractTuttiService { persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); String code; - + // if the protocol is set and the species is in the protocol if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { @@ -239,15 +254,20 @@ public class PupitriImportService extends AbstractTuttiService { } - protected void addFileAsAttachment(File f, CatchBatch catchBatch) { + protected String addFileAsAttachment(File f, CatchBatch catchBatch) { + return addFileAsAttachment(f, f.getName(), catchBatch); + } + + protected String addFileAsAttachment(File f, String attachmentName, CatchBatch catchBatch) { Attachment attachment = Attachments.newAttachment(); attachment.setObjectType(ObjectTypeCode.CATCH_BATCH); attachment.setObjectId(Integer.valueOf(catchBatch.getId())); - attachment.setName(f.getName()); + attachment.setName(attachmentName); String date = DateFormat.getDateTimeInstance().format(context.currentDate()); String comment = t("tutti.service.pupitri.import.attachment.comment", date); attachment.setComment(comment); - persistenceService.createAttachment(attachment, f); + Attachment savedAttachment = persistenceService.createAttachment(attachment, f); + return savedAttachment.getId(); } protected void importPupitriTrunk(PupitriImportResult result, File file, FishingOperation operation) { diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index d985a05..929293e 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -211,6 +211,9 @@ tutti.service.psionimport.error.unkonwSampleCategory.message= tutti.service.pupitri.export.species.error= tutti.service.pupitri.import.attachment.comment= tutti.service.pupitri.import.carrousel.error= +tutti.service.pupitri.import.createMelag.comment.part1= +tutti.service.pupitri.import.createMelag.comment.part2= +tutti.service.pupitri.import.createMelag.comment.part3= tutti.service.pupitri.import.trunk.error= tutti.service.referential.export.gear.error= tutti.service.referential.export.person.error= 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 1e4416b..dd6d0ad 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 @@ -191,15 +191,15 @@ tutti.service.psionimport.error.unkonwSampleCategory.message=Pour l'espèce '<st tutti.service.pupitri.export.species.error=Erreur lors de l'export des espèces pour Pupitri dans le fichier %s tutti.service.pupitri.import.attachment.comment=Import Pupitri du %s tutti.service.pupitri.import.carrousel.error=Erreur lors de l'import du fichier de carrousel %2s pour le trait %1s +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.pupitri.import.trunk.error=Erreur lors de l'import du fichier de trémie %2s pour le trait %1s tutti.service.referential.export.gear.error=Erreur lors de l'export des engins dans le fichier %s tutti.service.referential.export.person.error=Erreur lors de l'export des personnes dans le fichier %s 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 diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPupitriAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPupitriAction.java index 5937bd3..b9242c7 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPupitriAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPupitriAction.java @@ -39,6 +39,10 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchU import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUIModel; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; +import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler; import javax.swing.JOptionPane; import javax.swing.UIManager; @@ -55,6 +59,9 @@ import static org.nuiton.i18n.I18n.t; */ public class ImportPupitriAction extends AbstractTuttiAction<SpeciesBatchUIModel, SpeciesBatchUI, SpeciesBatchUIHandler> { + /** Logger. */ + private static final Log log = LogFactory.getLog(ImportPupitriAction.class); + protected File importedTrunkFile; protected File importedCarrouselFile; @@ -201,6 +208,36 @@ public class ImportPupitriAction extends AbstractTuttiAction<SpeciesBatchUIModel } + // Ask User to see pupiti report + + String reportAttachmentFilename = importResult.getReportAttachmentFilename(); + String htmlMessage = String.format( + AbstractApplicationUIHandler.CONFIRMATION_FORMAT, + t("tutti.editSpeciesBatch.action.importPupitri.showReport.message", reportAttachmentFilename), + ""); + + Component ui = getDialogParentComponent(); + + boolean showReport = JOptionPane.showOptionDialog( + ui, + htmlMessage, + t("tutti.editSpeciesBatch.action.importPupitri.showReport.title"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE, + null, + new Object[]{t("tutti.editSpeciesBatch.action.showReport"), t("tutti.editSpeciesBatch.action.doNotShowReport")}, t("tutti.editSpeciesBatch.action.showReport")) == 0; + + if (showReport) { + + String reportAttachmentId = importResult.getReportAttachmentId(); + File attachmentFile = persistenceService.getAttachmentFile(reportAttachmentId); + if (log.isInfoEnabled()) { + log.info("Open pupitri report at " + attachmentFile); + } + + TuttiUIUtil.browseFile(attachmentFile); + + } } else { displayWarningMessage( diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java index 4f2b2b5..463ec9c 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java @@ -35,9 +35,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.swing.*; +import java.awt.Desktop; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.io.File; +import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; @@ -136,4 +139,15 @@ public final class TuttiUIUtil extends ApplicationUIUtil { } return SwingUtil.createActionIcon(iconName); } + + public static void browseFile(File file) { + + Desktop desktop = getDesktopForBrowse(); + try { + desktop.browse(file.toURI()); + + } catch (IOException e) { + TuttiUIContext.getApplicationContext().getErrorHelper().showErrorDialog(t("swing.error.cannot.open.file")); + } + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java index c85f630..bdb59d0 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/attachment/AttachmentEditorUIHandler.java @@ -44,11 +44,9 @@ import javax.swing.JRootPane; import javax.swing.JToolBar; import javax.swing.KeyStroke; import java.awt.Component; -import java.awt.Desktop; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.File; -import java.io.IOException; import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -239,13 +237,7 @@ public class AttachmentEditorUIHandler extends AbstractTuttiUIHandler<TuttiUICon throw new ApplicationTechnicalException(t("tutti.attachmentEditor.fileNotFound", file.getAbsolutePath())); } - Desktop desktop = TuttiUIUtil.getDesktopForBrowse(); - try { - desktop.browse(file.toURI()); - - } catch (IOException e) { - getContext().getErrorHelper().showErrorDialog(t("swing.error.cannot.open.file")); - } + TuttiUIUtil.browseFile(file); } public void saveAttachment(Attachment attachment) { diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties index 6eabf35..d58638d 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties @@ -1015,6 +1015,7 @@ tutti.editSpeciesBatch.action.createBatch.tip= tutti.editSpeciesBatch.action.createMelag= tutti.editSpeciesBatch.action.createMelag.mnemonic= tutti.editSpeciesBatch.action.createMelag.tip= +tutti.editSpeciesBatch.action.doNotShowReport= tutti.editSpeciesBatch.action.editFrequencies= tutti.editSpeciesBatch.action.editFrequencies.mnemonic= tutti.editSpeciesBatch.action.editFrequencies.tip= @@ -1067,6 +1068,8 @@ tutti.editSpeciesBatch.action.importPupitri.mnemonic= tutti.editSpeciesBatch.action.importPupitri.no.matching.data= tutti.editSpeciesBatch.action.importPupitri.no.matching.fishingOperation= tutti.editSpeciesBatch.action.importPupitri.no.matching.fishingOperation.title= +tutti.editSpeciesBatch.action.importPupitri.showReport.message= +tutti.editSpeciesBatch.action.importPupitri.showReport.title= tutti.editSpeciesBatch.action.importPupitri.speciesNotImported.message= tutti.editSpeciesBatch.action.importPupitri.speciesNotImported.title= tutti.editSpeciesBatch.action.importPupitri.success= @@ -1084,6 +1087,7 @@ tutti.editSpeciesBatch.action.removeSubBatch.tip= tutti.editSpeciesBatch.action.renameBatch= tutti.editSpeciesBatch.action.renameBatch.mnemonic= tutti.editSpeciesBatch.action.renameBatch.tip= +tutti.editSpeciesBatch.action.showReport= tutti.editSpeciesBatch.action.splitBatch= tutti.editSpeciesBatch.action.splitBatch.mnemonic= tutti.editSpeciesBatch.action.splitBatch.tip= diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties index 4848047..cb83cdd 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties @@ -993,6 +993,7 @@ tutti.editSpeciesBatch.action.createBatch.tip=Créer un nouveau lot pour une esp tutti.editSpeciesBatch.action.createMelag=Espèces d'un MELAG (mélange) tutti.editSpeciesBatch.action.createMelag.mnemonic=C tutti.editSpeciesBatch.action.createMelag.tip=Calcul des poids des lots appartenant à un MELAG (mélange) +tutti.editSpeciesBatch.action.doNotShowReport=Continuer tutti.editSpeciesBatch.action.editFrequencies=Mensurations tutti.editSpeciesBatch.action.editFrequencies.mnemonic=M tutti.editSpeciesBatch.action.editFrequencies.tip=Éditer les mensurations @@ -1039,6 +1040,8 @@ tutti.editSpeciesBatch.action.importPupitri.mnemonic=u tutti.editSpeciesBatch.action.importPupitri.no.matching.data=Import pupitri non réalisé (Les identifiants de Station et/ ou de Date du trait ne correspondent pas) tutti.editSpeciesBatch.action.importPupitri.no.matching.fishingOperation=L'application n'a pas trouvé dans les fichiers Trunk et Carrousel les identifiants de Station et/ou de Date du trait en cours de saisie.<br/>Aucun lot n'a donc été importé. tutti.editSpeciesBatch.action.importPupitri.no.matching.fishingOperation.title=Import Pupitri +tutti.editSpeciesBatch.action.importPupitri.showReport.message=L'import pupitri a été réalisé et un rapport a été généré.<br/>Ce rapport (<strong>%s</strong>) a été enregistré dans les pièces-jointes de la capture. +tutti.editSpeciesBatch.action.importPupitri.showReport.title=Consulter le rapport d'import Pupitri tutti.editSpeciesBatch.action.importPupitri.speciesNotImported.message=%s espèces n'ont pas été importées lors de l'import Pupitri, en voici la liste \: <ul>%s</ul> tutti.editSpeciesBatch.action.importPupitri.speciesNotImported.title=Import Pupitri (espèces non importées) tutti.editSpeciesBatch.action.importPupitri.success=Import Pupitri réussi \: %1s espèces importées, %2s espèces rejetées @@ -1056,6 +1059,7 @@ tutti.editSpeciesBatch.action.removeSubBatch.tip=Supprimer tous les lots fils du tutti.editSpeciesBatch.action.renameBatch=Corriger l'espèce tutti.editSpeciesBatch.action.renameBatch.mnemonic=o tutti.editSpeciesBatch.action.renameBatch.tip=Corriger l'espèce +tutti.editSpeciesBatch.action.showReport=Consulter le rapport généré tutti.editSpeciesBatch.action.splitBatch=Catégoriser le lot tutti.editSpeciesBatch.action.splitBatch.mnemonic=C tutti.editSpeciesBatch.action.splitBatch.tip=Catégoriser le lot courant (celui de la ligne sélectionné) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm