branch develop updated (f88907d -> e68e5ae)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from f88907d fix loading protocol, remove too much stuff new 56a11f0 pas de write si pas de données new e68e5ae amélioration de l'export générique (meilleur découpage de l'export + progression plus fluide) The 2 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 e68e5aea927242ad2b0f5b5a1442c398d515db6b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 18 15:30:47 2015 +0100 amélioration de l'export générique (meilleur découpage de l'export + progression plus fluide) commit 56a11f04f53b263398585d80d27760c50232cd50 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 18 15:29:37 2015 +0100 pas de write si pas de données Summary of changes: .../service/catches/WeightComputingService.java | 97 ---- .../fr/ifremer/tutti/service/csv/CsvProducer.java | 14 +- .../genericformat/GenericFormatExportContext.java | 62 ++- .../GenericFormatExportOperationContext.java | 74 +++ .../genericformat/GenericFormatExportService.java | 497 +++++++++++---------- .../resources/i18n/tutti-service_en_GB.properties | 7 + .../resources/i18n/tutti-service_fr_FR.properties | 17 +- .../GenericFormatExportServiceTest.java | 59 ++- .../action/ExportGenericFormatCruiseAction.java | 12 +- .../ExportGenericFormatProgramCruisesAction.java | 11 +- .../resources/i18n/tutti-ui-swing_en_GB.properties | 2 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 2 + 12 files changed, 463 insertions(+), 391 deletions(-) -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit 56a11f04f53b263398585d80d27760c50232cd50 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 18 15:29:37 2015 +0100 pas de write si pas de données --- .../java/fr/ifremer/tutti/service/csv/CsvProducer.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/CsvProducer.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/CsvProducer.java index 6b10808..5fb54d9 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/CsvProducer.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/CsvProducer.java @@ -44,15 +44,17 @@ public abstract class CsvProducer<O, M extends AbstractTuttiImportExportModel<O> } public void write(O row) throws Exception { - - List<O> rows = new ArrayList<>(); - rows.add(row); - write(rows); - + if (row != null) { + List<O> rows = new ArrayList<>(1); + rows.add(row); + write(rows); + } } public void write(List<O> rows) throws Exception { - export.write(rows, writer); + if (rows != null) { + export.write(rows, writer); + } } } -- 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 develop in repository tutti. See http://git.codelutin.com/tutti.git commit e68e5aea927242ad2b0f5b5a1442c398d515db6b Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Feb 18 15:30:47 2015 +0100 amélioration de l'export générique (meilleur découpage de l'export + progression plus fluide) --- .../service/catches/WeightComputingService.java | 97 ---- .../genericformat/GenericFormatExportContext.java | 62 ++- .../GenericFormatExportOperationContext.java | 74 +++ .../genericformat/GenericFormatExportService.java | 497 +++++++++++---------- .../resources/i18n/tutti-service_en_GB.properties | 7 + .../resources/i18n/tutti-service_fr_FR.properties | 17 +- .../GenericFormatExportServiceTest.java | 59 ++- .../action/ExportGenericFormatCruiseAction.java | 12 +- .../ExportGenericFormatProgramCruisesAction.java | 11 +- .../resources/i18n/tutti-ui-swing_en_GB.properties | 2 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 2 + 11 files changed, 455 insertions(+), 385 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index 31514e7..3e2128b 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -22,8 +22,6 @@ package fr.ifremer.tutti.service.catches; * #L% */ -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; @@ -42,14 +40,10 @@ import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.util.Numbers; import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.validator.NuitonValidatorResult; import java.util.List; -import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -59,9 +53,6 @@ import static org.nuiton.i18n.I18n.t; */ public class WeightComputingService extends AbstractTuttiService { - private static final Log log = - LogFactory.getLog(WeightComputingService.class); - protected PersistenceService persistenceService; protected ValidationService validationService; @@ -80,94 +71,6 @@ public class WeightComputingService extends AbstractTuttiService { } /** - * To check if can compute for any fishing operation of the cruise given - * by his id. - * <p/> - * If no error found, then return is a empty map, otherwise the first error - * found for any bad fishing operation. - * <p/> - * Result keys are fishing operation id, values the first error for - * the fishing operation. - * - * @param cruiseId id of the cruise to check. - * @param uniqueFishingOperationId optional unique fishing operation to check - * @return map of errors, or empty map if no error found. - * @since 1.4 - */ - public Map<String, String> checkCruise(String cruiseId, - String uniqueFishingOperationId) { - - if (log.isDebugEnabled()) { - log.debug("Will check cruise: " + cruiseId); - } - Map<String, String> result = Maps.newTreeMap(); - - List<String> allFishingOperation; - - if (StringUtils.isNotBlank(uniqueFishingOperationId)) { - allFishingOperation = Lists.newArrayList(uniqueFishingOperationId); - } else { - allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); - } - - for (String fishingOperationId : allFishingOperation) { - - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); - - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); - } - continue; - } - CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); - - BatchContainer<SpeciesBatch> rootSpeciesBatch; - try { - rootSpeciesBatch = getComputedSpeciesBatches(fishingOperationId); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, false); - } - - BatchContainer<BenthosBatch> rootBenthosBatch; - try { - rootBenthosBatch = getComputedBenthosBatches(fishingOperationId); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); - } - - BatchContainer<MarineLitterBatch> rootMarineLitterBatch; - try { - Float weight = catchBatch == null ? null : catchBatch.getMarineLitterTotalWeight(); - rootMarineLitterBatch = getComputedMarineLitterBatches(fishingOperationId, weight); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); - } - - try { - if (catchBatch != null) { - computeCatchBatchWeights(catchBatch, - rootSpeciesBatch, - rootBenthosBatch, - rootMarineLitterBatch); - } - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - } - } - return result; - } - - /** * Compute the weights of the catch batch (not the ones of the species, benthos nor marine litter batches) * * @param catchBatch the catch batch with the weights to compute diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java index 9954494..b8d8889 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java @@ -1,6 +1,7 @@ package fr.ifremer.tutti.service.genericformat; import com.google.common.collect.Maps; +import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -33,6 +34,9 @@ import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryPers import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporarySpecies; import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryVessel; import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.decorator.Decorator; import java.io.Closeable; import java.io.File; @@ -48,12 +52,17 @@ import java.util.Map; */ public class GenericFormatExportContext implements Closeable { + /** Logger. */ + private static final Log log = LogFactory.getLog(GenericFormatExportContext.class); + private final SampleCategoryModel sampleCategoryModel; protected Map<String, GenericFormatExportOperationContext> operationContexts = Maps.newTreeMap(); private final GenericFormatArchive archive; + private final Decorator<FishingOperation> fishingOperationDecorator; + protected final PersistenceService persistenceService; protected final WeightComputingService weightComputingService; @@ -94,19 +103,26 @@ public class GenericFormatExportContext implements Closeable { private final CsvProducerForSampleCategory producerForSampleCategory; + protected final ProgressionModel progressionModel; + protected String checkError; - GenericFormatExportContext(GenericFormatArchive archive, + GenericFormatExportContext(ProgressionModel progressionModel, + GenericFormatArchive archive, char csvSeparator, PersistenceService persistenceService, WeightComputingService weightComputingService, + Decorator<FishingOperation> fishingOperationDecorator, SampleCategoryModel sampleCategoryModel) { + this.progressionModel = progressionModel; this.archive = archive; this.persistenceService = persistenceService; this.weightComputingService = weightComputingService; + this.fishingOperationDecorator = fishingOperationDecorator; + this.sampleCategoryModel = sampleCategoryModel; this.weightMeasuredCaracteristic = persistenceService.getWeightMeasuredCaracteristic(); @@ -135,6 +151,23 @@ public class GenericFormatExportContext implements Closeable { } + public GenericFormatExportOperationContext newOperationContext(Cruise cruise, FishingOperation operation) { + + String operationLabel = fishingOperationDecorator.toString(operation); + GenericFormatExportOperationContext operationExportContext = new GenericFormatExportOperationContext(cruise, + operation, + operationLabel, + persistenceService, + weightComputingService, + sampleCategoryModel, + weightMeasuredCaracteristic, + pmfmIdCaracteristic, + deadOrAliveCaracteristic, + genderCaracteristic); + return operationExportContext; + + } + public GenericFormatExportOperationContext getOperationContext(Cruise cruise, FishingOperation operation) { String operationId = operation.getId(); @@ -142,15 +175,17 @@ public class GenericFormatExportContext implements Closeable { GenericFormatExportOperationContext operationExportContext = operationContexts.get(operationId); if (operationExportContext == null) { + String operationLabel = fishingOperationDecorator.toString(operation); operationExportContext = new GenericFormatExportOperationContext(cruise, - operation, - persistenceService, - weightComputingService, - sampleCategoryModel, - weightMeasuredCaracteristic, - pmfmIdCaracteristic, - deadOrAliveCaracteristic, - genderCaracteristic); + operation, + operationLabel, + persistenceService, + weightComputingService, + sampleCategoryModel, + weightMeasuredCaracteristic, + pmfmIdCaracteristic, + deadOrAliveCaracteristic, + genderCaracteristic); operationContexts.put(operationId, operationExportContext); } @@ -249,4 +284,13 @@ public class GenericFormatExportContext implements Closeable { public SampleCategoryModel getSampleCategoryModel() { return sampleCategoryModel; } + + public void increments(String message) { + if (progressionModel != null) { + progressionModel.increments(message); + } + if (log.isInfoEnabled()) { + log.info(message); + } + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java index b17f267..dd0a025 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java @@ -16,6 +16,12 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; +import fr.ifremer.tutti.service.genericformat.csv.AccidentalCatchRow; +import fr.ifremer.tutti.service.genericformat.csv.CatchRow; +import fr.ifremer.tutti.service.genericformat.csv.IndividualObservationRow; +import fr.ifremer.tutti.service.genericformat.csv.MarineLitterRow; +import fr.ifremer.tutti.service.genericformat.csv.OperationRow; +import fr.ifremer.tutti.service.genericformat.csv.ParameterRow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,8 +68,23 @@ public class GenericFormatExportOperationContext { private final SampleCategoryModel sampleCategoryModel; + private final String operationLabel; + + private OperationRow operationRow; + + private List<ParameterRow> parameterRows; + + private List<MarineLitterRow> marineLitterRows; + + private List<IndividualObservationRow> individualObservationRows; + + private List<AccidentalCatchRow> accidentalCatchRows; + + private List<CatchRow> catchRows; + public GenericFormatExportOperationContext(Cruise cruise, FishingOperation operation, + String operationLabel, PersistenceService persistenceService, WeightComputingService weightComputingService, SampleCategoryModel sampleCategoryModel, @@ -73,6 +94,7 @@ public class GenericFormatExportOperationContext { Caracteristic genderCaracteristic) { this.cruise = cruise; this.operation = operation; + this.operationLabel = operationLabel; this.sampleCategoryModel = sampleCategoryModel; this.persistenceService = persistenceService; this.weightMeasuredCaracteristic = weightMeasuredCaracteristic; @@ -203,4 +225,56 @@ public class GenericFormatExportOperationContext { public SampleCategoryModel getSampleCategoryModel() { return sampleCategoryModel; } + + public String getOperationLabel() { + return operationLabel; + } + + public void setOperationRow(OperationRow operationRow) { + this.operationRow = operationRow; + } + + public OperationRow getOperationRow() { + return operationRow; + } + + public void setParameterRows(List<ParameterRow> parameterRows) { + this.parameterRows = parameterRows; + } + + public List<ParameterRow> getParameterRows() { + return parameterRows; + } + + public void setMarineLitterRows(List<MarineLitterRow> marineLitterRows) { + this.marineLitterRows = marineLitterRows; + } + + public List<MarineLitterRow> getMarineLitterRows() { + return marineLitterRows; + } + + public void setIndividualObservationRows(List<IndividualObservationRow> individualObservationRows) { + this.individualObservationRows = individualObservationRows; + } + + public List<IndividualObservationRow> getIndividualObservationRows() { + return individualObservationRows; + } + + public void setAccidentalCatchRows(List<AccidentalCatchRow> accidentalCatchRows) { + this.accidentalCatchRows = accidentalCatchRows; + } + + public List<AccidentalCatchRow> getAccidentalCatchRows() { + return accidentalCatchRows; + } + + public void setCatchRows(List<CatchRow> catchRows) { + this.catchRows = catchRows; + } + + public List<CatchRow> getCatchRows() { + return catchRows; + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java index 5f260d6..c043d6f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java @@ -33,6 +33,7 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; @@ -58,13 +59,8 @@ import fr.ifremer.tutti.service.genericformat.csv.ParameterRow; import fr.ifremer.tutti.service.genericformat.csv.SampleCategoryRow; import fr.ifremer.tutti.service.genericformat.csv.SpeciesExportRow; import fr.ifremer.tutti.service.genericformat.csv.SurveyRow; -import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForAccidentalCatch; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForCatch; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForGearCaracteristics; -import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForIndividualObservation; -import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForMarineLitter; -import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForOperation; -import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForParameter; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForSampleCategory; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForSpecies; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForSurvey; @@ -82,7 +78,6 @@ import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryPers import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporarySpecies; import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryVessel; import fr.ifremer.tutti.util.Numbers; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -92,8 +87,9 @@ import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; +import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -113,7 +109,7 @@ public class GenericFormatExportService extends AbstractTuttiService { protected WeightComputingService weightComputingService; - protected DecoratorService decoratorService; + protected DecoratorService decoratrService; protected ReferentialTemporaryGearService referentialTemporaryGearService; @@ -125,12 +121,17 @@ public class GenericFormatExportService extends AbstractTuttiService { protected ProtocolImportExportService protocolImportExportService; + private Decorator<FishingOperation> fishingOperationDecorator; + + private Decorator<Cruise> cruiseDecorator; + + ; + @Override public void setServiceContext(TuttiServiceContext context) { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); - decoratorService = getService(DecoratorService.class); weightComputingService = getService(WeightComputingService.class); referentialTemporaryGearService = getService(ReferentialTemporaryGearService.class); referentialTemporaryPersonService = getService(ReferentialTemporaryPersonService.class); @@ -138,6 +139,10 @@ public class GenericFormatExportService extends AbstractTuttiService { referentialTemporaryVesselService = getService(ReferentialTemporaryVesselService.class); protocolImportExportService = getService(ProtocolImportExportService.class); + DecoratorService decoratorService = getService(DecoratorService.class); + cruiseDecorator = decoratorService.getDecoratorByType(Cruise.class); + fishingOperationDecorator = decoratorService.getDecoratorByType(FishingOperation.class); + } public int getExportProgramNbSteps(String programId) { @@ -147,7 +152,19 @@ public class GenericFormatExportService extends AbstractTuttiService { List<Cruise> allCruise = persistenceService.getAllCruise(programId); - int result = 9 * allCruise.size() + 8; + int result = 8; + + for (Cruise cruise : allCruise) { + result += getCruiseNbStep(cruise.getId()); // check + export cruise + } + return result; + + } + + public int getExportCruiseNbSteps(String cruiseId) { + + int result = getCruiseNbStep(cruiseId) // check + export cruise + + 8; // export species + sampleCategoryModel + protocol + temporary gear + temporary person + temporar species + temporary vessel + zip return result; } @@ -179,17 +196,17 @@ public class GenericFormatExportService extends AbstractTuttiService { GenericFormatArchive genericFormatArchive = GenericFormatArchive.forExport(exportFile, context.getConfig().getTmpDirectory()); - try (GenericFormatExportContext exportContext = createExportContext(genericFormatArchive)) { + try (GenericFormatExportContext exportContext = createExportContext(progressionModel, genericFormatArchive)) { for (Cruise cruise : allCruise) { // load full cruise cruise = persistenceService.getCruise(cruise.getId()); - exportCruise(cruise, exportContext, progressionModel); + exportCruise(exportContext, cruise); } - terminatesExport(exportContext, progressionModel); + terminatesExport(exportContext); } catch (IOException e) { throw new ApplicationTechnicalException("Could not create program export", e); @@ -203,15 +220,6 @@ public class GenericFormatExportService extends AbstractTuttiService { } - public int getExportCruiseNbSteps() { - - // (check cruise / export cruise / gear caracteristics / operation / parameter / catches / individual observation / accidental catches / marine litter) + - // (species + sampleCategoryModel + protocol + temporary gear + temporary person + temporar species + temporary vessel + zip) - int result = 9 + 8; - return result; - - } - public void exportCruise(String cruiseId, File exportFile, ProgressionModel progressionModel) { Preconditions.checkNotNull(cruiseId); @@ -227,7 +235,13 @@ public class GenericFormatExportService extends AbstractTuttiService { // check cruise fishing operations ApplicationBusinessException checkError = null; try { - checkCruise(progressionModel, cruise, null); + + List<String> fishingOperationIds = persistenceService.getAllFishingOperationIds(cruise.getId()); + String error = getCruiseErrors(progressionModel, cruise, fishingOperationIds); + if (error != null) { + throw new ApplicationBusinessException(error); + } + } catch (ApplicationBusinessException e) { // error while checking cruise if (log.isDebugEnabled()) { @@ -237,11 +251,11 @@ public class GenericFormatExportService extends AbstractTuttiService { } GenericFormatArchive genericFormatArchive = GenericFormatArchive.forExport(exportFile, context.getConfig().getTmpDirectory()); - try (GenericFormatExportContext exportContext = createExportContext(genericFormatArchive)) { + try (GenericFormatExportContext exportContext = createExportContext(progressionModel, genericFormatArchive)) { - exportCruise(cruise, exportContext, progressionModel); + exportCruise(exportContext, cruise); - terminatesExport(exportContext, progressionModel); + terminatesExport(exportContext); } catch (IOException e) { throw new ApplicationTechnicalException("Could not create cruise export", e); @@ -277,7 +291,12 @@ public class GenericFormatExportService extends AbstractTuttiService { // check cruise fishing operations ApplicationBusinessException checkError = null; try { - checkCruise(null, cruise, fishingOperationId); + + String error = getCruiseErrors(null, cruise, Lists.newArrayList(fishingOperationId)); + if (error != null) { + throw new ApplicationBusinessException(error); + } + } catch (ApplicationBusinessException e) { // error while checking cruise if (log.isDebugEnabled()) { @@ -288,13 +307,13 @@ public class GenericFormatExportService extends AbstractTuttiService { GenericFormatArchive genericFormatArchive = GenericFormatArchive.forExport(null, context.getConfig().getTmpDirectory()); - try (GenericFormatExportContext exportContext = createExportContext(genericFormatArchive)) { + try (GenericFormatExportContext exportContext = createExportContext(null, genericFormatArchive)) { FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); - exportCruise(cruise, Lists.newArrayList(fishingOperation), exportContext, null); + exportCruise(exportContext, cruise, Lists.newArrayList(fishingOperation)); - terminatesExport(exportContext, null); + terminatesExport(exportContext); } catch (IOException e) { throw new ApplicationTechnicalException("Could not create cruise export", e); @@ -309,13 +328,15 @@ public class GenericFormatExportService extends AbstractTuttiService { } - protected GenericFormatExportContext createExportContext(GenericFormatArchive genericFormatArchive) { + protected GenericFormatExportContext createExportContext(ProgressionModel progressionModel, GenericFormatArchive genericFormatArchive) { - return new GenericFormatExportContext(genericFormatArchive, - ';', - persistenceService, - weightComputingService, - context.getSampleCategoryModel()); + return new GenericFormatExportContext(progressionModel, + genericFormatArchive, + ';', + persistenceService, + weightComputingService, + fishingOperationDecorator, + context.getSampleCategoryModel()); } @@ -325,7 +346,9 @@ public class GenericFormatExportService extends AbstractTuttiService { for (Cruise cruise : allCruise) { cruise = persistenceService.getCruise(cruise.getId()); - String error = getCruiseErrors(progressionModel, cruise, null); + + List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(cruise.getId()); + String error = getCruiseErrors(progressionModel, cruise, allFishingOperation); if (error != null) { @@ -347,52 +370,6 @@ public class GenericFormatExportService extends AbstractTuttiService { } } - protected void checkCruise(ProgressionModel progressionModel, Cruise cruise, String fishingOperationId) { - - String error = getCruiseErrors(progressionModel, cruise, fishingOperationId); - - if (error != null) { - throw new ApplicationBusinessException(error); - } - - } - - protected String getCruiseErrors(ProgressionModel progressionModel, Cruise cruise, String fishingOperationId) { - - Preconditions.checkNotNull(cruise); - - increments(progressionModel, t("tutti.service.exportCruise.checkCruise", cruise.getName())); - - // check cruise fishing operations - Map<String, String> errors = weightComputingService.checkCruise(cruise.getId(), fishingOperationId); - - String result; - - if (MapUtils.isEmpty(errors)) { - - result = null; - - } else { - - Decorator<Cruise> cruiseDecorator = decoratorService.getDecoratorByType(Cruise.class); - Decorator<FishingOperation> fishingOperationDecorator = decoratorService.getDecoratorByType(FishingOperation.class); - - StringBuilder sb = new StringBuilder(); - for (Map.Entry<String, String> entry : errors.entrySet()) { - String operationId = entry.getKey(); - FishingOperation fishingOperation = persistenceService.getFishingOperation(operationId); - String fishingOperationStr = fishingOperationDecorator.toString(fishingOperation); - sb.append(t("tutti.service.export.invalid.fishingOperation", fishingOperationStr, entry.getValue())); - } - String cruiseStr = cruiseDecorator.toString(cruise); - result = t("tutti.service.export.invalid.cruise", cruiseStr, sb.toString()); - - } - - return result; - - } - protected void increments(ProgressionModel progressionModel, String message) { if (progressionModel != null) { progressionModel.increments(message); @@ -402,37 +379,33 @@ public class GenericFormatExportService extends AbstractTuttiService { } } - protected void terminatesExport(GenericFormatExportContext exportContext, ProgressionModel progressionModel) { + protected void terminatesExport(GenericFormatExportContext exportContext) { SampleCategoryModel sampleCategoryModel = exportContext.getSampleCategoryModel(); - increments(progressionModel, t("tutti.service.genericExport.exportSampleCategoyModel", sampleCategoryModel.getNbSampling())); exportSampleCategoryModel(exportContext, sampleCategoryModel); - exportProtocol(exportContext, progressionModel); + exportProtocol(exportContext); List<Gear> temporaryGears = referentialTemporaryGearService.getTemporaryGears(); - increments(progressionModel, t("tutti.service.genericExport.exportTemporaryGear", temporaryGears.size())); exportTemporaryGears(exportContext, temporaryGears); List<Person> temporaryPersons = referentialTemporaryPersonService.getTemporaryPersons(); - increments(progressionModel, t("tutti.service.genericExport.exportTemporaryPerson", temporaryPersons.size())); exportTemporaryPersons(exportContext, temporaryPersons); List<Species> temporarySpeciess = referentialTemporarySpeciesService.getTemporarySpeciess(); - increments(progressionModel, t("tutti.service.genericExport.exportTemporarySpecies", temporarySpeciess.size())); exportTemporarySpeciess(exportContext, temporarySpeciess); List<Vessel> temporaryVessels = referentialTemporaryVesselService.getTemporaryVessels(); - increments(progressionModel, t("tutti.service.genericExport.exportTemporaryVessel", temporaryVessels.size())); exportTemporaryVessels(exportContext, temporaryVessels); - increments(progressionModel, t("tutti.service.genericExport.exportSpecies")); exportSpecies(exportContext); } protected void exportTemporaryGears(GenericFormatExportContext exportContext, List<Gear> temporaryGears) { + exportContext.increments(t("tutti.service.genericExport.exportTemporaryGear", temporaryGears.size())); + try { CsvProducerForTemporaryGear producerForTemporarySpecies = exportContext.getProducerForTemporaryGear(); @@ -448,6 +421,8 @@ public class GenericFormatExportService extends AbstractTuttiService { protected void exportTemporaryPersons(GenericFormatExportContext exportContext, List<Person> temporaryPersons) { + exportContext.increments(t("tutti.service.genericExport.exportTemporaryPerson", temporaryPersons.size())); + try { CsvProducerForTemporaryPerson producerForTemporarySpecies = exportContext.getProducerForTemporaryPerson(); @@ -463,6 +438,8 @@ public class GenericFormatExportService extends AbstractTuttiService { protected void exportTemporarySpeciess(GenericFormatExportContext exportContext, List<Species> temporarySpeciess) { + exportContext.increments(t("tutti.service.genericExport.exportTemporarySpecies", temporarySpeciess.size())); + try { CsvProducerForTemporarySpecies producerForTemporarySpecies = exportContext.getProducerForTemporarySpecies(); @@ -478,6 +455,8 @@ public class GenericFormatExportService extends AbstractTuttiService { protected void exportTemporaryVessels(GenericFormatExportContext exportContext, List<Vessel> temporaryVessels) { + exportContext.increments(t("tutti.service.genericExport.exportTemporaryVessel", temporaryVessels.size())); + try { CsvProducerForTemporaryVessel producerForTemporaryVessel = exportContext.getProducerForTemporaryVessel(); @@ -493,6 +472,8 @@ public class GenericFormatExportService extends AbstractTuttiService { protected void exportSampleCategoryModel(GenericFormatExportContext exportContext, SampleCategoryModel sampleCategoryModel) { + exportContext.increments(t("tutti.service.genericExport.exportSampleCategoyModel", sampleCategoryModel.getNbSampling())); + try { CsvProducerForSampleCategory producerForSampleCategory = exportContext.getProducerForSampleCategory(); @@ -506,65 +487,47 @@ public class GenericFormatExportService extends AbstractTuttiService { } - protected void exportProtocol(GenericFormatExportContext exportContext, ProgressionModel progressionModel) { + protected void exportProtocol(GenericFormatExportContext exportContext) { boolean protocolFilled = context.getDataContext().isProtocolFilled(); if (protocolFilled) { TuttiProtocol protocol = persistenceService.getProtocol(); - increments(progressionModel, t("tutti.service.genericExport.exportProtocol", protocol.getName())); + exportContext.increments(t("tutti.service.genericExport.exportProtocol", protocol.getName())); protocolImportExportService.exportProtocol(protocol, exportContext.getProtocolFile()); } else { - increments(progressionModel, t("tutti.service.genericExport.skipProtocolExport")); + exportContext.increments(t("tutti.service.genericExport.skipProtocolExport")); } } - protected void exportCruise(Cruise cruise, GenericFormatExportContext exportContext, ProgressionModel progressionModel) { + protected void exportCruise(GenericFormatExportContext exportContext, Cruise cruise) { List<FishingOperation> operations = persistenceService.getAllFishingOperation(cruise.getId()); - exportCruise(cruise, operations, exportContext, progressionModel); + exportCruise(exportContext, cruise, operations); } - protected void exportCruise(Cruise cruise, List<FishingOperation> operations, GenericFormatExportContext exportContext, ProgressionModel progressionModel) { + protected void exportCruise(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - // load fully operations - List<FishingOperation> loadedOperations = Lists.newArrayListWithCapacity(operations.size()); - for (FishingOperation operation : operations) { - FishingOperation loadedOeration = persistenceService.getFishingOperation(operation.getId()); - loadedOperations.add(loadedOeration); - } - - String cruiseName = cruise.getName(); - increments(progressionModel, t("tutti.service.exportCruise.exportSurvey", cruiseName)); exportSurvey(exportContext, cruise); - increments(progressionModel, t("tutti.service.exportCruise.exportGearCaracteristics", cruiseName)); exportGearCaracteristics(exportContext, cruise); - increments(progressionModel, t("tutti.service.exportCruise.exportOperations", cruiseName)); - exportOperations(exportContext, cruise, loadedOperations); - - increments(progressionModel, t("tutti.service.exportCruise.exportParameters", cruiseName)); - exportParameters(exportContext, cruise, loadedOperations); - - increments(progressionModel, t("tutti.service.exportCruise.exportMarineLitters", cruiseName)); - exportMarineLitters(exportContext, cruise, loadedOperations); + for (FishingOperation operation : operations) { - increments(progressionModel, t("tutti.service.exportCruise.exportIndividualObservations", cruiseName)); - exportIndividualObservations(exportContext, cruise, loadedOperations); + FishingOperation loadedOperation = persistenceService.getFishingOperation(operation.getId()); - increments(progressionModel, t("tutti.service.exportCruise.exportAccidentalCatches", cruiseName)); - exportAccidentalCatch(exportContext, cruise, loadedOperations); + exportOperation(exportContext, cruise, loadedOperation); - increments(progressionModel, t("tutti.service.exportCruise.exportCatches", cruiseName)); - exportCatches(exportContext, cruise, loadedOperations); + } } - protected void exportSurvey(GenericFormatExportContext exportContext, Cruise cruise) { + private void exportSurvey(GenericFormatExportContext exportContext, Cruise cruise) { + + exportContext.increments(t("tutti.service.exportCruise.exportSurvey", cruise.getName())); List<TuttiLocation> allCountry = persistenceService.getAllCountry(); String countryId = context.getConfig().getExportCountryId(); @@ -583,6 +546,9 @@ public class GenericFormatExportService extends AbstractTuttiService { } protected void exportGearCaracteristics(GenericFormatExportContext exportContext, Cruise cruise) { + + exportContext.increments(t("tutti.service.exportCruise.exportGearCaracteristics", cruise.getName())); + try { CsvProducerForGearCaracteristics producerForGearCaracteristics = exportContext.getProducerForGearCaracteristics(); @@ -607,139 +573,58 @@ public class GenericFormatExportService extends AbstractTuttiService { } } - protected void exportOperations(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - - try { + protected void exportOperation(GenericFormatExportContext exportContext, Cruise cruise, FishingOperation operation) { - CsvProducerForOperation producerForOperation = exportContext.getProducerForOperation(); + GenericFormatExportOperationContext operationContext = exportContext.newOperationContext(cruise, operation); + exportContext.increments(t("tutti.service.exportCruise.exportOperation", cruise.getName(), operationContext.getOperationLabel())); - List<OperationRow> rows = Lists.newArrayList(); - - for (FishingOperation operation : operations) { - - GenericFormatExportOperationContext operationContext = exportContext.getOperationContext(cruise, operation); - CatchBatch catchBatch = operationContext.getCatchBatch(); - - OperationRow operationRow = producerForOperation.getDataToExport(cruise, operation, catchBatch); - rows.add(operationRow); - - } + CatchBatch catchBatch = operationContext.getCatchBatch(); - producerForOperation.write(rows); + // FIXME cela va poser des problème si le catch n'existe pas ? + OperationRow operationRow = exportContext.getProducerForOperation().getDataToExport(cruise, operation, catchBatch); + operationContext.setOperationRow(operationRow); - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.operations.error"), e); - } - } + List<ParameterRow> parameterRows = exportContext.getProducerForParameter().getDataToExport(cruise, operation); + operationContext.setParameterRows(parameterRows); - protected void exportParameters(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { + boolean withCatchBatch = operationContext.isWithCatchBatch(); - try { + if (withCatchBatch) { - CsvProducerForParameter producerForParameter = exportContext.getProducerForParameter(); + List<MarineLitterRow> marineLitterRows = exportContext.getProducerForMarineLitter().getDataToExport(operationContext); + operationContext.setMarineLitterRows(marineLitterRows); - for (FishingOperation operation : operations) { + List<IndividualObservationRow> individualObservationRows = exportContext.getProducerForIndividualObservation().getDataToExport(operationContext); + operationContext.setIndividualObservationRows(individualObservationRows); + exportContext.getProducerForSpecies().prepareIndividualRows(individualObservationRows); - List<ParameterRow> rows = producerForParameter.getDataToExport(cruise, operation); - producerForParameter.write(rows); + List<AccidentalCatchRow> accidentalCatchRows = exportContext.getProducerForAccidentalCatch().getDataToExport(operationContext); + operationContext.setAccidentalCatchRows(accidentalCatchRows); + exportContext.getProducerForSpecies().prepareAccidentalRows(accidentalCatchRows); - } + List<CatchRow> catchRows = exportCatch(exportContext, operationContext); + operationContext.setCatchRows(catchRows); - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.parameters.error"), e); } - } - - protected void exportMarineLitters(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { try { - CsvProducerForMarineLitter producerForMarineLitter = exportContext.getProducerForMarineLitter(); - - for (FishingOperation operation : operations) { - GenericFormatExportOperationContext operationContext = exportContext.getOperationContext(cruise, operation); - - boolean withCatchBatch = operationContext.isWithCatchBatch(); - if (!withCatchBatch) { - continue; - } - - List<MarineLitterRow> rows = producerForMarineLitter.getDataToExport(operationContext); - producerForMarineLitter.write(rows); - - } + exportContext.getProducerForOperation().write(operationContext.getOperationRow()); + exportContext.getProducerForParameter().write(operationContext.getParameterRows()); + exportContext.getProducerForMarineLitter().write(operationContext.getMarineLitterRows()); + exportContext.getProducerForIndividualObservation().write(operationContext.getIndividualObservationRows()); + exportContext.getProducerForAccidentalCatch().write(operationContext.getAccidentalCatchRows()); + exportContext.getProducerForCatch().write(operationContext.getCatchRows()); } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.marineLitters.error"), e); - } - } - - protected void exportIndividualObservations(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - - try { - - CsvProducerForIndividualObservation producerForIndividualObservation = exportContext.getProducerForIndividualObservation(); - CsvProducerForSpecies producerForSpecies = exportContext.getProducerForSpecies(); - for (FishingOperation operation : operations) { - GenericFormatExportOperationContext operationContext = exportContext.getOperationContext(cruise, operation); + throw new ApplicationTechnicalException(t("tutti.service.export.operation.error", operationContext.getOperationLabel(), operationContext.getCruise().getName()), e); - boolean withCatchBatch = operationContext.isWithCatchBatch(); - if (!withCatchBatch) { - continue; - } - List<IndividualObservationRow> rows = producerForIndividualObservation.getDataToExport(operationContext); - producerForSpecies.prepareIndividualRows(rows); - producerForIndividualObservation.write(rows); - } - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.individualObservations.error"), e); } - } - protected void exportAccidentalCatch(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - try { - - CsvProducerForAccidentalCatch producerForAccidentalCatch = exportContext.getProducerForAccidentalCatch(); - CsvProducerForSpecies producerForSpecies = exportContext.getProducerForSpecies(); - - for (FishingOperation operation : operations) { - - GenericFormatExportOperationContext operationContext = exportContext.getOperationContext(cruise, operation); - - List<AccidentalCatchRow> rows = producerForAccidentalCatch.getDataToExport(operationContext); - producerForSpecies.prepareAccidentalRows(rows); - producerForAccidentalCatch.write(rows); - } - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.accidentalCatch.error"), e); - } } - protected void exportCatches(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - try { - - for (FishingOperation operation : operations) { - - GenericFormatExportOperationContext operationContext = exportContext.getOperationContext(cruise, operation); - - boolean withCatchBatch = operationContext.isWithCatchBatch(); - if (!withCatchBatch) { - continue; - } - - exportCatch(exportContext, operationContext); - - } - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.export.catches.error"), e); - } - } - - protected void exportCatch(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) throws Exception { + protected List<CatchRow> exportCatch(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { CatchBatch catchBatch = operationContext.getCatchBatch(); @@ -798,13 +683,14 @@ public class GenericFormatExportService extends AbstractTuttiService { List<CatchRow> rows = producerForCatch.getDataToExport(operationContext, speciesCatchRaisingFactor, benthosCatchRaisingFactor); - - producerForCatch.write(rows); + return rows; } protected void exportSpecies(GenericFormatExportContext exportContext) { + exportContext.increments(t("tutti.service.genericExport.exportSpecies")); + try { CsvProducerForSpecies producerForSpecies = exportContext.getProducerForSpecies(); @@ -816,5 +702,148 @@ public class GenericFormatExportService extends AbstractTuttiService { } } + protected String getCruiseErrors(ProgressionModel progressionModel, Cruise cruise, List<String> allFishingOperation) { + + Preconditions.checkNotNull(cruise); + + increments(progressionModel, t("tutti.service.exportCruise.checkCruise", cruise.getName())); + + // check cruise fishing operations + + StringBuilder errorMessageBuilder = new StringBuilder(); + + boolean withErrors = false; + + for (String fishingOperationId : allFishingOperation) { + + FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); + increments(progressionModel, t("tutti.service.exportCruise.checkCruiseFishingOperation", cruise.getName(), fishingOperationDecorator.toString(fishingOperation))); + + String error = checkCruiseFishingOperation(fishingOperationId); + + if (error != null) { + + withErrors = true; + errorMessageBuilder.append("<li>").append(error).append("</li>"); + + } + + } + + String result; + + if (withErrors) { + + String cruiseStr = cruiseDecorator.toString(cruise); + result = t("tutti.service.export.invalid.cruise", cruiseStr, errorMessageBuilder.toString()); + + } else { + + result = null; + + } + + return result; + + } + + protected String checkCruiseFishingOperation(String fishingOperationId) { + + if (log.isDebugEnabled()) { + log.debug("Will check operation: " + fishingOperationId); + } + + Set<String> errors = new LinkedHashSet<>(); + + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); + + if (!withCatchBatch) { + + if (log.isWarnEnabled()) { + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); + } + + } else { + + BatchContainer<SpeciesBatch> rootSpeciesBatch; + try { + rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(fishingOperationId); + + } catch (ApplicationBusinessException e) { + errors.add(e.getMessage()); + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, false); + } + + BatchContainer<BenthosBatch> rootBenthosBatch; + try { + rootBenthosBatch = weightComputingService.getComputedBenthosBatches(fishingOperationId); + + } catch (ApplicationBusinessException e) { + errors.add(e.getMessage()); + rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); + } + + CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); + + BatchContainer<MarineLitterBatch> rootMarineLitterBatch; + try { + Float weight = catchBatch == null ? null : catchBatch.getMarineLitterTotalWeight(); + rootMarineLitterBatch = weightComputingService.getComputedMarineLitterBatches(fishingOperationId, weight); + + } catch (ApplicationBusinessException e) { + errors.add(e.getMessage()); + rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); + } + + try { + if (catchBatch != null) { + weightComputingService.computeCatchBatchWeights(catchBatch, + rootSpeciesBatch, + rootBenthosBatch, + rootMarineLitterBatch); + } + } catch (ApplicationBusinessException e) { + errors.add(e.getMessage()); + } + } + + String errorMessage; + + if (errors.isEmpty()) { + + errorMessage = null; + + } else { + + FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); + String fishingOperationStr = fishingOperationDecorator.toString(fishingOperation); + + StringBuilder sb = new StringBuilder(); + for (String error : errors) { + sb.append("<li>").append(error).append("</li>"); + } + errorMessage = t("tutti.service.export.invalid.fishingOperation", fishingOperationStr, sb.toString()); + + } + + return errorMessage; + + } + + protected int getCruiseNbStep(String cruiseId) { + + Cruise cruise = persistenceService.getCruise(cruiseId); + Preconditions.checkNotNull(cruise); + List<String> allFishingOperationIds = persistenceService.getAllFishingOperationIds(cruiseId); + int nbFishingOperations = allFishingOperationIds.size(); + + int result = 1 + nbFishingOperations // check cruise + operations + + 1 // export cruise + + 1 // export gear caracteristics + + nbFishingOperations; // export operation + + return result; + + } } 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 f07ee23..1a5c17b 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 @@ -117,6 +117,7 @@ tutti.service.export.individualObservations.error= tutti.service.export.invalid.cruise= tutti.service.export.invalid.fishingOperation= tutti.service.export.marineLitters.error= +tutti.service.export.operation.error= tutti.service.export.operations.error= tutti.service.export.parameters.error= tutti.service.export.species.error= @@ -124,12 +125,18 @@ tutti.service.export.survey.error= tutti.service.export.zip.error= tutti.service.exportCruise.buildZip= tutti.service.exportCruise.checkCruise= +tutti.service.exportCruise.checkCruiseFishingOperation= tutti.service.exportCruise.exportAccidentalCatches= +tutti.service.exportCruise.exportCatch= tutti.service.exportCruise.exportCatches= tutti.service.exportCruise.exportGearCaracteristics= +tutti.service.exportCruise.exportIndividualObservation= tutti.service.exportCruise.exportIndividualObservations= +tutti.service.exportCruise.exportMarineLitter= tutti.service.exportCruise.exportMarineLitters= +tutti.service.exportCruise.exportOperation= tutti.service.exportCruise.exportOperations= +tutti.service.exportCruise.exportParameter= tutti.service.exportCruise.exportParameters= tutti.service.exportCruise.exportSpecies= tutti.service.exportCruise.exportSurvey= 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 8c6fd90..5763fbe 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 @@ -101,25 +101,24 @@ tutti.service.export.accidentalCatch.error=Erreur lors de l'export des captures tutti.service.export.catches.error=Erreur lors de l'export des captures tutti.service.export.closeContext.error=Erreur lors de la fermeture du contexte d'export tutti.service.export.context.error=Erreur lors de la création des fichiers pour l'export +tutti.service.export.error.invalid.cruise=Erreur d'élévation de poids sur les traits de la campagne %s \:<ul>%s</ul> +tutti.service.export.error.invalid.fishingOperation=L'élévation des poids ne peut pas être réalisée sur le trait %s, pour les raisons suivantes \:<ul>%s</ul> tutti.service.export.gearCaracteristics.error=Erreur lors de l'export des caractéristiques des engins tutti.service.export.individualObservations.error=Erreur lors de l'export des observations individuelles tutti.service.export.invalid.cruise=Erreur d'élévation de poids sur les traits de la campagne %s \:<ul>%s</ul> tutti.service.export.invalid.fishingOperation=<li>L'élévation des poids ne peut pas être réalisée sur le trait %s, pour la raison suivante \:<ul><li>%s</li></ul></li> tutti.service.export.marineLitters.error=Erreur lors de l'export des macro-déchets +tutti.service.export.operation.error=Impossible d'export le trait %s pour la campagne %s tutti.service.export.operations.error=Erreur lors de l'export des traits tutti.service.export.parameters.error=Erreur lors de l'export des paramètres tutti.service.export.species.error=Erreur lors de l'export des espèces tutti.service.export.survey.error=Erreur lors de l'export de la campagne tutti.service.exportCruise.checkCruise=Vérification de la campagne %s -tutti.service.exportCruise.exportAccidentalCatches=<html>Export du fichier <strong>accidentalCatch.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportCatches=<html>Export du fichier <strong>catch.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportGearCaracteristics=<html>Export du fichier <strong>gearCaracteristics.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportIndividualObservations=<html>Export du fichier <strong>individualObservation.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportMarineLitters=<html>Export du fichier <strong>marineLitter.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportOperations=<html>Export du fichier <strong>operations.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportParameters=<html>Export du fichier <strong>parameters.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportSpecies=<html>Export du fichier <strong>species.csv</strong> pour la campagne %s</html> -tutti.service.exportCruise.exportSurvey=<html>Export du fichier <strong>survey.csv</strong> pour la campagne %s</html> +tutti.service.exportCruise.checkCruiseFishingOperation=Vérification de la campagne <strong>%s</strong> ( trait <strong>%s</strong> ) +tutti.service.exportCruise.exportGearCaracteristics=<html>Export de la campagne <strong>%s</strong> ( caractéristiques des engins)</html> +tutti.service.exportCruise.exportOperation=<html>Export de la campagne <strong>%s</strong> (trait <strong>%s</strong> )</html> +tutti.service.exportCruise.exportSpecies=<html>Export de la campagne <strong>%s</strong> ( espèces )</html> +tutti.service.exportCruise.exportSurvey=<html>Export de la campagne <strong>%s</strong></html> tutti.service.exportPdf.error=Erreur lors de la génération du pdf %s tutti.service.exportSumatra.error.species.null=L'espèce est nulle tutti.service.exportSumatra.error.station.null=Le trait est nul diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceTest.java index 498583e..1c1062a 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceTest.java @@ -22,7 +22,6 @@ package fr.ifremer.tutti.service.genericformat; * #L% */ -import com.google.common.collect.Lists; import com.google.common.io.Files; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.TuttiEntities; @@ -63,8 +62,8 @@ public class GenericFormatExportServiceTest { public static final String OPERATION_2_ID = "100107"; public static final String SURVEY_CONTENT = - "Annee;Serie;Serie_Partielle;Navire;Pays;Zone_Etude;Campagne;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire;Navire_Id;Port_Deb_Campagne_Id;Port_Fin_Campagne_Id;Chef_Mission_Id;Resp_Salle_Tri_Id\n" + - "2013;Campagne CGFS;;278970;FRA;CGFS - Manche Est / Sud Mer du Nord;Campagne CGFS_2013;;01/05/2013 00:00:00;La Barbotière (Gujan-Mestras);31/05/2013 00:00:00;Etang de Palo;Vincent AURECHE;Alain TETARD;;278970;892;12407;1981;104"; + "Annee;Serie;Serie_Partielle;Navire;Nombre_Poches;Pays;Zone_Etude;Campagne;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire;Serie_Id;Navire_Id;Engin_Id;Port_Deb_Campagne_Id;Port_Fin_Campagne_Id;Chef_Mission_Id;Resp_Salle_Tri_Id\n" + + "2013;Campagne CGFS;;278970;1;FRA;CGFS - Manche Est / Sud Mer du Nord;Campagne CGFS_2013;;01/05/2013 00:00:00;La Barbotière (Gujan-Mestras);31/05/2013 00:00:00;Etang de Palo;Vincent AURECHE;Alain TETARD;;CAM-CGFS;278970;377|-2;892;12407;1981;104"; // "Annee;Serie;Serie_Partielle;Navire;Pays;Zone_Etude;Campagne;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire\n" + // "2013;Campagne CGFS;;278970;FRA;CGFS - Manche Est / Sud Mer du Nord;Campagne CGFS_2013;;01/05/2013 00:00:00;La Barbotière (Gujan-Mestras);31/05/2013 00:00:00;Etang de Palo;Vincent AURECHE;Alain TETARD;"; @@ -323,6 +322,7 @@ public class GenericFormatExportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 2, OPERATION_1_ID, OPERATION_2_ID); progressionModel = new ProgressionModel(); + progressionModel.setTotal(1); exportFile = new File(dataDirectory, "export.zip"); @@ -353,7 +353,7 @@ public class GenericFormatExportServiceTest { Assert.assertFalse(exportFile.exists()); - progressionModel.setTotal(service.getExportCruiseNbSteps()); + progressionModel.setTotal(service.getExportCruiseNbSteps(dataContext.cruise.getId())); service.exportCruise(dataContext.cruise.getId(), exportFile, progressionModel); Assert.assertTrue(exportFile.exists()); @@ -362,8 +362,8 @@ public class GenericFormatExportServiceTest { @Test public void exportSurvey() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportSurvey(exportContext, dataContext.cruise); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("Survey export:\n", archive.getSurveyPath().toFile(), @@ -373,7 +373,7 @@ public class GenericFormatExportServiceTest { @Test public void exportGearCaracteristics() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { service.exportGearCaracteristics(exportContext, dataContext.cruise); } ServiceDbResource.assertFileContent("Gear caracteristics export:\n", @@ -384,8 +384,8 @@ public class GenericFormatExportServiceTest { @Test public void exportOperations() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportOperations(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("Operation export:\n", archive.getOperationPath().toFile(), @@ -398,10 +398,9 @@ public class GenericFormatExportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); FishingOperation operation = TuttiEntities.findById(dataContext.operations, "100105"); - dataContext.operations = Lists.newArrayList(operation); - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportOperations(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportOperation(exportContext, dataContext.cruise, operation); } ServiceDbResource.assertFileContent("Operation export:\n", @@ -416,10 +415,9 @@ public class GenericFormatExportServiceTest { FishingOperation operation = TuttiEntities.findById(dataContext.operations, "100105"); operation.setGear(null); - dataContext.operations = Lists.newArrayList(operation); - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportOperations(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportOperation(exportContext, dataContext.cruise, operation); } ServiceDbResource.assertFileContent("Operation export:\n", @@ -430,8 +428,8 @@ public class GenericFormatExportServiceTest { @Test public void exportParameters() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportParameters(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("Parameter export:\n", @@ -442,8 +440,8 @@ public class GenericFormatExportServiceTest { @Test public void exportCatches() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("Catch export:\n", archive.getCatchPath().toFile(), @@ -463,10 +461,9 @@ public class GenericFormatExportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); FishingOperation operation = TuttiEntities.findById(dataContext.operations, "100000"); - dataContext.operations = Lists.newArrayList(operation); - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportOperation(exportContext, dataContext.cruise, operation); service.exportSpecies(exportContext); } @@ -487,16 +484,16 @@ public class GenericFormatExportServiceTest { dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } } @Test public void exportMarineLitters() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportMarineLitters(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("MarineLitter export:\n", archive.getMarineLitterPath().toFile(), @@ -506,8 +503,8 @@ public class GenericFormatExportServiceTest { @Test public void exportIndividualObservations() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportIndividualObservations(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("individualObservation export:\n", archive.getIndividualObservationPath().toFile(), @@ -517,8 +514,8 @@ public class GenericFormatExportServiceTest { @Test public void exportAccidentalCatch() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { - service.exportAccidentalCatch(exportContext, dataContext.cruise, dataContext.operations); + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { + service.exportCruise(exportContext, dataContext.cruise, dataContext.operations); } ServiceDbResource.assertFileContent("accidentalCatch export:\n", archive.getAccidentalCatchPath().toFile(), @@ -528,7 +525,7 @@ public class GenericFormatExportServiceTest { @Test public void exportSpecies() throws Exception { - try (GenericFormatExportContext exportContext = service.createExportContext(archive)) { + try (GenericFormatExportContext exportContext = service.createExportContext(progressionModel, archive)) { List<Species> allReferentSpecies = persistenceService.getAllReferentSpecies(); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatCruiseAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatCruiseAction.java index ad7b3f7..6a42f66 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatCruiseAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatCruiseAction.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.genericformat.GenericFormatExportService; import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUI; @@ -95,13 +96,18 @@ public class ExportGenericFormatCruiseAction extends AbstractTuttiAction<SelectC GenericFormatExportService service = getContext().getGenericFormatExportService(); - int nbSteps = service.getExportCruiseNbSteps(); - createProgressionModelIfRequired(nbSteps); + createProgressionModelIfRequired(1); + + ProgressionModel progressionModel = getProgressionModel(); + progressionModel.increments(t("tutti.exportCruise.action.computeNbSteps")); + + int nbSteps = service.getExportCruiseNbSteps(cruise.getId()); + progressionModel.adaptTotal(nbSteps); ApplicationBusinessException exportError = null; try { - service.exportCruise(cruise.getId(), file, getProgressionModel()); + service.exportCruise(cruise.getId(), file, progressionModel); sendMessage(t("tutti.exportCruise.action.success", cruise.getName(), file.getName())); } catch (ApplicationBusinessException e) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatProgramCruisesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatProgramCruisesAction.java index d2cf969..66382f7 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatProgramCruisesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportGenericFormatProgramCruisesAction.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.Program; import fr.ifremer.tutti.service.genericformat.GenericFormatExportService; import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUI; @@ -93,14 +94,20 @@ public class ExportGenericFormatProgramCruisesAction extends AbstractTuttiAction GenericFormatExportService service = getContext().getGenericFormatExportService(); + createProgressionModelIfRequired(1); + + ProgressionModel progressionModel = getProgressionModel(); + + progressionModel.increments(t("tutti.exportProgram.action.computeNbSteps")); + int nbSteps = service.getExportProgramNbSteps(program.getId()); + progressionModel.adaptTotal(nbSteps); - createProgressionModelIfRequired(nbSteps); ApplicationBusinessException exportError = null; try { - service.exportProgram(program.getId(), file, getProgressionModel()); + service.exportProgram(program.getId(), file, progressionModel); } catch (ApplicationBusinessException e) { String errorMessage; 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 992aa11..49fc205 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 @@ -1298,6 +1298,7 @@ tutti.error.update.bad.url.syntax= tutti.error.update.could.not.found.url= tutti.error.update.could.not.reach.url= tutti.error.write.startActionFile=could not write action content to file %s +tutti.exportCruise.action.computeNbSteps= tutti.exportCruise.action.exportErrors= tutti.exportCruise.action.success= tutti.exportCruiseCsv.action.chooseFile= @@ -1346,6 +1347,7 @@ tutti.exportFishingOperationReport.action.success= tutti.exportFishingOperationReport.message.model.modified=Catch was modified, please save it before launching an export. tutti.exportFishingOperationReport.title.choose.exportFile= tutti.exportFishingOperationReport.title.model.modified=Can't export, catch is modified +tutti.exportProgram.action.computeNbSteps= tutti.exportProgram.action.exportErrors= tutti.exportProgram.action.success= tutti.exportProtocol.action.success= 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 1ca8a02..7824bb7 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 @@ -1258,6 +1258,7 @@ tutti.error.update.bad.url.syntax=Mise à jour impossible (le format de l'url <s tutti.error.update.could.not.found.url=Mise à jour impossible (l'url <strong>%s</strong> n'existe pas) tutti.error.update.could.not.reach.url=Mise à jour impossible (l'url <strong>%s</strong> n'est pas joignable) tutti.error.write.startActionFile=impossible d'écrire dans le fichier %s +tutti.exportCruise.action.computeNbSteps=Calcul du nombre d'opérations à réaliser tutti.exportCruise.action.exportErrors=Des erreurs sont apparues pendant l'élévation des poids de la campagne <strong>%s</strong>.<br/>L'export a cependant été réalisé.<hr/>Erreur(s) rencontrée(s) \: <br/>%s tutti.exportCruise.action.success=La campagne <strong>%s</strong> a été exportée dans le fichier <strong>%s</strong>. tutti.exportCruiseCsv.action.chooseFile=Choisir le fichier d'export @@ -1290,6 +1291,7 @@ tutti.exportFishingOperationReport.action.success=Le trait a été exporté dans tutti.exportFishingOperationReport.message.model.modified=La capture a été modifiée, veuillez l'enregistrer avant de lancer un export. tutti.exportFishingOperationReport.title.choose.exportFile=Exporter le trait de la campagne tutti.exportFishingOperationReport.title.model.modified=Impossible d'exporter, capture modifiée +tutti.exportProgram.action.computeNbSteps=Calcul du nombre d'opérations à réaliser tutti.exportProgram.action.exportErrors=Des erreurs sont apparues pendant l'élévation des poids d'une campagne de la série <strong>%s</strong>.<br/>L'export a cependant été réalisé.<hr/>Erreur(s) rencontrée(s) \: <br/>%s tutti.exportProgram.action.success=La série de campagne <strong>%s</strong> a été exportée dans le fichier <strong>%s</strong>. tutti.exportProtocol.action.success=Protocole [%1s] exporté dans le fichier <strong>%2s</strong>. -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm