This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 34ff86b8bc4a97fb489ac6c97cb64644f02e4fc1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Feb 9 15:30:22 2015 +0100 code review on refs #6575 (Use objects please) --- ...try.java => ToConfirmReportBatchEntryBean.java} | 34 ++-- .../toconfirmreport/ToConfirmReportBean.java | 55 +++++++ .../toconfirmreport/ToConfirmReportContext.java | 114 ------------- .../ToConfirmReportFishingOperationBean.java | 60 +++++++ .../ToConfirmReportFishingOperationData.java | 117 ++++++++++++++ .../toconfirmreport/ToConfirmReportOperation.java | 50 ------ .../toconfirmreport/ToConfirmReportService.java | 178 +++++++++------------ .../resources/ftl/toConfirmSpeciesReport_fr.ftl | 14 +- .../resources/i18n/tutti-service_en_GB.properties | 6 + .../resources/i18n/tutti-service_fr_FR.properties | 4 + .../SpeciesToConfirmReportForCruiseAction.java | 15 +- 11 files changed, 346 insertions(+), 301 deletions(-) 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/ToConfirmReportBatchEntryBean.java similarity index 69% rename from tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBatchEntry.java rename to tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBatchEntryBean.java index b2aa394..9be6ca5 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/ToConfirmReportBatchEntryBean.java @@ -22,6 +22,9 @@ package fr.ifremer.tutti.service.export.toconfirmreport; * #L% */ +import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Speciess; + /** * To store a species or batch entry within his speices informations, * his sorted weight, total weight and percentage amoong the total catch @@ -30,13 +33,9 @@ package fr.ifremer.tutti.service.export.toconfirmreport; * @author Kevin Morin (Code Lutin) * @since 3.13 */ -public class ToConfirmReportBatchEntry { - - protected final String code; +public class ToConfirmReportBatchEntryBean { - protected final String scientificName; - - protected final String vernacularCode; + private final Species species; protected final String category; @@ -46,16 +45,12 @@ public class ToConfirmReportBatchEntry { protected final String comment; - public ToConfirmReportBatchEntry(String code, - String scientificName, - String vernacularCode, - String category, - String categoryWeight, - String weight, - String comment) { - this.code = code; - this.scientificName = scientificName; - this.vernacularCode = vernacularCode; + public ToConfirmReportBatchEntryBean(Species species, + String category, + String categoryWeight, + String weight, + String comment) { + this.species = species; this.category = category; this.categoryWeight = categoryWeight; this.weight = weight; @@ -63,15 +58,15 @@ public class ToConfirmReportBatchEntry { } public String getCode() { - return code; + return Speciess.getSurveyCodeOrRefTaxCode(species); } public String getScientificName() { - return scientificName; + return species.getName(); } public String getVernacularCode() { - return vernacularCode; + return species.getVernacularCode(); } public String getCategory() { @@ -89,4 +84,5 @@ public class ToConfirmReportBatchEntry { public String getComment() { return comment; } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBean.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBean.java new file mode 100644 index 0000000..2d3a35c --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportBean.java @@ -0,0 +1,55 @@ +package fr.ifremer.tutti.service.export.toconfirmreport; + +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.type.WeightUnit; + +import java.util.LinkedList; +import java.util.List; + +/** + * To store the cruise and fishing operation to report. + * + * Created on 2/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.13 + */ +public class ToConfirmReportBean { + + private final Cruise cruise; + + private final WeightUnit speciesWeightUnit; + + private final WeightUnit benthosWeightUnit; + + private final List<ToConfirmReportFishingOperationBean> operations; + + public ToConfirmReportBean(Cruise cruise, + WeightUnit speciesWeightUnit, + WeightUnit benthosWeightUnit) { + this.cruise = cruise; + this.speciesWeightUnit = speciesWeightUnit; + this.benthosWeightUnit = benthosWeightUnit; + this.operations = new LinkedList<>(); + } + + public Cruise getCruise() { + return cruise; + } + + public WeightUnit getSpeciesWeightUnit() { + return speciesWeightUnit; + } + + public WeightUnit getBenthosWeightUnit() { + return benthosWeightUnit; + } + + public void addOperation(ToConfirmReportFishingOperationBean operation) { + operations.add(operation); + } + + public List<ToConfirmReportFishingOperationBean> getOperations() { + return operations; + } +} 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 deleted file mode 100644 index 05f6a25..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportContext.java +++ /dev/null @@ -1,114 +0,0 @@ -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/ToConfirmReportFishingOperationBean.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationBean.java new file mode 100644 index 0000000..2b62c7a --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationBean.java @@ -0,0 +1,60 @@ +package fr.ifremer.tutti.service.export.toconfirmreport; + +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; + +import java.util.Date; +import java.util.List; + +/** + * To store an fishing operation data and his species or benthos batch entries to report. + * + * Created on 2/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.13 + */ +public class ToConfirmReportFishingOperationBean { + + private final FishingOperation fishingOperation; + + private final List<ToConfirmReportBatchEntryBean> speciesCatches; + + private final List<ToConfirmReportBatchEntryBean> benthosCatches; + + public ToConfirmReportFishingOperationBean(FishingOperation fishingOperation, + List<ToConfirmReportBatchEntryBean> speciesCatches, + List<ToConfirmReportBatchEntryBean> benthosCatches) { + this.fishingOperation = fishingOperation; + this.speciesCatches = speciesCatches; + this.benthosCatches = benthosCatches; + } + + public Integer getFishingOperationNumber() { + return fishingOperation.getFishingOperationNumber(); + } + + public String getStationNumber() { + return fishingOperation.getStationNumber(); + } + + public Date getGearShootingStartDate() { + return fishingOperation.getGearShootingStartDate(); + } + + public Date getGearShootingEndDate() { + return fishingOperation.getGearShootingEndDate(); + } + + public String getMultirigAggregation() { + return fishingOperation.getMultirigAggregation(); + } + + public List<ToConfirmReportBatchEntryBean> getSpeciesCatches() { + return speciesCatches; + } + + public List<ToConfirmReportBatchEntryBean> getBenthosCatches() { + return benthosCatches; + } + +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java new file mode 100644 index 0000000..aeaa300 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportFishingOperationData.java @@ -0,0 +1,117 @@ +package fr.ifremer.tutti.service.export.toconfirmreport; + +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 org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.List; + +/** + * Contains a fishing operation data need to get species or benthos batch to report. + * + * Created on 2/9/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.13 + */ +public class ToConfirmReportFishingOperationData { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ToConfirmReportFishingOperationData.class); + + public static ToConfirmReportFishingOperationData create(PersistenceService persistenceService, + String fishingOperationId) { + + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); + + ToConfirmReportFishingOperationData result; + + if (!withCatchBatch) { + + if (log.isWarnEnabled()) { + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); + } + result = null; + + } else { + + FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); + + CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); + + List<SpeciesBatch> speciesBatchToConfirm = persistenceService.getAllSpeciesBatchToConfirm(fishingOperationId); + + List<BenthosBatch> benthosBatchToConfirm = persistenceService.getAllBenthosBatchToConfirm(fishingOperationId); + + if (CollectionUtils.isEmpty(speciesBatchToConfirm) && CollectionUtils.isEmpty(benthosBatchToConfirm)) { + + if (log.isInfoEnabled()) { + log.info("No species nor benthos to confirm for fishing operation: " + fishingOperationId); + } + result = null; + + } else { + + if (log.isInfoEnabled()) { + log.info("Found some species or benthos to confirm for fishing operation: " + fishingOperationId); + } + result = new ToConfirmReportFishingOperationData(fishingOperation, + catchBatch, + speciesBatchToConfirm, + benthosBatchToConfirm); + } + + } + + return result; + + } + + final FishingOperation fishingOperation; + + final CatchBatch catchBatch; + + final List<SpeciesBatch> speciesBatchToConfirm; + + final List<BenthosBatch> benthosBatchToConfirm; + + public FishingOperation getFishingOperation() { + return fishingOperation; + } + + public CatchBatch getCatchBatch() { + return catchBatch; + } + + public List<SpeciesBatch> getSpeciesBatchToConfirm() { + return speciesBatchToConfirm; + } + + public boolean isWithSpeciesBatchToConfirm() { + return CollectionUtils.isNotEmpty(speciesBatchToConfirm); + } + + public List<BenthosBatch> getBenthosBatchToConfirm() { + return benthosBatchToConfirm; + } + + public boolean isWithBenthosBatchToConfirm() { + return CollectionUtils.isNotEmpty(benthosBatchToConfirm); + } + + private ToConfirmReportFishingOperationData(FishingOperation fishingOperation, + CatchBatch catchBatch, + List<SpeciesBatch> speciesBatchToConfirm, + List<BenthosBatch> benthosBatchToConfirm) { + this.fishingOperation = fishingOperation; + this.catchBatch = catchBatch; + this.speciesBatchToConfirm = speciesBatchToConfirm; + this.benthosBatchToConfirm = benthosBatchToConfirm; + } + +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java deleted file mode 100644 index 0ca07f5..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportOperation.java +++ /dev/null @@ -1,50 +0,0 @@ -package fr.ifremer.tutti.service.export.toconfirmreport; - -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; - -import java.util.List; - -/** - * @author Kevin Morin (Code Lutin) - * @since 3.13 - */ -public class ToConfirmReportOperation { - - protected String operation; - protected List<SpeciesBatch> speciesBatches; - protected List<BenthosBatch> benthosBatches; - - public ToConfirmReportOperation() { - } - - public ToConfirmReportOperation(String operation, List<SpeciesBatch> speciesBatches, List<BenthosBatch> benthosBatches) { - this.operation = operation; - this.speciesBatches = speciesBatches; - this.benthosBatches = benthosBatches; - } - - public String getOperation() { - return operation; - } - - public void setOperation(String operation) { - this.operation = operation; - } - - public List<SpeciesBatch> getSpeciesBatches() { - return speciesBatches; - } - - public void setSpeciesBatches(List<SpeciesBatch> speciesBatches) { - this.speciesBatches = speciesBatches; - } - - public List<BenthosBatch> getBenthosBatches() { - return benthosBatches; - } - - public void setBenthosBatches(List<BenthosBatch> benthosBatches) { - this.benthosBatches = benthosBatches; - } -} 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 94d04e2..d7219ee 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 @@ -1,21 +1,20 @@ package fr.ifremer.tutti.service.export.toconfirmreport; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import fr.ifremer.tutti.persistence.ProgressionModel; +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.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; +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.SpeciesMap; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; 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; @@ -24,7 +23,8 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.Map; + +import static org.nuiton.i18n.I18n.t; /** * @author Kevin Morin (Code Lutin) @@ -35,11 +35,15 @@ 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; protected WeightUnit speciesWeightUnit; + protected WeightUnit benthosWeightUnit; @Override @@ -54,123 +58,102 @@ public class ToConfirmReportService extends AbstractTuttiService { benthosWeightUnit = context.getConfig().getBenthosWeightUnit(); } - public void createToConfirmReport(File file, String cruiseId, Locale locale) { + public int getNumberOfSteps(String cruiseId) { + + List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); + return allFishingOperation.size() + 3; + + } + + public void createToConfirmReport(File file, String cruiseId, ProgressionModel progressionModel) { + + progressionModel.increments(t("tutti.toconfirmReport.loading.cruise", cruiseId)); Cruise cruise = persistenceService.getCruise(cruiseId); if (log.isDebugEnabled()) { log.debug("Cruise " + decoratorService.getDecorator(cruise).toString(cruise)); } - List<String> allFishingOperation = - persistenceService.getAllFishingOperationIds(cruiseId); + progressionModel.increments(t("tutti.toconfirmReport.loading.protocol")); - List<Map<String, Object>> operations = Lists.newArrayList(); + SpeciesMap speciesMap = SpeciesMap.create(context.getDataContext(), persistenceService); - for (String operationId : allFishingOperation) { - prepareOperation(operationId, operations); - } + List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); - generatePdf(file, locale, decoratorService.getDecorator(cruise).toString(cruise), operations); + ToConfirmReportBean reportBean = new ToConfirmReportBean(cruise, speciesWeightUnit, benthosWeightUnit); - } + int currentOperation = 1; + int nbOperations = allFishingOperation.size(); + + for (String operationId : allFishingOperation) { - protected void prepareOperation(String fishingOperationId, - List<Map<String, Object>> operations) { + progressionModel.increments(t("tutti.toconfirmReport.loading.operation", operationId, currentOperation++, nbOperations)); - // get operation and catch data - boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); + ToConfirmReportFishingOperationData fishingOperationData = + ToConfirmReportFishingOperationData.create(persistenceService, operationId); - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + if (fishingOperationData != null) { + + ToConfirmReportFishingOperationBean operationBean = createOperationBean(fishingOperationData, speciesMap); + reportBean.addOperation(operationBean); } - return; + } - ToConfirmReportContext toConfirmReportContext = ToConfirmReportContext.newToConfirmReportContext( - persistenceService, - fishingOperationId); + progressionModel.increments(t("tutti.toconfirmReport.generate.report")); - // create operation data model - Map<String, Object> op = createOperation(toConfirmReportContext.getFishingOperation()); + generatePdf(file, reportBean); + + } - boolean protocolFilled = context.getDataContext().isProtocolFilled(); + protected ToConfirmReportFishingOperationBean createOperationBean(ToConfirmReportFishingOperationData fishingOperationData, + SpeciesMap speciesMap) { // Species - List<SpeciesAbleBatch> speciesBatchEntries = - new ArrayList<SpeciesAbleBatch>(toConfirmReportContext.getSpeciesBatchToConfirm()); - boolean speciesNotEmpty = CollectionUtils.isNotEmpty(speciesBatchEntries); - if (speciesNotEmpty) { + List<ToConfirmReportBatchEntryBean> speciesCatchList; - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; + if (fishingOperationData.isWithSpeciesBatchToConfirm()) { - if (protocolFilled) { - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - } + List<SpeciesBatch> speciesBatchEntries = fishingOperationData.getSpeciesBatchToConfirm(); + speciesMap.loadSpecies(speciesBatchEntries); + speciesCatchList = createBatchBeans(speciesWeightUnit, speciesBatchEntries); - List<ToConfirmReportBatchEntry> speciesCatchList = - findSpeciesToConfirm(protocolFilled, speciesWeightUnit, speciesBatchEntries, speciesProtocolMap); + } else { - op.put("speciesCatches", speciesCatchList); + speciesCatchList = null; } // Benthos - List<SpeciesAbleBatch> benthosBatchEntries = - new ArrayList<SpeciesAbleBatch>(toConfirmReportContext.getBenthosBatchToConfirm()); - - boolean benthosNotEmpty = CollectionUtils.isNotEmpty(benthosBatchEntries); - if (benthosNotEmpty) { + List<ToConfirmReportBatchEntryBean> benthosCatchList; - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; + if (fishingOperationData.isWithBenthosBatchToConfirm()) { - if (protocolFilled) { - speciesProtocolMap = persistenceService.toBenthosProtocolMap(); - } + List<BenthosBatch> benthosBatchEntries = fishingOperationData.getBenthosBatchToConfirm(); + speciesMap.loadBenthos(benthosBatchEntries); + benthosCatchList = createBatchBeans(benthosWeightUnit, benthosBatchEntries); - List<ToConfirmReportBatchEntry> benthosCatchList = - findSpeciesToConfirm(protocolFilled, benthosWeightUnit, benthosBatchEntries, speciesProtocolMap); + } else { - op.put("benthosCatches", benthosCatchList); + benthosCatchList = null; } - if (speciesNotEmpty || benthosNotEmpty) { - operations.add(op); - } + ToConfirmReportFishingOperationBean op = new ToConfirmReportFishingOperationBean(fishingOperationData.getFishingOperation(), + speciesCatchList, + benthosCatchList); + + return op; + } - protected List<ToConfirmReportBatchEntry> findSpeciesToConfirm(boolean protocolFilled, - WeightUnit weightUnit, - List<SpeciesAbleBatch> batchEntries, - Map<Integer, SpeciesProtocol> speciesProtocolMap) { + protected <A extends SpeciesAbleBatch> List<ToConfirmReportBatchEntryBean> createBatchBeans(WeightUnit weightUnit, List<A> batchEntries) { - List<ToConfirmReportBatchEntry> catchList = new ArrayList<>(); + List<ToConfirmReportBatchEntryBean> catchList = new ArrayList<>(); for (SpeciesAbleBatch batch : batchEntries) { 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(); Float sampleCategoryWeightValue = weightUnit.fromEntity(batch.getSampleCategoryWeight()); String sampleCategoryWeight = Weights.getWeightStringValue(sampleCategoryWeightValue); @@ -187,13 +170,11 @@ public class ToConfirmReportService extends AbstractTuttiService { category = getBatchDecoratedSampleCategoryValue(batch) + " / " + category; } - ToConfirmReportBatchEntry reportEntry = new ToConfirmReportBatchEntry(code, - name, - vernacularCode, - category, - sampleCategoryWeight, - weight, - comment); + ToConfirmReportBatchEntryBean reportEntry = new ToConfirmReportBatchEntryBean(species, + category, + sampleCategoryWeight, + weight, + comment); catchList.add(reportEntry); } @@ -206,26 +187,11 @@ public class ToConfirmReportService extends AbstractTuttiService { return decoratedCategory; } - 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) { + protected void generatePdf(File targetFile, ToConfirmReportBean reportBean) { - Map<String, Object> data = Maps.newHashMap(); - data.put("cruise", cruiseName); - data.put("speciesWeightUnit", speciesWeightUnit); - data.put("benthosWeightUnit", benthosWeightUnit); - data.put("operations", operations); + Locale locale = context.getConfig().getI18nLocale(); - pdfGeneratorService.generatePdf(targetFile, locale, "toConfirmSpeciesReport.ftl", data); + pdfGeneratorService.generatePdf(targetFile, locale, "toConfirmSpeciesReport.ftl", reportBean); } } diff --git a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl index 6899217..72d490c 100644 --- a/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl +++ b/tutti-service/src/main/resources/ftl/toConfirmSpeciesReport_fr.ftl @@ -1,8 +1,6 @@ <#-- #%L Tutti :: Service - $Id$ - $HeadURL$ %% Copyright (C) 2012 - 2014 Ifremer %% @@ -107,17 +105,17 @@ <body> <h1>Rapport des espèces à confirmer</h1> - <h2>${cruise}</h2> + <h2>${cruise.name}</h2> - <#assign orderedOperations = operations?sort_by("startDate")?reverse> + <#assign orderedOperations = operations?sort_by("gearShootingStartDate")?reverse> <#list orderedOperations as operation> <p class='operationInfo'> - <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">Station :</span> <span class="value">${operation.stationNumber} - ${operation.fishingOperationNumber}</span> + <span class="label">Poche :</span> <span class="value">${operation.multirigAggregation}</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> + du ${operation.gearShootingStartDate?date?string.full} ${operation.gearShootingStartDate?time?string.short} + <#if operation.gearShootingEndDate??>au ${operation.gearShootingEndDate?date?string.full} ${operation.gearShootingEndDate?time?string.short}</#if> </span> </p> diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index 6dcc7c5..91dc1b2 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -283,6 +283,12 @@ tutti.service.validateCruise.exportResult.error= tutti.service.validateCruise.operations.check= tutti.service.validateCruise.operations.loading= tutti.service.validateCruise.operations.progress= +tutti.toconfirmReport.generate.report= +tutti.toconfirmReport.loading.cruise= +tutti.toconfirmReport.loading.fishingOperation= +tutti.toconfirmReport.loading.operation= +tutti.toconfirmReport.loading.protocol= +tutti.toconfirmReport.start.fishingOperation= tutti.validator.error.accidental.species.required= tutti.validator.error.accidentalBatch.species.required= tutti.validator.error.accidentalBatch.species.temporary= diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index abe02d5..221c6fe 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -253,6 +253,10 @@ tutti.service.validateCruise.cruise.loading=chargement de la campagne d'identifi tutti.service.validateCruise.exportResult.error=Erreur lors de l'export des résultats de validation de la campagne dans le fichier %s tutti.service.validateCruise.operations.check=Vérification du trait %s (%s) tutti.service.validateCruise.operations.loading=Chargement du trait d'identifiant %s +tutti.toconfirmReport.generate.report=Génération du rapport +tutti.toconfirmReport.loading.cruise=Chargement de la campagne %s +tutti.toconfirmReport.loading.operation=Chargement des données du trait %s ( %s / %s ) +tutti.toconfirmReport.loading.protocol=Chargement du protocol tutti.validator.error.accidentalBatch.species.required=L'espèce est obligatoire tutti.validator.error.accidentalBatch.species.temporary=La capture accidentelle utilise une espèce temporaire tutti.validator.error.benthosBatch.species.required=L'espèce est obligatoire 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 7f5812a..57bb7f2 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 @@ -23,6 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.service.export.toconfirmreport.ToConfirmReportService; import fr.ifremer.tutti.ui.swing.content.MainUIHandler; @@ -75,6 +76,7 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc ); doAction = file != null; } + return doAction; } @@ -91,13 +93,18 @@ public class SpeciesToConfirmReportForCruiseAction extends AbstractMainUITuttiAc Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will export cruise " + cruise.getId() + - " to file: " + file); + log.info("Will export cruise " + cruise.getId() + " to file: " + file); } - // create report ToConfirmReportService toConfirmReportService = getContext().getToConfirmReportService(); - toConfirmReportService.createToConfirmReport(file, cruise.getId(), getConfig().getI18nLocale()); + + int nbSteps = toConfirmReportService.getNumberOfSteps(getDataContext().getCruiseId()); + createProgressionModelIfRequired(1); + + ProgressionModel progressionModel = getProgressionModel(); + progressionModel.adaptTotal(nbSteps); + + toConfirmReportService.createToConfirmReport(file, cruise.getId(), progressionModel); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.