This is an automated email from the git hooks/post-receive script. New commit to branch feature/6575 in repository tutti. See http://git.codelutin.com/tutti.git commit 47f83beb685fddd9dfcd82fa5dc09cecb5ea82e1 Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 18:38:39 2015 +0100 add species code, name and vernacular name + catch comment --- .../ifremer/tutti/service/PdfGeneratorService.java | 1 + .../tutti/service/export/ExportCatchContext.java | 145 ++++++++-- .../toconfirmreport/ToConfirmReportBatchEntry.java | 72 +++++ .../toconfirmreport/ToConfirmReportOperation.java | 2 +- .../toconfirmreport/ToConfirmReportService.java | 321 +++++++++++++++++++++ .../toconfirmreport/ToConfirmReportService.java | 125 -------- .../resources/ftl/toConfirmSpeciesReport_fr.ftl | 87 +++--- .../fr/ifremer/tutti/ui/swing/TuttiUIContext.java | 2 +- .../SpeciesToConfirmReportForCruiseAction.java | 2 +- .../operation/catches/EditCatchesUIHandler.java | 6 +- 10 files changed, 569 insertions(+), 194 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 index 9881944..a76a7f1 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PdfGeneratorService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PdfGeneratorService.java @@ -86,6 +86,7 @@ public class PdfGeneratorService extends AbstractTuttiService { Writer out = new StringWriter(); mapTemplate.process(model, out); + out.flush(); // render template output as pdf diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java index e37da42..1966dce 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java @@ -41,6 +41,9 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.util.Numbers; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.jaxx.application.ApplicationBusinessException; import java.util.Collection; import java.util.List; @@ -56,6 +59,8 @@ import java.util.Map; */ public class ExportCatchContext { + private static final Log log = LogFactory.getLog(ExportCatchContext.class); + final FishingOperation fishingOperation; final CatchBatch catchBatch; @@ -72,10 +77,20 @@ public class ExportCatchContext { final Predicate<SpeciesAbleBatch> vracPredicate; + final boolean weightComputationSucceeded; + public static ExportCatchContext newExportContext(PersistenceService persistenceService, WeightComputingService weightComputingService, String fishingOperationId, boolean loadFrequencies) { + return newExportContext(persistenceService, weightComputingService, fishingOperationId, loadFrequencies, true); + } + + public static ExportCatchContext newExportContext(PersistenceService persistenceService, + WeightComputingService weightComputingService, + String fishingOperationId, + boolean loadFrequencies, + boolean failOnWeightComputingError) { FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); @@ -83,20 +98,74 @@ public class ExportCatchContext { CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); - BatchContainer<SpeciesBatch> rootSpeciesBatch = - weightComputingService.getComputedSpeciesBatches(fishingOperationId); + boolean weightComputationSucceeded = true; - BatchContainer<BenthosBatch> rootBenthosBatch = - weightComputingService.getComputedBenthosBatches(fishingOperationId); + BatchContainer<SpeciesBatch> rootSpeciesBatch = null; + try { + rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(fishingOperationId); - BatchContainer<MarineLitterBatch> marineLitterBatches = - weightComputingService.getComputedMarineLitterBatches( - fishingOperationId, - catchBatch.getMarineLitterTotalWeight()); - weightComputingService.computeCatchBatchWeights(catchBatch, - rootSpeciesBatch, - rootBenthosBatch, - marineLitterBatches); + } catch (ApplicationBusinessException ex) { + if (failOnWeightComputingError) { + throw ex; + } + if (log.isWarnEnabled()) { + log.warn("Error on weight computing", ex); + } + weightComputationSucceeded = false; + if (persistenceService.isFishingOperationWithCatchBatch(fishingOperationId)) { + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, false); + } + } + + BatchContainer<BenthosBatch> rootBenthosBatch = null; + try { + rootBenthosBatch = weightComputingService.getComputedBenthosBatches(fishingOperationId); + + } catch (ApplicationBusinessException ex) { + if (failOnWeightComputingError) { + throw ex; + } + if (log.isWarnEnabled()) { + log.warn("Error on weight computing", ex); + } + weightComputationSucceeded = false; + if (persistenceService.isFishingOperationWithCatchBatch(fishingOperationId)) { + rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); + } + } + + BatchContainer<MarineLitterBatch> marineLitterBatches; + try { + marineLitterBatches = + weightComputingService.getComputedMarineLitterBatches(fishingOperationId, + catchBatch.getMarineLitterTotalWeight()); + + } catch (ApplicationBusinessException ex) { + if (failOnWeightComputingError) { + throw ex; + } + if (log.isWarnEnabled()) { + log.warn("Error on weight computing", ex); + } + weightComputationSucceeded = false; + marineLitterBatches = persistenceService.getRootMarineLitterBatch(fishingOperationId);; + } + + try { + weightComputingService.computeCatchBatchWeights(catchBatch, + rootSpeciesBatch, + rootBenthosBatch, + marineLitterBatches); + + } catch (ApplicationBusinessException ex) { + if (failOnWeightComputingError) { + throw ex; + } + if (log.isWarnEnabled()) { + log.warn("Error on weight computing", ex); + } + weightComputationSucceeded = false; + } Multimap<Species, SpeciesBatchFrequency> speciesFrequencies; Multimap<Species, BenthosBatchFrequency> benthosFrequencies; @@ -119,7 +188,8 @@ public class ExportCatchContext { speciesFrequencies, rootBenthosBatch, benthosFrequencies, - marineLitterBatches); + marineLitterBatches, + weightComputationSucceeded); return result; } @@ -131,7 +201,8 @@ public class ExportCatchContext { Multimap<Species, SpeciesBatchFrequency> speciesFrequencies, BatchContainer<BenthosBatch> rootBenthosBatch, Multimap<Species, BenthosBatchFrequency> benthosFrequencies, - BatchContainer<MarineLitterBatch> marineLitterBatches) { + BatchContainer<MarineLitterBatch> marineLitterBatches, + boolean weightComputationSucceeded) { this.vracPredicate = vracPredicate; this.fishingOperation = fishingOperation; this.catchBatch = catchBatch; @@ -140,6 +211,7 @@ public class ExportCatchContext { this.benthosFrequencies = benthosFrequencies; this.rootBenthosBatch = rootBenthosBatch; this.marineLitterBatches = marineLitterBatches; + this.weightComputationSucceeded = weightComputationSucceeded; } public FishingOperation getFishingOperation() { @@ -177,6 +249,7 @@ public class ExportCatchContext { } public List<ExportBatchEntry> getSpeciesBatchEntry(boolean computeNumber) { + List<ExportBatchEntry> catchList = Lists.newArrayList(); if (withSpeciesBatches()) { @@ -288,33 +361,45 @@ public class ExportCatchContext { } protected float getSpeciesElevationRate() { + float result; + if (weightComputationSucceeded) { - float globalRatio = (getCatchTotalWeight() - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); + float globalRatio = (getCatchTotalWeight() - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); - float speciesTotalSortedWeight = Numbers.getValueOrComputedValue( - catchBatch.getSpeciesTotalSortedWeight(), - catchBatch.getSpeciesTotalSortedComputedWeight()); + float speciesTotalSortedWeight = Numbers.getValueOrComputedValue( + catchBatch.getSpeciesTotalSortedWeight(), + catchBatch.getSpeciesTotalSortedComputedWeight()); - // ratio total species weight / total sorted sampled species weight - float result = globalRatio * speciesTotalSortedWeight; - if (catchBatch.getSpeciesTotalSampleSortedComputedWeight() > 0) { - result /= catchBatch.getSpeciesTotalSampleSortedComputedWeight(); + // ratio total species weight / total sorted sampled species weight + result = globalRatio * speciesTotalSortedWeight; + if (catchBatch.getSpeciesTotalSampleSortedComputedWeight() > 0) { + result /= catchBatch.getSpeciesTotalSampleSortedComputedWeight(); + } + + } else { + result = 0; } return result; } protected float getBenthosElevationRate() { + float result; + if (weightComputationSucceeded) { + + float globalRatio = (getCatchTotalWeight() - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); - float globalRatio = (getCatchTotalWeight() - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); + float benthosTotalSortedWeight = Numbers.getValueOrComputedValue( + catchBatch.getBenthosTotalSortedWeight(), + catchBatch.getBenthosTotalSortedComputedWeight()); - float benthosTotalSortedWeight = Numbers.getValueOrComputedValue( - catchBatch.getBenthosTotalSortedWeight(), - catchBatch.getBenthosTotalSortedComputedWeight()); + // ratio total benthos weight / total sorted sampled benthos weight + result = globalRatio * benthosTotalSortedWeight; + if (catchBatch.getBenthosTotalSampleSortedComputedWeight() > 0) { + result /= catchBatch.getBenthosTotalSampleSortedComputedWeight(); + } - // ratio total benthos weight / total sorted sampled benthos weight - float result = globalRatio * benthosTotalSortedWeight; - if (catchBatch.getBenthosTotalSampleSortedComputedWeight() > 0) { - result /= catchBatch.getBenthosTotalSampleSortedComputedWeight(); + } else { + result = 0; } return result; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBatchEntry.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBatchEntry.java new file mode 100644 index 0000000..1954119 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBatchEntry.java @@ -0,0 +1,72 @@ +package fr.ifremer.tutti.service.export.toconfirmreport; + +/* + * #%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% + */ + +import fr.ifremer.tutti.service.export.ExportBatchEntry; + +/** + * To store a species or batch entry within his speices informations, + * his sorted weight, total weight and percentage amoong the total catch + * weight. + * + * @author Kevin Morin (Code Lutin) + * @since 3.13 + */ +public class ToConfirmReportBatchEntry extends ExportBatchEntry { + + protected final String code; + + protected final String scientificName; + + protected final String vernacularCode; + + protected final String comment; + + public ToConfirmReportBatchEntry(String code, + String scientificName, + String vernacularCode, + String comment) { + super(null); + + this.code = code; + this.scientificName = scientificName; + this.vernacularCode = vernacularCode; + this.comment = comment; + } + + public String getCode() { + return code; + } + + public String getScientificName() { + return scientificName; + } + + public String getVernacularCode() { + return vernacularCode; + } + + public String getComment() { + return comment; + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportOperation.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java similarity index 95% rename from tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportOperation.java rename to tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java index abaa627..0ca07f5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportOperation.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java @@ -1,4 +1,4 @@ -package fr.ifremer.tutti.service.toconfirmreport; +package fr.ifremer.tutti.service.export.toconfirmreport; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java new file mode 100644 index 0000000..1356913 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java @@ -0,0 +1,321 @@ +package fr.ifremer.tutti.service.export.toconfirmreport; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +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.DecoratorService; +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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +/** + * @author Kevin Morin (Code Lutin) + * @since 3.13 + */ +public class ToConfirmReportService extends AbstractTuttiService { + + private static final Log log = LogFactory.getLog(ToConfirmReportService.class); + + protected PersistenceService persistenceService; + protected DecoratorService decoratorService; + protected PdfGeneratorService pdfGeneratorService; + protected WeightComputingService weightComputingService; + + @Override + public void setServiceContext(TuttiServiceContext context) { + super.setServiceContext(context); + persistenceService = getService(PersistenceService.class); + decoratorService = getService(DecoratorService.class); + pdfGeneratorService = getService(PdfGeneratorService.class); + weightComputingService = getService(WeightComputingService.class); + } + + public void createToConfirmReport(String cruiseId, Locale locale) { + + Cruise cruise = persistenceService.getCruise(cruiseId); + if (log.isDebugEnabled()) { + log.debug("Cruise " + decoratorService.getDecorator(cruise).toString(cruise)); + } + + List<String> allFishingOperation = + persistenceService.getAllFishingOperationIds(cruiseId); + + List<Map<String, Object>> operations = Lists.newArrayList(); + for (String operationId : allFishingOperation) { + prepareOperation(operationId, operations); + } + +// List<ToConfirmReportOperation> toConfirmReportOperations = new ArrayList<>(); +// +// List<FishingOperation> allFishingOperation = persistenceService.getAllFishingOperation(cruiseId); +// for (FishingOperation fishingOperation : allFishingOperation) { +// +// if (log.isDebugEnabled()) { +// log.debug("|- Operation " + decoratorService.getDecorator(fishingOperation).toString(fishingOperation)); +// } +// +// String operationId = fishingOperation.getId(); +// +// boolean withCatchBath = persistenceService.isFishingOperationWithCatchBatch(operationId); +// +// List<PdfExportBatchEntry> speciesBatchesToConfirm = null; +// List<PdfExportBatchEntry> benthosBatchesToConfirm = null; +// +// if (withCatchBath) { +// +// boolean protocolFilled = context.getDataContext().isProtocolFilled(); +// +// Map<Integer, SpeciesProtocol> speciesProtocolMap = null; +// +// if (protocolFilled) { +// speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); +// } +// +// for (ExportBatchEntry entry : speciesBatchEntries) { +// +// SpeciesAbleBatch batch = entry.getBatch(); +// Species species = batch.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(); +// +// } +// +// if (StringUtils.isEmpty(code)) { +// +// +// throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), species.getName())); +// } +// +// PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry(code, +// species.getName(), +// speciesWithVerncularCode.getVernacularCode(), +// entry.getSortedWeight(), +// entry.getTotalWeight(), +// totalWeight); +// catchList.add(pdfEntry); +// } +// +// // load it +// try { +// speciesBatchesToConfirm = persistenceService.getAllSpeciesBatchToConfirm(operationId); +// for (SpeciesBatch speciesBatch : speciesBatchesToConfirm) { +// if (log.isDebugEnabled()) { +// Species species = speciesBatch.getSpecies(); +// Serializable sampleCategoryValue = speciesBatch.getSampleCategoryValue(); +// log.debug(" |- " + decoratorService.getDecorator(species).toString(species) + +// " / " + decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue)); +// } +// } +// +// benthosBatchesToConfirm = persistenceService.getAllBenthosBatchToConfirm(operationId); +// for (BenthosBatch benthosBatch : benthosBatchesToConfirm) { +// if (log.isDebugEnabled()) { +// Species species = benthosBatch.getSpecies(); +// Serializable sampleCategoryValue = benthosBatch.getSampleCategoryValue(); +// log.debug(" |- " + decoratorService.getDecorator(species).toString(species) + +// " / " + decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue)); +// } +// } +// +// } catch (InvalidBatchModelException e) { +// +// // batch is not compatible with Tutti +// if (log.isDebugEnabled()) { +// log.debug("Invalid batch model", e); +// } +// } +// +// } else { +// if (log.isDebugEnabled()) { +// log.debug(" |- No catchBatch "); +// } +// } +// +// String operation = decoratorService.getDecorator(fishingOperation).toString(fishingOperation); +// ToConfirmReportOperation toConfirmReportOperation = new ToConfirmReportOperation(operation, speciesBatchesToConfirm, benthosBatchesToConfirm); +// toConfirmReportOperations.add(toConfirmReportOperation); +// } + + + generatePdf(new File("/tmp/test.pdf"), locale, decoratorService.getDecorator(cruise).toString(cruise), operations); + + } + + protected void prepareOperation(String fishingOperationId, + List<Map<String, Object>> operations) { + + // get operation and catch data + boolean withCatchBatch = + persistenceService.isFishingOperationWithCatchBatch( + fishingOperationId); + + if (!withCatchBatch) { + if (log.isWarnEnabled()) { + log.warn("Skip fishing operation " + fishingOperationId + + " since no catchBatch associated."); + } + return; + } + + ExportCatchContext exportCatchContext = ExportCatchContext.newExportContext( + persistenceService, + weightComputingService, + fishingOperationId, + false, + false); + + // create operation data model + Map<String, Object> op = createOperation(exportCatchContext.getFishingOperation()); + + boolean protocolFilled = context.getDataContext().isProtocolFilled(); + + // Species + List<ToConfirmReportBatchEntry> speciesCatchList = Lists.newArrayList(); + + if (exportCatchContext.withSpeciesBatches()) { + + List<ExportBatchEntry> speciesBatchEntries = + exportCatchContext.getSpeciesBatchEntry(false); + + Map<Integer, SpeciesProtocol> speciesProtocolMap = null; + + if (protocolFilled) { + speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); + } + + findSpeciesToConfirm(protocolFilled, speciesBatchEntries, speciesCatchList, speciesProtocolMap); + } + + if (!speciesCatchList.isEmpty()) { + op.put("speciesCatches", speciesCatchList); + } + + // Benthos + List<ToConfirmReportBatchEntry> benthosCatchList = Lists.newArrayList(); + + if (exportCatchContext.withBenthosBatches()) { + + List<ExportBatchEntry> benthosBatchEntries = + exportCatchContext.getBenthosBatchEntry(false); + + Map<Integer, SpeciesProtocol> speciesProtocolMap = null; + + if (protocolFilled) { + speciesProtocolMap = persistenceService.toBenthosProtocolMap(); + } + + findSpeciesToConfirm(protocolFilled, benthosBatchEntries, benthosCatchList, speciesProtocolMap); + } + + if (!benthosCatchList.isEmpty()) { + op.put("benthosCatches", benthosCatchList); + } + + if (!speciesCatchList.isEmpty() || !benthosCatchList.isEmpty()) { + operations.add(op); + } + } + + protected void findSpeciesToConfirm(boolean protocolFilled, + List<ExportBatchEntry> batchEntries, + List<ToConfirmReportBatchEntry> catchList, + Map<Integer, SpeciesProtocol> speciesProtocolMap) { + + for (ExportBatchEntry entry : batchEntries) { + SpeciesAbleBatch batch = entry.getBatch(); + + Species species = batch.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(); + String vernacularCode = speciesWithVerncularCode.getVernacularCode(); + + findSpeciesToConfirm(catchList, batch, code, name, vernacularCode); + } + } + + protected void findSpeciesToConfirm(List<ToConfirmReportBatchEntry> catchList, SpeciesAbleBatch batch, String code, String name, String vernacularCode) { + if (batch.isSpeciesToConfirm()) { + String comment = batch.getComment(); + ToConfirmReportBatchEntry reportEntry = new ToConfirmReportBatchEntry(code, + name, + vernacularCode, + comment); + catchList.add(reportEntry); + + } else if (!batch.isChildBatchsEmpty()) { + + for (SpeciesAbleBatch speciesAbleBatch : batch.getChildBatchs()) { + findSpeciesToConfirm(catchList, speciesAbleBatch, code, name, vernacularCode); + } + } + } + + protected Map<String, Object> createOperation(FishingOperation fishingOperation) { + Map<String, Object> op = Maps.newHashMap(); + op.put("number", fishingOperation.getFishingOperationNumber()); + op.put("station", fishingOperation.getStationNumber()); + op.put("rigNumber", fishingOperation.getMultirigAggregation()); + op.put("startDate", fishingOperation.getGearShootingStartDate()); + op.put("endDate", fishingOperation.getGearShootingEndDate()); + + return op; + } + + protected void generatePdf(File targetFile, Locale locale, String cruiseName, List<Map<String, Object>> operations) { + + Map<String, Object> data = Maps.newHashMap(); + data.put("operations", operations); + + pdfGeneratorService.generatePdf(targetFile, locale, "toConfirmSpeciesReport.ftl", data); + + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportService.java deleted file mode 100644 index 15ed549..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/toconfirmreport/ToConfirmReportService.java +++ /dev/null @@ -1,125 +0,0 @@ -package fr.ifremer.tutti.service.toconfirmreport; - -import fr.ifremer.tutti.persistence.InvalidBatchModelException; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.referential.Species; -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.TuttiServiceContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.File; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * @author Kevin Morin (Code Lutin) - * @since 3.13 - */ -public class ToConfirmReportService extends AbstractTuttiService { - - private static final Log log = LogFactory.getLog(ToConfirmReportService.class); - - protected PersistenceService persistenceService; - protected DecoratorService decoratorService; - protected PdfGeneratorService pdfGeneratorService; - - @Override - public void setServiceContext(TuttiServiceContext context) { - super.setServiceContext(context); - persistenceService = getService(PersistenceService.class); - decoratorService = getService(DecoratorService.class); - pdfGeneratorService = getService(PdfGeneratorService.class); - } - - public void createToConfirmReport(String cruiseId, Locale locale) { - - Cruise cruise = persistenceService.getCruise(cruiseId); - if (log.isDebugEnabled()) { - log.debug("Cruise " + decoratorService.getDecorator(cruise).toString(cruise)); - } - - List<ToConfirmReportOperation> toConfirmReportOperations = new ArrayList<>(); - - List<FishingOperation> allFishingOperation = persistenceService.getAllFishingOperation(cruiseId); - for (FishingOperation fishingOperation : allFishingOperation) { - - if (log.isDebugEnabled()) { - log.debug("|- Operation " + decoratorService.getDecorator(fishingOperation).toString(fishingOperation)); - } - - String operationId = fishingOperation.getId(); - - boolean withCatchBath = persistenceService.isFishingOperationWithCatchBatch(operationId); - - List<SpeciesBatch> speciesBatchesToConfirm = null; - List<BenthosBatch> benthosBatchesToConfirm = null; - - if (withCatchBath) { - - // load it - try { - speciesBatchesToConfirm = persistenceService.getAllSpeciesBatchToConfirm(operationId); - for (SpeciesBatch speciesBatch : speciesBatchesToConfirm) { - if (log.isDebugEnabled()) { - Species species = speciesBatch.getSpecies(); - Serializable sampleCategoryValue = speciesBatch.getSampleCategoryValue(); - log.debug(" |- " + decoratorService.getDecorator(species).toString(species) + - " / " + decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue)); - } - } - - benthosBatchesToConfirm = persistenceService.getAllBenthosBatchToConfirm(operationId); - for (BenthosBatch benthosBatch : benthosBatchesToConfirm) { - if (log.isDebugEnabled()) { - Species species = benthosBatch.getSpecies(); - Serializable sampleCategoryValue = benthosBatch.getSampleCategoryValue(); - log.debug(" |- " + decoratorService.getDecorator(species).toString(species) + - " / " + decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue)); - } - } - - } catch (InvalidBatchModelException e) { - - // batch is not compatible with Tutti - if (log.isDebugEnabled()) { - log.debug("Invalid batch model", e); - } - } - - } else { - if (log.isDebugEnabled()) { - log.debug(" |- No catchBatch "); - } - } - - String operation = decoratorService.getDecorator(fishingOperation).toString(fishingOperation); - ToConfirmReportOperation toConfirmReportOperation = new ToConfirmReportOperation(operation, speciesBatchesToConfirm, benthosBatchesToConfirm); - toConfirmReportOperations.add(toConfirmReportOperation); - } - - - generatePdf(new File("/tmp/test.pdf"), locale, decoratorService.getDecorator(cruise).toString(cruise), toConfirmReportOperations); - - } - - protected void generatePdf(File targetFile, Locale locale, String cruiseName, List<ToConfirmReportOperation> toConfirmReportOperations) { - - Map<String, Object> data = new HashMap<>(); - data.put("cruise", cruiseName); - data.put("operations", toConfirmReportOperations); - - pdfGeneratorService.generatePdf(targetFile, locale, "toConfirmSpeciesReport.ftl", data); - - } -} diff --git a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl index 7d84b28..40068fa 100644 --- a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl +++ b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl @@ -27,6 +27,8 @@ <#assign blueColor="#000080"> + @page { size: A4 landscape;} + h1, h4 { color: ${blueColor}; font-weight: bold; @@ -64,55 +66,72 @@ <h1>Rapport des espèces à confirmer</h1> - <h2>${cruise}</h2> - - <#list operations as operation> + <#assign orderedOperations = operations?sort_by("startDate")?reverse> + <#list orderedOperations as operation> <p class='operationInfo'> - <span class="label">Opération :</span> <span class="value">${operation.operation}</span> + <span class="label">Station :</span> <span class="value">${operation.station} - ${operation.number}</span> + <span class="label">Poche :</span> <span class="value">${operation.rigNumber}</span> + <span class="label"> + du ${operation.startDate?date?string.full} ${operation.startDate?time?string.short} + <#if operation.endDate??>au ${operation.endDate?date?string.full} ${operation.endDate?time?string.short}</#if> + </span> </p> - <#if operation.speciesBatches??> - <h4>Espèces :</h4> - + <#if operation.speciesCatches??> <table> - <tr> - <th>Espèce</th> - <th>Catégorie</th> - <th>Poids</th> - <th>Commentaire</th> - </tr> - - <#list operation.speciesBatches as batch> + <caption>Espèces</caption> + <thead> <tr> - <td>${batch.species}</td> - <td></td><td></td> - <td>${batch.comment!""}</td> + <th>Espèce</th> + <th>Nom scientifique</th> + <th>Nom commun</th> + <th>Trié (kg)</th> + <th>Commentaire</th> </tr> - </#list> + </thead> + <tbody> + <#list operation.speciesCatches?sort_by("sortedWeight")?reverse as catch> + <tr> + <td><#if catch.code??>${catch.code}</#if></td> + <td><em>${catch.scientificName}</em></td> + <td><#if catch.vernacularCode??>${catch.vernacularCode}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.sortedWeight?string("0.00")}</#if></td> + <td><#if catch.comment??>${catch.comment?html}</#if></td> + </tr> + </#list> + </tbody> </table> - </#if> - <#if operation.benthosBatches??> - <h4>Benthos :</h4> + <#if operation.benthosCatches??> <table> - <tr> - <th>Espèce</th> - <th>Catégorie</th> - <th>Poids</th> - <th>Commentaire</th> - </tr> - - <#list operation.benthosBatches as batch> + <caption>Benthos</caption> + <thead> <tr> - <td>${batch.species}</td> - <td></td><td></td> - <td>${batch.comment!""}</td> + <th>Espèce</th> + <th>Nom scientifique</th> + <th>Nom commun</th> + <th>Trié (kg)</th> + <th>Commentaire</th> </tr> - </#list> + </thead> + <tbody> + <#list operation.benthosCatches?sort_by("sortedWeight")?reverse as catch> + <tr> + <td><#if catch.code??>${catch.code}</#if></td> + <td><em>${catch.scientificName}</em></td> + <td><#if catch.vernacularCode??>${catch.vernacularCode}</#if></td> + <td class="number"><#if catch.sortedWeight??>${catch.sortedWeight?string("0.00")}</#if></td> + <td><#if catch.comment??>${catch.comment?html}</#if></td> + </tr> + </#list> + </tbody> </table> + </#if> + <#if operation != orderedOperations?last> + <h2 style="page-break-after:always"/> </#if> </#list> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java index 10dcf6d..8b086b2 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java @@ -53,7 +53,7 @@ import fr.ifremer.tutti.service.referential.ReferentialTemporarySpeciesService; import fr.ifremer.tutti.service.referential.ReferentialTemporaryVesselService; import fr.ifremer.tutti.service.referential.TuttiReferentialSynchronizeService; import fr.ifremer.tutti.service.report.ReportService; -import fr.ifremer.tutti.service.toconfirmreport.ToConfirmReportService; +import fr.ifremer.tutti.service.export.toconfirmreport.ToConfirmReportService; import fr.ifremer.tutti.ui.swing.content.MainUI; import fr.ifremer.tutti.ui.swing.updater.DeleteHelper; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SpeciesToConfirmReportForCruiseAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SpeciesToConfirmReportForCruiseAction.java index 8828a97..0f64476 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SpeciesToConfirmReportForCruiseAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SpeciesToConfirmReportForCruiseAction.java @@ -24,7 +24,7 @@ package fr.ifremer.tutti.ui.swing.action; import com.google.common.base.Preconditions; import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.service.toconfirmreport.ToConfirmReportService; +import fr.ifremer.tutti.service.export.toconfirmreport.ToConfirmReportService; import fr.ifremer.tutti.ui.swing.content.MainUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index e27cc5f..dfafc77 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -1139,8 +1139,10 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi } svgRelatedPropertyChangeListeners.clear(); - canvas.dispose(); - getUI().getSvgCanvasPanel().remove(canvas); + if (canvas != null) { + canvas.dispose(); + getUI().getSvgCanvasPanel().remove(canvas); + } } protected void addSvgRelatedPropertyChangeListener(String property, PropertyChangeListener listener) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.