Author: tchemit Date: 2013-11-20 14:56:44 +0100 (Wed, 20 Nov 2013) New Revision: 1366 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1366 Log: refs 3823: [TECH] Temps d'affichage d'un trait trop lent (use snapshot of adagio) refs #3803: [CAPTURE] ?\195?\169l?\195?\169vations : marche pas en .csv et .pdf depuis l'onglet r?\195?\169sum?\195?\169 (improve pdf export code + add a test on medits data) Added: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/ExportCatchesReportServiceTest.java trunk/tutti-service/src/test/resources/tutti-test-read-dbMedits.properties Modified: trunk/pom.xml 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/entities/TuttiEntities.java 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/WeightComputingService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java trunk/tutti-ui-swing/src/main/profiling/META-INF/aop.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-11-20 08:11:09 UTC (rev 1365) +++ trunk/pom.xml 2013-11-20 13:56:44 UTC (rev 1366) @@ -137,9 +137,8 @@ <slf4jVersion>1.7.5</slf4jVersion> - <adagioVersion>3.4</adagioVersion> + <adagioVersion>3.4.0-1-SNAPSHOT</adagioVersion> <birtVersion>4.2.1a</birtVersion> - <!--<adagioVersion>3.4.1-SNAPSHOT</adagioVersion>--> <bluecoveVersion>2.1.0</bluecoveVersion> @@ -218,7 +217,7 @@ <dependency> <groupId>org.nuiton</groupId> <artifactId>nuiton-profiling</artifactId> - <version>2.7</version> + <version>2.7.1</version> </dependency> <dependency> 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -38,6 +38,7 @@ import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -268,10 +269,12 @@ Caracteristic getCaracteristic(Integer pmfmId); - boolean isVracSpeciesBatch(SpeciesBatch speciesBatch); + boolean isVracBatch(SpeciesAbleBatch speciesBatch); - boolean isVracBenthosBatch(BenthosBatch benthosBatch); +// boolean isVracSpeciesBatch(SpeciesBatch speciesBatch); +// boolean isVracBenthosBatch(BenthosBatch benthosBatch); + boolean isTemporary(TuttiReferentialEntity entity); List<Gear> getAllScientificGear(); 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -46,6 +46,7 @@ import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; @@ -138,9 +139,11 @@ @Autowired protected DatabaseSchemaDao databaseSchemaDao; - protected Predicate<SpeciesBatch> speciesBatchVracPredicate; + protected Predicate<SpeciesAbleBatch> speciesAbleBatchVracPredicate; - protected Predicate<BenthosBatch> benthosBatchVracPredicate; +// protected Predicate<SpeciesBatch> speciesBatchVracPredicate; +// +// protected Predicate<BenthosBatch> benthosBatchVracPredicate; @Override public String getImplementationName() { @@ -226,8 +229,9 @@ TuttiEnumerationFile enumerationFile = getEnumerationFile(); - speciesBatchVracPredicate = TuttiEntities.newSpeciesBatchCategoryPredicate(enumerationFile.PMFM_ID_SORTED_UNSORTED, enumerationFile.QUALITATIVE_VRAC_ID); - benthosBatchVracPredicate = TuttiEntities.newBenthosBatchCategoryPredicate(enumerationFile.PMFM_ID_SORTED_UNSORTED, enumerationFile.QUALITATIVE_VRAC_ID); + speciesAbleBatchVracPredicate = TuttiEntities.newSpeciesAbleBatchCategoryPredicate(enumerationFile.PMFM_ID_SORTED_UNSORTED, enumerationFile.QUALITATIVE_VRAC_ID); +// speciesBatchVracPredicate = TuttiEntities.newSpeciesBatchCategoryPredicate(enumerationFile.PMFM_ID_SORTED_UNSORTED, enumerationFile.QUALITATIVE_VRAC_ID); +// benthosBatchVracPredicate = TuttiEntities.newBenthosBatchCategoryPredicate(enumerationFile.PMFM_ID_SORTED_UNSORTED, enumerationFile.QUALITATIVE_VRAC_ID); } @Override @@ -416,14 +420,19 @@ } @Override - public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { - return speciesBatchVracPredicate.apply(speciesBatch); + public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + return speciesAbleBatchVracPredicate.apply(speciesBatch); } - @Override - public boolean isVracBenthosBatch(BenthosBatch benthosBatch) { - return benthosBatchVracPredicate.apply(benthosBatch); - } +// @Override +// public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { +// return speciesBatchVracPredicate.apply(speciesBatch); +// } +// +// @Override +// public boolean isVracBenthosBatch(BenthosBatch benthosBatch) { +// return benthosBatchVracPredicate.apply(benthosBatch); +// } @Override public boolean isTemporary(TuttiReferentialEntity entity) { 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -38,6 +38,7 @@ import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -96,17 +97,17 @@ throw notImplemented(); } - @Override - public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { - throw notImplemented(); - } +// @Override +// public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { +// throw notImplemented(); +// } +// +// @Override +// public boolean isVracBenthosBatch(BenthosBatch benthosBatch) { +// throw notImplemented(); +// } @Override - public boolean isVracBenthosBatch(BenthosBatch benthosBatch) { - throw notImplemented(); - } - - @Override public void clearAllCaches() { throw notImplemented(); } @@ -257,6 +258,11 @@ } @Override + public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + throw notImplemented(); + } + + @Override public boolean isTemporary(TuttiReferentialEntity entity) { throw notImplemented(); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -32,8 +32,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.Sets; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; @@ -189,14 +188,10 @@ return new SampleCategoryCaracteristicPredicate(); } - public static Predicate<SpeciesBatch> newSpeciesBatchCategoryPredicate(Integer cateogryId, Integer value) { - return new SpeciesBatchCategoryPredicate(cateogryId, value); + public static Predicate<SpeciesAbleBatch> newSpeciesAbleBatchCategoryPredicate(Integer cateogryId, Integer value) { + return new SpeciesAbleBatchCategoryPredicate(cateogryId, value); } - public static Predicate<BenthosBatch> newBenthosBatchCategoryPredicate(Integer cateogryId, Integer value) { - return new BenthosBatchCategoryPredicate(cateogryId, value); - } - public static <B extends TuttiEntity> B findById(Iterable<B> beans, String id) { B result = Iterables.tryFind(beans, newIdPredicate(id)).orNull(); @@ -386,44 +381,25 @@ } } - protected static class SpeciesBatchCategoryPredicate implements Predicate<SpeciesBatch> { + protected static class SpeciesAbleBatchCategoryPredicate implements Predicate<SpeciesAbleBatch> { private final Integer id; private final Integer qualitativeValue; - public SpeciesBatchCategoryPredicate(Integer id, Integer qualitativeValue) { + public SpeciesAbleBatchCategoryPredicate(Integer id, Integer qualitativeValue) { this.id = id; this.qualitativeValue = qualitativeValue; } @Override - public boolean apply(SpeciesBatch input) { + public boolean apply(SpeciesAbleBatch input) { return id.equals(input.getSampleCategoryId()) && input.getSampleCategoryValue() instanceof CaracteristicQualitativeValue && qualitativeValue.equals(((CaracteristicQualitativeValue) input.getSampleCategoryValue()).getIdAsInt()); } } - protected static class BenthosBatchCategoryPredicate implements Predicate<BenthosBatch> { - - private final Integer id; - - private final Integer qualitativeValue; - - public BenthosBatchCategoryPredicate(Integer id, Integer qualitativeValue) { - this.id = id; - this.qualitativeValue = qualitativeValue; - } - - @Override - public boolean apply(BenthosBatch input) { - return id.equals(input.getSampleCategoryId()) && - input.getSampleCategoryValue() instanceof CaracteristicQualitativeValue && - qualitativeValue.equals(((CaracteristicQualitativeValue) input.getSampleCategoryValue()).getIdAsInt()); - } - } - public static <K, V> void fillEntries(Map<K, V> map, Collection<K> keys, Function<K, V> function) { 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -832,16 +832,11 @@ } @Override - public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { - return driver.isVracSpeciesBatch(speciesBatch); + public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { + return driver.isVracBatch(speciesBatch); } @Override - public boolean isVracBenthosBatch(BenthosBatch benthosBatch) { - return driver.isVracBenthosBatch(benthosBatch); - } - - @Override public boolean isTemporary(TuttiReferentialEntity entity) { return driver.isTemporary(entity); } 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ExportCatchesReportService.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -28,6 +28,7 @@ import com.google.common.collect.Maps; import fr.ifremer.tutti.TuttiBusinessException; import fr.ifremer.tutti.TuttiTechnicalException; +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; @@ -184,10 +185,10 @@ // create operation data model Map<String, Object> op = createOperation(fishingOperation); - Float totalWeight = catchBatch.getCatchTotalWeight(); - if (totalWeight == null) { - totalWeight = catchBatch.getCatchTotalComputedWeight(); - } + float totalWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getCatchTotalWeight(), + catchBatch.getCatchTotalComputedWeight()); + op.put("totalWeight", totalWeight); op.put("totalSortedWeight", catchBatch.getSpeciesTotalSampleSortedComputedWeight() + catchBatch.getBenthosTotalSampleSortedComputedWeight()); @@ -196,52 +197,77 @@ // Species - Map<Species, Map<String, Object>> catches = Maps.newHashMap(); - Float ratio = (totalWeight - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); + Map<Species, SpeciesBatchEntry> catches = Maps.newHashMap(); - Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); + float globalRatio = (totalWeight - catchBatch.getCatchTotalUnsortedComputedWeight()) / catchBatch.getCatchTotalSortedComputedWeight(); + + float speciesTotalSortedWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getSpeciesTotalSortedWeight(), + catchBatch.getSpeciesTotalSortedComputedWeight()); + + // ratio total species weight / total sorted sampled species weight + float speciesRatio = globalRatio * speciesTotalSortedWeight; + if (catchBatch.getSpeciesTotalSampleSortedComputedWeight() > 0) { + speciesRatio /= catchBatch.getSpeciesTotalSampleSortedComputedWeight(); } - // ratio total species weight / total sorted sampled species weight - Float speciesRatio = speciesTotalSortedWeight / catchBatch.getSpeciesTotalSampleSortedComputedWeight(); // create catches rows if (rootSpeciesBatch != null) { + List<SpeciesBatch> speciesBatches = rootSpeciesBatch.getChildren(); for (SpeciesBatch batch : speciesBatches) { - createSpeciesCatch(batch, catches, speciesRatio * ratio, totalWeight); + + createSpeciesCatch(batch, catches, speciesRatio); } } - List<Map<String, Object>> catchList = Lists.newArrayList(catches.values()); + List<SpeciesBatchEntry> catchList = Lists.newArrayList(catches.values()); + // Benthos - Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); + float benthosTotalSortedWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getBenthosTotalSortedWeight(), + catchBatch.getBenthosTotalSortedComputedWeight()); + + // ratio total benthos weight / total sorted sampled benthos weight + float benthosRatio = globalRatio * benthosTotalSortedWeight; + if (catchBatch.getBenthosTotalSampleSortedComputedWeight() > 0) { + benthosRatio /= catchBatch.getBenthosTotalSampleSortedComputedWeight(); } - // 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); + SpeciesBatchEntry benthosCatch = + createBenthosCatch(rootBenthosBatch, benthosRatio); catchList.add(benthosCatch); } } // Inert and living not itemized - Map<String, Object> inertLivingNotItemizedCatch = createInertAndLivingNotItemizedCatch(catchBatch, - ratio * speciesRatio, - ratio * benthosRatio, - totalWeight); - if ((Float) inertLivingNotItemizedCatch.get("sortedWeight") > 0f) { + SpeciesBatchEntry inertLivingNotItemizedCatch = + createInertAndLivingNotItemizedCatch(catchBatch, + speciesRatio, + benthosRatio); + if (inertLivingNotItemizedCatch.getSortedWeight() > 0f) { catchList.add(inertLivingNotItemizedCatch); } + if (log.isDebugEnabled()) { + + // recompute total for check + float computedTotalWeight = 0f; + float computedPercentage = 0f; + for (SpeciesBatchEntry entry : catchList) { + entry.computePercentage(totalWeight); + computedTotalWeight += entry.getTotalWeight(); + computedPercentage += entry.getPercentage(); + } + log.debug("TotalWeight: " + totalWeight); + log.debug("ComputedTotalWeight: " + computedTotalWeight); + log.debug("ComputedPercentage: " + computedPercentage); + } op.put("catches", catchList); operations.add(op); } @@ -290,128 +316,178 @@ } protected void createSpeciesCatch(SpeciesBatch batch, - Map<Species, Map<String, Object>> catches, - float ratio, - float totalWeight) { + Map<Species, SpeciesBatchEntry> catches, + float ratio) { Species species = batch.getSpecies(); - Float existingSortedWeight; - Float existingTotalWeight; - Map<String, Object> ktch = catches.get(species); + SpeciesBatchEntry ktch = catches.get(species); if (ktch == null) { - ktch = Maps.newHashMap(); - ktch.put("code", species.getRefTaxCode()); - ktch.put("scientificName", species.getName()); + Species speciesWithVerncularCode = + persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - Species speciesWithVerncularCode = persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - ktch.put("commonName", speciesWithVerncularCode.getVernacularCode()); + ktch = new SpeciesBatchEntry( + species.getRefTaxCode(), + species.getName(), + speciesWithVerncularCode.getVernacularCode() + ); + catches.put(species, ktch); + } - existingSortedWeight = 0f; - existingTotalWeight = 0f; + float sortedWeight = TuttiEntities.getValueOrComputedValue( + batch.getSampleCategoryWeight(), + batch.getSampleCategoryComputedWeight()); - } else { - existingSortedWeight = (Float) ktch.get("sortedWeight"); - existingTotalWeight = (Float) ktch.get("totalWeight"); - } + ktch.addSortedWeight(sortedWeight); - Float weight = batch.getSampleCategoryWeight(); - if (weight == null) { - weight = batch.getSampleCategoryComputedWeight(); + float speciesTotalWeight = sortedWeight; + if (persistenceService.isVracBatch(batch)) { + speciesTotalWeight *= ratio; } - ktch.put("sortedWeight", weight + existingSortedWeight); - - if (persistenceService.isVracSpeciesBatch(batch)) { - weight *= ratio; - } - weight += existingTotalWeight; - - ktch.put("totalWeight", weight); - ktch.put("percentage", 100 * weight / totalWeight); - catches.put(species, ktch); + ktch.addTotalWeight(speciesTotalWeight); } - protected Map<String, Object> createBenthosCatch(BatchContainer<BenthosBatch> rootBenthosBatch, - float ratio, - float totalWeight) { - Map<String, Object> ktch = Maps.newHashMap(); - ktch.put("code", _("tutti.service.operations.exportCatchesReport.specialRows.benthos.code")); - ktch.put("scientificName", ""); - ktch.put("commonName", _("tutti.service.operations.exportCatchesReport.specialRows.benthos.name")); + protected SpeciesBatchEntry createBenthosCatch(BatchContainer<BenthosBatch> rootBenthosBatch, + float ratio) { + SpeciesBatchEntry ktch = new SpeciesBatchEntry( + _("tutti.service.operations.exportCatchesReport.specialRows.benthos.code"), + "", + _("tutti.service.operations.exportCatchesReport.specialRows.benthos.name") + ); - Float sortedWeight = 0f; - Float benthosTotalWeight = 0f; + float sortedWeight = 0f; + float benthosTotalWeight = 0f; List<BenthosBatch> benthosBatches = rootBenthosBatch.getChildren(); for (BenthosBatch batch : benthosBatches) { - Float batchWeight = batch.getSampleCategoryWeight(); - if (batchWeight == null) { - batchWeight = batch.getSampleCategoryComputedWeight(); - } + float batchWeight = TuttiEntities.getValueOrComputedValue( + batch.getSampleCategoryWeight(), + batch.getSampleCategoryComputedWeight()); sortedWeight += batchWeight; - if (persistenceService.isVracBenthosBatch(batch)) { + if (persistenceService.isVracBatch(batch)) { batchWeight *= ratio; } benthosTotalWeight += batchWeight; } - ktch.put("sortedWeight", sortedWeight); - ktch.put("totalWeight", benthosTotalWeight); - ktch.put("percentage", 100 * benthosTotalWeight / totalWeight); + ktch.addSortedWeight(sortedWeight); + ktch.addTotalWeight(benthosTotalWeight); return ktch; } - protected Map<String, Object> createInertAndLivingNotItemizedCatch(CatchBatch catchBatch, - float speciesRatio, - float benthosRatio, - float totalWeight) { - Map<String, Object> inertLivingNotItemizedCatch = Maps.newHashMap(); - inertLivingNotItemizedCatch.put("code", _("tutti.service.operations.exportCatchesReport.specialRows.inertAndLivinngNotItemized.code")); - inertLivingNotItemizedCatch.put("scientificName", ""); - inertLivingNotItemizedCatch.put("commonName", _("tutti.service.operations.exportCatchesReport.specialRows.inertAndLivinngNotItemized.name")); + protected SpeciesBatchEntry createInertAndLivingNotItemizedCatch(CatchBatch catchBatch, + float speciesRatio, + float benthosRatio) { + SpeciesBatchEntry ktch = new SpeciesBatchEntry( + _("tutti.service.operations.exportCatchesReport.specialRows.inertAndLivinngNotItemized.code"), + "", + _("tutti.service.operations.exportCatchesReport.specialRows.inertAndLivinngNotItemized.name")); - Float inertLivingNotItemizedSortedWeight = 0f; - Float inertLivingNotItemizedTotalWeight = 0f; + float sortedWeight = 0f; + float totalWeight = 0f; - Float speciesInterWeight = catchBatch.getSpeciesTotalInertWeight(); - if (speciesInterWeight == null) { - speciesInterWeight = catchBatch.getSpeciesTotalInertComputedWeight(); - } + Float speciesInterWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getSpeciesTotalInertWeight(), + catchBatch.getSpeciesTotalInertComputedWeight()); + if (speciesInterWeight != null) { - inertLivingNotItemizedSortedWeight += speciesInterWeight; - inertLivingNotItemizedTotalWeight += speciesInterWeight * speciesRatio; + sortedWeight += speciesInterWeight; + totalWeight += speciesInterWeight * speciesRatio; } - Float speciesLivingNotItemizedWeigth = catchBatch.getSpeciesTotalLivingNotItemizedWeight(); - if (speciesLivingNotItemizedWeigth == null) { - speciesLivingNotItemizedWeigth = catchBatch.getSpeciesTotalLivingNotItemizedComputedWeight(); - } + Float speciesLivingNotItemizedWeigth = TuttiEntities.getValueOrComputedValue( + catchBatch.getSpeciesTotalLivingNotItemizedWeight(), + catchBatch.getSpeciesTotalLivingNotItemizedComputedWeight()); + if (speciesLivingNotItemizedWeigth != null) { - inertLivingNotItemizedSortedWeight += speciesLivingNotItemizedWeigth; - inertLivingNotItemizedTotalWeight += speciesLivingNotItemizedWeigth * speciesRatio; + sortedWeight += speciesLivingNotItemizedWeigth; + totalWeight += speciesLivingNotItemizedWeigth * speciesRatio; } - Float benthosInterWeight = catchBatch.getBenthosTotalInertWeight(); - if (benthosInterWeight == null) { - benthosInterWeight = catchBatch.getBenthosTotalInertComputedWeight(); - } + Float benthosInterWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getBenthosTotalInertWeight(), + catchBatch.getBenthosTotalInertComputedWeight()); + if (benthosInterWeight != null) { - inertLivingNotItemizedSortedWeight += benthosInterWeight; - inertLivingNotItemizedTotalWeight += benthosInterWeight * benthosRatio; + sortedWeight += benthosInterWeight; + totalWeight += benthosInterWeight * benthosRatio; } - Float benthosLivingNotItemizedWeight = catchBatch.getBenthosTotalLivingNotItemizedWeight(); - if (benthosLivingNotItemizedWeight == null) { - benthosLivingNotItemizedWeight = catchBatch.getBenthosTotalLivingNotItemizedComputedWeight(); - } + Float benthosLivingNotItemizedWeight = TuttiEntities.getValueOrComputedValue( + catchBatch.getBenthosTotalLivingNotItemizedWeight(), + catchBatch.getBenthosTotalLivingNotItemizedComputedWeight()); + if (benthosLivingNotItemizedWeight != null) { - inertLivingNotItemizedSortedWeight += benthosLivingNotItemizedWeight; - inertLivingNotItemizedTotalWeight += benthosLivingNotItemizedWeight * benthosRatio; + sortedWeight += benthosLivingNotItemizedWeight; + totalWeight += benthosLivingNotItemizedWeight * benthosRatio; } - inertLivingNotItemizedCatch.put("sortedWeight", inertLivingNotItemizedSortedWeight); - inertLivingNotItemizedCatch.put("totalWeight", inertLivingNotItemizedTotalWeight); - inertLivingNotItemizedCatch.put("percentage", 100 * inertLivingNotItemizedTotalWeight / totalWeight); + ktch.addSortedWeight(sortedWeight); + ktch.addTotalWeight(totalWeight); - return inertLivingNotItemizedCatch; + return ktch; } + + /** + * To store a species or batch entry within his speices informations, + * his sorted weight, total weight and percentage amoong the total catch + * weight. + * + * @since 2.10 + */ + public static class SpeciesBatchEntry { + + protected final String code; + + protected final String scientificName; + + protected final String commonName; + + float sortedWeight; + + float totalWeight; + + float percentage; + + SpeciesBatchEntry(String code, String scientificName, String commonName) { + this.code = code; + this.scientificName = scientificName; + this.commonName = commonName; + } + + public void addSortedWeight(float weight) { + sortedWeight += weight; + } + + public void addTotalWeight(float weight) { + totalWeight += weight; + } + + public void computePercentage(float totalWeight) { + this.percentage = 100 * this.totalWeight / totalWeight; + } + + public String getCode() { + return code; + } + + public String getScientificName() { + return scientificName; + } + + public String getCommonName() { + return commonName; + } + + public float getSortedWeight() { + return sortedWeight; + } + + public float getTotalWeight() { + return totalWeight; + } + + public float getPercentage() { + return percentage; + } + } } 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -186,7 +186,7 @@ break; } - if (persistenceService.isVracSpeciesBatch(row)) { + if (persistenceService.isVracBatch(row)) { speciesTotalComputedSortedWeight += weight; } else { speciesTotalComputedUnsortedWeight += weight; @@ -243,7 +243,7 @@ break; } - if (persistenceService.isVracBenthosBatch(row)) { + if (persistenceService.isVracBatch(row)) { benthosTotalComputedSortedWeight += weight; } else { benthosTotalComputedUnsortedWeight += weight; Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java 2013-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/CatchExportModel.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -114,7 +114,7 @@ row.setSpecies(speciesBatch.getSpecies()); row.setBatchWeightUnit(batchWeightUnit); - if (persistenceService.isVracSpeciesBatch(speciesBatch)) { + if (persistenceService.isVracBatch(speciesBatch)) { // compute species total weight in catch @@ -142,7 +142,7 @@ row.setSpecies(benthosBatch.getSpecies()); row.setBatchWeightUnit(batchWeightUnit); - if (persistenceService.isVracBenthosBatch(benthosBatch)) { + if (persistenceService.isVracBatch(benthosBatch)) { // compute species total weight in catch Added: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/ExportCatchesReportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/ExportCatchesReportServiceTest.java (rev 0) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/ExportCatchesReportServiceTest.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -0,0 +1,70 @@ +package fr.ifremer.tutti.service.catches; + +import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.io.File; +import java.util.Locale; + +/** + * Created on 11/19/13. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.10 + */ +public class ExportCatchesReportServiceTest { + + @ClassRule + public static final ServiceDbResource dbResource = + ServiceDbResource.readDb("dbMedits"); + + public static final String PROGRAM_ID = "CAM-MEDITS"; + + public static final String CRUISE_ID = "100001"; + + public static final String OPERATION_1_ID = "100106"; + + protected ExportCatchesReportService exportService; + + protected PersistenceService persistenceService; + + protected File dataDirectory; + + @Before + public void setUp() throws Exception { + + dataDirectory = dbResource.getServiceConfig().getDataDirectory(); + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + persistenceService = serviceContext.getService(PersistenceService.class); + + serviceContext.getDataContext().open(serviceContext.getConfig(), persistenceService); + exportService = serviceContext.getService(ExportCatchesReportService.class); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void generateFishingOperationPDFFile() throws Exception { + + File exportFile = new File(dataDirectory, "exportOperation.pdf"); + + Assert.assertFalse(exportFile.exists()); + + exportService.generateFishingOperationPDFFile(exportFile, + OPERATION_1_ID, + Locale.FRENCH); + + Assert.assertTrue(exportFile.exists()); + } +} Property changes on: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/ExportCatchesReportServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/tutti-service/src/test/resources/tutti-test-read-dbMedits.properties (from rev 1361, trunk/tutti-service/src/test/resources/tutti-test-read-dbCGFS.properties) =================================================================== --- trunk/tutti-service/src/test/resources/tutti-test-read-dbMedits.properties (rev 0) +++ trunk/tutti-service/src/test/resources/tutti-test-read-dbMedits.properties 2013-11-20 13:56:44 UTC (rev 1366) @@ -0,0 +1,25 @@ +### +# #%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% +### +tutti.persistence.db.directory=src/test/dbMedits +tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/dbMedits/allegro \ No newline at end of file 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-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeBatchWeightsAction.java 2013-11-20 13:56:44 UTC (rev 1366) @@ -273,7 +273,7 @@ List<SpeciesBatch> children = computedSpeciesBatches.getChildren(); for (SpeciesBatch batch : children) { SpeciesBatchRowModel row = getUI().getSpeciesTabContent().getHandler().loadBatch(batch, null, rows); - if (persistenceService.isVracSpeciesBatch(row)) { + if (persistenceService.isVracBatch(row)) { SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); Float weight = TuttiEntities.getValueOrComputedValue( sampleCategory.getCategoryWeight(), @@ -296,7 +296,7 @@ for (BenthosBatch batch : children) { BenthosBatchRowModel row = getUI().getBenthosTabContent().getHandler().loadBatch(batch, null, rows); - if (persistenceService.isVracBenthosBatch(row)) { + if (persistenceService.isVracBatch(row)) { SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); Float weight = TuttiEntities.getValueOrComputedValue( sampleCategory.getCategoryWeight(), Modified: trunk/tutti-ui-swing/src/main/profiling/META-INF/aop.xml =================================================================== --- trunk/tutti-ui-swing/src/main/profiling/META-INF/aop.xml 2013-11-20 08:11:09 UTC (rev 1365) +++ trunk/tutti-ui-swing/src/main/profiling/META-INF/aop.xml 2013-11-20 13:56:44 UTC (rev 1366) @@ -33,9 +33,9 @@ expression=" execution(* fr.ifremer.tutti..*(..)) ||execution(* fr.ifremer.adagio.core..*(..)) - ||execution(* org.springframework..*(..)) - ||execution(* org.hibernate..*(..)) "/> </concrete-aspect> </aspects> + <!--||execution(* org.springframework..*(..))--> + <!--||execution(* org.hibernate..*(..))--> </aspectj> \ No newline at end of file