r1650 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/export tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra tutti-service/src/main/resources/i18n tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra tutti-service/src/test/resources tutti-ui-swing/src/main/filtered-
Author: tchemit Date: 2014-03-28 14:11:04 +0100 (Fri, 28 Mar 2014) New Revision: 1650 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1650 Log: fixes #4845: Evolution format export SUMATRA Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModelV2.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowV2.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2Test.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportCruiseForSumatraV2Action.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportFishingOperationForSumatraV2Action.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModel.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties trunk/tutti-service/src/test/resources/tuttiProtocol.tuttiProtocol trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties trunk/tutti-ui-swing/src/main/help/fr/editFishingOperation.html trunk/tutti-ui-swing/src/main/help/fr/selectCruise.html trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -25,6 +25,7 @@ */ import com.google.common.base.Predicate; +import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; @@ -585,6 +586,15 @@ List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId); /** + * Get all frequencies for the given root species batch container. + * + * @param batchContainer the root batch containter + * @return the list of species frequencies indexed by their species + * @since 3.3 + */ + Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer); + + /** * Save all given {@link SpeciesBatchFrequency} into the given * {@code speciesBatchId}. If some are not existing then creates them. * <p/> @@ -643,6 +653,15 @@ List<BenthosBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId); /** + * Get all frequencies for the given root benthos batch container. + * + * @param batchContainer the root batch containter + * @return the list of benthos frequencies indexed by their species + * @since 3.3 + */ + Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer); + + /** * Save all given {@link BenthosBatchFrequency} into the given * {@code benthosBatchId}. If some are not existing then creates them. * <p/> Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -25,7 +25,9 @@ */ import com.google.common.base.Predicate; +import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import fr.ifremer.adagio.core.dao.technical.DatabaseSchemaDao; import fr.ifremer.adagio.core.dao.technical.DatabaseSchemaUpdateException; import fr.ifremer.adagio.core.dao.technical.VersionNotFoundException; @@ -783,6 +785,17 @@ } @Override + public Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { + + Multimap<Species, SpeciesBatchFrequency> result = ArrayListMultimap.create(); + for (SpeciesBatch speciesBatch : batchContainer.getChildren()) { + List<SpeciesBatchFrequency> speciesBatchFrequency = getAllSpeciesBatchFrequency(speciesBatch.getId()); + result.putAll(speciesBatch.getSpecies(), speciesBatchFrequency); + } + return result; + } + + @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { return speciesBatchService.saveSpeciesBatchFrequency(speciesBatchId, frequencies); } @@ -827,6 +840,17 @@ } @Override + public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + + Multimap<Species, BenthosBatchFrequency> result = ArrayListMultimap.create(); + for (BenthosBatch speciesBatch : batchContainer.getChildren()) { + List<BenthosBatchFrequency> speciesBatchFrequency = getAllBenthosBatchFrequency(speciesBatch.getId()); + result.putAll(speciesBatch.getSpecies(), speciesBatchFrequency); + } + return result; + } + + @Override public List<BenthosBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, List<BenthosBatchFrequency> frequencies) { return benthosBatchService.saveBenthosBatchFrequency(benthosBatchId, frequencies); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -25,6 +25,7 @@ */ import com.google.common.base.Predicate; +import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; @@ -526,6 +527,11 @@ } @Override + public Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { + throw notImplemented(); + } + + @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { throw notImplemented(); } @@ -566,6 +572,11 @@ } @Override + public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + throw notImplemented(); + } + + @Override public List<BenthosBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, List<BenthosBatchFrequency> frequencies) { throw notImplemented(); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -29,6 +29,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import fr.ifremer.tutti.TuttiConfiguration; import fr.ifremer.tutti.persistence.InvalidBatchModelException; import fr.ifremer.tutti.persistence.TuttiPersistence; @@ -66,6 +67,7 @@ import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.AllFileSelector; @@ -74,6 +76,7 @@ import org.apache.commons.vfs2.FileType; import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.ApplicationIOUtil; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.nuiton.util.TimeLog; import org.nuiton.util.Version; @@ -605,6 +608,50 @@ return null; } + public void fillSpeciesSurveyCode(Collection<Species> speciesList) { + + TuttiProtocol protocol = getProtocol(); + + if (protocol != null) { + // fill available species from protocol + if (!protocol.isSpeciesEmpty()) { + + Map<Integer, SpeciesProtocol> protocolMap = toSpeciesProtocolMap(); + + for (Species species : speciesList) { + SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); + if (speciesProtocol == null || + StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { + throw new ApplicationTechnicalException(t("tutti.error.species.not.in.protocol", species.getName())); + } + species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); + } + } + } + } + + public void fillBenthosSurveyCode(Collection<Species> benthosList) { + + TuttiProtocol protocol = getProtocol(); + + if (protocol != null) { + // fill available benthos from protocol + if (!protocol.isBenthosEmpty()) { + + Map<Integer, SpeciesProtocol> protocolMap = toBenthosProtocolMap(); + + for (Species species : benthosList) { + SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); + if (speciesProtocol == null || + StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { + throw new ApplicationTechnicalException(t("tutti.error.benthos.not.in.protocol", species.getName())); + } + species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); + } + } + } + } + public static final TimeLog TIME_LOG = new TimeLog(PersistenceService.class); @Override @@ -1154,6 +1201,11 @@ } @Override + public Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer) { + return driver.getAllSpeciesBatchFrequencyForBatch(batchContainer); + } + + @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { return driver.saveSpeciesBatchFrequency(speciesBatchId, frequencies); @@ -1200,6 +1252,11 @@ } @Override + public Multimap<Species, BenthosBatchFrequency> getAllBenthosBatchFrequencyForBatch(BatchContainer<BenthosBatch> batchContainer) { + return driver.getAllBenthosBatchFrequencyForBatch(batchContainer); + } + + @Override public List<BenthosBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, List<BenthosBatchFrequency> frequencies) { return driver.saveBenthosBatchFrequency(benthosBatchId, frequencies); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiCsvUtil.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -26,6 +26,7 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.TuttiEntities; @@ -117,6 +118,29 @@ } }; + public static final ValueFormatter<Species> SPECIES_NAME_FORMATTER = new ValueFormatter<Species>() { + @Override + public String format(Species s) { + Preconditions.checkNotNull(s, t("tutti.service.error.species.null")); + return s.getName(); + } + }; + + public static final ValueFormatter<Number> NUMBER_OR_NA = new ValueFormatter<Number>() { + @Override + public String format(Number s) { + return s==null?"NA": s.toString(); + } + }; + + public static final ValueFormatter<Species> SPECIES_SURVEY_CODE_FORMATTER = new ValueFormatter<Species>() { + @Override + public String format(Species s) { + Preconditions.checkNotNull(s, t("tutti.service.error.species.null")); + return s.getSurveyCode(); + } + }; + public static final ValueFormatter<Serializable> CARACTERISTIC_VALUE_FORMATTER2 = new ValueFormatter<Serializable>() { @Override public String format(Serializable value) { Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportBatchEntry.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -25,9 +25,13 @@ */ import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import org.apache.commons.lang3.mutable.MutableInt; +import java.util.Map; +import java.util.TreeMap; + /** - * To store a species or batch entry within his speices informations, + * To store a species or batch entry within his species informations, * his sorted weight, total weight and optional his total number. * * @since 3.0-rc-1 @@ -42,8 +46,16 @@ protected int totalNumber; + /** + * Frequencies (key = step, value = number). + * + * @since 3.3 + */ + protected Map<Float, MutableInt> frequencies; + public ExportBatchEntry(SpeciesAbleBatch batch) { this.batch = batch; + this.frequencies = new TreeMap<>(); } public SpeciesAbleBatch getBatch() { @@ -62,6 +74,15 @@ totalNumber += number; } + public void addFrequency(float lengthStep, int number) { + MutableInt totalNumber = frequencies.get(lengthStep); + if (totalNumber == null) { + totalNumber = new MutableInt(); + frequencies.put(lengthStep, totalNumber); + } + totalNumber.add(number); + } + public float getSortedWeight() { return sortedWeight; } @@ -73,4 +94,17 @@ public int getTotalNumber() { return totalNumber; } + + public Float getAverageFrequency() { + int totNumber = 0; + float totSize = 0; + for (Map.Entry<Float, MutableInt> entry : frequencies.entrySet()) { + float size = entry.getKey(); + int number = entry.getValue().intValue(); + totSize += (size * number); + totNumber += number; + } + Float result = totNumber == 0 ? null : totSize / (float) totNumber; + return result; + } } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/ExportCatchContext.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -27,18 +27,24 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; +import org.apache.commons.collections4.CollectionUtils; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -62,11 +68,16 @@ final BatchContainer<MarineLitterBatch> marineLitterBatches; + final Multimap<Species, SpeciesBatchFrequency> speciesFrequencies; + + final Multimap<Species, BenthosBatchFrequency> benthosFrequencies; + final Predicate<SpeciesAbleBatch> vracPredicate; public static ExportCatchContext newExportContext(PersistenceService persistenceService, WeightComputingService weightComputingService, - String fishingOperationId) { + String fishingOperationId, + boolean loadFrequencies) { FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); @@ -89,13 +100,27 @@ rootBenthosBatch, marineLitterBatches); + Multimap<Species, SpeciesBatchFrequency> speciesFrequencies; + Multimap<Species, BenthosBatchFrequency> benthosFrequencies; + + if (loadFrequencies) { + + speciesFrequencies = persistenceService.getAllSpeciesBatchFrequencyForBatch(rootSpeciesBatch); + benthosFrequencies = persistenceService.getAllBenthosBatchFrequencyForBatch(rootBenthosBatch); + } else { + speciesFrequencies = null; + benthosFrequencies = null; + } + Predicate<SpeciesAbleBatch> vracPredicate = persistenceService.getVracBatchPredicate(); ExportCatchContext result = new ExportCatchContext(vracPredicate, fishingOperation, catchBatch, rootSpeciesBatch, + speciesFrequencies, rootBenthosBatch, + benthosFrequencies, marineLitterBatches); return result; @@ -105,12 +130,16 @@ FishingOperation fishingOperation, CatchBatch catchBatch, BatchContainer<SpeciesBatch> rootSpeciesBatch, + Multimap<Species, SpeciesBatchFrequency> speciesFrequencies, BatchContainer<BenthosBatch> rootBenthosBatch, + Multimap<Species, BenthosBatchFrequency> benthosFrequencies, BatchContainer<MarineLitterBatch> marineLitterBatches) { this.vracPredicate = vracPredicate; this.fishingOperation = fishingOperation; this.catchBatch = catchBatch; this.rootSpeciesBatch = rootSpeciesBatch; + this.speciesFrequencies = speciesFrequencies; + this.benthosFrequencies = benthosFrequencies; this.rootBenthosBatch = rootBenthosBatch; this.marineLitterBatches = marineLitterBatches; } @@ -141,11 +170,21 @@ return rootBenthosBatch != null && !rootBenthosBatch.isEmptyChildren(); } + public boolean withSpeciesFrequencies() { + return speciesFrequencies != null && !speciesFrequencies.isEmpty(); + } + + public boolean withBenthosFrequencies() { + return benthosFrequencies != null && !benthosFrequencies.isEmpty(); + } + public List<ExportBatchEntry> getSpeciesBatchEntry(boolean computeNumber) { List<ExportBatchEntry> catchList = Lists.newArrayList(); if (withSpeciesBatches()) { + boolean withFrequencies = withSpeciesFrequencies(); + Map<Species, ExportBatchEntry> catches = Maps.newLinkedHashMap(); // ratio total species weight / total sorted sampled species weight @@ -154,11 +193,15 @@ List<SpeciesBatch> batches = rootSpeciesBatch.getChildren(); for (SpeciesBatch batch : batches) { - createExportBatchCatch( + ExportBatchEntry aCatch = createExportBatchCatch( batch, catches, rate, computeNumber); + + if (withFrequencies) { + addFrequencies(aCatch, speciesFrequencies); + } } catchList.addAll(catches.values()); } @@ -170,6 +213,8 @@ if (withBenthosBatches()) { + boolean withFrequencies = withBenthosFrequencies(); + Map<Species, ExportBatchEntry> catches = Maps.newLinkedHashMap(); // ratio total species weight / total sorted sampled species weight @@ -178,11 +223,15 @@ List<BenthosBatch> batches = rootBenthosBatch.getChildren(); for (BenthosBatch batch : batches) { - createExportBatchCatch( + ExportBatchEntry aCatch = createExportBatchCatch( batch, catches, rate, computeNumber); + + if (withFrequencies) { + addFrequencies(aCatch, benthosFrequencies); + } } catchList.addAll(catches.values()); @@ -272,10 +321,10 @@ return result; } - protected void createExportBatchCatch(SpeciesAbleBatch batch, - Map<Species, ExportBatchEntry> catches, - float ratio, - boolean computeNumber) { + protected ExportBatchEntry createExportBatchCatch(SpeciesAbleBatch batch, + Map<Species, ExportBatchEntry> catches, + float ratio, + boolean computeNumber) { Species species = batch.getSpecies(); @@ -305,6 +354,7 @@ } ktch.addNumber(Math.round(number)); } + return ktch; } protected float computeNumber(SpeciesAbleBatch batch, float rf) { @@ -361,4 +411,17 @@ } return result; } + + protected <F extends SpeciesAbleBatchFrequency> void addFrequencies(ExportBatchEntry aCatch, + Multimap<Species, F> frequencies) { + Species species = aCatch.getBatch().getSpecies(); + Collection<F> batchFrequencies = frequencies.get(species); + if (CollectionUtils.isNotEmpty(batchFrequencies)) { + for (F batchFrequency : batchFrequencies) { + Integer number = batchFrequency.getNumber(); + Float lengthStep = batchFrequency.getLengthStep(); + aCatch.addFrequency(lengthStep, number); + } + } + } } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -156,7 +156,10 @@ } ExportCatchContext exportContext = ExportCatchContext.newExportContext( - persistenceService, weightComputingService, fishingOperationId); + persistenceService, + weightComputingService, + fishingOperationId, + false); // create operation data model Map<String, Object> op = createOperation(exportContext.getFishingOperation()); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModel.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModel.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -28,6 +28,7 @@ import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.TuttiCsvUtil; +import fr.ifremer.tutti.service.export.ExportBatchEntry; import org.nuiton.csv.Common; import org.nuiton.csv.ValueFormatter; @@ -67,4 +68,13 @@ return new CatchRow(); } + public CatchRow newRow(FishingOperation operation, ExportBatchEntry entry) { + CatchRow row = newEmptyInstance(); + row.setFishingOperation(operation); + row.setSpecies(entry.getBatch().getSpecies()); + row.setWeight(entry.getTotalWeight()); + row.setNumber(entry.getTotalNumber()); + return row; + } + } Copied: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModelV2.java (from rev 1646, trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModel.java) =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModelV2.java (rev 0) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowModelV2.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,83 @@ +package fr.ifremer.tutti.service.export.sumatra; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.service.TuttiCsvUtil; +import fr.ifremer.tutti.service.export.ExportBatchEntry; + +import static org.nuiton.i18n.I18n.t; + +/** + * @author tchemit + * @since 3.3 + */ +public class CatchRowModelV2 extends TuttiCsvUtil.AbstractTuttiImportExportModel<CatchRowV2> { + + public CatchRowModelV2(char separator) { + super(separator); + + newColumnForExport(t("tutti.service.exportSumatraV2.header.year"), CatchRowV2.PROPERTY_GEAR_SHOOTING_START_DATE, TuttiCsvUtil.YEAR); + newColumnForExport(t("tutti.service.exportSumatraV2.header.station"), CatchRowV2.PROPERTY_STATION_NUMBER); + newColumnForExport(t("tutti.service.exportSumatraV2.header.multirigAggregation"), CatchRowV2.PROPERTY_MULTIRIG_AGGREGATION); + + newColumnForExport(t("tutti.service.exportSumatraV2.header.species"), CatchRowV2.PROPERTY_SPECIES, TuttiCsvUtil.SPECIES_SURVEY_CODE_FORMATTER); + newColumnForExport(t("tutti.service.exportSumatraV2.header.sign"), CatchRowV2.PROPERTY_SIGN); + + newColumnForExport(t("tutti.service.exportSumatraV2.header.sortedWeight"), CatchRowV2.PROPERTY_SORTED_WEIGHT, TuttiCsvUtil.PRIMITIVE_FLOAT); + newColumnForExport(t("tutti.service.exportSumatraV2.header.totalWeight"), CatchRowV2.PROPERTY_TOTAL_WEIGHT, TuttiCsvUtil.PRIMITIVE_FLOAT); + newColumnForExport(t("tutti.service.exportSumatraV2.header.averageWeight"), CatchRowV2.PROPERTY_AVERAGE_WEIGHT, TuttiCsvUtil.NUMBER_OR_NA); + newColumnForExport(t("tutti.service.exportSumatraV2.header.averageSize"), CatchRowV2.PROPERTY_AVERAGE_SIZE, TuttiCsvUtil.NUMBER_OR_NA); + newColumnForExport(t("tutti.service.exportSumatraV2.header.number"), CatchRowV2.PROPERTY_NUMBER, TuttiCsvUtil.PRIMITIVE_INTEGER); + newColumnForExport(t("tutti.service.exportSumatraV2.header.moule"), CatchRowV2.PROPERTY_MOULE, TuttiCsvUtil.NUMBER_OR_NA); + } + + @Override + public CatchRowV2 newEmptyInstance() { + return new CatchRowV2(); + } + + public CatchRowV2 newRow(FishingOperation operation, ExportBatchEntry entry) { + CatchRowV2 row = newEmptyInstance(); + row.setFishingOperation(operation); + row.setSpecies(entry.getBatch().getSpecies()); + row.setSortedWeight(entry.getSortedWeight()); + float totalWeight = entry.getTotalWeight(); + int number = entry.getTotalNumber(); + + row.setNumber(number); + row.setTotalWeight(totalWeight); + + // average size + row.setAverageSize(entry.getAverageFrequency()); + + // avarage weight + row.setAverageWeight(number == 0 ? null : totalWeight / (float) number); + // moule + row.setMoule(totalWeight == 0 ? null : (float) number / totalWeight); + return row; + } + +} Copied: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowV2.java (from rev 1646, trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRow.java) =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowV2.java (rev 0) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchRowV2.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,160 @@ +package fr.ifremer.tutti.service.export.sumatra; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.referential.Species; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author tchemit + * @since 3.3 + */ +public class CatchRowV2 implements Serializable { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_STATION_NUMBER = FishingOperation.PROPERTY_STATION_NUMBER; + + public static final String PROPERTY_GEAR_SHOOTING_START_DATE = FishingOperation.PROPERTY_GEAR_SHOOTING_START_DATE; + + public static final String PROPERTY_MULTIRIG_AGGREGATION = FishingOperation.PROPERTY_MULTIRIG_AGGREGATION; + + public static final String PROPERTY_SPECIES = "species"; + + public static final String PROPERTY_SIGN = "sign"; + + public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; + + public static final String PROPERTY_SORTED_WEIGHT = "sortedWeight"; + + public static final String PROPERTY_AVERAGE_WEIGHT = "averageWeight"; + + public static final String PROPERTY_AVERAGE_SIZE = "averageSize"; + + public static final String PROPERTY_NUMBER = "number"; + + public static final String PROPERTY_MOULE = "moule"; + + protected FishingOperation fishingOperation; + + protected Species species; + + protected String sign; + + protected Float totalWeight; + + protected Float sortedWeight; + + protected Float averageWeight; + + protected Float averageSize; + + protected Integer number; + + protected Float moule; + + public String getStationNumber() { + return fishingOperation.getStationNumber(); + } + + public Date getGearShootingStartDate() { + return fishingOperation.getGearShootingStartDate(); + } + + public String getMultirigAggregation() { + return fishingOperation.getMultirigAggregation(); + } + + public void setFishingOperation(FishingOperation fishingOperation) { + this.fishingOperation = fishingOperation; + } + + public Species getSpecies() { + return species; + } + + public void setSpecies(Species species) { + this.species = species; + } + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public Float getTotalWeight() { + return totalWeight; + } + + public void setTotalWeight(Float totalWeight) { + this.totalWeight = totalWeight; + } + + public Float getSortedWeight() { + return sortedWeight; + } + + public void setSortedWeight(Float sortedWeight) { + this.sortedWeight = sortedWeight; + } + + public Float getAverageWeight() { + return averageWeight; + } + + public void setAverageWeight(Float averageWeight) { + this.averageWeight = averageWeight; + } + + public Float getAverageSize() { + return averageSize; + } + + public void setAverageSize(Float averageSize) { + this.averageSize = averageSize; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public Float getMoule() { + return moule; + } + + public void setMoule(Float moule) { + this.moule = moule; + } +} Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -28,7 +28,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.io.Files; -import org.nuiton.jaxx.application.ApplicationTechnicalException; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -42,6 +41,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.BufferedWriter; import java.io.File; @@ -144,6 +144,9 @@ List<CatchRow> rows = Lists.newArrayList(); + CatchRowModel csvModel = + new CatchRowModel(context.getConfig().getCsvSeparator()); + if (operations != null) { for (String operationId : operations) { @@ -156,13 +159,11 @@ break; } - prepareFishingOperation(rows, operationId); + prepareFishingOperation(csvModel, rows, operationId); } } progressionModel.increments(t("tutti.service.sumatra.export.step.export", file)); - CatchRowModel csvModel = - new CatchRowModel(context.getConfig().getCsvSeparator()); BufferedWriter writer = null; try { @@ -178,10 +179,15 @@ } } - protected void prepareFishingOperation(List<CatchRow> rows, String operationId) { + protected void prepareFishingOperation(CatchRowModel csvModel, + List<CatchRow> rows, + String operationId) { ExportCatchContext exportContext = ExportCatchContext.newExportContext( - persistenceService, weightComputingService, operationId); + persistenceService, + weightComputingService, + operationId, + false); FishingOperation operation = exportContext.getFishingOperation(); @@ -193,11 +199,7 @@ for (ExportBatchEntry entry : entries) { - CatchRow row = new CatchRow(); - row.setFishingOperation(operation); - row.setSpecies(entry.getBatch().getSpecies()); - row.setWeight(entry.getTotalWeight()); - row.setNumber(entry.getTotalNumber()); + CatchRow row = csvModel.newRow(operation, entry); rows.add(row); } } @@ -210,192 +212,9 @@ for (ExportBatchEntry entry : entries) { - CatchRow row = new CatchRow(); - row.setFishingOperation(operation); - row.setSpecies(entry.getBatch().getSpecies()); - row.setWeight(entry.getTotalWeight()); - row.setNumber(entry.getTotalNumber()); + CatchRow row = csvModel.newRow(operation, entry); rows.add(row); } } - -// FishingOperation operation = persistenceService.getFishingOperation(operationId); -// -// CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation( -// operationId); -// -// BatchContainer<SpeciesBatch> speciesBatchContainer = -// weightComputingService.getComputedSpeciesBatches(operationId); -// BatchContainer<BenthosBatch> benthosBatchContainer = -// weightComputingService.getComputedBenthosBatches(operationId); -// -// BatchContainer<MarineLitterBatch> marineLitterBatch = -// weightComputingService.getComputedMarineLitterBatches( -// operationId, catchBatch.getMarineLitterTotalWeight()); -// -// weightComputingService.computeCatchBatchWeights(catchBatch, -// speciesBatchContainer, -// benthosBatchContainer, -// marineLitterBatch); -// -// Float totalWeight = TuttiEntities.getValueOrComputedValue( -// catchBatch.getCatchTotalWeight(), -// catchBatch.getCatchTotalComputedWeight()); -// -// Float totalUnsortedWeight = -// TuttiEntities.getValueOrComputedValue( -// catchBatch.getCatchTotalUnsortedComputedWeight(), -// 0f); -// -// Float totalSortedSpeciesWeight = TuttiEntities.getValueOrComputedValue( -// catchBatch.getSpeciesTotalSortedWeight(), -// catchBatch.getSpeciesTotalSortedComputedWeight()); -// -// Float totalSampleSortedSpeciesWeight = -// catchBatch.getSpeciesTotalSampleSortedComputedWeight(); -// -// Float totalSortedBenthosWeight = TuttiEntities.getValueOrComputedValue( -// catchBatch.getBenthosTotalSortedWeight(), -// catchBatch.getBenthosTotalSortedComputedWeight()); -// -// Float totalSampleSortedBenthosWeight = -// catchBatch.getBenthosTotalSampleSortedComputedWeight(); -// -// Float totalSortedWeight = catchBatch.getCatchTotalSortedComputedWeight(); -// -// //FIXME tchemit 2013-07-12 J'utilise en fait la formule (Poids de la capture totale - poids du HV dans la capture totale) / (poids total capture triée) -// // (Poids de la capture totale - poids du HV dans la capture totale) / (poids total capture triée - poids du HV dans la capture totale) -// -// Float catchRaisingFactor = totalWeight == null || totalUnsortedWeight == null || totalSortedWeight == null ? 1 : (totalWeight - totalUnsortedWeight) / totalSortedWeight; -// -// Float speciesCatchRaisingFactor = totalSampleSortedSpeciesWeight == null || totalSortedSpeciesWeight == null || totalSampleSortedSpeciesWeight == null ? 1 : (totalSampleSortedSpeciesWeight == 0 ? 0 : (totalSortedSpeciesWeight / totalSampleSortedSpeciesWeight) * catchRaisingFactor); -// Float benthosCatchRaisingFactor = totalSampleSortedBenthosWeight == null || totalSortedBenthosWeight == null || totalSampleSortedBenthosWeight == null ? 1 : (totalSampleSortedBenthosWeight == 0 ? 0 : (totalSortedBenthosWeight / totalSampleSortedBenthosWeight) * catchRaisingFactor); -// -// speciesCatchRaisingFactor *= catchRaisingFactor; -// benthosCatchRaisingFactor *= catchRaisingFactor; -// -// // add species rows -// Map<Species, CatchRow> rowMap = Maps.newLinkedHashMap(); -// if (speciesBatchContainer != null) { -// List<SpeciesBatch> speciesBatches = speciesBatchContainer.getChildren(); -// for (SpeciesBatch batch : speciesBatches) { -// Species sp = batch.getSpecies(); -// -// int number = Math.round(computeNumber(batch, 1.0f)); -// -// Float weight = TuttiEntities.getValueOrComputedValue( -// batch.getSampleCategoryWeight(), -// batch.getSampleCategoryComputedWeight()); -// -// weight *= speciesCatchRaisingFactor; -// number = (int) (speciesCatchRaisingFactor * (float) number); -// -// CatchRow row = rowMap.get(sp); -// if (row == null) { -// row = new CatchRow(); -// row.setFishingOperation(operation); -// row.setSpecies(sp); -// row.setWeight(weight); -// row.setNumber(number); -// -// } else { -// row.setWeight(row.getWeight() + weight); -// row.setNumber(row.getNumber() + number); -// } -// rowMap.put(sp, row); -// } -// rows.addAll(rowMap.values()); -// } -// -// // add benthos rows -// rowMap.clear(); -// if (benthosBatchContainer != null) { -// List<BenthosBatch> benthosBatches = benthosBatchContainer.getChildren(); -// for (BenthosBatch batch : benthosBatches) { -// Species sp = batch.getSpecies(); -// -// int number = Math.round(computeNumber(batch, 1.0f)); -// -// Float weight = TuttiEntities.getValueOrComputedValue( -// batch.getSampleCategoryWeight(), -// batch.getSampleCategoryComputedWeight()); -// -// weight *= benthosCatchRaisingFactor; -// number = (int) (benthosCatchRaisingFactor * (float) number); -// -// CatchRow row = rowMap.get(sp); -// if (row == null) { -// row = new CatchRow(); -// row.setFishingOperation(operation); -// row.setSpecies(sp); -// row.setWeight(weight); -// row.setNumber(number); -// -// } else { -// row.setWeight(row.getWeight() + weight); -// row.setNumber(row.getNumber() + number); -// } -// rowMap.put(sp, row); -// } -// } -// -// rows.addAll(rowMap.values()); } - - -// protected float computeNumber(SpeciesAbleBatch batch, float rf) { -// float result; -// -// float weight = TuttiEntities.getValueOrComputedValue( -// batch.getSampleCategoryWeight(), -// batch.getSampleCategoryComputedWeight()); -// -// if (batch.isChildBatchsEmpty()) { -// -// // on a leaf, get his weight -// -// Integer number = TuttiEntities.getValueOrComputedValue( -// batch.getNumber(), -// batch.getComputedNumber()); -// if (number == null) { -// -// // no count -// number = 0; -// } -// -// // get the sample weight -// Float subweight = TuttiEntities.getValueOrComputedValue( -// batch.getWeight(), -// batch.getComputedWeight()); -// -// if (subweight != null) { -// -// // with sub sample, update the raising factor -// rf *= weight / subweight; -// } -// -// result = number.floatValue() * rf; -// } else { -// -// // get total weight of all childs -// float totalWeight = 0.f; -// for (SpeciesAbleBatch child : batch.getChildBatchs()) { -// totalWeight += TuttiEntities.getValueOrComputedValue( -// child.getSampleCategoryWeight(), -// child.getSampleCategoryComputedWeight()); -// } -// -// result = 0f; -// -// float rf2 = rf * weight / totalWeight; -// // sum result of each child -// for (SpeciesAbleBatch child : batch.getChildBatchs()) { -// -// result += computeNumber(child, rf2); -// } -// -// } -// return result; -// } - } Copied: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2.java (from rev 1646, trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java) =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2.java (rev 0) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,242 @@ +package fr.ifremer.tutti.service.export.sumatra; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Charsets; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.google.common.io.Files; +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.referential.Species; +import fr.ifremer.tutti.service.AbstractTuttiService; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.TuttiServiceContext; +import fr.ifremer.tutti.service.catches.WeightComputingService; +import fr.ifremer.tutti.service.export.ExportBatchEntry; +import fr.ifremer.tutti.service.export.ExportCatchContext; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.Export; +import org.nuiton.jaxx.application.ApplicationTechnicalException; + +import java.io.BufferedWriter; +import java.io.File; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * To export as sumatra format (v2). + * + * @author tchemit + * @since 3.3 + */ +public class CatchesSumatraExportServiceV2 extends AbstractTuttiService { + + private static final Log log = + LogFactory.getLog(CatchesSumatraExportServiceV2.class); + + protected PersistenceService persistenceService; + + protected WeightComputingService weightComputingService; + + @Override + public void setServiceContext(TuttiServiceContext context) { + super.setServiceContext(context); + persistenceService = getService(PersistenceService.class); + weightComputingService = getService(WeightComputingService.class); + } + + /** + * Export selected cruise with the csv sumatra (v2) format. + * + * @param file where to generate report + * @param cruiseId id of the cruise to export + * @since 3.3 + */ + public void exportCruiseForSumatra(File file, + String cruiseId, + ProgressionModel progressionModel) { + + Preconditions.checkNotNull(cruiseId, "Cannot export a null cruise"); + Preconditions.checkNotNull(file, "Cannot export to a null file"); + + if (log.isInfoEnabled()) { + log.info("Will export cruise " + cruiseId + " to file: " + file); + } + + progressionModel.increments(t("tutti.service.sumatra.export.step.load.cruise", cruiseId)); + + Cruise cruise = persistenceService.getCruise(cruiseId); + Preconditions.checkNotNull(cruise, "Cruise [" + cruiseId + "] not found"); + + progressionModel.increments(t("tutti.service.sumatra.export.step.load.fishingOperationIds")); + + List<String> operations = + persistenceService.getAllFishingOperationIds(cruiseId); + + if (log.isInfoEnabled()) { + log.info(operations.size() + " operations found for cruise: " + cruiseId); + } + + progressionModel.adaptTotal(operations.size() + 3); + + prepareOperationsAndExport(file, operations, progressionModel); + } + + /** + * Export selected fishing operation with the csv sumatra (v2) format. + * + * @param file where to generate report + * @param cruiseId id of the cruise to export + * @param fishingOperationId id of the fishing operation to export + * @since 3.3 + */ + public void exportFishingOperationForSumatra(File file, + String cruiseId, + String fishingOperationId, + ProgressionModel progressionModel) { + + Preconditions.checkNotNull(file, "Cannot export to a null file"); + Preconditions.checkNotNull(cruiseId, "Cannot export a null cruise"); + Preconditions.checkNotNull(fishingOperationId, "Cannot export a null fishing operation"); + + if (log.isInfoEnabled()) { + log.info("Will export fishing operation " + + fishingOperationId + " to file: " + file); + } + + progressionModel.increments(t("tutti.service.sumatra.export.step.load.cruise", cruiseId)); + + Cruise cruise = persistenceService.getCruise(cruiseId); + Preconditions.checkNotNull(cruise, "Cruise [" + cruiseId + "] not found"); + + List<String> operations = Lists.newArrayList(fishingOperationId); + + prepareOperationsAndExport(file, operations, progressionModel); + } + + protected void prepareOperationsAndExport(File file, + List<String> operations, + ProgressionModel progressionModel) { + + List<CatchRowV2> rows = Lists.newArrayList(); + + CatchRowModelV2 csvModel = + new CatchRowModelV2(context.getConfig().getCsvSeparator()); + + if (operations != null) { + for (String operationId : operations) { + + progressionModel.increments(t("tutti.service.sumatra.export.step.load.fishingOperation", operationId)); + if (!persistenceService.isFishingOperationWithCatchBatch(operationId)) { + + if (log.isWarnEnabled()) { + log.warn("No catch for operation with id: " + operationId); + } + break; + } + + prepareFishingOperation(csvModel, rows, operationId); + } + } + + progressionModel.increments(t("tutti.service.sumatra.export.step.export", file)); + + + BufferedWriter writer = null; + try { + writer = Files.newWriter(file, Charsets.UTF_8); + Export export = Export.newExport(csvModel, rows); + export.write(writer); + writer.close(); + + } catch (Exception e) { + throw new ApplicationTechnicalException(t("tutti.service.sumatra.export.error", file), e); + } finally { + IOUtils.closeQuietly(writer); + } + } + + protected void prepareFishingOperation(CatchRowModelV2 csvModel, + List<CatchRowV2> rows, + String operationId) { + + ExportCatchContext exportContext = ExportCatchContext.newExportContext( + persistenceService, + weightComputingService, + operationId, + true); + + FishingOperation operation = exportContext.getFishingOperation(); + + // Species + if (exportContext.withSpeciesBatches()) { + + Set<Species> allspecies = new HashSet<>(); + + List<ExportBatchEntry> entries = + exportContext.getSpeciesBatchEntry(true); + + for (ExportBatchEntry entry : entries) { + + // get species campaign code from protocol + + allspecies.add(entry.getBatch().getSpecies()); + + CatchRowV2 row = csvModel.newRow(operation, entry); + row.getSpecies(); + rows.add(row); + } + + // fill survey code in species + persistenceService.fillSpeciesSurveyCode(allspecies); + } + + // Benthos + if (exportContext.withBenthosBatches()) { + + Set<Species> allspecies = new HashSet<>(); + + List<ExportBatchEntry> entries = + exportContext.getBenthosBatchEntry(true); + + for (ExportBatchEntry entry : entries) { + + CatchRowV2 row = csvModel.newRow(operation, entry); + allspecies.add(entry.getBatch().getSpecies()); + rows.add(row); + } + + // fill survey code in benthos + persistenceService.fillBenthosSurveyCode(allspecies); + } + } +} Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2014-03-28 13:11:04 UTC (rev 1650) @@ -1,3 +1,5 @@ +tutti.error.benthos.not.in.protocol= +tutti.error.species.not.in.protocol= tutti.io.mkDir.error= tutti.property.attachment= tutti.property.caracteristic= @@ -49,6 +51,7 @@ tutti.service.csv.parse.entityNotFound= tutti.service.cvs.format.error= tutti.service.cvs.mandatory.value= +tutti.service.error.species.null= tutti.service.export.accidentalCatch.error= tutti.service.export.catches.error= tutti.service.export.closeContext.error= @@ -79,6 +82,17 @@ tutti.service.exportSumatra.header.species= tutti.service.exportSumatra.header.station= tutti.service.exportSumatra.header.weight= +tutti.service.exportSumatraV2.header.averageSize=Averagesize +tutti.service.exportSumatraV2.header.averageWeight=AverageWeight +tutti.service.exportSumatraV2.header.moule=Moule +tutti.service.exportSumatraV2.header.multirigAggregation=MultirigAggregation +tutti.service.exportSumatraV2.header.number=Number +tutti.service.exportSumatraV2.header.sign=Sign +tutti.service.exportSumatraV2.header.sortedWeight=SortedWeight +tutti.service.exportSumatraV2.header.species=Species +tutti.service.exportSumatraV2.header.station=Station number +tutti.service.exportSumatraV2.header.totalWeight=TotalWeight +tutti.service.exportSumatraV2.header.year=Year tutti.service.multipost.attachment.copy.error= tutti.service.multipost.attachment.mkdir.error= tutti.service.multipost.export.attachments.error= Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2014-03-28 13:11:04 UTC (rev 1650) @@ -1,3 +1,5 @@ +tutti.error.benthos.not.in.protocol=L'espèce (onglet Benthos) %s n'est pas déclarée dans le protocole. +tutti.error.species.not.in.protocol=L'espèce %s (onglet Espèce) n'est pas déclarée dans le protocole. tutti.io.mkDir.error=Erreur à la création du dossier %s tutti.property.attachment=Pièce jointe tutti.property.caracteristic=Caractéristique @@ -48,6 +50,7 @@ tutti.service.csv.parse.entityNotFound=L'entité de type %1s avec la propriété %2s de valeur %3s n'a pas été trouvée tutti.service.cvs.format.error=Erreur lors du formatage de la valeur %s tutti.service.cvs.mandatory.value=Valeur obligatoire +tutti.service.error.species.null= tutti.service.export.accidentalCatch.error=Erreur lors de l'export des captures accidentelles 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 @@ -78,6 +81,17 @@ tutti.service.exportSumatra.header.species=Espèce tutti.service.exportSumatra.header.station=Station tutti.service.exportSumatra.header.weight=Total +tutti.service.exportSumatraV2.header.averageSize=LongueurMoy +tutti.service.exportSumatraV2.header.averageWeight=PoidsMoy +tutti.service.exportSumatraV2.header.moule=Moule +tutti.service.exportSumatraV2.header.multirigAggregation=Poche +tutti.service.exportSumatraV2.header.number=NbIndividus +tutti.service.exportSumatraV2.header.sign=Signe +tutti.service.exportSumatraV2.header.sortedWeight=Tri +tutti.service.exportSumatraV2.header.species=Espèce +tutti.service.exportSumatraV2.header.station=Station +tutti.service.exportSumatraV2.header.totalWeight=Total +tutti.service.exportSumatraV2.header.year=Année tutti.service.multipost.attachment.copy.error=Erreur lors de l'export de la pièce-jointe %s tutti.service.multipost.attachment.mkdir.error=Impossible de créer le répertoire %s tutti.service.multipost.export.attachments.error=Erreur lors de l'export des pièces-jointes Copied: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2Test.java (from rev 1646, trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceTest.java) =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2Test.java (rev 0) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportServiceV2Test.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,123 @@ +package fr.ifremer.tutti.service.export.sumatra; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import fr.ifremer.tutti.service.catches.TuttiWeightComputingException; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.io.File; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 3.3 + */ +public class CatchesSumatraExportServiceV2Test { + + @ClassRule + public static final ServiceDbResource dbResource = + ServiceDbResource.readDb("dbExport"); + + public static final String PROGRAM_ID = "CAM-TEST_ELEVATION"; + + public static final String CRUISE_BAD_ID = "100003"; + + public static final String CRUISE_ID = "100004"; + + public static final String OPERATION_1_ID = "100116"; + + public static final String OPERATION_BAD_1_ID = "100112"; + + public static final String OPERATION_BAD_2_ID = "100113"; + + public static final String OPERATION_BAD_3_ID = "100115"; + + public static final String EXPORT_CONTENT = + "Année;Station;Poche;Espèce;Signe;Tri;Total;PoidsMoy;LongueurMoy;NbIndividus;Moule\n" + + "2013;A;1;CHAMMAG;;100.0;100.0;2.5;NA;40;0.4\n" + + "2013;A;1;ECHIGAM;;100.0;100.0;0.23980816;NA;417;4.17\n" + + "2013;A;1;BRISATLAN;;100.0;100.0;1.0638298;NA;94;0.94"; + + protected CatchesSumatraExportServiceV2 service; + + protected ServiceDbResource.DataContext dataContext; + + protected File dataDirectory; + + @Before + public void setUp() throws Exception { + + dataDirectory = dbResource.getConfig().getDataDirectory(); + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + dbResource.openDataContext(); + + File protocolFile = new File("src/test/resources/tuttiProtocol.tuttiProtocol"); + + TuttiProtocol protocol = dbResource.loadProtocol(protocolFile); + + serviceContext.getService(PersistenceService.class).setProtocol(protocol); + + service = serviceContext.getService(CatchesSumatraExportServiceV2.class); + } + + @Test(expected = TuttiWeightComputingException.class) + public void testExportCruiseForSumatraBadCruise() throws Exception { + + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_BAD_ID, 3, + OPERATION_BAD_2_ID, + OPERATION_BAD_1_ID, + OPERATION_BAD_3_ID); + + File exportFile = new File(dataDirectory, "exportSumatra.csv"); + + ProgressionModel progressionModel = new ProgressionModel(); + progressionModel.setTotal(3); + service.exportCruiseForSumatra(exportFile, CRUISE_BAD_ID, progressionModel); + } + + @Test + public void testExportCruiseForSumatra() throws Exception { + + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 1, OPERATION_1_ID); + + File exportFile = new File(dataDirectory, "exportSumatra.csv"); + + ProgressionModel progressionModel = new ProgressionModel(); + progressionModel.setTotal(3); + service.exportCruiseForSumatra(exportFile, CRUISE_ID, progressionModel); + + ServiceDbResource.assertFileContent("Sumatra export file:\n", + exportFile, + EXPORT_CONTENT); + } +} Modified: trunk/tutti-service/src/test/resources/tuttiProtocol.tuttiProtocol =================================================================== --- trunk/tutti-service/src/test/resources/tuttiProtocol.tuttiProtocol 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-service/src/test/resources/tuttiProtocol.tuttiProtocol 2014-03-28 13:11:04 UTC (rev 1650) @@ -1,8 +1,18 @@ id: aefaad71-2731-4184-978b-847f6e60c692 name: ano-2486 -benthos: +benthos: - !SpeciesProtocol countIfNoFrequencyEnabled: true + speciesReferenceTaxonId: 4622 + speciesSurveyCode: ABIEABI + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true + speciesReferenceTaxonId: 380 + speciesSurveyCode: ACANECH + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true speciesReferenceTaxonId: 907 speciesSurveyCode: ALPHGLA weightEnabled: true @@ -453,13 +463,49 @@ weightEnabled: true gearUseFeaturePmfmId: [] lengthClassesPmfmId: [] -species: +species: - !SpeciesProtocol countIfNoFrequencyEnabled: true lengthStepPmfmId: 299 maturityEnabled: true sexEnabled: true sizeEnabled: true + speciesReferenceTaxonId: 11183 + speciesSurveyCode: BRISATLAN + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 299 + maturityEnabled: true + sexEnabled: true + sizeEnabled: true + speciesReferenceTaxonId: 1938 + speciesSurveyCode: AGONCAT + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 299 + maturityEnabled: true + sexEnabled: true + sizeEnabled: true + speciesReferenceTaxonId: 11654 + speciesSurveyCode: ECHIGAM + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 299 + maturityEnabled: true + sexEnabled: true + sizeEnabled: true + speciesReferenceTaxonId: 11750 + speciesSurveyCode: CHAMMAG + weightEnabled: true +- !SpeciesProtocol + countIfNoFrequencyEnabled: true + lengthStepPmfmId: 299 + maturityEnabled: true + sexEnabled: true + sizeEnabled: true speciesReferenceTaxonId: 848 speciesSurveyCode: ARISFOL weightEnabled: true Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2014-03-28 13:11:04 UTC (rev 1650) @@ -1,28 +1,5 @@ -### -# #%L -# Tutti :: UI -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2012 - 2014 Ifremer -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program. If not, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Wed Jan 29 07:36:56 CET 2014 +#Fri Mar 28 12:07:10 CET 2014 tutti.config.help=config.html tutti.createAccidentalBatch.action.cancel.help=editFishingOperation.html\#captureCapturesAccidentellesActions tutti.createAccidentalBatch.action.saveAndClose.help=editFishingOperation.html\#captureCapturesAccidentellesActions @@ -144,6 +121,8 @@ tutti.editCatchBatch.action.computeWeights.help=editFishingOperation.html\#captureResumeActions tutti.editCatchBatch.action.exportFishingOperationReport.help=editFishingOperation.html\#captureResumeActions tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.help=editFishingOperation.html\#captureResumeActions +tutti.editCatchBatch.action.exportFishingOperationReportForSumatra2.help=editFishingOperation.html\#captureResumeActions +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.help= tutti.editCatchBatch.action.saveCatchBatch.help=editFishingOperation.html\#captureResumeActions tutti.editCatchBatch.field.benthosTotalSampleSortedWeight.help=editFishingOperation.html\#captureResumeFields tutti.editCatchBatch.field.benthosTotalSortedWeight.help=editFishingOperation.html\#captureResumeFields @@ -329,6 +308,8 @@ tutti.main.menu.action.changeLocaleFR.help=menu.html\#menu_aide tutti.main.menu.action.changeLocaleUK.help=menu.html\#menu_aide tutti.main.menu.action.configuration.help=menu.html\#menu_fichier_configuration +tutti.main.menu.action.connectIchtyometer.help=menu.html\#menu_fichier +tutti.main.menu.action.disconnectIchtyometer.help=menu.html\#menu_fichier tutti.main.menu.action.editCatches.help=menu.html\#menu_action tutti.main.menu.action.editCruise.help=menu.html\#menu_action tutti.main.menu.action.editProgram.help=menu.html\#menu_action @@ -343,8 +324,6 @@ tutti.main.menu.action.showHelp.help=menu.html\#menu_aide tutti.main.menu.action.site.help=menu.html\#menu_aide tutti.main.menu.action.updateApplication.help=menu.html\#menu_fichier -tutti.main.menu.action.connectIchtyometer.help=menu.html\#menu_fichier -tutti.main.menu.action.disconnectIchtyometer.help=menu.html\#menu_fichier tutti.main.menu.action.updateReport.help=menu.html\#menu_fichier tutti.main.menu.action.validateCatches.help=menu.html\#menu_action tutti.main.status.ichtyometer.help=menu.html\#status @@ -374,6 +353,7 @@ tutti.selectCruise.action.editProtocol.help=selectCruise.html\#actions tutti.selectCruise.action.exportCruise.help=selectCruise.html\#actions tutti.selectCruise.action.exportCruiseForSumatra.help=selectCruise.html\#actions +tutti.selectCruise.action.exportCruiseForSumatraV2.help=selectCruise.html\#actions tutti.selectCruise.action.exportProgram.help=selectCruise.html\#actions tutti.selectCruise.action.exportProtocol.help=selectCruise.html\#actions tutti.selectCruise.action.generateCruiseReport.help=selectCruise.html\#actions Modified: trunk/tutti-ui-swing/src/main/help/fr/editFishingOperation.html =================================================================== --- trunk/tutti-ui-swing/src/main/help/fr/editFishingOperation.html 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/help/fr/editFishingOperation.html 2014-03-28 13:11:04 UTC (rev 1650) @@ -364,6 +364,14 @@ l'échelle de la capture. Le format du fichier est compatible avec le logiciel SUMATRA </dd> + <dt>Résumé sumatra v2</dt> + <dd> + déclenche la + génération d'un fichier .csv qui contient la composition de la capture + du trait par espèce et benthos. les poids et nombre sont élevés à + l'échelle de la capture. Le format du fichier est compatible avec le + logiciel SUMATRA (V2). + </dd> <dt>Piéces jointes (icone trombone)</dt> <dd>permet d'associer des pièces jointes au trait. Contiendra aussi les fichiers en cas d'import pupitri dans l'onglet espèces Modified: trunk/tutti-ui-swing/src/main/help/fr/selectCruise.html =================================================================== --- trunk/tutti-ui-swing/src/main/help/fr/selectCruise.html 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/help/fr/selectCruise.html 2014-03-28 13:11:04 UTC (rev 1650) @@ -83,11 +83,11 @@ <dd>permet de créer une nouvelle série de campagne.</dd> <dt>Campagne <strong>Éditer</strong></dt> <dd>permet d'éditer la campagne sélectionnée dans le champ.</dd> - <dt>Campagne <strong>Éditer...Exporter</strong> </dt> + <dt>Campagne <strong>Éditer...Exporter Générique</strong> </dt> <dd> permet d'exporter toutes les données brutes de la campagne sélectionnée dans un fichier .zip contenant des fichiers .csv. </dd> - <dt>Campagne <strong>Éditer...Envoyer</strong></dt> + <dt>Campagne <strong>Éditer...Exporter Pdf</strong></dt> <dd>génère un courriel et un fichier PDF qui présente la composition de toutes les @@ -97,12 +97,18 @@ liste de destinataires. </dd> - <dt>Campagne <strong>Éditer...Sumatra</strong></dt> + <dt>Campagne <strong>Éditer...Exporter Csv v1 (sumatra v1)</strong></dt> <dd>génère un fichier .csv qui résume la composition des captures saisies en espèces scientifiques et les poids associés. Le fichier créé est compatible avec le système Sumatra disponible à bord de la Thalassa. </dd> + <dt>Campagne <strong>Éditer...Exporter Csv v2 (sumatra v2)</strong></dt> + <dd>génère + un fichier .csv qui résume la composition des captures saisies en + espèces scientifiques et les poids associés. Le fichier créé est + compatible avec le système Sumatra (v2) disponible à bord de la Thalassa. + </dd> <dt>Campagne <strong>Nouveau</strong></dt> <dd>permet de créer une nouvelle campagne.</dd> <dt>Protocole de saisie <strong>Éditer</strong></dt> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -44,6 +44,7 @@ import fr.ifremer.tutti.service.export.generic.TuttiExportService; import fr.ifremer.tutti.service.export.pdf.CatchesPdfExportService; import fr.ifremer.tutti.service.export.sumatra.CatchesSumatraExportService; +import fr.ifremer.tutti.service.export.sumatra.CatchesSumatraExportServiceV2; import fr.ifremer.tutti.service.protocol.ProtocolImportExportService; import fr.ifremer.tutti.service.psionimport.PsionImportService; import fr.ifremer.tutti.service.pupitri.PupitriImportExportService; @@ -705,6 +706,10 @@ return serviceContext.getService(CatchesSumatraExportService.class); } + public CatchesSumatraExportServiceV2 getCatchesSumatraExportServiceV2() { + return serviceContext.getService(CatchesSumatraExportServiceV2.class); + } + public MultiPostImportService getMultiPostImportService() { return serviceContext.getService(MultiPostImportService.class); } Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportCruiseForSumatraV2Action.java (from rev 1646, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportCruiseForSumatraAction.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportCruiseForSumatraV2Action.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportCruiseForSumatraV2Action.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,112 @@ +package fr.ifremer.tutti.ui.swing.action; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.service.export.sumatra.CatchesSumatraExportServiceV2; +import fr.ifremer.tutti.ui.swing.content.MainUIHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.DateUtil; + +import java.io.File; +import java.util.Date; + +import static org.nuiton.i18n.I18n.t; + +/** + * Export the hole cruise using the sumatra format (V2). + * + * @author tchemit + * @since 3.3 + */ +public class ExportCruiseForSumatraV2Action extends AbstractMainUITuttiAction { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ExportCruiseForSumatraV2Action.class); + + protected File file; + + public ExportCruiseForSumatraV2Action(MainUIHandler handler) { + super(handler, false); + } + + @Override + public boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (doAction) { + + String date = DateUtil.formatDate(new Date(), "dd-MM-yyyy"); + // choose file to export + file = saveFile( + String.format("sumatra_v2_%s_%s", getDataContext().getCruise().getName(), date), + "csv", + t("tutti.exportCruiseForSumatraV2.title.choose.exportFile"), + t("tutti.exportCruiseForSumatraV2.action.chooseFile"), + "^.+\\.csv$", t("tutti.common.file.csv") + ); + doAction = file != null; + } + return doAction; + } + + @Override + public void releaseAction() { + file = null; + super.releaseAction(); + } + + @Override + public void doAction() throws Exception { + Cruise cruise = getDataContext().getCruise(); + Preconditions.checkNotNull(cruise); + Preconditions.checkNotNull(file); + + if (log.isInfoEnabled()) { + log.info("Will export cruise " + cruise.getId() + + " to file: " + file); + } + ProgressionModel pm = new ProgressionModel(); + pm.setTotal(3); // loading cruise + loading fishing operationIds + export + setProgressionModel(pm); + + // export catches + CatchesSumatraExportServiceV2 service = + getContext().getCatchesSumatraExportServiceV2(); + service.exportCruiseForSumatra(file, cruise.getId(), pm); + + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + sendMessage(t("tutti.exportCruiseForSumatraV2.action.success", file)); + } +} Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportFishingOperationForSumatraV2Action.java (from rev 1648, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportFishingOperationForSumatraAction.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportFishingOperationForSumatraV2Action.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportFishingOperationForSumatraV2Action.java 2014-03-28 13:11:04 UTC (rev 1650) @@ -0,0 +1,132 @@ +package fr.ifremer.tutti.ui.swing.action; + +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +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.service.export.sumatra.CatchesSumatraExportServiceV2; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; +import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.DateUtil; + +import java.io.File; +import java.util.Date; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 10/1/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 3.3 + */ +public class ExportFishingOperationForSumatraV2Action extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ExportFishingOperationForSumatraV2Action.class); + + protected File file; + + public ExportFishingOperationForSumatraV2Action(EditCatchesUIHandler handler) { + super(handler, true); + } + + @Override + public boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (getModel().isModify()) { + + displayWarningMessage( + t("tutti.exportFishingOperationForSumatraV2.title.model.modified"), + t("tutti.exportFishingOperationForSumatraV2.message.model.modified") + ); + doAction = false; + } + + if (doAction) { + + FishingOperation fishingOperation = getModel().getFishingOperation(); + + String date = DateUtil.formatDate(new Date(), "dd-MM-yyyy"); + // choose file to export + file = saveFile( + String.format("sumatra_v2_%s_%s_%s", getDataContext().getCruise().getName(), fishingOperation.getId(), date), + "csv", + t("tutti.exportFishingOperationForSumatraV2.title.choose.exportFile"), + t("tutti.exportFishingOperationForSumatraV2.action.chooseFile"), + "^.+\\.csv$", t("tutti.common.file.csv") + ); + doAction = file != null; + } + return doAction; + } + + @Override + public void releaseAction() { + file = null; + super.releaseAction(); + } + + @Override + public void doAction() throws Exception { + Cruise cruise = getDataContext().getCruise(); + FishingOperation fishingOperation = getModel().getFishingOperation(); + Preconditions.checkNotNull(cruise); + Preconditions.checkNotNull(fishingOperation); + Preconditions.checkNotNull(file); + + if (log.isInfoEnabled()) { + log.info("Will export fishingOperation " + cruise.getId() + "-" + fishingOperation.getStationNumber() + + " to file: " + file); + } + + ProgressionModel pm = new ProgressionModel(); + pm.setTotal(3); // loading cruise + loading fishing operationIds + export + setProgressionModel(pm); + + // export catches + CatchesSumatraExportServiceV2 service = + getContext().getCatchesSumatraExportServiceV2(); + service.exportFishingOperationForSumatra(file, + cruise.getId(), + fishingOperation.getId(), + pm); + + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + sendMessage(t("tutti.exportFishingOperationForSumatraV2.action.success", file)); + } +} Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.css 2014-03-28 13:11:04 UTC (rev 1650) @@ -105,7 +105,7 @@ } #editCruiseComboBox { - model: {handler.newComboModel(editCruiseButton, exportCruiseButton, sendCruiseReportButton, exportCruiseForSumatraButton)}; + model: {handler.newComboModel(editCruiseButton, exportCruiseButton, sendCruiseReportButton, exportCruiseForSumatraButton, exportCruiseForSumatraV2Button)}; enabled: {model.isProgramFound() && model.isCruiseFound()}; renderer: {new ActionListCellRenderer()}; } @@ -143,6 +143,14 @@ _help: {"tutti.selectCruise.action.exportCruiseForSumatra.help"}; } +#exportCruiseForSumatraV2Button { + actionIcon: export; + text: "tutti.selectCruise.action.exportCruiseForSumatraV2"; + toolTipText: "tutti.selectCruise.action.exportCruiseForSumatraV2.tip"; + _applicationAction: {fr.ifremer.tutti.ui.swing.action.ExportCruiseForSumatraV2Action.class}; + _help: {"tutti.selectCruise.action.exportCruiseForSumatraV2.help"}; +} + #newCruiseButton { actionIcon: add; text: "tutti.selectCruise.action.newCruise"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SelectCruiseUI.jaxx 2014-03-28 13:11:04 UTC (rev 1650) @@ -69,6 +69,7 @@ <JButton id='exportCruiseButton'/> <JButton id='sendCruiseReportButton'/> <JButton id='exportCruiseForSumatraButton'/> + <JButton id='exportCruiseForSumatraV2Button'/> <JButton id='newProtocolButton'/> <JButton id='importProtocolButton'/> <JButton id='editProtocolButton'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2014-03-28 13:11:04 UTC (rev 1650) @@ -362,6 +362,15 @@ _help: {"tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.help"}; } +#exportFishingOperationReportForSumatraV2Button { + actionIcon: export; + text: "tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2"; + toolTipText: "tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.tip"; + i18nMnemonic: "tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.mnemonic"; + _applicationAction: {fr.ifremer.tutti.ui.swing.action.ExportFishingOperationForSumatraV2Action.class}; + _help: {"tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.help"}; +} + #saveButton { actionIcon: save; text: "tutti.editCatchBatch.action.saveCatchBatch"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2014-03-28 13:11:04 UTC (rev 1650) @@ -105,6 +105,7 @@ <JToolBar id='catchesCaracteristicsTabToolBar'> <JButton id='exportFishingOperationReportButton'/> <JButton id='exportFishingOperationReportForSumatraButton'/> + <JButton id='exportFishingOperationReportForSumatraV2Button'/> <ButtonAttachment id='catchesCaracteristicsAttachmentsButton' constructorParams='getHandler().getContext(), getModel()'/> </JToolBar> Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2014-03-28 13:11:04 UTC (rev 1650) @@ -549,6 +549,9 @@ tutti.editCatchBatch.action.exportFishingOperationReportForSumatra= tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.mnemonic= tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.tip= +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2= +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.mnemonic= +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.tip= tutti.editCatchBatch.action.saveCatchBatch= tutti.editCatchBatch.action.saveCatchBatch.mnemonic= tutti.editCatchBatch.action.saveCatchBatch.tip= @@ -1128,6 +1131,9 @@ tutti.exportCruiseForSumatra.action.chooseFile= tutti.exportCruiseForSumatra.action.success= tutti.exportCruiseForSumatra.title.choose.exportFile= +tutti.exportCruiseForSumatraV2.action.chooseFile= +tutti.exportCruiseForSumatraV2.action.success= +tutti.exportCruiseForSumatraV2.title.choose.exportFile= tutti.exportDb.step.closeDb= tutti.exportDb.step.createArchive= tutti.exportDb.step.openDb= @@ -1137,6 +1143,11 @@ tutti.exportFishingOperationForSumatra.message.model.modified=Catch was modified, please save it before launching an export. tutti.exportFishingOperationForSumatra.title.choose.exportFile= tutti.exportFishingOperationForSumatra.title.model.modified=Can't export, catch is modified +tutti.exportFishingOperationForSumatraV2.action.chooseFile= +tutti.exportFishingOperationForSumatraV2.action.success= +tutti.exportFishingOperationForSumatraV2.message.model.modified= +tutti.exportFishingOperationForSumatraV2.title.choose.exportFile= +tutti.exportFishingOperationForSumatraV2.title.model.modified= tutti.exportFishingOperationReport.action.chooseFile= tutti.exportFishingOperationReport.action.success= tutti.exportFishingOperationReport.message.model.modified=Catch was modified, please save it before launching an export. @@ -1450,6 +1461,8 @@ tutti.selectCruise.action.exportCruise.tip= tutti.selectCruise.action.exportCruiseForSumatra= tutti.selectCruise.action.exportCruiseForSumatra.tip= +tutti.selectCruise.action.exportCruiseForSumatraV2= +tutti.selectCruise.action.exportCruiseForSumatraV2.tip= tutti.selectCruise.action.exportProgram= tutti.selectCruise.action.exportProgram.tip= tutti.selectCruise.action.exportProtocol= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2014-03-28 10:59:34 UTC (rev 1649) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2014-03-28 13:11:04 UTC (rev 1650) @@ -540,6 +540,9 @@ tutti.editCatchBatch.action.exportFishingOperationReportForSumatra=Résumé Sumatra tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.mnemonic=u tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.tip=Exporter le trait sélectionnée pour Sumatra (au format csv) +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2=Résumé Sumatra V2 +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.mnemonic=2 +tutti.editCatchBatch.action.exportFishingOperationReportForSumatraV2.tip=Exporter le trait sélectionnée pour Sumatra V2 (au format csv) tutti.editCatchBatch.action.saveCatchBatch=Enregistrer tutti.editCatchBatch.action.saveCatchBatch.mnemonic=S tutti.editCatchBatch.action.saveCatchBatch.tip=Enregistrer la capture @@ -1115,6 +1118,9 @@ tutti.exportCruiseForSumatra.action.chooseFile=Choisir le fichier d'export tutti.exportCruiseForSumatra.action.success=La campagne sélectionnée a été exportée dans le fichier <strong>%s</strong> tutti.exportCruiseForSumatra.title.choose.exportFile=Exporter la campagne +tutti.exportCruiseForSumatraV2.action.chooseFile=Choisir le fichier d'export +tutti.exportCruiseForSumatraV2.action.success=La campagne sélectionnée a été exportée dans le fichier <strong>%s</strong> +tutti.exportCruiseForSumatraV2.title.choose.exportFile=Exporter la campagne tutti.exportDb.step.closeDb=Fermeture de la base courante tutti.exportDb.step.createArchive=Création de l'archive %s tutti.exportDb.step.openDb=Réouverture de la base courante @@ -1124,6 +1130,11 @@ tutti.exportFishingOperationForSumatra.message.model.modified=La capture a été modifié, veuillez l'enregistrer avant de lancer un export. tutti.exportFishingOperationForSumatra.title.choose.exportFile=Exporter le trait de la campagne tutti.exportFishingOperationForSumatra.title.model.modified=Impossible d'exporter, capture modifiée +tutti.exportFishingOperationForSumatraV2.action.chooseFile=Choisir le fichier d'export +tutti.exportFishingOperationForSumatraV2.action.success=Le trait a été exporté dans le fichier <strong>%s</strong> +tutti.exportFishingOperationForSumatraV2.message.model.modified=La capture a été modifié, veuillez l'enregistrer avant de lancer un export. +tutti.exportFishingOperationForSumatraV2.title.choose.exportFile=Exporter le trait de la campagne +tutti.exportFishingOperationForSumatraV2.title.model.modified=Impossible d'exporter, capture modifiée tutti.exportFishingOperationReport.action.chooseFile=Choisir le fichier de rapport tutti.exportFishingOperationReport.action.success=Le trait a été exporté dans le fichier <strong>%s</strong> tutti.exportFishingOperationReport.message.model.modified=La capture a été modifié, veuillez l'enregistrer avant de lancer un export. @@ -1434,6 +1445,8 @@ tutti.selectCruise.action.exportCruise.tip=Exporter la campagne sélectionnée tutti.selectCruise.action.exportCruiseForSumatra=Sumatra tutti.selectCruise.action.exportCruiseForSumatra.tip=Exporter la campagne sélectionnée pour Sumatra +tutti.selectCruise.action.exportCruiseForSumatraV2=Sumatra (V2) +tutti.selectCruise.action.exportCruiseForSumatraV2.tip=Exporter la campagne sélectionnée pour Sumatra (V2) tutti.selectCruise.action.exportProgram=Exporter tutti.selectCruise.action.exportProgram.tip=Exporter la série sélectionnée tutti.selectCruise.action.exportProtocol=Exporter
participants (1)
-
tchemit@users.forge.codelutin.com