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 c5240d364bb3b772a72a5db55ba31f5aa207138a Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 30 15:57:29 2015 +0200 can now export partial data --- .../GenericFormatExportActionEngine.java | 21 ++- .../GenericFormatExportConfiguration.java | 84 +++++++++- .../genericformat/GenericFormatExportContext.java | 167 ++++++++++-------- .../genericformat/GenericFormatExportResult.java | 4 + .../genericformat/GenericFormatExportService.java | 81 ++++----- .../service/genericformat/csv/CatchModel.java | 2 +- .../tutti/service/genericformat/csv/CatchRow.java | 6 +- .../service/genericformat/csv/OperationRow.java | 186 +++++++++++++++------ .../CreateAccidentalCatchRowsAction.java | 21 +-- .../exportactions/CreateCatchBatchRowsAction.java | 52 +++++- .../CreateIndividualObservationRowsAction.java | 23 +-- .../CreateMarineLitterRowsAction.java | 21 +-- .../exportactions/CreateOperationRowsAction.java | 13 ++ .../exportactions/CreateParameterRowsAction.java | 5 + .../ExportFishingOperationActionSupport.java | 3 + .../exportactions/FinalizeExportAction.java | 71 +++----- .../exportactions/FlushOperationAction.java | 5 + .../exportactions/LoadDataAction.java | 26 ++- .../producer/CsvProducerForCatch.java | 32 ++++ .../producer/CsvProducerForOperation.java | 1 - .../resources/i18n/tutti-service_en_GB.properties | 1 + .../resources/i18n/tutti-service_fr_FR.properties | 1 + .../GenericFormatExportServiceAno5804Test.java | 3 +- .../GenericFormatExportServiceTest.java | 3 +- 24 files changed, 541 insertions(+), 291 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportActionEngine.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportActionEngine.java index be3d49b..d4cb72d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportActionEngine.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportActionEngine.java @@ -81,8 +81,6 @@ public class GenericFormatExportActionEngine { public void executeCruiseActions(GenericFormatExportContext exportContext, Cruise cruise) { - exportContext.setCruiseExported(true); - for (ExportCruiseActionSupport action : cruiseActions) { if (log.isInfoEnabled()) { @@ -96,14 +94,22 @@ public class GenericFormatExportActionEngine { public void executeOperationActions(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - exportContext.setOperationExported(true); - for (ExportFishingOperationActionSupport action : fishingOperationsActions) { - if (log.isInfoEnabled()) { - log.info("Execute " + action.getClass().getSimpleName() + " on operation " + operationContext.getOperation().getId()); + if (action.doExecute(exportContext, operationContext)) { + + if (log.isInfoEnabled()) { + log.info("Execute " + action.getClass().getSimpleName() + " on operation " + operationContext.getOperation().getId()); + } + action.execute(exportContext, operationContext); + + } else { + + if (log.isInfoEnabled()) { + log.info("Skip " + action.getClass().getSimpleName() + " on operation " + operationContext.getOperation().getId()); + } + } - action.execute(exportContext, operationContext); } @@ -184,4 +190,5 @@ public class GenericFormatExportActionEngine { return actions; } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportConfiguration.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportConfiguration.java index 724c472..1c9a50b 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportConfiguration.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportConfiguration.java @@ -1,6 +1,6 @@ package fr.ifremer.tutti.service.genericformat; -import com.google.common.collect.Multimap; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; import java.io.File; import java.io.Serializable; @@ -16,9 +16,14 @@ public class GenericFormatExportConfiguration implements Serializable { private static final long serialVersionUID = -6500054741804757627L; /** - * Ids of cruise (keys) and fishing operations to export. + * Data to export. */ - private Multimap<String, String> cruiseAndFishingOperationIds; + private ProgramDataModel dataToExport; + + /** + * Archive file to produce. + */ + private File exportFile; /** * Should we export attachments ? @@ -26,16 +31,36 @@ public class GenericFormatExportConfiguration implements Serializable { private boolean exportAttachments; /** - * Archive file to produce. + * Should we export species batches ? */ - private File exportFile; + private boolean exportSpecies; + + /** + * Should we export benthos batches ? + */ + private boolean exportBenthos; - public Multimap<String, String> getCruiseAndFishingOperationIds() { - return cruiseAndFishingOperationIds; + /** + * Should we export marine litter batches ? + */ + private boolean exportMarineLitter; + + /** + * Should we export accidental catches ? + */ + private boolean exportAccidentalCatch; + + /** + * Should we export individual observations ? + */ + private boolean exportIndividualObservation; + + public ProgramDataModel getDataToExport() { + return dataToExport; } - public void setCruiseAndFishingOperationIds(Multimap<String, String> cruiseAndFishingOperationIds) { - this.cruiseAndFishingOperationIds = cruiseAndFishingOperationIds; + public void setDataToExport(ProgramDataModel dataToExport) { + this.dataToExport = dataToExport; } public boolean isExportAttachments() { @@ -53,4 +78,45 @@ public class GenericFormatExportConfiguration implements Serializable { public void setExportFile(File exportFile) { this.exportFile = exportFile; } + + public void setExportSpecies(boolean exportSpecies) { + this.exportSpecies = exportSpecies; + } + + public boolean isExportSpecies() { + return exportSpecies; + } + + public void setExportBenthos(boolean exportBenthos) { + this.exportBenthos = exportBenthos; + } + + public boolean isExportBenthos() { + return exportBenthos; + } + + public void setExportMarineLitter(boolean exportMarineLitter) { + this.exportMarineLitter = exportMarineLitter; + } + + public boolean isExportMarineLitter() { + return exportMarineLitter; + } + + public void setExportAccidentalCatch(boolean exportAccidentalCatch) { + this.exportAccidentalCatch = exportAccidentalCatch; + } + + public boolean isExportAccidentalCatch() { + return exportAccidentalCatch; + } + + public void setExportIndividualObservation(boolean exportIndividualObservation) { + this.exportIndividualObservation = exportIndividualObservation; + } + + public boolean isExportIndividualObservation() { + return exportIndividualObservation; + } + } 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 df7d922..1db7b3e 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 @@ -25,7 +25,7 @@ package fr.ifremer.tutti.service.genericformat; */ import com.google.common.base.Preconditions; -import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -34,8 +34,10 @@ import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; +import fr.ifremer.tutti.service.csv.CsvProducer; import fr.ifremer.tutti.service.genericformat.csv.AccidentalCatchModel; import fr.ifremer.tutti.service.genericformat.csv.AttachmentModel; import fr.ifremer.tutti.service.genericformat.csv.CatchModel; @@ -61,11 +63,13 @@ import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryGear import fr.ifremer.tutti.service.referential.producer.CsvProducerForTemporaryPerson; 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; +import java.io.IOException; import java.nio.file.Path; import java.util.Iterator; import java.util.LinkedHashSet; @@ -81,6 +85,9 @@ import java.util.Set; */ public class GenericFormatExportContext implements Closeable, Iterable<GenericFormatExportCruiseContext> { + /** Logger. */ + private static final Log log = LogFactory.getLog(GenericFormatExportContext.class); + private final GenericFormatExportRequest exportRequest; private final Decorator<FishingOperation> fishingOperationDecorator; @@ -125,10 +132,6 @@ public class GenericFormatExportContext implements Closeable, Iterable<GenericFo private final ProgressionModel progressionModel; - private boolean cruiseExported; - - private boolean operationExported; - private final Set<GenericFormatExportCruiseContext> cruiseContexts; GenericFormatExportContext(ProgressionModel progressionModel, @@ -138,11 +141,15 @@ public class GenericFormatExportContext implements Closeable, Iterable<GenericFo Preconditions.checkNotNull(progressionModel); this.progressionModel = progressionModel; + Preconditions.checkNotNull(exportRequest); this.exportRequest = exportRequest; + Preconditions.checkNotNull(fishingOperationDecorator); this.fishingOperationDecorator = fishingOperationDecorator; + Preconditions.checkNotNull(persistenceService); + this.weightMeasuredCaracteristic = persistenceService.getWeightMeasuredCaracteristic(); this.pmfmIdCaracteristic = persistenceService.getPmfmIdCaracteristic(); this.deadOrAliveCaracteristic = persistenceService.getDeadOrAliveCaracteristic(); @@ -184,51 +191,47 @@ public class GenericFormatExportContext implements Closeable, Iterable<GenericFo } public File getExportFile() { - return exportRequest.getExportConfiguration().getExportFile(); + return getExportConfiguration().getExportFile(); } - public Multimap<String, String> getDataIdsToExport() { - return exportRequest.getExportConfiguration().getCruiseAndFishingOperationIds(); + public ProgramDataModel getDataToExport() { + return getExportConfiguration().getDataToExport(); } - public GenericFormatExportOperationContext newOperationContext(PersistenceService persistenceService, - WeightComputingService weightComputingService, - Cruise cruise, FishingOperation operation) { + public boolean isExportAttachments() { + return getExportConfiguration().isExportAttachments(); + } - String operationLabel = fishingOperationDecorator.toString(operation); - GenericFormatExportOperationContext operationExportContext = new GenericFormatExportOperationContext(cruise, - operation, - operationLabel, - persistenceService, - weightComputingService, - getSampleCategoryModel(), - weightMeasuredCaracteristic, - pmfmIdCaracteristic, - deadOrAliveCaracteristic, - genderCaracteristic); - return operationExportContext; + public boolean isExportSpecies() { + return getExportConfiguration().isExportSpecies(); + } + public boolean isExportBenthos() { + return getExportConfiguration().isExportBenthos(); } - @Override - public void close() { + public boolean isExportMarineLitter() { + return getExportConfiguration().isExportMarineLitter(); + } + + public boolean isExportAccidentalCatch() { + return getExportConfiguration().isExportAccidentalCatch(); + } + + public boolean isExportIndividualObservation() { + return getExportConfiguration().isExportIndividualObservation(); + } - IOUtils.closeQuietly(producerForSurvey); - IOUtils.closeQuietly(producerForSpecies); - IOUtils.closeQuietly(producerForGearCaracteristics); - IOUtils.closeQuietly(producerForOperation); - IOUtils.closeQuietly(producerForParameter); - IOUtils.closeQuietly(producerForAccidentalCatch); - IOUtils.closeQuietly(producerForIndividualObservation); - IOUtils.closeQuietly(producerForCatch); - IOUtils.closeQuietly(producerForMarineLitter); - IOUtils.closeQuietly(producerForTemporaryGear); - IOUtils.closeQuietly(producerForTemporaryPerson); - IOUtils.closeQuietly(producerForTemporarySpecies); - IOUtils.closeQuietly(producerForTemporaryVessel); - IOUtils.closeQuietly(producerForSampleCategory); - IOUtils.closeQuietly(producerForAttachment); + public GenericFormatArchive getArchive() { + return exportRequest.getArchive(); + } + + public SampleCategoryModel getSampleCategoryModel() { + return exportRequest.getSampleCategoryModel(); + } + public File getProtocolFile() { + return getArchive().getProtocolPath().toFile(); } public ProgressionModel getProgressionModel() { @@ -295,44 +298,51 @@ public class GenericFormatExportContext implements Closeable, Iterable<GenericFo return producerForAttachment; } - public boolean isExportAttachments() { - return exportRequest.getExportConfiguration().isExportAttachments(); + public void increments(String message) { + progressionModel.increments(message); } - public GenericFormatArchive getArchive() { - return exportRequest.getArchive(); - } + public void addCruiseContext(Cruise cruise, Set<FishingOperation> operations) { - public File getProtocolFile() { - return getArchive().getProtocolPath().toFile(); - } + GenericFormatExportCruiseContext cruiseContext = new GenericFormatExportCruiseContext(cruise, operations); + cruiseContexts.add(cruiseContext); - public SampleCategoryModel getSampleCategoryModel() { - return exportRequest.getSampleCategoryModel(); } - public void increments(String message) { - progressionModel.increments(message); - } + public GenericFormatExportOperationContext newOperationContext(PersistenceService persistenceService, + WeightComputingService weightComputingService, + Cruise cruise, FishingOperation operation) { - public void setCruiseExported(boolean cruiseExported) { - this.cruiseExported = cruiseExported; - } + String operationLabel = fishingOperationDecorator.toString(operation); + GenericFormatExportOperationContext operationExportContext = new GenericFormatExportOperationContext(cruise, + operation, + operationLabel, + persistenceService, + weightComputingService, + getSampleCategoryModel(), + weightMeasuredCaracteristic, + pmfmIdCaracteristic, + deadOrAliveCaracteristic, + genderCaracteristic); + return operationExportContext; - public boolean isCruiseExported() { - return cruiseExported; } - public void setOperationExported(boolean operationExported) { - this.operationExported = operationExported; - } + @Override + public void close() { - public boolean isOperationExported() { - return operationExported; - } + for (CsvProducer csvProducer : producers()) { + + try { + csvProducer.close(); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not close producer: " + csvProducer.getClass().getSimpleName(), e); + } + } + + } - public void addCruiseContext(GenericFormatExportCruiseContext cruiseContext) { - cruiseContexts.add(cruiseContext); } @Override @@ -340,4 +350,27 @@ public class GenericFormatExportContext implements Closeable, Iterable<GenericFo return cruiseContexts.iterator(); } + public Set<CsvProducer<?, ?>> producers() { + return Sets.newHashSet( + producerForSurvey, + producerForSpecies, + producerForGearCaracteristics, + producerForOperation, + producerForParameter, + producerForAccidentalCatch, + producerForIndividualObservation, + producerForCatch, + producerForMarineLitter, + producerForTemporaryGear, + producerForTemporaryPerson, + producerForTemporarySpecies, + producerForTemporaryVessel, + producerForSampleCategory, + producerForAttachment); + } + + protected GenericFormatExportConfiguration getExportConfiguration() { + return exportRequest.getExportConfiguration(); + } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportResult.java index 5330b7d..fa88bb5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportResult.java @@ -38,4 +38,8 @@ public class GenericFormatExportResult implements Serializable { public List<String> getErrorsByCruise() { return errorsByCruise; } + + public boolean isSuccess() { + return errorsByCruise.isEmpty(); + } } 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 3347457..518ba90 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 @@ -23,13 +23,12 @@ package fr.ifremer.tutti.service.genericformat; */ import com.google.common.base.Preconditions; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; 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.Program; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.model.CruiseDataModel; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; @@ -49,7 +48,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -91,84 +89,70 @@ public class GenericFormatExportService extends AbstractTuttiService { public GenericFormatExportConfiguration createExportConfigurationForProgram(String programId, File exportFile) { - Program program = persistenceService.getProgram(programId); - Preconditions.checkNotNull(program); - - if (log.isDebugEnabled()) { - log.debug("Will export program: " + programId); - } - - List<String> allCruiseIds = persistenceService.getAllCruiseId(programId); - Multimap<String, String> idsToExport = ArrayListMultimap.create(); - for (String cruiseId : allCruiseIds) { - List<String> operations = persistenceService.getAllFishingOperationIds(cruiseId); - idsToExport.putAll(cruiseId, operations); - } + ProgramDataModel dataToExport = persistenceService.loadProgram(programId, true); GenericFormatExportConfiguration configuration = new GenericFormatExportConfiguration(); configuration.setExportFile(exportFile); configuration.setExportAttachments(true); - configuration.setCruiseAndFishingOperationIds(idsToExport); + configuration.setExportSpecies(true); + configuration.setExportBenthos(true); + configuration.setExportMarineLitter(true); + configuration.setExportAccidentalCatch(true); + configuration.setExportIndividualObservation(true); + configuration.setDataToExport(dataToExport); return configuration; } - public GenericFormatExportConfiguration createExportConfigurationForCruise(String cruiseId, File exportFile) { + public GenericFormatExportConfiguration createExportConfigurationForCruise(String programId, String cruiseId, File exportFile) { Preconditions.checkNotNull(cruiseId); Preconditions.checkNotNull(exportFile); - Cruise cruise = persistenceService.getCruise(cruiseId); - Preconditions.checkNotNull(cruise); - - if (log.isDebugEnabled()) { - log.debug("Will export cruise: " + cruiseId); - } - - Multimap<String, String> idsToExport = ArrayListMultimap.create(); - List<String> operations = persistenceService.getAllFishingOperationIds(cruiseId); - idsToExport.putAll(cruiseId, operations); + ProgramDataModel dataToExport = persistenceService.loadCruises(programId, true, cruiseId); GenericFormatExportConfiguration configuration = new GenericFormatExportConfiguration(); configuration.setExportFile(exportFile); configuration.setExportAttachments(true); - configuration.setCruiseAndFishingOperationIds(idsToExport); + configuration.setExportSpecies(true); + configuration.setExportBenthos(true); + configuration.setExportMarineLitter(true); + configuration.setExportAccidentalCatch(true); + configuration.setExportIndividualObservation(true); + configuration.setDataToExport(dataToExport); return configuration; } - public GenericFormatExportConfiguration createExportConfigurationForFishingOperation(String cruiseId, String fishingOperationId, File exportFile) { + public GenericFormatExportConfiguration createExportConfigurationForFishingOperation(String programId, String cruiseId, String fishingOperationId, File exportFile) { + Preconditions.checkNotNull(programId); Preconditions.checkNotNull(cruiseId); Preconditions.checkNotNull(fishingOperationId); - Cruise cruise = persistenceService.getCruise(cruiseId); - Preconditions.checkNotNull(cruise); - - if (log.isDebugEnabled()) { - log.debug("Will export fishing operation: " + fishingOperationId); - } - FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); - Preconditions.checkNotNull(fishingOperation); - - Multimap<String, String> idsToExport = ArrayListMultimap.create(); - idsToExport.putAll(cruiseId, Collections.singletonList(fishingOperationId)); + ProgramDataModel dataToExport = persistenceService.loadCruise(programId, cruiseId, fishingOperationId); GenericFormatExportConfiguration configuration = new GenericFormatExportConfiguration(); configuration.setExportFile(exportFile); configuration.setExportAttachments(true); - configuration.setCruiseAndFishingOperationIds(idsToExport); + configuration.setExportSpecies(true); + configuration.setExportBenthos(true); + configuration.setExportMarineLitter(true); + configuration.setExportAccidentalCatch(true); + configuration.setExportIndividualObservation(true); + configuration.setDataToExport(dataToExport); return configuration; } public int getExportNbSteps(GenericFormatExportConfiguration configuration) { - Multimap<String, String> cruiseAndFishingOperationIds = configuration.getCruiseAndFishingOperationIds(); + ProgramDataModel dataToExport = configuration.getDataToExport(); int result = 8; // export species + sampleCategoryModel + protocol + temporary gear + temporary person + temporar species + temporary vessel + zip - for (String cruiseId : cruiseAndFishingOperationIds.keySet()) { - result += getCruiseNbStep(cruiseId, cruiseAndFishingOperationIds.get(cruiseId).size()); + for (CruiseDataModel cruise : dataToExport) { + int nbFishingOperations = cruise.size(); + result += getCruiseNbStep(nbFishingOperations); } return result; @@ -288,10 +272,7 @@ public class GenericFormatExportService extends AbstractTuttiService { } - protected int getCruiseNbStep(String cruiseId, int nbFishingOperations) { - - Cruise cruise = persistenceService.getCruise(cruiseId); - Preconditions.checkNotNull(cruise); + protected int getCruiseNbStep(int nbFishingOperations) { int result = 1 + nbFishingOperations // check cruise + operations + 1 // export cruise diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java index e97c7ff..6e66b56 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java @@ -121,7 +121,7 @@ public class CatchModel extends AbstractTuttiImportExportModel<CatchRow> { newColumnForExport("Poids_Reference", CatchRow.REFERENCE_WEIGHT, TuttiCsvUtil.PRIMITIVE_FLOAT); newColumnForExport("Coef_Elev_Espece_Capture", CatchRow.RAISING_FACTOR, TuttiCsvUtil.PRIMITIVE_FLOAT); - newColumnForExport("Coef_Final_Elevation", CatchRow.FINAL_RAISING_FACTOR, TuttiCsvUtil.PRIMITIVE_FLOAT); + newColumnForExport("Coef_Final_Elevation", CatchRow.FINAL_RAISING_FACTOR, TuttiCsvUtil.FLOAT); newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER); for (SampleCategoryModelEntry entry : sampleCategoryModel.getCategory()) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java index 79c79f6..cf73b2e 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java @@ -85,7 +85,7 @@ public class CatchRow extends RowWithOperationContextSupport { protected float raisingFactor; - protected float finalRaisingFactor; + protected Float finalRaisingFactor; protected Integer batchNumber; @@ -149,7 +149,7 @@ public class CatchRow extends RowWithOperationContextSupport { setFrequencyWeight(frequency.getWeight()); } - public void setFinalRaisingFactor(float finalRaisingFactor) { + public void setFinalRaisingFactor(Float finalRaisingFactor) { this.finalRaisingFactor = finalRaisingFactor; } @@ -177,7 +177,7 @@ public class CatchRow extends RowWithOperationContextSupport { return sampleCategory; } - public float getFinalRaisingFactor() { + public Float getFinalRaisingFactor() { return finalRaisingFactor; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java index 27fe645..c33e9c6 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java @@ -151,6 +151,18 @@ public class OperationRow extends RowWithOperationContextSupport { protected Boolean marineLitterTotalWeightComputed; + private Boolean speciesTotalWeightComputed; + + private Boolean speciesTotalUnsortedWeightComputed; + + private Boolean speciesTotalSampleSortedWeightComputed; + + private Boolean benthosTotalWeightComputed; + + private Boolean benthosTotalUnsortedWeightComputed; + + private Boolean benthosTotalSampleSortedWeightComputed; + protected Integer fishingOperationObjectId; protected Integer catchObjectId; @@ -166,31 +178,113 @@ public class OperationRow extends RowWithOperationContextSupport { public void setCatchBatch(CatchBatch catchBatch) { - if (catchBatch == null) { - - // Avoid any NPE - catchBatch = CatchBatchs.newCatchBatch(); - } - - this.catchBatch = catchBatch; + CatchBatch batch = CatchBatchs.newCatchBatch(); + + batch.setCatchTotalWeight(catchBatch.getCatchTotalWeight()); + batch.setCatchTotalComputedWeight(catchBatch.getCatchTotalComputedWeight()); + batch.setCatchTotalSortedTremisWeight(catchBatch.getCatchTotalSortedTremisWeight()); + batch.setCatchTotalSortedCarousselWeight(catchBatch.getCatchTotalSortedCarousselWeight()); + batch.setCatchTotalSortedComputedWeight(catchBatch.getCatchTotalSortedComputedWeight()); + batch.setCatchTotalUnsortedComputedWeight(catchBatch.getCatchTotalUnsortedComputedWeight()); + batch.setCatchTotalRejectedWeight(catchBatch.getCatchTotalRejectedWeight()); + batch.setCatchTotalRejectedComputedWeight(catchBatch.getCatchTotalRejectedComputedWeight()); + + batch.setSpeciesTotalComputedWeight(catchBatch.getSpeciesTotalComputedWeight()); + batch.setSpeciesTotalSortedWeight(catchBatch.getSpeciesTotalSortedWeight()); + batch.setSpeciesTotalSortedWeight(catchBatch.getSpeciesTotalSortedWeight()); + batch.setSpeciesTotalUnsortedComputedWeight(catchBatch.getSpeciesTotalUnsortedComputedWeight()); + batch.setSpeciesTotalSampleSortedComputedWeight(catchBatch.getSpeciesTotalSampleSortedComputedWeight()); + batch.setSpeciesTotalLivingNotItemizedWeight(catchBatch.getSpeciesTotalLivingNotItemizedWeight()); + batch.setSpeciesTotalLivingNotItemizedWeight(catchBatch.getSpeciesTotalLivingNotItemizedWeight()); + batch.setSpeciesTotalInertWeight(catchBatch.getSpeciesTotalInertWeight()); + batch.setSpeciesTotalInertComputedWeight(catchBatch.getSpeciesTotalInertComputedWeight()); + + batch.setBenthosTotalComputedWeight(catchBatch.getBenthosTotalComputedWeight()); + batch.setBenthosTotalSortedWeight(catchBatch.getBenthosTotalSortedWeight()); + batch.setBenthosTotalSortedComputedWeight(catchBatch.getBenthosTotalSortedComputedWeight()); + batch.setBenthosTotalUnsortedComputedWeight(catchBatch.getBenthosTotalUnsortedComputedWeight()); + batch.setBenthosTotalInertWeight(catchBatch.getBenthosTotalInertWeight()); + batch.setBenthosTotalInertComputedWeight(catchBatch.getBenthosTotalInertComputedWeight()); + batch.setBenthosTotalSampleSortedComputedWeight(catchBatch.getBenthosTotalSampleSortedComputedWeight()); + batch.setBenthosTotalLivingNotItemizedWeight(catchBatch.getBenthosTotalLivingNotItemizedWeight()); + batch.setBenthosTotalLivingNotItemizedComputedWeight(catchBatch.getBenthosTotalLivingNotItemizedComputedWeight()); + + batch.setMarineLitterTotalWeight(catchBatch.getMarineLitterTotalWeight()); + batch.setMarineLitterTotalComputedWeight(catchBatch.getMarineLitterTotalComputedWeight()); + + this.catchBatch = batch; setCatchObjectId(catchBatch.getIdAsInt()); } - public void computeCatchValues() { + public void computeCatchValues(boolean exportSpecies, boolean exportBenthos, boolean exportMarineLitter) { setCatchTotalWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getCatchTotalWeight(), catchBatch.getCatchTotalComputedWeight())); setCatchTotalRejectedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getCatchTotalRejectedWeight(), catchBatch.getCatchTotalRejectedComputedWeight())); - setSpeciesTotalSortedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalSortedWeight(), catchBatch.getSpeciesTotalSortedComputedWeight())); - setSpeciesTotalInertWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalInertWeight(), catchBatch.getSpeciesTotalInertComputedWeight())); - setSpeciesTotalLivingNotItemizedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalLivingNotItemizedWeight(), catchBatch.getSpeciesTotalLivingNotItemizedComputedWeight())); - setBenthosTotalSortedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalSortedWeight(), catchBatch.getBenthosTotalSortedComputedWeight())); - setBenthosTotalInertWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalInertWeight(), catchBatch.getBenthosTotalInertComputedWeight())); - setBenthosTotalLivingNotItemizedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalLivingNotItemizedWeight(), catchBatch.getBenthosTotalLivingNotItemizedComputedWeight())); + if (exportSpecies) { + + setSpeciesTotalSortedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalSortedWeight(), catchBatch.getSpeciesTotalSortedComputedWeight())); + setSpeciesTotalInertWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalInertWeight(), catchBatch.getSpeciesTotalInertComputedWeight())); + setSpeciesTotalLivingNotItemizedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getSpeciesTotalLivingNotItemizedWeight(), catchBatch.getSpeciesTotalLivingNotItemizedComputedWeight())); + + speciesTotalWeightComputed = true; + speciesTotalUnsortedWeightComputed = true; + speciesTotalSampleSortedWeightComputed = true; + + } else { + + // remove species values + + catchBatch.setSpeciesTotalComputedWeight(null); + catchBatch.setSpeciesTotalSortedWeight(null); + catchBatch.setSpeciesTotalSortedWeight(null); + catchBatch.setSpeciesTotalUnsortedComputedWeight(null); + catchBatch.setSpeciesTotalSampleSortedComputedWeight(null); + catchBatch.setSpeciesTotalLivingNotItemizedWeight(null); + catchBatch.setSpeciesTotalLivingNotItemizedComputedWeight(null); + catchBatch.setSpeciesTotalInertWeight(null); + catchBatch.setSpeciesTotalInertComputedWeight(null); + + } + + if (exportBenthos) { + + setBenthosTotalSortedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalSortedWeight(), catchBatch.getBenthosTotalSortedComputedWeight())); + setBenthosTotalInertWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalInertWeight(), catchBatch.getBenthosTotalInertComputedWeight())); + setBenthosTotalLivingNotItemizedWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getBenthosTotalLivingNotItemizedWeight(), catchBatch.getBenthosTotalLivingNotItemizedComputedWeight())); + + benthosTotalWeightComputed = true; + benthosTotalUnsortedWeightComputed = true; + benthosTotalSampleSortedWeightComputed = true; - setMarineLitterTotalWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getMarineLitterTotalWeight(), catchBatch.getMarineLitterTotalComputedWeight())); + } else { + + // remove benthos values + + catchBatch.setBenthosTotalComputedWeight(null); + catchBatch.setBenthosTotalSortedWeight(null); + catchBatch.setBenthosTotalSortedComputedWeight(null); + catchBatch.setBenthosTotalUnsortedComputedWeight(null); + catchBatch.setBenthosTotalInertWeight(null); + catchBatch.setBenthosTotalInertComputedWeight(null); + catchBatch.setBenthosTotalSampleSortedComputedWeight(null); + catchBatch.setBenthosTotalLivingNotItemizedWeight(null); + catchBatch.setBenthosTotalLivingNotItemizedComputedWeight(null); + + } + + if (exportMarineLitter) { + + setMarineLitterTotalWeightComputed(Numbers.getValueOrComputedValueComputed(catchBatch.getMarineLitterTotalWeight(), catchBatch.getMarineLitterTotalComputedWeight())); + + } else { + + // remove marine litter values + catchBatch.setMarineLitterTotalWeight(null); + catchBatch.setMarineLitterTotalComputedWeight(null); + } } @@ -452,7 +546,7 @@ public class OperationRow extends RowWithOperationContextSupport { public Float getSpeciesTotalSortedWeight() { return Numbers.getValueOrComputedValue( catchBatch.getSpeciesTotalSortedWeight(), - catchBatch.getSpeciesTotalSortedComputedWeight()); + catchBatch.getSpeciesTotalSortedWeight()); } public Float getSpeciesTotalUnsortedWeight() { @@ -460,9 +554,7 @@ public class OperationRow extends RowWithOperationContextSupport { } public Float getSpeciesTotalSampleSortedWeight() { - return Numbers.getValueOrComputedValue( - catchBatch.getSpeciesTotalSampleSortedComputedWeight(), - catchBatch.getSpeciesTotalSampleSortedComputedWeight()); + return catchBatch.getSpeciesTotalSampleSortedComputedWeight(); } public Float getSpeciesTotalLivingNotItemizedWeight() { @@ -513,52 +605,40 @@ public class OperationRow extends RowWithOperationContextSupport { catchBatch.getMarineLitterTotalComputedWeight()); } - public boolean isCatchTotalSortedTremisWeightComputed() { - return false; - } - - public boolean isCatchTotalSortedCarousselWeightComputed() { - return false; - } - - public boolean isCatchTotalSortedWeightComputed() { - return true; - } - - public boolean isCatchTotalUnsortedWeightComputed() { - return true; + public Boolean getCatchTotalWeightComputed() { + return catchTotalWeightComputed; } - public boolean isSpeciesTotalWeightComputed() { - return true; + public Boolean getCatchTotalRejectedWeightComputed() { + return catchTotalRejectedWeightComputed; } - public boolean isSpeciesTotalUnsortedWeightComputed() { - return true; + public Boolean getCatchTotalSortedTremisWeightComputed() { + return false; } - public boolean isSpeciesTotalSampleSortedWeightComputed() { - return true; + public Boolean getCatchTotalSortedCarousselWeightComputed() { + return false; } - public boolean isBenthosTotalWeightComputed() { + public Boolean getCatchTotalSortedWeightComputed() { return true; } - public boolean isBenthosTotalUnsortedWeightComputed() { + public Boolean getCatchTotalUnsortedWeightComputed() { return true; } - public boolean isBenthosTotalSampleSortedWeightComputed() { - return true; + public Boolean getSpeciesTotalWeightComputed() { + return speciesTotalWeightComputed; } - public Boolean getCatchTotalWeightComputed() { - return catchTotalWeightComputed; + public Boolean getSpeciesTotalUnsortedWeightComputed() { + return speciesTotalUnsortedWeightComputed; } - public Boolean getCatchTotalRejectedWeightComputed() { - return catchTotalRejectedWeightComputed; + public Boolean getSpeciesTotalSampleSortedWeightComputed() { + return speciesTotalSampleSortedWeightComputed; } public Boolean getSpeciesTotalSortedWeightComputed() { @@ -585,6 +665,18 @@ public class OperationRow extends RowWithOperationContextSupport { return benthosTotalLivingNotItemizedWeightComputed; } + public Boolean getBenthosTotalWeightComputed() { + return benthosTotalWeightComputed; + } + + public Boolean getBenthosTotalUnsortedWeightComputed() { + return benthosTotalUnsortedWeightComputed; + } + + public Boolean getBenthosTotalSampleSortedWeightComputed() { + return benthosTotalSampleSortedWeightComputed; + } + public Boolean getMarineLitterTotalWeightComputed() { return marineLitterTotalWeightComputed; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateAccidentalCatchRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateAccidentalCatchRowsAction.java index 829b5f0..b44964d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateAccidentalCatchRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateAccidentalCatchRowsAction.java @@ -28,20 +28,21 @@ public class CreateAccidentalCatchRowsAction extends ExportFishingOperationActio } @Override - public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - - if (operationContext.isWithCatchBatch()) { + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return exportContext.isExportAccidentalCatch() && operationContext.isWithCatchBatch(); + } - List<AccidentalCatchRow> accidentalCatchRows = exportContext.getProducerForAccidentalCatch().getDataToExport(operationContext); - operationContext.setAccidentalCatchRows(accidentalCatchRows); - exportContext.getProducerForSpecies().prepareAccidentalRows(accidentalCatchRows); + @Override + public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - if (exportContext.isExportAttachments()) { + List<AccidentalCatchRow> accidentalCatchRows = exportContext.getProducerForAccidentalCatch().getDataToExport(operationContext); + operationContext.setAccidentalCatchRows(accidentalCatchRows); + exportContext.getProducerForSpecies().prepareAccidentalRows(accidentalCatchRows); - List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getAccidentalBatches()); - operationContext.addAttachmentRows(attachmentRows); + if (exportContext.isExportAttachments()) { - } + List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getAccidentalBatches()); + operationContext.addAttachmentRows(attachmentRows); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java index cd8b839..88f15aa 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateCatchBatchRowsAction.java @@ -39,28 +39,68 @@ public class CreateCatchBatchRowsAction extends ExportFishingOperationActionSupp } @Override + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return (exportContext.isExportSpecies() || exportContext.isExportBenthos()) && operationContext.isWithCatchBatch(); + } + + @Override public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - if (operationContext.isWithCatchBatch()) { + boolean exportSpecies = exportContext.isExportSpecies(); + boolean exportBenthos = exportContext.isExportBenthos(); + boolean exportAll = exportSpecies && exportBenthos; + if (exportSpecies) { prepareSpeciesBatches(exportContext, operationContext); + } + if (exportBenthos) { prepareBenthosBatches(exportContext, operationContext); + } + + CatchBatch catchBatch = operationContext.getCatchBatch(); - CatchBatch catchBatch = operationContext.getCatchBatch(); + Float catchRaisingfactor = computeCatchRaisingfactor(catchBatch); - Float catchRaisingfactor = computeCatchRaisingfactor(catchBatch); - Float speciesCatchRaisingFactor = computeSpeciesRaisingFactor(catchBatch, catchRaisingfactor); - Float benthosCatchRaisingFactor = computeBenthosRaisingFactor(catchBatch, catchRaisingfactor); + Float speciesCatchRaisingFactor = null; + if (exportSpecies) { + speciesCatchRaisingFactor = computeSpeciesRaisingFactor(catchBatch, catchRaisingfactor); + } + + Float benthosCatchRaisingFactor = null; + if (exportBenthos) { + benthosCatchRaisingFactor = computeBenthosRaisingFactor(catchBatch, catchRaisingfactor); + } + + CsvProducerForCatch producerForCatch = exportContext.getProducerForCatch(); + + if (exportAll) { if (log.isInfoEnabled()) { log.info(String.format("Operation %s [catchRF: %s / speciesRF: %s / benthosRF: %s ]", operationContext.getOperation().getId(), catchRaisingfactor, speciesCatchRaisingFactor, benthosCatchRaisingFactor)); } - CsvProducerForCatch producerForCatch = exportContext.getProducerForCatch(); List<CatchRow> catchRows = producerForCatch.getDataToExport(operationContext, speciesCatchRaisingFactor, benthosCatchRaisingFactor); operationContext.setCatchRows(catchRows); + } else if (exportSpecies) { + + if (log.isInfoEnabled()) { + log.info(String.format("Operation %s [catchRF: %s / speciesRF: %s ]", operationContext.getOperation().getId(), catchRaisingfactor, speciesCatchRaisingFactor)); + } + + List<CatchRow> catchRows = producerForCatch.getSpeciesOnlyDataToExport(operationContext, speciesCatchRaisingFactor); + operationContext.setCatchRows(catchRows); + + } else if (exportBenthos) { + + if (log.isInfoEnabled()) { + log.info(String.format("Operation %s [catchRF: %s / benthosRF: %s ]", operationContext.getOperation().getId(), catchRaisingfactor, benthosCatchRaisingFactor)); + } + + List<CatchRow> catchRows = producerForCatch.getBenthosOnlyDataToExport(operationContext, benthosCatchRaisingFactor); + operationContext.setCatchRows(catchRows); + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateIndividualObservationRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateIndividualObservationRowsAction.java index 3230f49..17210d6 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateIndividualObservationRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateIndividualObservationRowsAction.java @@ -28,20 +28,21 @@ public class CreateIndividualObservationRowsAction extends ExportFishingOperatio } @Override - public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - - if (operationContext.isWithCatchBatch()) { + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return exportContext.isExportIndividualObservation() && operationContext.isWithCatchBatch(); + } - List<IndividualObservationRow> individualObservationRows = exportContext.getProducerForIndividualObservation().getDataToExport(operationContext); - operationContext.setIndividualObservationRows(individualObservationRows); - exportContext.getProducerForSpecies().prepareIndividualRows(individualObservationRows); + @Override + public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - if (exportContext.isExportAttachments()) { + List<IndividualObservationRow> individualObservationRows = exportContext.getProducerForIndividualObservation().getDataToExport(operationContext); + operationContext.setIndividualObservationRows(individualObservationRows); + exportContext.getProducerForSpecies().prepareIndividualRows(individualObservationRows); - List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getIndividualObservations()); - operationContext.addAttachmentRows(attachmentRows); + if (exportContext.isExportAttachments()) { - } + List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getIndividualObservations()); + operationContext.addAttachmentRows(attachmentRows); } @@ -55,7 +56,7 @@ public class CreateIndividualObservationRowsAction extends ExportFishingOperatio for (IndividualObservationBatch individualObservationBatch : individualObservationBatches) { List<Attachment> attachments = persistenceService.getAllAttachments(ObjectTypeCode.SAMPLE, individualObservationBatch.getIdAsInt()); - producerForAttachment. addAttachments(attachments, attachmentRows); + producerForAttachment.addAttachments(attachments, attachmentRows); } return attachmentRows; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateMarineLitterRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateMarineLitterRowsAction.java index 452b336..b6a2855 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateMarineLitterRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateMarineLitterRowsAction.java @@ -29,19 +29,20 @@ public class CreateMarineLitterRowsAction extends ExportFishingOperationActionSu } @Override - public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - - if (operationContext.isWithCatchBatch()) { + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return exportContext.isExportMarineLitter() && operationContext.isWithCatchBatch(); + } - List<MarineLitterRow> marineLitterRows = exportContext.getProducerForMarineLitter().getDataToExport(operationContext); - operationContext.setMarineLitterRows(marineLitterRows); + @Override + public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { - if (exportContext.isExportAttachments()) { + List<MarineLitterRow> marineLitterRows = exportContext.getProducerForMarineLitter().getDataToExport(operationContext); + operationContext.setMarineLitterRows(marineLitterRows); - List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getRootMarineLitterBatch()); - operationContext.addAttachmentRows(attachmentRows); + if (exportContext.isExportAttachments()) { - } + List<AttachmentRow> attachmentRows = getAttachmentRows(exportContext, operationContext.getRootMarineLitterBatch()); + operationContext.addAttachmentRows(attachmentRows); } @@ -54,7 +55,7 @@ public class CreateMarineLitterRowsAction extends ExportFishingOperationActionSu List<AttachmentRow> attachmentRows = new ArrayList<>(); for (MarineLitterBatch marineLitterBatch : marineLitterBatches.getChildren()) { - List<Attachment> attachments =persistenceService.getAllAttachments(ObjectTypeCode.BATCH, marineLitterBatch.getIdAsInt()); + List<Attachment> attachments = persistenceService.getAllAttachments(ObjectTypeCode.BATCH, marineLitterBatch.getIdAsInt()); producerForAttachment.addAttachments(attachments, attachmentRows); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateOperationRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateOperationRowsAction.java index 43ec895..373c863 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateOperationRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateOperationRowsAction.java @@ -30,13 +30,25 @@ public class CreateOperationRowsAction extends ExportFishingOperationActionSuppo } @Override + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return true; + } + + @Override public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { FishingOperation operation = operationContext.getOperation(); Cruise cruise = operationContext.getCruise(); CatchBatch catchBatch = operationContext.getCatchBatch(); + boolean exportSpecies = exportContext.isExportSpecies(); + boolean exportBenthos = exportContext.isExportBenthos(); + boolean exportMarineLitter = exportContext.isExportMarineLitter(); + OperationRow operationRow = exportContext.getProducerForOperation().getDataToExport(cruise, operation, catchBatch); + + operationRow.computeCatchValues(exportSpecies, exportBenthos, exportMarineLitter); + operationContext.setOperationRow(operationRow); if (exportContext.isExportAttachments()) { @@ -70,4 +82,5 @@ public class CreateOperationRowsAction extends ExportFishingOperationActionSuppo return attachmentRows; } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateParameterRowsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateParameterRowsAction.java index 2013771..f5cdec5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateParameterRowsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/CreateParameterRowsAction.java @@ -17,6 +17,11 @@ import java.util.List; public class CreateParameterRowsAction extends ExportFishingOperationActionSupport { @Override + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return true; + } + + @Override public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { FishingOperation operation = operationContext.getOperation(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/ExportFishingOperationActionSupport.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/ExportFishingOperationActionSupport.java index 8ce71d8..3ee5466 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/ExportFishingOperationActionSupport.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/ExportFishingOperationActionSupport.java @@ -11,6 +11,9 @@ import fr.ifremer.tutti.service.genericformat.GenericFormatExportOperationContex */ public abstract class ExportFishingOperationActionSupport { + + public abstract boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext); + public abstract void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext); } \ No newline at end of file diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FinalizeExportAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FinalizeExportAction.java index 35d3d1c..c8f530d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FinalizeExportAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FinalizeExportAction.java @@ -1,8 +1,13 @@ package fr.ifremer.tutti.service.genericformat.exportactions; +import fr.ifremer.tutti.service.csv.CsvProducer; import fr.ifremer.tutti.service.genericformat.GenericFormatExportContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.application.ApplicationTechnicalException; +import java.util.Set; + import static org.nuiton.i18n.I18n.t; /** @@ -13,21 +18,28 @@ import static org.nuiton.i18n.I18n.t; */ public class FinalizeExportAction extends ExportTechnicalActionSupport { + /** Logger. */ + private static final Log log = LogFactory.getLog(FinalizeExportAction.class); + @Override public void execute(GenericFormatExportContext exportContext) { try { - if (!exportContext.isCruiseExported()) { - addEmptyCruiseFiles(exportContext); - } + Set<CsvProducer<?, ?>> producers = exportContext.producers(); + for (CsvProducer<?, ?> producer : producers) { - if (!exportContext.isOperationExported()) { - addEmptyOperationFiles(exportContext); - } + if (!producer.wasTouched()) { + try { + if (log.isInfoEnabled()) { + log.info("Write empty file for csv producer: " + producer); + } + producer.writeEmpty(); + } catch (Exception e) { + throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.emptyFile.error"), e); + } - if (!exportContext.isExportAttachments()) { - addEmptyAttachmentFile(exportContext); + } } } finally { @@ -38,47 +50,4 @@ public class FinalizeExportAction extends ExportTechnicalActionSupport { } - protected void addEmptyCruiseFiles(GenericFormatExportContext exportContext) { - - try { - - exportContext.getProducerForSurvey().writeEmpty(); - exportContext.getProducerForGearCaracteristics().writeEmpty(); - exportContext.getProducerForAttachment().writeEmpty(); - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.survey.error"), e); - } - - } - - protected void addEmptyOperationFiles(GenericFormatExportContext exportContext) { - - try { - - exportContext.getProducerForOperation().writeEmpty(); - exportContext.getProducerForParameter().writeEmpty(); - exportContext.getProducerForAccidentalCatch().writeEmpty(); - exportContext.getProducerForIndividualObservation().writeEmpty(); - exportContext.getProducerForCatch().writeEmpty(); - exportContext.getProducerForMarineLitter().writeEmpty(); - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.operations.error"), e); - } - - } - - protected void addEmptyAttachmentFile(GenericFormatExportContext exportContext) { - - try { - - exportContext.getProducerForAttachment().writeEmpty(); - - } catch (Exception e) { - throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.attachments.error"), e); - } - - } - } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FlushOperationAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FlushOperationAction.java index fbbb8cd..a226f0e 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FlushOperationAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/FlushOperationAction.java @@ -15,6 +15,11 @@ import static org.nuiton.i18n.I18n.t; public class FlushOperationAction extends ExportFishingOperationActionSupport { @Override + public boolean doExecute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + return true; + } + + @Override public void execute(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { try { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/LoadDataAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/LoadDataAction.java index f932632..fa45a02 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/LoadDataAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/exportactions/LoadDataAction.java @@ -1,14 +1,14 @@ package fr.ifremer.tutti.service.genericformat.exportactions; import com.google.common.base.Preconditions; -import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.model.CruiseDataModel; +import fr.ifremer.tutti.persistence.model.OperationDataModel; +import fr.ifremer.tutti.persistence.model.ProgramDataModel; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.genericformat.GenericFormatExportContext; -import fr.ifremer.tutti.service.genericformat.GenericFormatExportCruiseContext; -import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; @@ -23,35 +23,29 @@ public class LoadDataAction extends ExportTechnicalActionSupport { private final PersistenceService persistenceService; public LoadDataAction(PersistenceService persistenceService) { - this.persistenceService = persistenceService; } @Override public void execute(GenericFormatExportContext exportContext) { - Multimap<String, String> dataIdsToExport = exportContext.getDataIdsToExport(); - - for (String cruiseId : dataIdsToExport.keySet()) { + ProgramDataModel dataToExport = exportContext.getDataToExport(); - Collection<String> operationIds = dataIdsToExport.get(cruiseId); + for (CruiseDataModel cruiseDataModel : dataToExport) { - Cruise cruise = persistenceService.getCruise(cruiseId); + Cruise cruise = persistenceService.getCruise(cruiseDataModel.getId()); Preconditions.checkNotNull(cruise); Set<FishingOperation> operations = new LinkedHashSet<>(); - if (!operationIds.isEmpty()) { - for (String operationId : operationIds) { - FishingOperation operation = persistenceService.getFishingOperation(operationId); - operations.add(operation); + for (OperationDataModel operationDataModel : cruiseDataModel) { - } + FishingOperation operation = persistenceService.getFishingOperation(operationDataModel.getId()); + operations.add(operation); } - GenericFormatExportCruiseContext cruiseContext = new GenericFormatExportCruiseContext(cruise, operations); - exportContext.addCruiseContext(cruiseContext); + exportContext.addCruiseContext(cruise, operations); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java index 54389b6..1091dc2 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java @@ -89,6 +89,38 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { } + public List<CatchRow> getBenthosOnlyDataToExport(GenericFormatExportOperationContext operationExportContext, + Float benthosCatchRaisingFactor) { + + List<CatchRow> rows = new ArrayList<>(); + + BatchContainer<BenthosBatch> rootBenthosBatch = operationExportContext.getRootBenthosBatch(); + + Caracteristic weightMeasuredCaracteristic = operationExportContext.getWeightMeasuredCaracteristic(); + String batchWeightUnit = weightMeasuredCaracteristic.getUnit(); + + addBenthosBatches(operationExportContext, rootBenthosBatch, benthosCatchRaisingFactor, batchWeightUnit, rows); + + return rows; + + } + + public List<CatchRow> getSpeciesOnlyDataToExport(GenericFormatExportOperationContext operationExportContext, + Float speciesCatchRaisingFactor) { + + List<CatchRow> rows = new ArrayList<>(); + + BatchContainer<SpeciesBatch> rootSpeciesBatch = operationExportContext.getRootSpeciesBatch(); + + Caracteristic weightMeasuredCaracteristic = operationExportContext.getWeightMeasuredCaracteristic(); + String batchWeightUnit = weightMeasuredCaracteristic.getUnit(); + + addSpeciesBatches(operationExportContext, rootSpeciesBatch, speciesCatchRaisingFactor, batchWeightUnit, rows); + + return rows; + + } + protected void addBenthosBatches(GenericFormatExportOperationContext operationExportContext, BatchContainer<BenthosBatch> rootBenthosBatch, Float benthosCatchRaisingFactor, diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForOperation.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForOperation.java index 508cd05..7ae4a55 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForOperation.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForOperation.java @@ -51,7 +51,6 @@ public class CsvProducerForOperation extends CsvProducer<OperationRow, Operation row.setCruise(cruise); row.setFishingOperation(operation); row.setCatchBatch(catchBatch); - row.computeCatchValues(); return row; 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 61b00b9..5fb02a1 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 @@ -130,6 +130,7 @@ tutti.service.genericFormat.export.buildZip= tutti.service.genericFormat.export.catches.error= tutti.service.genericFormat.export.closeContext.error= tutti.service.genericFormat.export.context.error= +tutti.service.genericFormat.export.emptyFile.error= tutti.service.genericFormat.export.exportProtocol= tutti.service.genericFormat.export.exportSampleCategoyModel= tutti.service.genericFormat.export.exportSpecies= 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 226148a..4bf7a12 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 @@ -106,6 +106,7 @@ tutti.service.genericFormat.export.buildZip=Création de l'archive de l'export ( tutti.service.genericFormat.export.catches.error=Erreur lors de l'export des captures tutti.service.genericFormat.export.closeContext.error=Erreur lors de la fermeture du contexte d'export tutti.service.genericFormat.export.context.error=Erreur lors de la création des fichiers pour l'export +tutti.service.genericFormat.export.emptyFile.error=Erreur lors de la création d'un fichier pour l'export tutti.service.genericFormat.export.error.invalid.cruise=Erreur d'élévation de poids sur les traits de la campagne %s \:<ul>%s</ul> tutti.service.genericFormat.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.genericFormat.export.exportProtocol=Export du protocol %s diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceAno5804Test.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceAno5804Test.java index 3ce33ec..322bc47 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceAno5804Test.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportServiceAno5804Test.java @@ -99,8 +99,9 @@ public class GenericFormatExportServiceAno5804Test { Assert.assertFalse(exportFile.exists()); + String programId = dataContext.program.getId(); String cruiseId = dataContext.cruise.getId(); - GenericFormatExportConfiguration exportConfiguration = service.createExportConfigurationForCruise(cruiseId, exportFile); + GenericFormatExportConfiguration exportConfiguration = service.createExportConfigurationForCruise(programId, cruiseId, exportFile); int nbSteps = service.getExportNbSteps(exportConfiguration); progressionModel.setTotal(nbSteps); 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 f0677ab..ca91118 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 @@ -249,8 +249,9 @@ public class GenericFormatExportServiceTest { Assert.assertFalse(exportFile.exists()); + String programId = dataContext.program.getId(); String cruiseId = dataContext.cruise.getId(); - GenericFormatExportConfiguration exportConfiguration = service.createExportConfigurationForCruise(cruiseId, exportFile); + GenericFormatExportConfiguration exportConfiguration = service.createExportConfigurationForCruise(programId, cruiseId, exportFile); int nbSteps = service.getExportNbSteps(exportConfiguration); progressionModel.setTotal(nbSteps); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.