branch feature/6575 updated (47f83be -> 0a01441)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6575 in repository tutti. See http://git.codelutin.com/tutti.git from 47f83be add species code, name and vernacular name + catch comment adds 34486ea fix NPE new e039703 Merge branch 'develop' of https://git.codelutin.com/tutti into feature/6575 new fe84276 ajout des catégories new 0a01441 mise en page du pdf 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 0a0144160f2afdf4faef3d6c780dbb571f951dc5 Author: Kevin Morin <morin@codelutin.com> Date: Fri Feb 6 17:50:15 2015 +0100 mise en page du pdf commit fe84276065ca0214635966e59b154b5e710b3d1f Author: Kevin Morin <morin@codelutin.com> Date: Fri Feb 6 14:12:10 2015 +0100 ajout des catégories commit e039703efe679be1f78ebe2de8f2ea478863cff5 Merge: 47f83be 34486ea Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 18:41:57 2015 +0100 Merge branch 'develop' of https://git.codelutin.com/tutti into feature/6575 Summary of changes: .../tutti/service/export/ExportCatchContext.java | 107 ++-------- .../toconfirmreport/ToConfirmReportBatchEntry.java | 36 +++- .../toconfirmreport/ToConfirmReportContext.java | 114 +++++++++++ .../toconfirmreport/ToConfirmReportService.java | 218 ++++++--------------- .../resources/ftl/toConfirmSpeciesReport_fr.ftl | 101 +++++++--- .../SpeciesToConfirmReportForCruiseAction.java | 36 ++-- .../resources/i18n/tutti-ui-swing_en_GB.properties | 3 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 3 + 8 files changed, 320 insertions(+), 298 deletions(-) create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportContext.java -- 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/6575 in repository tutti. See http://git.codelutin.com/tutti.git commit e039703efe679be1f78ebe2de8f2ea478863cff5 Merge: 47f83be 34486ea Author: Kevin Morin <morin@codelutin.com> Date: Thu Feb 5 18:41:57 2015 +0100 Merge branch 'develop' of https://git.codelutin.com/tutti into feature/6575 -- 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/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>.
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 0a0144160f2afdf4faef3d6c780dbb571f951dc5 Author: Kevin Morin <morin@codelutin.com> Date: Fri Feb 6 17:50:15 2015 +0100 mise en page du pdf --- .../resources/ftl/toConfirmSpeciesReport_fr.ftl | 102 ++++++++++++++------- .../SpeciesToConfirmReportForCruiseAction.java | 8 +- .../resources/i18n/tutti-ui-swing_en_GB.properties | 1 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 1 + 4 files changed, 78 insertions(+), 34 deletions(-) diff --git a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl index 409276c..6899217 100644 --- a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl +++ b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl @@ -26,6 +26,7 @@ <style type="text/css"> <#assign blueColor="#000080"> + <#assign lightGrayColor="#f2f2f2"> @page { size: A4 landscape;} @@ -35,25 +36,60 @@ font-style: italic; } + h2 { + margin-bottom: 50pt; + } + table { + margin-bottom: 25pt; border-collapse: collapse; } th { color: ${blueColor}; font-weight: bold; + background: ${lightGrayColor}; } td, th { - padding-right: 10pt; - border-left: 1px solid black; - border-right: 1px solid black; + padding: 1pt 5pt; + border-left: 1px solid #ccc; + border-right: 1px solid #ccc; + } + + tbody tr:nth-child(even) { + background: ${lightGrayColor}; + } + tbody tr:nth-child(odd) { + background: #fff; } td.number { text-align: right; } + .species { + width: 10%; + } + .scientificName { + width: 18%; + } + .vernacular { + width: 17%; + } + .category { + width: 15%; + } + .categoryWeight { + width: 10%; + } + .weight { + width: 10%; + } + .comment { + width: 20%; + } + .operationInfo { font-weight: bold; } @@ -86,29 +122,29 @@ </p> <#if operation.speciesCatches??> + <h3>Espèces</h3> <table> - <caption>Espèces</caption> <thead> <tr> - <th>Espèce</th> - <th>Nom scientifique</th> - <th>Nom commun</th> - <th>Catégorie</th> - <th>Poids (${speciesWeightUnit.shortLabel})</th> - <th>Poids sous-échantilloné (${speciesWeightUnit.shortLabel})</th> - <th>Commentaire</th> + <th class="species">Espèce</th> + <th class="scientificName">Nom scientifique</th> + <th class="vernacular">Nom commun</th> + <th class="category">Catégorie</th> + <th class="categoryWeight">Poids (${speciesWeightUnit.shortLabel})</th> + <th class="weight">Poids sous échantilloné (${speciesWeightUnit.shortLabel})</th> + <th class="comment">Commentaire</th> </tr> </thead> <tbody> <#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>${catch.category}</td> - <td class="number">${catch.categoryWeight}</td> - <td class="number">${catch.weight}</td> - <td><#if catch.comment??>${catch.comment?html}</#if></td> + <td class="species"><#if catch.code??>${catch.code}</#if></td> + <td class="scientificName"><em>${catch.scientificName}</em></td> + <td class="vernacular"><#if catch.vernacularCode??>${catch.vernacularCode}</#if></td> + <td class="category">${catch.category}</td> + <td class="number categoryWeight">${catch.categoryWeight}</td> + <td class="number weight">${catch.weight}</td> + <td class="comment"><#if catch.comment??>${catch.comment?html}</#if></td> </tr> </#list> </tbody> @@ -116,29 +152,29 @@ </#if> <#if operation.benthosCatches??> + <h3>Benthos</h3> <table> - <caption>Benthos</caption> <thead> <tr> - <th>Espèce</th> - <th>Nom scientifique</th> - <th>Nom commun</th> - <th>Catégorie</th> - <th>Poids (${benthosWeightUnit.shortLabel})</th> - <th>Poids sous-échantilloné (${benthosWeightUnit.shortLabel})</th> - <th>Commentaire</th> + <th class="species">Espèce</th> + <th class="scientificName">Nom scientifique</th> + <th class="vernacular">Nom commun</th> + <th class="category">Catégorie</th> + <th class="categoryWeight">Poids (${benthosWeightUnit.shortLabel})</th> + <th class="weight">Poids sous échantilloné (${benthosWeightUnit.shortLabel})</th> + <th class="comment">Commentaire</th> </tr> </thead> <tbody> <#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>${catch.category}</td> - <td class="number">${catch.categoryWeight}</td> - <td class="number">${catch.weight}</td> - <td><#if catch.comment??>${catch.comment?html}</#if></td> + <td class="species"><#if catch.code??>${catch.code}</#if></td> + <td class="scientificName"><em>${catch.scientificName}</em></td> + <td class="vernacular"><#if catch.vernacularCode??>${catch.vernacularCode}</#if></td> + <td class="category">${catch.category}</td> + <td class="number categoryWeight">${catch.categoryWeight}</td> + <td class="number weight">${catch.weight}</td> + <td class="comment"><#if catch.comment??>${catch.comment?html}</#if></td> </tr> </#list> </tbody> 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 f127046..7f5812a 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 @@ -30,6 +30,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import static org.nuiton.i18n.I18n.t; @@ -45,6 +48,8 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc private static final Log log = LogFactory.getLog(SpeciesToConfirmReportForCruiseAction.class); + public static final DateFormat df = new SimpleDateFormat("yyyyMMddHHmm"); + protected File file; public SpeciesToConfirmReportForCruiseAction(MainUIHandler handler) { @@ -60,8 +65,9 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc Cruise cruise = getDataContext().getCruise(); // choose file to export + String now = df.format(new Date()); file = saveFile( - "toConfirm-" + cruise.getName(), + t("tutti.speciesToConfirmReport.fileName.default", cruise.getName(), now), "pdf", t("tutti.speciesToConfirmReport.title.choose.exportFile"), t("tutti.speciesToConfirmReport.action.chooseFile"), 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 a236f1f..a48299d 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 @@ -1815,6 +1815,7 @@ tutti.species.name.tip= tutti.species.refTaxCode.tip= tutti.species.surveyCode.tip= tutti.speciesToConfirmReport.action.chooseFile= +tutti.speciesToConfirmReport.fileName.default= tutti.speciesToConfirmReport.title.choose.exportFile= tutti.splitBenthosBatch.action.cancel= tutti.splitBenthosBatch.action.cancel.mnemonic= 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 686646d..31f0931 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 @@ -1715,6 +1715,7 @@ 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.fileName.default=Especes_a_confirmer_%1$s_%2$s tutti.speciesToConfirmReport.title.choose.exportFile=Rapport des espèces à confirmer tutti.splitBenthosBatch.action.cancel=Annuler tutti.splitBenthosBatch.action.cancel.mnemonic=A -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm