Author: kmorin Date: 2013-04-17 11:16:32 +0200 (Wed, 17 Apr 2013) New Revision: 811 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/811 Log: improve weight computing Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-04-16 19:06:17 UTC (rev 810) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-04-17 09:16:32 UTC (rev 811) @@ -373,11 +373,14 @@ } } + private int currentSpeciesRowIndex; + public BatchContainer<SpeciesBatch> getComputedSpeciesBatches(FishingOperation operation) { BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId()); + currentSpeciesRowIndex = 0; if (rootSpeciesBatch != null) { List<SpeciesBatch> roots = rootSpeciesBatch.getChildren(); @@ -389,33 +392,9 @@ return rootSpeciesBatch; } - public BatchContainer<BenthosBatch> getComputedBenthosBatches(FishingOperation operation) { - - BatchContainer<BenthosBatch> rootBenthosBatch = - persistenceService.getRootBenthosBatch(operation.getId()); - - currentBenthosRowIndex = 0; - if (rootBenthosBatch != null) { - List<BenthosBatch> roots = rootBenthosBatch.getChildren(); - - for (BenthosBatch batch : roots) { - computeBenthosBatch(batch); - } - } - - return rootBenthosBatch; - } - - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(FishingOperation operation) { - - BatchContainer<MarineLitterBatch> rootMarineLitterBatch = - persistenceService.getRootMarineLitterBatch(operation.getId()); - - return rootMarineLitterBatch; - } - protected Float computeSpeciesBatch(SpeciesBatch batch) { Float result = null; + int thisIndex = currentSpeciesRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); @@ -444,7 +423,10 @@ batch.setSampleCategoryComputedWeight(sum); } else if (categoryWeight < sum) { - throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.species.error.incoherentParentCategoryWeight")); + throw new TuttiWeightComputingException( + _("tutti.service.operations.computeWeights.species.error.incoherentParentCategoryWeight"), + TuttiWeightComputingException.CatchType.SPECIES, + thisIndex); } else { sum = categoryWeight; @@ -491,13 +473,19 @@ // if the weight of the frequencies is different from the category // weight, then set the weight of the sample if (frequencyWeight > categoryWeight) { - throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.species.error.incoherentCategoryWeight")); + throw new TuttiWeightComputingException(_ + ("tutti.service.operations.computeWeights.species.error.incoherentCategoryWeight"), + TuttiWeightComputingException.CatchType.SPECIES, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); } else if (!rowWeight.equals(frequencyWeight)) { - throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.species.error.incoherentRowWeightFrequency")); + throw new TuttiWeightComputingException( + _("tutti.service.operations.computeWeights.species.error.incoherentRowWeightFrequency"), + TuttiWeightComputingException.CatchType.SPECIES, + thisIndex); } result = categoryWeight; @@ -510,7 +498,10 @@ } } if (result == null && batch.getParentBatch() == null) { - throw new TuttiBusinessException(_("tutti.service.operations.computeWeights.species.error.noWeight")); + throw new TuttiWeightComputingException( + _("tutti.service.operations.computeWeights.species.error.noWeight"), + TuttiWeightComputingException.CatchType.SPECIES, + thisIndex); } return result; @@ -518,6 +509,23 @@ private int currentBenthosRowIndex; + public BatchContainer<BenthosBatch> getComputedBenthosBatches(FishingOperation operation) { + + BatchContainer<BenthosBatch> rootBenthosBatch = + persistenceService.getRootBenthosBatch(operation.getId()); + + currentBenthosRowIndex = 0; + if (rootBenthosBatch != null) { + List<BenthosBatch> roots = rootBenthosBatch.getChildren(); + + for (BenthosBatch batch : roots) { + computeBenthosBatch(batch); + } + } + + return rootBenthosBatch; + } + protected Float computeBenthosBatch(BenthosBatch batch) { Float result = null; int thisIndex = currentBenthosRowIndex++; @@ -634,4 +642,25 @@ return result; } + + public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(FishingOperation operation) { + + BatchContainer<MarineLitterBatch> rootMarineLitterBatch = + persistenceService.getRootMarineLitterBatch(operation.getId()); + + if (rootMarineLitterBatch != null) { + List<MarineLitterBatch> children = rootMarineLitterBatch.getChildren(); + for (int i = 0 ; i < children.size() ; i++) { + MarineLitterBatch batch = children.get(i); + if (batch.getWeight() == null) { + throw new TuttiWeightComputingException( + _("tutti.service.operations.computeWeights.marineLitter.error.noWeight"), + TuttiWeightComputingException.CatchType.MARINE_LITTER, + i); + } + } + } + + return rootMarineLitterBatch; + } } Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2013-04-16 19:06:17 UTC (rev 810) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2013-04-17 09:16:32 UTC (rev 811) @@ -75,6 +75,7 @@ tutti.service.operations.computeWeights.error.incoherentSpeciesTotalSorted= tutti.service.operations.computeWeights.error.incoherentTotal= tutti.service.operations.computeWeights.marineLitter.error.incoherentTotal= +tutti.service.operations.computeWeights.marineLitter.error.noWeight= tutti.service.operations.computeWeights.species.error.incoherentCategoryWeight= tutti.service.operations.computeWeights.species.error.incoherentParentCategoryWeight= tutti.service.operations.computeWeights.species.error.incoherentRowWeightFrequency= Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-04-16 19:06:17 UTC (rev 810) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-04-17 09:16:32 UTC (rev 811) @@ -58,6 +58,7 @@ tutti.service.operations.computeWeights.error.incoherentRowWeightCategory= tutti.service.operations.computeWeights.error.incoherentTotal=Le poids total de la capture ne correspond pas à la somme des poids totaux Vrac, Hors Vrac et non triés tutti.service.operations.computeWeights.marineLitter.error.incoherentTotal=Le poids total des macro-déchets est inférieur à la somme des poids des macro-déchets saisis +tutti.service.operations.computeWeights.marineLitter.error.noWeight= tutti.service.operations.computeWeights.species.error.incoherentCategoryWeight=Le poids total des mensurations d'un lot des espèces est supérieur au poids de la catégorie tutti.service.operations.computeWeights.species.error.incoherentParentCategoryWeight=Le poids de la catégorie d'un lot des espèces est différent de la somme des poids de ses sous-catégories tutti.service.operations.computeWeights.species.error.incoherentRowWeightFrequency=Le poids total des mensurations d'un lot des espèces est différent du poids du sous-échantillon Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-04-16 19:06:17 UTC (rev 810) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-04-17 09:16:32 UTC (rev 811) @@ -62,33 +62,43 @@ EditCatchesUIModel model = getModel(); - BatchContainer<SpeciesBatch> computedSpeciesBatches = - tuttiWeightComputingService.getComputedSpeciesBatches(model.getFishingOperation()); - Float totalSpeciesSortedWeight = computeSpeciesBatches(computedSpeciesBatches); + BatchContainer<SpeciesBatch> computedSpeciesBatches; + Float totalSpeciesSortedWeight; + try { + computedSpeciesBatches = + tuttiWeightComputingService.getComputedSpeciesBatches(model.getFishingOperation()); + totalSpeciesSortedWeight = computeSpeciesBatches(computedSpeciesBatches); + } catch (TuttiWeightComputingException e) { + getUI().getTabPane().setSelectedIndex(1); + AbstractSelectTableAction.doSelectCell(getUI().getSpeciesTabContent().getTable(), e.getIndex(), 1); + throw e; + } + BatchContainer<BenthosBatch> computedBenthosBatches; Float totalBenthosSortedWeight; - Integer rowIndex = null; try { computedBenthosBatches = tuttiWeightComputingService.getComputedBenthosBatches(model.getFishingOperation()); totalBenthosSortedWeight = computeBenthosBatches(computedBenthosBatches); } catch (TuttiWeightComputingException e) { - rowIndex = e.getIndex(); + getUI().getTabPane().setSelectedIndex(2); + AbstractSelectTableAction.doSelectCell(getUI().getBenthosTabContent().getTable(), e.getIndex(), 1); throw e; - - } finally { - if (rowIndex != null) { - getUI().getTabPane().setSelectedIndex(2); - AbstractSelectTableAction.doSelectCell(getUI().getBenthosTabContent().getTable(), rowIndex, 1); - } } - BatchContainer<MarineLitterBatch> computedMarineLitterBatches = + BatchContainer<MarineLitterBatch> computedMarineLitterBatches; + try { + computedMarineLitterBatches = tuttiWeightComputingService.getComputedMarineLitterBatches(model.getFishingOperation()); - Float totalMarineLitterWeight = computeMarineLitterBatches(computedMarineLitterBatches); + } catch (TuttiWeightComputingException e) { + getUI().getTabPane().setSelectedIndex(3); + AbstractSelectTableAction.doSelectCell(getUI().getMarineLitterTabContent().getTable(), e.getIndex(), 3); + throw e; + } + Float rate = getConfig().getDifferenceRateBetweenSortedAndTotalWeights(); if (model.getSpeciesTotalSortedWeight() != null && model.getSpeciesTotalSortedWeight() >= totalSpeciesSortedWeight @@ -175,12 +185,7 @@ if (weight == null) { weight = row.getSortedUnsortedCategoryComputedWeight(); } - if (weight == null) { - getUI().getTabPane().setSelectedIndex(1); - AbstractSelectTableAction.doSelectCell(getUI().getSpeciesTabContent().getTable(), rowIndex, 1); - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - - } else if (SortedUnsortedEnum.SORTED.matchValue( + if (SortedUnsortedEnum.SORTED.matchValue( row.getSortedUnsortedCategoryValue())) { totalSortedWeight += weight; } @@ -206,7 +211,8 @@ if (weight == null) { weight = row.getSortedUnsortedCategoryComputedWeight(); - } else if (SortedUnsortedEnum.SORTED.matchValue( + } + if (SortedUnsortedEnum.SORTED.matchValue( row.getSortedUnsortedCategoryValue())) { totalSortedWeight += weight; } @@ -219,27 +225,4 @@ return totalSortedWeight; } - - protected Float computeMarineLitterBatches(BatchContainer<MarineLitterBatch> computedMarineLitterBatches) { - Float totalWeight = 0f; - - List<MarineLitterBatch> children = computedMarineLitterBatches.getChildren(); - for (int i = 0; i < children.size(); i++) { - MarineLitterBatch batch = children.get(i); - Float weight = batch.getWeight(); - if (weight == null) { - if (getModel().getMarineLitterTotalWeight() != null) { - return null; - } - getUI().getTabPane().setSelectedIndex(3); - AbstractSelectTableAction.doSelectCell(getUI().getMarineLitterTabContent().getTable(), i, 1); - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - - } else { - totalWeight += weight; - } - } - - return totalWeight; - } }