r1265 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/main/resources tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/catches tutti-service/src/main/java/fr/ifremer/tutti/service/export tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra tutti-service/src/test/java/fr/ifremer/tutti/service/export tutti-ui-swing/s
Author: tchemit Date: 2013-10-02 12:08:19 +0200 (Wed, 02 Oct 2013) New Revision: 1265 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1265 Log: fixes #3412: [EXPORT SUMATRA] le nombre d'individus dans la capture est faux fixes #3414: [RAPPORT] ajouter sur onglet "R?\195?\169sum?\195?\169" un bouton pour obtenir la composition de la capture Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationForSumatraAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationReportAction.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-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ExportCatchesReportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/CatchesSumatraExportService.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SendCruiseReportAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -471,6 +471,8 @@ int getFishingOperationCount(String cruiseId); + List<String> getAllFishingOperationIds(String cruiseId); + List<FishingOperation> getAllFishingOperation(String cruiseId); FishingOperation getFishingOperation(String id); 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -630,6 +630,11 @@ } @Override + public List<String> getAllFishingOperationIds(String cruiseId) { + return fishingOperationService.getAllFishingOperationIds(cruiseId); + } + + @Override public List<FishingOperation> getAllFishingOperation(String cruiseId) { return fishingOperationService.getAllFishingOperation(cruiseId); } 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -420,6 +420,11 @@ } @Override + public List<String> getAllFishingOperationIds(String cruiseId) { + throw notImplemented(); + } + + @Override public List<FishingOperation> getAllFishingOperation(String cruiseId) { throw notImplemented(); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -42,6 +42,8 @@ int getFishingOperationCount(String cruiseId); + List<String> getAllFishingOperationIds(String cruiseId); + List<FishingOperation> getAllFishingOperation(String cruiseId); FishingOperation getFishingOperation(String id); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -90,7 +90,6 @@ import java.io.Serializable; import java.sql.Timestamp; import java.text.MessageFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -175,6 +174,23 @@ } @Override + public List<String> getAllFishingOperationIds(String cruiseId) { + Preconditions.checkNotNull(cruiseId); + + Iterator list = queryList( + "allFishingOperationIds", + "cruiseId", IntegerType.INSTANCE, Integer.valueOf(cruiseId) + ); + + List<String> result = Lists.newArrayList(); + while (list.hasNext()) { + Integer id = (Integer) list.next(); + result.add(id.toString()); + } + return result; + } + + @Override public List<FishingOperation> getAllFishingOperation(String cruiseId) { Preconditions.checkNotNull(cruiseId); @@ -185,7 +201,7 @@ "pmfmIdMultirigAggregation", IntegerType.INSTANCE, enumeration.PMFM_ID_MULTIRIG_AGGREGATION ); - List<FishingOperation> result = new ArrayList<FishingOperation>(); + List<FishingOperation> result = Lists.newArrayList(); int fishingOperationRankOrder = 0; while (list.hasNext()) { Object[] source = list.next(); Modified: trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml =================================================================== --- trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-10-02 10:08:19 UTC (rev 1265) @@ -204,6 +204,7 @@ sc.id = :cruiseId AND gpf.gear.id = :gearId AND gpf.rankOrder = :rankOrder + AND gpm != null ]]> <query-param name="cruiseId" type="java.lang.Integer"/> <query-param name="gearId" type="java.lang.Integer"/> @@ -227,6 +228,20 @@ <query-param name="cruiseId" type="java.lang.Integer"/> </query> + <query cacheable="true" name="allFishingOperationIds"> + <![CDATA[ + SELECT + o.id AS id + FROM + FishingOperationImpl o + WHERE + o.fishingTrip.scientificCruise.id=:cruiseId + ORDER BY + o.startDateTime + ]]> + <query-param name="cruiseId" type="java.lang.Integer"/> + </query> + <query cacheable="true" name="allFishingOperations"> <![CDATA[ SELECT @@ -242,7 +257,7 @@ LEFT OUTER JOIN o.vesselUseFeatures vuf WHERE o.fishingTrip.scientificCruise.id=:cruiseId - ORDER BY + ORDER BY o.startDateTime ]]> <query-param name="cruiseId" type="java.lang.Integer"/> 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -955,6 +955,11 @@ } @Override + public List<String> getAllFishingOperationIds(String cruiseId) { + return driver.getAllFishingOperationIds(cruiseId); + } + + @Override public List<FishingOperation> getAllFishingOperation(String cruiseId) { return driver.getAllFishingOperation(cruiseId); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ExportCatchesReportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ExportCatchesReportService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ExportCatchesReportService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -32,6 +32,7 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.AbstractTuttiService; @@ -99,118 +100,158 @@ } /** - * Generate the PDF report + * Generate the PDF report for the fiven cruise. * * @param targetFile pdf file to generate * @param locale generated pdf locale - * @return the generated file * @throws TuttiBusinessException */ - public File generatePDFFile(File targetFile, String cruiseId, Locale locale) throws TuttiBusinessException { + public void generateCruisePDFFile(File targetFile, + String cruiseId, + Locale locale) throws TuttiBusinessException { - File result = null; - OutputStream os = null; + List<String> allFishingOperation = + persistenceService.getAllFishingOperationIds(cruiseId); - Map<String, Object> data = Maps.newHashMap(); + List<Map<String, Object>> operations = Lists.newArrayList(); + for (String operationId : allFishingOperation) { - List<FishingOperation> allFishingOperation = - persistenceService.getAllFishingOperation(cruiseId); + prepareOperation(operationId, operations); + } + + generatePdf(targetFile, locale, operations); + } + + /** + * Generate the PDF report for the given fishing operation. + * + * @param targetFile pdf file to generate + * @param fishingOperationId id of the fishing operation to export + * @param locale generated pdf locale + * @throws TuttiBusinessException + * @since 2.7 + */ + public void generateFishingOperationPDFFile(File targetFile, + String fishingOperationId, + Locale locale) throws TuttiBusinessException { + List<Map<String, Object>> operations = Lists.newArrayList(); - for (FishingOperation fishingOperation : allFishingOperation) { - // get operation and catch data - String fishingOperationId = fishingOperation.getId(); + prepareOperation(fishingOperationId, operations); - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + generatePdf(targetFile, locale, operations); + } - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperation + - " since no catchBatch associated."); - } - continue; + protected void prepareOperation(String fishingOperationId, + List<Map<String, Object>> operations) { + + // get operation and catch data + boolean withCatchBatch = + persistenceService.isFishingOperationWithCatchBatch( + fishingOperationId); + + if (!withCatchBatch) { + if (log.isWarnEnabled()) { + log.warn("Skip fishing operation " + fishingOperationId + + " since no catchBatch associated."); } - CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); + return; + } - BatchContainer<SpeciesBatch> rootSpeciesBatch = - weightComputingService.getComputedSpeciesBatches(fishingOperation); + FishingOperation fishingOperation = + persistenceService.getFishingOperation(fishingOperationId); - BatchContainer<BenthosBatch> rootBenthosBatch = - weightComputingService.getComputedBenthosBatches(fishingOperation); + CatchBatch catchBatch = + persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); - weightComputingService.computeCatchBatchWeights(catchBatch, rootSpeciesBatch, rootBenthosBatch, null); + BatchContainer<SpeciesBatch> rootSpeciesBatch = + weightComputingService.getComputedSpeciesBatches(fishingOperationId); - // create operation data model - Map<String, Object> op = createOperation(fishingOperation); + BatchContainer<BenthosBatch> rootBenthosBatch = + weightComputingService.getComputedBenthosBatches(fishingOperationId); - Float totalWeight = catchBatch.getCatchTotalWeight(); - if (totalWeight == null) { - totalWeight = catchBatch.getCatchTotalComputedWeight(); - } - op.put("totalWeight", totalWeight); + BatchContainer<MarineLitterBatch> marineLitterBatches = + weightComputingService.getComputedMarineLitterBatches( + fishingOperationId, + catchBatch.getMarineLitterTotalWeight()); + weightComputingService.computeCatchBatchWeights(catchBatch, + rootSpeciesBatch, + rootBenthosBatch, + marineLitterBatches); - op.put("totalSortedWeight", catchBatch.getSpeciesTotalSampleSortedComputedWeight() + catchBatch.getBenthosTotalSampleSortedComputedWeight()); + // create operation data model + Map<String, Object> op = createOperation(fishingOperation); - // create catches data model + Float totalWeight = catchBatch.getCatchTotalWeight(); + if (totalWeight == null) { + totalWeight = catchBatch.getCatchTotalComputedWeight(); + } + op.put("totalWeight", totalWeight); - // Species + op.put("totalSortedWeight", catchBatch.getSpeciesTotalSampleSortedComputedWeight() + catchBatch.getBenthosTotalSampleSortedComputedWeight()); - Map<Species, Map<String, Object>> catches = Maps.newHashMap(); - Float ratio = (totalWeight - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); + // create catches data model - Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); - } - // ratio total species weight / total sorted sampled species weight - Float speciesRatio = speciesTotalSortedWeight / catchBatch.getSpeciesTotalSampleSortedComputedWeight(); + // Species - // create catches rows - if (rootSpeciesBatch != null) { - List<SpeciesBatch> speciesBatches = rootSpeciesBatch.getChildren(); - for (SpeciesBatch batch : speciesBatches) { - createSpeciesCatch(batch, catches, speciesRatio * ratio, totalWeight); - } - } - List<Map<String, Object>> catchList = Lists.newArrayList(catches.values()); + Map<Species, Map<String, Object>> catches = Maps.newHashMap(); + Float ratio = (totalWeight - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); - // Benthos + Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); + if (speciesTotalSortedWeight == null) { + speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); + } + // ratio total species weight / total sorted sampled species weight + Float speciesRatio = speciesTotalSortedWeight / catchBatch.getSpeciesTotalSampleSortedComputedWeight(); - Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); + // create catches rows + if (rootSpeciesBatch != null) { + List<SpeciesBatch> speciesBatches = rootSpeciesBatch.getChildren(); + for (SpeciesBatch batch : speciesBatches) { + createSpeciesCatch(batch, catches, speciesRatio * ratio, totalWeight); } - // ratio total benthos weight / total sorted sampled benthos weight - Float benthosRatio = benthosTotalSortedWeight / catchBatch.getBenthosTotalSampleSortedComputedWeight(); + } + List<Map<String, Object>> catchList = Lists.newArrayList(catches.values()); - // add the benthos row - if (rootBenthosBatch != null) { - if (CollectionUtils.isNotEmpty(rootBenthosBatch.getChildren())) { - Map<String, Object> benthosCatch = - createBenthosCatch(rootBenthosBatch, ratio * benthosRatio, totalWeight); - catchList.add(benthosCatch); - } - } + // Benthos - // Inert and living not itemized - Map<String, Object> inertLivingNotItemizedCatch = createInertAndLivingNotItemizedCatch(catchBatch, - ratio * speciesRatio, - ratio * benthosRatio, - totalWeight); - if ((Float) inertLivingNotItemizedCatch.get("sortedWeight") > 0f) { - catchList.add(inertLivingNotItemizedCatch); + Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); + if (benthosTotalSortedWeight == null) { + benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); + } + // ratio total benthos weight / total sorted sampled benthos weight + Float benthosRatio = benthosTotalSortedWeight / catchBatch.getBenthosTotalSampleSortedComputedWeight(); + + // add the benthos row + if (rootBenthosBatch != null) { + if (CollectionUtils.isNotEmpty(rootBenthosBatch.getChildren())) { + Map<String, Object> benthosCatch = + createBenthosCatch(rootBenthosBatch, ratio * benthosRatio, totalWeight); + catchList.add(benthosCatch); } + } - op.put("catches", catchList); - operations.add(op); + // Inert and living not itemized + Map<String, Object> inertLivingNotItemizedCatch = createInertAndLivingNotItemizedCatch(catchBatch, + ratio * speciesRatio, + ratio * benthosRatio, + totalWeight); + if ((Float) inertLivingNotItemizedCatch.get("sortedWeight") > 0f) { + catchList.add(inertLivingNotItemizedCatch); } + + op.put("catches", catchList); + operations.add(op); + } + + protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { + + Map<String, Object> data = Maps.newHashMap(); data.put("operations", operations); - // generate the report + OutputStream os = null; try { // render freemarker template @@ -235,8 +276,6 @@ } finally { IOUtils.closeQuietly(os); } - - return result; } protected Map<String, Object> createOperation(FishingOperation fishingOperation) { Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -292,7 +292,7 @@ BatchContainer<MarineLitterBatch> rootMarineLitterBatch; try { Float weight = catchBatch == null ? null : catchBatch.getMarineLitterTotalWeight(); - rootMarineLitterBatch = weightComputingService.getComputedMarineLitterBatches(fishingOperation, weight); + rootMarineLitterBatch = weightComputingService.getComputedMarineLitterBatches(fishingOperationId, weight); } catch (TuttiBusinessException e) { errors.add(e.getMessage()); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -31,7 +31,6 @@ 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.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; @@ -100,20 +99,18 @@ } Map<String, String> result = Maps.newTreeMap(); - List<FishingOperation> allFishingOperation = - persistenceService.getAllFishingOperation(cruiseId); + List<String> allFishingOperation = + persistenceService.getAllFishingOperationIds(cruiseId); - for (FishingOperation fishingOperation : allFishingOperation) { + for (String fishingOperationId : allFishingOperation) { - String fishingOperationId = fishingOperation.getId(); - boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch( fishingOperationId); if (!withCatchBatch) { if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperation + + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); } continue; @@ -122,7 +119,7 @@ BatchContainer<SpeciesBatch> rootSpeciesBatch; try { - rootSpeciesBatch = getComputedSpeciesBatches(fishingOperation); + rootSpeciesBatch = getComputedSpeciesBatches(fishingOperationId); } catch (TuttiBusinessException e) { result.put(fishingOperationId, e.getMessage()); @@ -131,7 +128,7 @@ BatchContainer<BenthosBatch> rootBenthosBatch; try { - rootBenthosBatch = getComputedBenthosBatches(fishingOperation); + rootBenthosBatch = getComputedBenthosBatches(fishingOperationId); } catch (TuttiBusinessException e) { result.put(fishingOperationId, e.getMessage()); @@ -141,7 +138,7 @@ BatchContainer<MarineLitterBatch> rootMarineLitterBatch; try { Float weight = catchBatch == null ? null : catchBatch.getMarineLitterTotalWeight(); - rootMarineLitterBatch = getComputedMarineLitterBatches(fishingOperation, weight); + rootMarineLitterBatch = getComputedMarineLitterBatches(fishingOperationId, weight); } catch (TuttiBusinessException e) { result.put(fishingOperationId, e.getMessage()); @@ -347,12 +344,12 @@ private int currentSpeciesRowIndex; - public BatchContainer<SpeciesBatch> getComputedSpeciesBatches(FishingOperation operation) { + public BatchContainer<SpeciesBatch> getComputedSpeciesBatches(String operationId) { BatchContainer<SpeciesBatch> rootSpeciesBatch = null; - if (persistenceService.isFishingOperationWithCatchBatch(operation.getId())) { - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), null); + if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operationId, null); currentSpeciesRowIndex = 0; if (rootSpeciesBatch != null) { @@ -540,12 +537,12 @@ private int currentBenthosRowIndex; - public BatchContainer<BenthosBatch> getComputedBenthosBatches(FishingOperation operation) { + public BatchContainer<BenthosBatch> getComputedBenthosBatches(String operationId) { BatchContainer<BenthosBatch> rootBenthosBatch = null; - if (persistenceService.isFishingOperationWithCatchBatch(operation.getId())) { - rootBenthosBatch = persistenceService.getRootBenthosBatch(operation.getId(), null); + if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { + rootBenthosBatch = persistenceService.getRootBenthosBatch(operationId, null); currentBenthosRowIndex = 0; if (rootBenthosBatch != null) { @@ -730,10 +727,9 @@ return result; } - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(FishingOperation operation, + public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(String fishingOperationId, Float marineLitterweight) { - String fishingOperationId = operation.getId(); BatchContainer<MarineLitterBatch> rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/TuttiExportService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -277,7 +277,6 @@ String cruiseStr = cruiseDecorator.toString(cruise); throw new TuttiBusinessException( _("tutti.service.export.invalid.cruise", cruiseStr, sb.toString())); -// _("tutti.service.export.invalid.cruise2", cruiseStr, sb.toString())); } } @@ -674,8 +673,6 @@ Caracteristic verticalOpeningCaracteristic, Caracteristic horizontalOpeningWingCaracteristic, Caracteristic horizontalOpeningDoorCaracteristic, -// Caracteristic sampleIdCaracteristic, -// Caracteristic otolitheIdCaracteristic, Caracteristic weightMeasuredCaracteristic, Caracteristic deadOrAliveCaracteristic, Caracteristic genderCaracteristic, @@ -746,8 +743,6 @@ pmfmIdCaracteristic); individualObservationModel = new IndividualObservationExportModel( csvSeparator, -// sampleIdCaracteristic, -// otolitheIdCaracteristic, weightMeasuredCaracteristic, pmfmIdCaracteristic); @@ -859,7 +854,7 @@ boolean withError = false; try { - rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(operation); + rootSpeciesBatch = weightComputingService.getComputedSpeciesBatches(operationId); } catch (Exception e) { withError = true; rootSpeciesBatch = @@ -868,7 +863,7 @@ try { rootBenthosBatch = - weightComputingService.getComputedBenthosBatches(operation); + weightComputingService.getComputedBenthosBatches(operationId); } catch (Exception e) { withError = true; rootBenthosBatch = @@ -877,7 +872,7 @@ try { rootMarineLitterBatch = - weightComputingService.getComputedMarineLitterBatches(operation, catchBatch.getMarineLitterTotalWeight()); + weightComputingService.getComputedMarineLitterBatches(operationId, catchBatch.getMarineLitterTotalWeight()); } catch (Exception e) { withError = true; rootMarineLitterBatch = Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/CatchesSumatraExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/CatchesSumatraExportService.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/CatchesSumatraExportService.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -33,8 +33,10 @@ 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.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -74,6 +76,13 @@ weightComputingService = getService(WeightComputingService.class); } + /** + * Export selected cruise with the csv sumatra format. + * + * @param file where to generate report + * @param cruiseId id of the cruise to export + * @since 2.0 + */ public void exportCruiseForSumatra(File file, String cruiseId) { @@ -87,86 +96,56 @@ Cruise cruise = persistenceService.getCruise(cruiseId); Preconditions.checkNotNull(cruise, "Cruise [" + cruiseId + "] not found"); - CatchRowModel csvModel = - new CatchRowModel(context.getConfig().getCsvSeparator()); - List<CatchRow> rows = Lists.newArrayList(); + List<String> operations = + persistenceService.getAllFishingOperationIds(cruiseId); - List<FishingOperation> operations = persistenceService.getAllFishingOperation(cruiseId); - if (operations != null) { - for (FishingOperation operation : operations) { + prepareOperationsAndExport(file, operations); + } - // add species rows + /** + * Export selected fishing operation with the csv sumatra 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 2.7 + */ + public void exportFishingOperationForSumatra(File file, + String cruiseId, + String fishingOperationId) { - BatchContainer<SpeciesBatch> speciesBatchContainer = - weightComputingService.getComputedSpeciesBatches(operation); + 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"); - Map<Species, CatchRow> rowMap = Maps.newLinkedHashMap(); - if (speciesBatchContainer != null) { - List<SpeciesBatch> speciesBatches = speciesBatchContainer.getChildren(); - for (SpeciesBatch batch : speciesBatches) { - Species sp = batch.getSpecies(); + if (log.isInfoEnabled()) { + log.info("Will export fishing operation " + + fishingOperationId + " to file: " + file); + } - int number = Math.round(computeNumber(batch, 1.0f)); + Cruise cruise = persistenceService.getCruise(cruiseId); + Preconditions.checkNotNull(cruise, "Cruise [" + cruiseId + "] not found"); - Float weight = TuttiEntities.getValueOrComputedValue( - batch.getSampleCategoryWeight(), - batch.getSampleCategoryComputedWeight()); + List<String> operations = Lists.newArrayList(fishingOperationId); + prepareOperationsAndExport(file, operations); + } - CatchRow row = rowMap.get(sp); - if (row == null) { - row = new CatchRow(); - row.setFishingOperation(operation); - row.setSpecies(sp); - row.setWeight(weight); - row.setNumber(number); + protected void prepareOperationsAndExport(File file, + List<String> operations) { - } else { - row.setWeight(row.getWeight() + weight); - row.setNumber(row.getNumber() + number); - } - rowMap.put(sp, row); - } - rows.addAll(rowMap.values()); - } + List<CatchRow> rows = Lists.newArrayList(); - // add benthos rows + if (operations != null) { + for (String operationId : operations) { - BatchContainer<BenthosBatch> benthosBatchContainer = - weightComputingService.getComputedBenthosBatches(operation); - - rowMap.clear(); - if (benthosBatchContainer != null) { - List<BenthosBatch> benthosBatches = benthosBatchContainer.getChildren(); - for (BenthosBatch batch : benthosBatches) { - Species sp = batch.getSpecies(); - - Float weight = TuttiEntities.getValueOrComputedValue( - batch.getSampleCategoryWeight(), - batch.getSampleCategoryComputedWeight()); - - int number = Math.round(computeNumber(batch, 1.0f)); - - 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()); + prepareFishingOperation(rows, operationId); } } + CatchRowModel csvModel = + new CatchRowModel(context.getConfig().getCsvSeparator()); + BufferedWriter writer = null; try { writer = Files.newWriter(file, Charsets.UTF_8); @@ -181,6 +160,132 @@ } } + protected void prepareFishingOperation(List<CatchRow> rows, String operationId) { + + 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; @@ -199,16 +304,6 @@ // no count number = 0; - -// // try to get frequency -// List<SpeciesBatchFrequency> frequencies = -// persistenceService.getAllSpeciesBatchFrequency(batch.getId()); -// if (CollectionUtils.isNotEmpty(frequencies)) { -// -// for (SpeciesBatchFrequency frequency : frequencies) { -// number += frequency.getNumber(); -// } -// } } // get the sample weight Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -27,7 +27,6 @@ import com.google.common.io.Files; import fr.ifremer.tutti.TuttiBusinessException; import fr.ifremer.tutti.persistence.ProgressionModel; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -95,8 +94,8 @@ // check there is a error while compute weight for a cruise boolean errorDetected = false; WeightComputingService computingService = serviceContext.getService(WeightComputingService.class); - List<FishingOperation> allFishingOperation = persistenceService.getAllFishingOperation(CRUISE_ID); - for (FishingOperation fishingOperation : allFishingOperation) { + List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(CRUISE_ID); + for (String fishingOperation : allFishingOperation) { try { computingService.getComputedSpeciesBatches(fishingOperation); } catch (Exception e) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SendCruiseReportAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SendCruiseReportAction.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SendCruiseReportAction.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -98,7 +98,7 @@ // export catches ExportCatchesReportService service = getContext().getGeneratePDFService(); - service.generatePDFFile(file, cruise.getId(), getConfig().getI18nLocale()); + service.generateCruisePDFFile(file, cruise.getId(), getConfig().getI18nLocale()); try { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -110,9 +110,10 @@ BatchContainer<SpeciesBatch> computedSpeciesBatches; Float totalSpeciesSortedWeight; + String operationId = model.getFishingOperation().getId(); try { computedSpeciesBatches = - weightComputingService.getComputedSpeciesBatches(model.getFishingOperation()); + weightComputingService.getComputedSpeciesBatches(operationId); totalSpeciesSortedWeight = computeSpeciesBatches(persistenceService, computedSpeciesBatches); } catch (TuttiWeightComputingException e) { @@ -139,7 +140,7 @@ Float totalBenthosSortedWeight; try { computedBenthosBatches = - weightComputingService.getComputedBenthosBatches(model.getFishingOperation()); + weightComputingService.getComputedBenthosBatches(operationId); totalBenthosSortedWeight = computeBenthosBatches(persistenceService, computedBenthosBatches); } catch (TuttiWeightComputingException e) { @@ -165,7 +166,7 @@ BatchContainer<MarineLitterBatch> computedMarineLitterBatches; try { computedMarineLitterBatches = - weightComputingService.getComputedMarineLitterBatches(model.getFishingOperation(), + weightComputingService.getComputedMarineLitterBatches(operationId, model.getMarineLitterTotalWeight()); } catch (TuttiWeightComputingException e) { 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-10-02 10:08:19 UTC (rev 1265) @@ -327,20 +327,20 @@ border: {BorderFactory.createTitledBorder(_("tutti.editCatchBatch.legend.individualObservation"))}; } -#sendCruiseReportButton { - actionIcon: email; - text: "tutti.selectCruise.action.sendCruiseReport"; - toolTipText: "tutti.selectCruise.action.sendCruiseReport.tip"; - _tuttiAction: {SendCruiseReportAction.class}; - _help: {"tutti.selectCruise.action.sendCruiseReport.help"}; +#exportFishingOperationReportButton { + actionIcon: export; + text: "tutti.editCatchBatch.action.exportFishingOperationReport"; + toolTipText: "tutti.editCatchBatch.action.exportFishingOperationReport.tip"; + _tuttiAction: {ExportFishingOperationReportAction.class}; + _help: {"tutti.editCatchBatch.action.exportFishingOperationReport.help"}; } -#exportCruiseForSumatraButton { +#exportFishingOperationReportForSumatraButton { actionIcon: export; - text: "tutti.selectCruise.action.exportCruiseForSumatra"; - toolTipText: "tutti.selectCruise.action.exportCruiseForSumatra.tip"; - _tuttiAction: {ExportCruiseForSumatraAction.class}; - _help: {"tutti.selectCruise.action.exportCruiseForSumatra.help"}; + text: "tutti.editCatchBatch.action.exportFishingOperationReportForSumatra"; + toolTipText: "tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.tip"; + _tuttiAction: {ExportFishingOperationForSumatraAction.class}; + _help: {"tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.help"}; } 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-10-02 10:08:19 UTC (rev 1265) @@ -115,8 +115,8 @@ <TuttiHelpBroker id='broker' constructorParams='"tutti.editCatchBatch.help"'/> <JToolBar id='catchesCaracteristicsTabToolBar'> - <JButton id='sendCruiseReportButton'/> - <JButton id='exportCruiseForSumatraButton'/> + <JButton id='exportFishingOperationReportButton'/> + <JButton id='exportFishingOperationReportForSumatraButton'/> <ButtonAttachment id='catchesCaracteristicsAttachmentsButton' constructorParams='getHandler().getContext(), getModel()'/> </JToolBar> Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationForSumatraAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationForSumatraAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationForSumatraAction.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -0,0 +1,91 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +import com.google.common.base.Preconditions; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.service.sumatra.CatchesSumatraExportService; +import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction; +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._; + +/** + * Created on 10/1/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.7 + */ +public class ExportFishingOperationForSumatraAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ExportFishingOperationForSumatraAction.class); + + protected File file; + + public ExportFishingOperationForSumatraAction(EditCatchesUIHandler handler) { + super(handler, true); + } + + @Override + public boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (doAction) { + + FishingOperation fishingOperation = getModel().getFishingOperation(); + + String date = DateUtil.formatDate(new Date(), "dd-MM-yyyy"); + // choose file to export + file = saveFile( + String.format("sumatra_%s_%s_%s", getDataContext().getCruise().getName(), fishingOperation.getId(), date), + "csv", + _("tutti.exportFishingOperationForSumatra.title.choose.exportFile"), + _("tutti.exportFishingOperationForSumatra.action.chooseFile"), + "^.+\\.csv$", _("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); + } + + // export catches + CatchesSumatraExportService service = + getContext().getCatchesSumatraExportService(); + service.exportFishingOperationForSumatra(file, + cruise.getId(), + fishingOperation.getId()); + + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + sendMessage(_("tutti.exportFishingOperationForSumatra.action.success", file)); + } +} Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationForSumatraAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationReportAction.java (from rev 1264, trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/home/SendCruiseReportAction.java) =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationReportAction.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ExportFishingOperationReportAction.java 2013-10-02 10:08:19 UTC (rev 1265) @@ -0,0 +1,110 @@ +package fr.ifremer.tutti.ui.swing.content.operation.catches; + +/* + * #%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.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.service.catches.ExportCatchesReportService; +import fr.ifremer.tutti.ui.swing.util.action.AbstractTuttiAction; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; + +import static org.nuiton.i18n.I18n._; + +/** + * Opens a file chooser, exports the cruise catches into the selected file and open the default email editor. + * + * @author kmorin <morin@codelutin.com> + * @since 1.0 + */ +public class ExportFishingOperationReportAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ExportFishingOperationReportAction.class); + + protected File file; + + public ExportFishingOperationReportAction(EditCatchesUIHandler handler) { + super(handler, true); + } + + @Override + public boolean prepareAction() throws Exception { + + boolean doAction = super.prepareAction(); + + if (doAction) { + + Cruise cruise = getDataContext().getCruise(); + FishingOperation fishingOperation = getModel().getFishingOperation(); + // choose file to export + file = saveFile( + "exportFishingOperation-" + cruise.getName() + "-" + fishingOperation.getStationNumber(), + "pdf", + _("tutti.exportFishingOperationReport.title.choose.exportFile"), + _("tutti.exportFishingOperationReport.action.chooseFile"), + "^.+\\.pdf$", _("tutti.common.file.pdf") + ); + 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); + } + + // export catches + ExportCatchesReportService service = + getContext().getGeneratePDFService(); + service.generateFishingOperationPDFFile(file, fishingOperation.getId(), getConfig().getI18nLocale()); + + } + + @Override + public void postSuccessAction() { + super.postSuccessAction(); + sendMessage(_("tutti.exportFishingOperationReport.action.success", file)); + } +} 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-10-02 10:08:19 UTC (rev 1265) @@ -513,9 +513,15 @@ tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.message.species= tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title= tutti.editCatchBatch.action.computeWeights.tip= +tutti.editCatchBatch.action.exportFishingOperationReport= +tutti.editCatchBatch.action.exportFishingOperationReport.tip= +tutti.editCatchBatch.action.exportFishingOperationReportForSumatra= +tutti.editCatchBatch.action.exportFishingOperationReportForSumatra.tip= tutti.editCatchBatch.action.saveCatchBatch= tutti.editCatchBatch.action.saveCatchBatch.mnemonic= tutti.editCatchBatch.action.saveCatchBatch.tip= +tutti.editCatchBatch.action.sendCruiseReport= +tutti.editCatchBatch.action.sendCruiseReport.tip= tutti.editCatchBatch.askCancelEditBeforeLeaving.cancelEditCatchBatch= tutti.editCatchBatch.askSaveBeforeLeaving.saveCatchBatch= tutti.editCatchBatch.field.benthosTotalSampleSortedWeight= @@ -1058,6 +1064,15 @@ tutti.exportDb.step.createArchive= tutti.exportDb.step.openDb= tutti.exportDb.step.reloadApplication= +tutti.exportFishingOperationForSumatra.action.chooseFile= +tutti.exportFishingOperationForSumatra.action.success= +tutti.exportFishingOperationForSumatra.title.choose.exportFile= +tutti.exportFishingOperationReport.action.chooseFile= +tutti.exportFishingOperationReport.action.success= +tutti.exportFishingOperationReport.title.choose.exportFile= +tutti.exportFishingOperationReportForSumatra.action.chooseFile= +tutti.exportFishingOperationReportForSumatra.action.success= +tutti.exportFishingOperationReportForSumatra.title.choose.exportFile= tutti.exportProgram.action.exportErrors= tutti.exportProgram.action.success= tutti.exportProtocol.action.success= @@ -1363,6 +1378,9 @@ tutti.sendCruiseReport.mail.body= tutti.sendCruiseReport.mail.subject= tutti.sendCruiseReport.title.choose.exportFile= +tutti.sendFishingOperationReport.action.chooseFile= +tutti.sendFishingOperationReport.action.success= +tutti.sendFishingOperationReport.title.choose.exportFile= tutti.splitBenthosBatch.action.cancel= tutti.splitBenthosBatch.action.cancel.mnemonic= tutti.splitBenthosBatch.action.cancel.tip= 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 2013-10-01 12:57:43 UTC (rev 1264) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-10-02 10:08:19 UTC (rev 1265) @@ -1,3 +1,4 @@ +enthosBatch.field.batchWeight=Poids total à catégoriser swing.error.cannot.mail=Erreur lors de l'ouverture du client mail swing.error.cannot.open.file=Aucun programme n'est défini pour ouvrir ce type de fichier. Enregistrez le fichier et ouvrez le en dehors de l'application swing.error.cannot.open.link=Impossible d'ouvrir le fichier %s @@ -512,15 +513,15 @@ tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.message.species=Le Poids total VRAC saisi sur les espèces est supérieur de moins de %s%% au Poids total Vrac trié. tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title=Poids total VRAC peu différent du Poids total Vrac trié tutti.editCatchBatch.action.computeWeights.tip=Élever les poids -tutti.editCatchBatch.action.exportCruiseForSumatra=Sumatra -tutti.editCatchBatch.action.exportCruiseForSumatra.mnemonic=u -tutti.editCatchBatch.action.exportCruiseForSumatra.tip=Exporter la campagne sélectionnée pour Sumatra +tutti.editCatchBatch.action.exportFishingOperationReport=Résumé PDF +tutti.editCatchBatch.action.exportFishingOperationReport.mnemonic=P +tutti.editCatchBatch.action.exportFishingOperationReport.tip=Envoyer le résumé au format pdf du trait sélectionné +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.saveCatchBatch=Enregistrer tutti.editCatchBatch.action.saveCatchBatch.mnemonic=S tutti.editCatchBatch.action.saveCatchBatch.tip=Enregistrer la capture -tutti.editCatchBatch.action.sendCruiseReport=Envoyer -tutti.editCatchBatch.action.sendCruiseReport.mnemonic=E -tutti.editCatchBatch.action.sendCruiseReport.tip=Envoyer le rapport de la campagne tutti.editCatchBatch.askCancelEditBeforeLeaving.cancelEditCatchBatch=La capture n'est pas valide et ne peut pas être enregistrée tutti.editCatchBatch.askSaveBeforeLeaving.saveCatchBatch=Des modifications sur la capture n'ont pas été enregistrées tutti.editCatchBatch.field.benthosTotalSampleSortedWeight=Poids VRAC trié @@ -1058,12 +1059,21 @@ tutti.exportCruise.action.exportErrors=Des erreurs sont apparues pendant l'élévation des poids de la campagne <strong>%s</strong>.<br/>L'export a cependant été réalisé.<hr/>Erreur(s) rencontrée(s) \: <br/>%s tutti.exportCruise.action.success=La campagne <strong>%s</strong> a été exportée dans le fichier <strong>%s</strong>. tutti.exportCruiseForSumatra.action.chooseFile=Choisir le fichier d'export -tutti.exportCruiseForSumatra.action.success=Les captures ont correctement été exporté dans le fichier %s -tutti.exportCruiseForSumatra.title.choose.exportFile=Exporter les captures de la campagne +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.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 tutti.exportDb.step.reloadApplication=Redémarrage de l'application +tutti.exportFishingOperationForSumatra.action.chooseFile=Choisir le fichier d'export +tutti.exportFishingOperationForSumatra.action.success=Le trait a été exporté dans le fichier <strong>%s</strong> +tutti.exportFishingOperationForSumatra.title.choose.exportFile=Exporter le trait de la campagne +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.title.choose.exportFile=Exporter le trait de la campagne +tutti.exportFishingOperationReportForSumatra.action.chooseFile=Choisir le fichier d'export +tutti.exportFishingOperationReportForSumatra.action.success=Les captures du trait ont correctement été exporté dans le fichier <strong>%s</strong> +tutti.exportFishingOperationReportForSumatra.title.choose.exportFile=Exporter les captures du trait sélectionné tutti.exportProgram.action.exportErrors=Des erreurs sont apparues pendant l'élévation des poids d'une campagne de la série <strong>%s</strong>.<br/>L'export a cependant été réalisé.<hr/>Erreur(s) rencontrée(s) \: <br/>%s tutti.exportProgram.action.success=La série de campagne <strong>%s</strong> a été exportée dans le fichier <strong>%s</strong>. tutti.exportProtocol.action.success=Protocole [%1s] exporté dans le fichier <strong>%2s</strong>. @@ -1366,7 +1376,7 @@ tutti.sendCruiseReport.action.chooseFile=Choisir le fichier de rapport tutti.sendCruiseReport.action.error.mail.message=<html>Le client email n'a pas pu être ouvert.<hr/>Vous pouvez ouvrir manuellement votre client email et ajouter le fichier<br/><em>%s</em><br/>en pièce-jointe.</html> tutti.sendCruiseReport.action.error.mail.title=Impossible d'ouvrir le client d'email -tutti.sendCruiseReport.action.success=Les captures ont correctement été exporté dans le fichier %s +tutti.sendCruiseReport.action.success=Les captures ont correctement été exporté dans le fichier <strong>%s</strong> tutti.sendCruiseReport.mail.body=Bonjour,\n\nVeuillez trouver ci-joint le rapport des captures de la campagne %1s.\n*Pensez à joindre le fichier %2s*\n\nCordialement,\n\n*Votre nom* tutti.sendCruiseReport.mail.subject=Captures de la campagne %s tutti.sendCruiseReport.title.choose.exportFile=Envoyer les captures de la campagne @@ -1376,7 +1386,7 @@ tutti.splitBenthosBatch.action.save=Enregistrer tutti.splitBenthosBatch.action.save.mnemonic=E tutti.splitBenthosBatch.action.save.tip=Sauver le sous-échantillonnage -tutti.splitBenthosBatch.field.batchWeight=Poids total à catégoriser +tutti.splitBenthosBatch.field.batchWeight= tutti.splitBenthosBatch.field.batchWeight.tip=Poids du lot père (si renseigné) tutti.splitBenthosBatch.field.category=Catégorie tutti.splitBenthosBatch.field.category.tip=Choisir le mode de catégorisation @@ -1386,6 +1396,7 @@ tutti.splitBenthosBatch.table.header.selected=Sélection tutti.splitBenthosBatch.table.header.weight=Poids tutti.splitBenthosBatch.title=Catégorisation du lot +tutti.splitBtutti.exportFishingOperationReport.action.success=Le trait a correctement été exporté dans le fichier <strong>%s</strong> tutti.splitSpeciesBatch.action.cancel=Annuler tutti.splitSpeciesBatch.action.cancel.mnemonic=A tutti.splitSpeciesBatch.action.cancel.tip=Annuler le sous-échantillonnage
participants (1)
-
tchemit@users.forge.codelutin.com