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 fe84276065ca0214635966e59b154b5e710b3d1f Author: Kevin Morin <morin@codelutin.com> Date: Fri Feb 6 14:12:10 2015 +0100 ajout des catégories --- .../tutti/service/export/ExportCatchContext.java | 107 ++-------- .../toconfirmreport/ToConfirmReportBatchEntry.java | 36 +++- .../toconfirmreport/ToConfirmReportContext.java | 114 +++++++++++ .../toconfirmreport/ToConfirmReportService.java | 218 ++++++--------------- .../resources/ftl/toConfirmSpeciesReport_fr.ftl | 27 ++- .../SpeciesToConfirmReportForCruiseAction.java | 30 +-- .../resources/i18n/tutti-ui-swing_en_GB.properties | 2 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 2 + 8 files changed, 257 insertions(+), 279 deletions(-) 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 1966dce..51ae285 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,9 +41,6 @@ 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; @@ -59,8 +56,6 @@ import java.util.Map; */ public class ExportCatchContext { - private static final Log log = LogFactory.getLog(ExportCatchContext.class); - final FishingOperation fishingOperation; final CatchBatch catchBatch; @@ -77,20 +72,10 @@ 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); @@ -98,75 +83,21 @@ public class ExportCatchContext { CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); - boolean weightComputationSucceeded = true; - - BatchContainer<SpeciesBatch> rootSpeciesBatch = null; - try { - rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(fishingOperationId); - - } 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); + BatchContainer<SpeciesBatch> rootSpeciesBatch = + weightComputingService.getComputedSpeciesBatches(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<BenthosBatch> rootBenthosBatch = + weightComputingService.getComputedBenthosBatches(fishingOperationId); - BatchContainer<MarineLitterBatch> marineLitterBatches; - try { - marineLitterBatches = - weightComputingService.getComputedMarineLitterBatches(fishingOperationId, + BatchContainer<MarineLitterBatch> 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; @@ -188,8 +119,7 @@ public class ExportCatchContext { speciesFrequencies, rootBenthosBatch, benthosFrequencies, - marineLitterBatches, - weightComputationSucceeded); + marineLitterBatches); return result; } @@ -201,8 +131,7 @@ public class ExportCatchContext { Multimap<Species, SpeciesBatchFrequency> speciesFrequencies, BatchContainer<BenthosBatch> rootBenthosBatch, Multimap<Species, BenthosBatchFrequency> benthosFrequencies, - BatchContainer<MarineLitterBatch> marineLitterBatches, - boolean weightComputationSucceeded) { + BatchContainer<MarineLitterBatch> marineLitterBatches) { this.vracPredicate = vracPredicate; this.fishingOperation = fishingOperation; this.catchBatch = catchBatch; @@ -211,7 +140,6 @@ public class ExportCatchContext { this.benthosFrequencies = benthosFrequencies; this.rootBenthosBatch = rootBenthosBatch; this.marineLitterBatches = marineLitterBatches; - this.weightComputationSucceeded = weightComputationSucceeded; } public FishingOperation getFishingOperation() { @@ -249,7 +177,6 @@ public class ExportCatchContext { } public List<ExportBatchEntry> getSpeciesBatchEntry(boolean computeNumber) { - List<ExportBatchEntry> catchList = Lists.newArrayList(); if (withSpeciesBatches()) { @@ -361,8 +288,6 @@ public class ExportCatchContext { } protected float getSpeciesElevationRate() { - float result; - if (weightComputationSucceeded) { float globalRatio = (getCatchTotalWeight() - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); @@ -371,20 +296,14 @@ public class ExportCatchContext { catchBatch.getSpeciesTotalSortedComputedWeight()); // ratio total species weight / total sorted sampled species weight - result = globalRatio * speciesTotalSortedWeight; + float 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(); @@ -393,13 +312,9 @@ public class ExportCatchContext { catchBatch.getBenthosTotalSortedComputedWeight()); // ratio total benthos weight / total sorted sampled benthos weight - result = globalRatio * benthosTotalSortedWeight; + 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 index 1954119..b2aa394 100644 --- 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 @@ -22,8 +22,6 @@ package fr.ifremer.tutti.service.export.toconfirmreport; * #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 @@ -32,7 +30,7 @@ import fr.ifremer.tutti.service.export.ExportBatchEntry; * @author Kevin Morin (Code Lutin) * @since 3.13 */ -public class ToConfirmReportBatchEntry extends ExportBatchEntry { +public class ToConfirmReportBatchEntry { protected final String code; @@ -40,17 +38,27 @@ public class ToConfirmReportBatchEntry extends ExportBatchEntry { protected final String vernacularCode; + protected final String category; + + protected final String categoryWeight; + + protected final String weight; + protected final String comment; public ToConfirmReportBatchEntry(String code, - String scientificName, - String vernacularCode, - String comment) { - super(null); - + String scientificName, + String vernacularCode, + String category, + String categoryWeight, + String weight, + String comment) { this.code = code; this.scientificName = scientificName; this.vernacularCode = vernacularCode; + this.category = category; + this.categoryWeight = categoryWeight; + this.weight = weight; this.comment = comment; } @@ -66,6 +74,18 @@ public class ToConfirmReportBatchEntry extends ExportBatchEntry { return vernacularCode; } + public String getCategory() { + return category; + } + + public String getCategoryWeight() { + return categoryWeight; + } + + public String getWeight() { + return weight; + } + public String getComment() { return comment; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportContext.java new file mode 100644 index 0000000..05f6a25 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportContext.java @@ -0,0 +1,114 @@ +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.persistence.entities.data.BenthosBatch; +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.service.PersistenceService; +import fr.ifremer.tutti.util.Numbers; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.List; + +/** + * Contains the global context for a species confirm report. + * + * @author Kevin Morin (Code Lutin) + * @since 3.13 + */ +public class ToConfirmReportContext { + + private static final Log log = LogFactory.getLog(ToConfirmReportContext.class); + + final FishingOperation fishingOperation; + + final CatchBatch catchBatch; + + final List<SpeciesBatch> speciesBatchToConfirm; + + final List<BenthosBatch> benthosBatchToConfirm; + + public static ToConfirmReportContext newToConfirmReportContext(PersistenceService persistenceService, + String fishingOperationId) { + + FishingOperation fishingOperation = + persistenceService.getFishingOperation(fishingOperationId); + + CatchBatch catchBatch = + persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); + + List<SpeciesBatch> speciesBatchToConfirm = null; + List<BenthosBatch> benthosBatchToConfirm = null; + + if (persistenceService.isFishingOperationWithCatchBatch(fishingOperationId)) { + speciesBatchToConfirm = persistenceService.getAllSpeciesBatchToConfirm(fishingOperationId); + benthosBatchToConfirm = persistenceService.getAllBenthosBatchToConfirm(fishingOperationId); + } + + ToConfirmReportContext result = new ToConfirmReportContext(fishingOperation, + catchBatch, + speciesBatchToConfirm, + benthosBatchToConfirm); + return result; + + } + + private ToConfirmReportContext(FishingOperation fishingOperation, + CatchBatch catchBatch, + List<SpeciesBatch> speciesBatchToConfirm, + List<BenthosBatch> benthosBatchToConfirm) { + this.fishingOperation = fishingOperation; + this.catchBatch = catchBatch; + this.speciesBatchToConfirm = speciesBatchToConfirm; + this.benthosBatchToConfirm = benthosBatchToConfirm; + } + + public FishingOperation getFishingOperation() { + return fishingOperation; + } + + public float getCatchTotalWeight() { + float result = Numbers.getValueOrComputedValue( + catchBatch.getCatchTotalWeight(), + catchBatch.getCatchTotalComputedWeight()); + return result; + } + + public float getCatchTotalSortedWeight() { + return catchBatch.getSpeciesTotalSampleSortedComputedWeight() + + catchBatch.getBenthosTotalSampleSortedComputedWeight() + + catchBatch.getSpeciesTotalUnsortedComputedWeight() + + catchBatch.getBenthosTotalUnsortedComputedWeight(); + } + + public List<SpeciesBatch> getSpeciesBatchToConfirm() { + return speciesBatchToConfirm; + } + + public List<BenthosBatch> getBenthosBatchToConfirm() { + return benthosBatchToConfirm; + } +} 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 index 1356913..94d04e2 100644 --- 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 @@ -13,12 +13,15 @@ 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 fr.ifremer.tutti.type.WeightUnit; +import fr.ifremer.tutti.util.Weights; +import org.apache.commons.collections4.CollectionUtils; 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.List; import java.util.Locale; import java.util.Map; @@ -36,6 +39,9 @@ public class ToConfirmReportService extends AbstractTuttiService { protected PdfGeneratorService pdfGeneratorService; protected WeightComputingService weightComputingService; + protected WeightUnit speciesWeightUnit; + protected WeightUnit benthosWeightUnit; + @Override public void setServiceContext(TuttiServiceContext context) { super.setServiceContext(context); @@ -43,9 +49,12 @@ public class ToConfirmReportService extends AbstractTuttiService { decoratorService = getService(DecoratorService.class); pdfGeneratorService = getService(PdfGeneratorService.class); weightComputingService = getService(WeightComputingService.class); + + speciesWeightUnit = context.getConfig().getSpeciesWeightUnit(); + benthosWeightUnit = context.getConfig().getBenthosWeightUnit(); } - public void createToConfirmReport(String cruiseId, Locale locale) { + public void createToConfirmReport(File file, String cruiseId, Locale locale) { Cruise cruise = persistenceService.getCruise(cruiseId); if (log.isDebugEnabled()) { @@ -56,120 +65,12 @@ public class ToConfirmReportService extends AbstractTuttiService { 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); + generatePdf(file, locale, decoratorService.getDecorator(cruise).toString(cruise), operations); } @@ -177,9 +78,7 @@ public class ToConfirmReportService extends AbstractTuttiService { List<Map<String, Object>> operations) { // get operation and catch data - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); if (!withCatchBatch) { if (log.isWarnEnabled()) { @@ -189,25 +88,21 @@ public class ToConfirmReportService extends AbstractTuttiService { return; } - ExportCatchContext exportCatchContext = ExportCatchContext.newExportContext( + ToConfirmReportContext toConfirmReportContext = ToConfirmReportContext.newToConfirmReportContext( persistenceService, - weightComputingService, - fishingOperationId, - false, - false); + fishingOperationId); // create operation data model - Map<String, Object> op = createOperation(exportCatchContext.getFishingOperation()); + Map<String, Object> op = createOperation(toConfirmReportContext.getFishingOperation()); boolean protocolFilled = context.getDataContext().isProtocolFilled(); // Species - List<ToConfirmReportBatchEntry> speciesCatchList = Lists.newArrayList(); + List<SpeciesAbleBatch> speciesBatchEntries = + new ArrayList<SpeciesAbleBatch>(toConfirmReportContext.getSpeciesBatchToConfirm()); - if (exportCatchContext.withSpeciesBatches()) { - - List<ExportBatchEntry> speciesBatchEntries = - exportCatchContext.getSpeciesBatchEntry(false); + boolean speciesNotEmpty = CollectionUtils.isNotEmpty(speciesBatchEntries); + if (speciesNotEmpty) { Map<Integer, SpeciesProtocol> speciesProtocolMap = null; @@ -215,20 +110,19 @@ public class ToConfirmReportService extends AbstractTuttiService { speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); } - findSpeciesToConfirm(protocolFilled, speciesBatchEntries, speciesCatchList, speciesProtocolMap); - } + List<ToConfirmReportBatchEntry> speciesCatchList = + findSpeciesToConfirm(protocolFilled, speciesWeightUnit, speciesBatchEntries, speciesProtocolMap); - if (!speciesCatchList.isEmpty()) { op.put("speciesCatches", speciesCatchList); } // Benthos - List<ToConfirmReportBatchEntry> benthosCatchList = Lists.newArrayList(); - if (exportCatchContext.withBenthosBatches()) { + List<SpeciesAbleBatch> benthosBatchEntries = + new ArrayList<SpeciesAbleBatch>(toConfirmReportContext.getBenthosBatchToConfirm()); - List<ExportBatchEntry> benthosBatchEntries = - exportCatchContext.getBenthosBatchEntry(false); + boolean benthosNotEmpty = CollectionUtils.isNotEmpty(benthosBatchEntries); + if (benthosNotEmpty) { Map<Integer, SpeciesProtocol> speciesProtocolMap = null; @@ -236,25 +130,25 @@ public class ToConfirmReportService extends AbstractTuttiService { speciesProtocolMap = persistenceService.toBenthosProtocolMap(); } - findSpeciesToConfirm(protocolFilled, benthosBatchEntries, benthosCatchList, speciesProtocolMap); - } + List<ToConfirmReportBatchEntry> benthosCatchList = + findSpeciesToConfirm(protocolFilled, benthosWeightUnit, benthosBatchEntries, speciesProtocolMap); - if (!benthosCatchList.isEmpty()) { op.put("benthosCatches", benthosCatchList); } - if (!speciesCatchList.isEmpty() || !benthosCatchList.isEmpty()) { + if (speciesNotEmpty || benthosNotEmpty) { operations.add(op); } } - protected void findSpeciesToConfirm(boolean protocolFilled, - List<ExportBatchEntry> batchEntries, - List<ToConfirmReportBatchEntry> catchList, - Map<Integer, SpeciesProtocol> speciesProtocolMap) { + protected List<ToConfirmReportBatchEntry> findSpeciesToConfirm(boolean protocolFilled, + WeightUnit weightUnit, + List<SpeciesAbleBatch> batchEntries, + Map<Integer, SpeciesProtocol> speciesProtocolMap) { + + List<ToConfirmReportBatchEntry> catchList = new ArrayList<>(); - for (ExportBatchEntry entry : batchEntries) { - SpeciesAbleBatch batch = entry.getBatch(); + for (SpeciesAbleBatch batch : batchEntries) { Species species = batch.getSpecies(); Species speciesWithVerncularCode = @@ -278,25 +172,38 @@ public class ToConfirmReportService extends AbstractTuttiService { String name = species.getName(); String vernacularCode = speciesWithVerncularCode.getVernacularCode(); - findSpeciesToConfirm(catchList, batch, code, name, vernacularCode); - } - } + Float sampleCategoryWeightValue = weightUnit.fromEntity(batch.getSampleCategoryWeight()); + String sampleCategoryWeight = Weights.getWeightStringValue(sampleCategoryWeightValue); + + Float weightValue = weightUnit.fromEntity(batch.getWeight()); + String weight = Weights.getWeightStringValue(weightValue); - protected void findSpeciesToConfirm(List<ToConfirmReportBatchEntry> catchList, SpeciesAbleBatch batch, String code, String name, String vernacularCode) { - if (batch.isSpeciesToConfirm()) { String comment = batch.getComment(); + + String category = getBatchDecoratedSampleCategoryValue(batch); + + while (batch.getParentBatch() != null) { + batch = batch.getParentBatch(); + category = getBatchDecoratedSampleCategoryValue(batch) + " / " + category; + } + ToConfirmReportBatchEntry reportEntry = new ToConfirmReportBatchEntry(code, name, vernacularCode, + category, + sampleCategoryWeight, + weight, comment); catchList.add(reportEntry); + } - } else if (!batch.isChildBatchsEmpty()) { + return catchList; + } - for (SpeciesAbleBatch speciesAbleBatch : batch.getChildBatchs()) { - findSpeciesToConfirm(catchList, speciesAbleBatch, code, name, vernacularCode); - } - } + protected String getBatchDecoratedSampleCategoryValue(SpeciesAbleBatch batch) { + Serializable sampleCategoryValue = batch.getSampleCategoryValue(); + String decoratedCategory = decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue); + return decoratedCategory; } protected Map<String, Object> createOperation(FishingOperation fishingOperation) { @@ -313,6 +220,9 @@ public class ToConfirmReportService extends AbstractTuttiService { protected void generatePdf(File targetFile, Locale locale, String cruiseName, List<Map<String, Object>> operations) { Map<String, Object> data = Maps.newHashMap(); + data.put("cruise", cruiseName); + data.put("speciesWeightUnit", speciesWeightUnit); + data.put("benthosWeightUnit", benthosWeightUnit); data.put("operations", operations); 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 40068fa..409276c 100644 --- a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl +++ b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl @@ -35,6 +35,10 @@ font-style: italic; } + table { + border-collapse: collapse; + } + th { color: ${blueColor}; font-weight: bold; @@ -42,6 +46,8 @@ td, th { padding-right: 10pt; + border-left: 1px solid black; + border-right: 1px solid black; } td.number { @@ -65,6 +71,7 @@ <body> <h1>Rapport des espèces à confirmer</h1> + <h2>${cruise}</h2> <#assign orderedOperations = operations?sort_by("startDate")?reverse> <#list orderedOperations as operation> @@ -86,17 +93,21 @@ <th>Espèce</th> <th>Nom scientifique</th> <th>Nom commun</th> - <th>Trié (kg)</th> + <th>Catégorie</th> + <th>Poids (${speciesWeightUnit.shortLabel})</th> + <th>Poids sous-échantilloné (${speciesWeightUnit.shortLabel})</th> <th>Commentaire</th> </tr> </thead> <tbody> - <#list operation.speciesCatches?sort_by("sortedWeight")?reverse as catch> + <#list operation.speciesCatches 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>${catch.category}</td> + <td class="number">${catch.categoryWeight}</td> + <td class="number">${catch.weight}</td> <td><#if catch.comment??>${catch.comment?html}</#if></td> </tr> </#list> @@ -112,17 +123,21 @@ <th>Espèce</th> <th>Nom scientifique</th> <th>Nom commun</th> - <th>Trié (kg)</th> + <th>Catégorie</th> + <th>Poids (${benthosWeightUnit.shortLabel})</th> + <th>Poids sous-échantilloné (${benthosWeightUnit.shortLabel})</th> <th>Commentaire</th> </tr> </thead> <tbody> - <#list operation.benthosCatches?sort_by("sortedWeight")?reverse as catch> + <#list operation.benthosCatches 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>${catch.category}</td> + <td class="number">${catch.categoryWeight}</td> + <td class="number">${catch.weight}</td> <td><#if catch.comment??>${catch.comment?html}</#if></td> </tr> </#list> 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 0f64476..f127046 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 @@ -56,19 +56,19 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc boolean doAction = super.prepareAction(); -// if (doAction) { -// -// Cruise cruise = getDataContext().getCruise(); -// // choose file to export -// file = saveFile( -// "exportCruise-" + cruise.getName(), -// "pdf", -// t("tutti.sendCruiseReport.title.choose.exportFile"), -// t("tutti.sendCruiseReport.action.chooseFile"), -// "^.+\\.pdf$", t("tutti.common.file.pdf") -// ); -// doAction = file != null; -// } + if (doAction) { + + Cruise cruise = getDataContext().getCruise(); + // choose file to export + file = saveFile( + "toConfirm-" + cruise.getName(), + "pdf", + t("tutti.speciesToConfirmReport.title.choose.exportFile"), + t("tutti.speciesToConfirmReport.action.chooseFile"), + "^.+\\.pdf$", t("tutti.common.file.pdf") + ); + doAction = file != null; + } return doAction; } @@ -82,7 +82,7 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc public void doAction() throws Exception { Cruise cruise = getDataContext().getCruise(); Preconditions.checkNotNull(cruise); -// Preconditions.checkNotNull(file); + Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { log.info("Will export cruise " + cruise.getId() + @@ -91,7 +91,7 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc // create report ToConfirmReportService toConfirmReportService = getContext().getToConfirmReportService(); - toConfirmReportService.createToConfirmReport(cruise.getId(), getConfig().getI18nLocale()); + toConfirmReportService.createToConfirmReport(file, cruise.getId(), getConfig().getI18nLocale()); } 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 f62e1ce..a236f1f 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 @@ -1814,6 +1814,8 @@ tutti.sendCruiseReport.title.choose.exportFile= tutti.species.name.tip= tutti.species.refTaxCode.tip= tutti.species.surveyCode.tip= +tutti.speciesToConfirmReport.action.chooseFile= +tutti.speciesToConfirmReport.title.choose.exportFile= tutti.splitBenthosBatch.action.cancel= tutti.splitBenthosBatch.action.cancel.mnemonic= tutti.splitBenthosBatch.action.cancel.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 442ddd2..686646d 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 @@ -1714,6 +1714,8 @@ tutti.sendCruiseReport.title.choose.exportFile=Envoyer les captures de la campag tutti.species.name.tip=Nom scientifique tutti.species.refTaxCode.tip=Code Rubin tutti.species.surveyCode.tip=Code campagne ou code rubin +tutti.speciesToConfirmReport.action.chooseFile=Choisir le fichier de rapport +tutti.speciesToConfirmReport.title.choose.exportFile=Rapport des espèces à confirmer tutti.splitBenthosBatch.action.cancel=Annuler tutti.splitBenthosBatch.action.cancel.mnemonic=A tutti.splitBenthosBatch.action.cancel.tip=Annuler le sous-échantillonnage -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.