r1363 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities tutti-service/src/main/java/fr/ifremer/tutti/service/catches
Author: tchemit Date: 2013-11-19 14:16:50 +0100 (Tue, 19 Nov 2013) New Revision: 1363 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1363 Log: fixes #3804: [CAPTURE] mauvais affichage des // Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java 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-19 07:51:45 UTC (rev 1362) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-11-19 13:16:50 UTC (rev 1363) @@ -46,6 +46,8 @@ import org.hibernate.cfg.Environment; import java.io.File; +import java.math.BigDecimal; +import java.math.MathContext; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; @@ -97,6 +99,8 @@ } }; + private static final MathContext MATH_CONTEXT_4_DIGIT = new MathContext(4); + /** Logger. */ private static final Log log = LogFactory.getLog(TuttiEntities.class); @@ -113,8 +117,8 @@ public static <B extends TuttiEntity> List<Integer> toIntegerIds(Collection<B> list) { List<Integer> result = list == null ? - Collections.<Integer>emptyList() : - Lists.transform(Lists.newArrayList(list), GET_ID_AS_INT); + Collections.<Integer>emptyList() : + Lists.transform(Lists.newArrayList(list), GET_ID_AS_INT); return result; } @@ -333,6 +337,19 @@ } } + /** + * Round the given value to max 4 digits. + * + * @param value the float to round. + * @return the rounded value + * @since 2.10 + */ + public static float roundKiloGram(float value) { + BigDecimal sumB = new BigDecimal(value); + float result = sumB.abs(MATH_CONTEXT_4_DIGIT).floatValue(); + return result; + } + protected static class IdPredicate<B extends TuttiEntity> implements Predicate<B> { private final String id; 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-19 07:51:45 UTC (rev 1362) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java 2013-11-19 13:16:50 UTC (rev 1363) @@ -213,18 +213,21 @@ Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); if (speciesTotalSortedWeight == null) { speciesTotalSortedWeight = speciesTotalComputedSortedWeight; - catchBatch.setSpeciesTotalSortedComputedWeight(speciesTotalSortedWeight); + catchBatch.setSpeciesTotalSortedComputedWeight( + TuttiEntities.roundKiloGram(speciesTotalSortedWeight)); } else if (speciesTotalSortedWeight < speciesTotalComputedSortedWeight) { throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); } - catchBatch.setSpeciesTotalUnsortedComputedWeight(speciesTotalComputedUnsortedWeight); + catchBatch.setSpeciesTotalUnsortedComputedWeight( + TuttiEntities.roundKiloGram(speciesTotalComputedUnsortedWeight)); if (speciesTotalSortedWeight == null) { speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); } Float speciesTotalWeight = speciesTotalComputedUnsortedWeight + speciesTotalSortedWeight; - catchBatch.setSpeciesTotalComputedWeight(speciesTotalWeight); + catchBatch.setSpeciesTotalComputedWeight( + TuttiEntities.roundKiloGram(speciesTotalWeight)); // Benthos Float benthosTotalComputedSortedWeight = 0f; @@ -262,23 +265,27 @@ catchBatch.setBenthosTotalLivingNotItemizedComputedWeight(0f); } - catchBatch.setBenthosTotalSampleSortedComputedWeight(benthosTotalComputedSortedWeight); + catchBatch.setBenthosTotalSampleSortedComputedWeight( + TuttiEntities.roundKiloGram(benthosTotalComputedSortedWeight)); Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); if (benthosTotalSortedWeight == null) { benthosTotalSortedWeight = benthosTotalComputedSortedWeight; - catchBatch.setBenthosTotalSortedComputedWeight(benthosTotalSortedWeight); + catchBatch.setBenthosTotalSortedComputedWeight( + TuttiEntities.roundKiloGram(benthosTotalSortedWeight)); } else if (benthosTotalSortedWeight < benthosTotalComputedSortedWeight) { throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); } - catchBatch.setBenthosTotalUnsortedComputedWeight(benthosTotalComputedUnsortedWeight); + catchBatch.setBenthosTotalUnsortedComputedWeight( + TuttiEntities.roundKiloGram(benthosTotalComputedUnsortedWeight)); if (benthosTotalSortedWeight == null) { benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); } Float benthosTotalWeight = benthosTotalComputedUnsortedWeight + benthosTotalSortedWeight; - catchBatch.setBenthosTotalComputedWeight(benthosTotalWeight); + catchBatch.setBenthosTotalComputedWeight( + TuttiEntities.roundKiloGram(benthosTotalWeight)); // Marine litter Float marineLitterTotalComputedWeight = 0f; @@ -294,7 +301,8 @@ marineLitterTotalComputedWeight += rowWeight; } } - catchBatch.setMarineLitterTotalComputedWeight(marineLitterTotalComputedWeight); + catchBatch.setMarineLitterTotalComputedWeight( + TuttiEntities.roundKiloGram(marineLitterTotalComputedWeight)); Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); if (marineLitterTotalWeight == null) { @@ -311,8 +319,8 @@ Float totalSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; - catchBatch.setCatchTotalSortedComputedWeight(totalSortedWeight); - catchBatch.setCatchTotalUnsortedComputedWeight(totalUnsortedWeight); + catchBatch.setCatchTotalSortedComputedWeight(TuttiEntities.roundKiloGram(totalSortedWeight)); + catchBatch.setCatchTotalUnsortedComputedWeight(TuttiEntities.roundKiloGram(totalUnsortedWeight)); Float totalWeight = catchBatch.getCatchTotalWeight(); Float rejectedWeight = catchBatch.getCatchTotalRejectedWeight(); @@ -323,9 +331,10 @@ throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.error.incoherentTotal")); } else { - catchBatch.setCatchTotalRejectedComputedWeight(totalWeight - - totalUnsortedWeight - - totalSortedWeight); + catchBatch.setCatchTotalRejectedComputedWeight( + TuttiEntities.roundKiloGram(totalWeight + - totalUnsortedWeight + - totalSortedWeight)); } } else if (totalWeight == null) { @@ -333,9 +342,10 @@ rejectedWeight = 0f; catchBatch.setCatchTotalRejectedComputedWeight(0f); } - catchBatch.setCatchTotalComputedWeight(totalUnsortedWeight - + totalSortedWeight - + rejectedWeight); + catchBatch.setCatchTotalComputedWeight( + TuttiEntities.roundKiloGram(totalUnsortedWeight + + totalSortedWeight + + rejectedWeight)); } else if (!totalWeight.equals(totalUnsortedWeight + totalSortedWeight + rejectedWeight)) { throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.error.incoherentTotal")); @@ -410,7 +420,7 @@ if (sum != null) { if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(sum); + batch.setSampleCategoryComputedWeight(TuttiEntities.roundKiloGram(sum)); } else if (categoryWeight < sum) { String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); @@ -475,7 +485,7 @@ } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, // then this weight is the result - batch.setSampleCategoryComputedWeight(frequencyWeight); + batch.setSampleCategoryComputedWeight(TuttiEntities.roundKiloGram(frequencyWeight)); result = frequencyWeight; } else if (frequencyWeight != null @@ -498,7 +508,7 @@ thisIndex); } else if (rowWeight == null) { - batch.setComputedWeight(frequencyWeight); + batch.setComputedWeight(TuttiEntities.roundKiloGram(frequencyWeight)); } result = categoryWeight; @@ -532,7 +542,7 @@ thisIndex); } - return result; + return TuttiEntities.roundKiloGram(result); } private int currentBenthosRowIndex; @@ -597,7 +607,7 @@ if (sum != null) { if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(sum); + batch.setSampleCategoryComputedWeight(TuttiEntities.roundKiloGram(sum)); } else if (categoryWeight < sum) { String categoryLabel = @@ -666,7 +676,7 @@ } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, // then this weight is the result - batch.setSampleCategoryComputedWeight(frequencyWeight); + batch.setSampleCategoryComputedWeight(TuttiEntities.roundKiloGram(frequencyWeight)); result = frequencyWeight; } else if (frequencyWeight != null @@ -690,7 +700,7 @@ thisIndex); } else if (rowWeight == null) { - batch.setComputedWeight(frequencyWeight); + batch.setComputedWeight(TuttiEntities.roundKiloGram(frequencyWeight)); } result = categoryWeight; @@ -724,7 +734,7 @@ thisIndex); } - return result; + return TuttiEntities.roundKiloGram(result); } public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(String fishingOperationId,
participants (1)
-
tchemit@users.forge.codelutin.com