Author: kmorin Date: 2013-03-12 19:25:31 +0100 (Tue, 12 Mar 2013) New Revision: 596 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/596 Log: fixes #2128 [especes] ?\195?\169l?\195?\169vation de spoids impossible alors que tout semble ok Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 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-03-12 18:24:26 UTC (rev 595) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-03-12 18:25:31 UTC (rev 596) @@ -46,8 +46,6 @@ */ public class ComputeWeightsAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { - protected String errorMessage; - public ComputeWeightsAction(EditCatchesUIHandler handler) { super(handler, false); } @@ -63,50 +61,44 @@ computeSpeciesBatches(); - if (errorMessage == null) { - Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = model.getSpeciesTotalSortedComputedWeight(); - } - Float speciesTotalUnsortedWeight = model.getSpeciesTotalUnsortedComputedWeight(); + Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); + if (speciesTotalSortedWeight == null) { + speciesTotalSortedWeight = model.getSpeciesTotalSortedComputedWeight(); + } + Float speciesTotalUnsortedWeight = model.getSpeciesTotalUnsortedComputedWeight(); - model.setCatchTotalSortedComputedWeight(speciesTotalSortedWeight); - model.setCatchTotalUnsortedComputedWeight(speciesTotalUnsortedWeight); + model.setCatchTotalSortedComputedWeight(speciesTotalSortedWeight); + model.setCatchTotalUnsortedComputedWeight(speciesTotalUnsortedWeight); - Float totalWeight = model.getCatchTotalWeight(); - Float rejectedWeight = model.getCatchTotalRejectedWeight(); + Float totalWeight = model.getCatchTotalWeight(); + Float rejectedWeight = model.getCatchTotalRejectedWeight(); - if (rejectedWeight == null && totalWeight != null) { - if (!totalWeight.equals(speciesTotalUnsortedWeight - + speciesTotalSortedWeight)) { - errorMessage = _("tutti.action.computeWeights.error.incoherentTotal"); + if (rejectedWeight == null && totalWeight != null) { + if (!totalWeight.equals(speciesTotalUnsortedWeight + + speciesTotalSortedWeight)) { + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentTotal")); - } else { + } else { - model.setCatchTotalRejectedComputedWeight(totalWeight - - speciesTotalUnsortedWeight - - speciesTotalSortedWeight); - } + model.setCatchTotalRejectedComputedWeight(totalWeight + - speciesTotalUnsortedWeight + - speciesTotalSortedWeight); + } - } else if (totalWeight == null) { - if (rejectedWeight == null) { - rejectedWeight = 0f; - model.setCatchTotalRejectedComputedWeight(0f); - } - model.setCatchTotalComputedWeight(speciesTotalUnsortedWeight - + speciesTotalSortedWeight - + rejectedWeight); - - } else if (rejectedWeight != null - && !totalWeight.equals(speciesTotalUnsortedWeight - + speciesTotalSortedWeight - + rejectedWeight)) { - errorMessage = _("tutti.action.computeWeights.error.incoherentTotal"); + } else if (totalWeight == null) { + if (rejectedWeight == null) { + rejectedWeight = 0f; + model.setCatchTotalRejectedComputedWeight(0f); } - } + model.setCatchTotalComputedWeight(speciesTotalUnsortedWeight + + speciesTotalSortedWeight + + rejectedWeight); - if (errorMessage != null) { - throw new TuttiBusinessException(errorMessage); + } else if (rejectedWeight != null + && !totalWeight.equals(speciesTotalUnsortedWeight + + speciesTotalSortedWeight + + rejectedWeight)) { + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentTotal")); } } @@ -131,9 +123,8 @@ if (row.isBatchRoot()) { Float weight = computeSpeciesBatch(row); if (weight == null) { - errorMessage = _("tutti.action.computeWeights.error.noWeight"); AbstractSelectTableAction.doSelectCell(speciesUI.getTable(), i, 1); - break; + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.noWeight")); } if (persistenceService.isSortedQualitativeValue(row.getSortedUnsortedCategory().getCategoryValue())) { totalSortedWeight += weight; @@ -143,56 +134,54 @@ } } - if (errorMessage == null) { - Number inertWeight = model.getSpeciesTotalInertWeight(); - if (inertWeight != null) { - totalSortedWeight += inertWeight.floatValue(); - } else { - model.setSpeciesTotalInertComputedWeight(0f); - } + Number inertWeight = model.getSpeciesTotalInertWeight(); + if (inertWeight != null) { + totalSortedWeight += inertWeight.floatValue(); + } else { + model.setSpeciesTotalInertComputedWeight(0f); + } - Number livingNotItemizedWeight = model.getSpeciesTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - totalSortedWeight += livingNotItemizedWeight.floatValue(); - } else { - model.setSpeciesTotalLivingNotItemizedComputedWeight(0f); - } + Number livingNotItemizedWeight = model.getSpeciesTotalLivingNotItemizedWeight(); + if (livingNotItemizedWeight != null) { + totalSortedWeight += livingNotItemizedWeight.floatValue(); + } else { + model.setSpeciesTotalLivingNotItemizedComputedWeight(0f); + } - model.setSpeciesTotalSampleSortedComputedWeight(totalSortedWeight); + model.setSpeciesTotalSampleSortedComputedWeight(totalSortedWeight); - Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); - Float rate = getConfig().getDifferenceRateBetweenSortedAndTotalWeights(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = totalSortedWeight; - model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); + Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); + Float rate = getConfig().getDifferenceRateBetweenSortedAndTotalWeights(); + if (speciesTotalSortedWeight == null) { + speciesTotalSortedWeight = totalSortedWeight; + model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); - } else if (speciesTotalSortedWeight < totalSortedWeight) { - errorMessage = _("tutti.action.computeWeights.error.incoherentSpeciesTotalSorted"); + } else if (speciesTotalSortedWeight < totalSortedWeight) { + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentSpeciesTotalSorted")); - } else if (speciesTotalSortedWeight < (1 + rate / 100) * totalSortedWeight) { - // Si le "Poids total VRAC" est saisi est que sa valeur - // est supérieure de moins de x% (x en configuration) - // du "Poids total Vrac trié", demander confirmation que - // le "Poids total VRAC" est bien une valeur observée - // sinon la remplacer par le "Poids total Vrac trié" - int answer = JOptionPane.showConfirmDialog(getContext().getActionUI(), - _("tutti.action.computeWeights.replaceTotalSortedWeight.message", rate), - _("tutti.action.computeWeights.replaceTotalSortedWeight.title"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); + } else if (speciesTotalSortedWeight < (1 + rate / 100) * totalSortedWeight) { + // Si le "Poids total VRAC" est saisi est que sa valeur + // est supérieure de moins de x% (x en configuration) + // du "Poids total Vrac trié", demander confirmation que + // le "Poids total VRAC" est bien une valeur observée + // sinon la remplacer par le "Poids total Vrac trié" + int answer = JOptionPane.showConfirmDialog(getContext().getActionUI(), + _("tutti.action.computeWeights.replaceTotalSortedWeight.message", rate), + _("tutti.action.computeWeights.replaceTotalSortedWeight.title"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); - if (answer == JOptionPane.NO_OPTION) { - model.setSpeciesTotalSortedWeight(null); - speciesTotalSortedWeight = totalSortedWeight; - model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); - } + if (answer == JOptionPane.NO_OPTION) { + model.setSpeciesTotalSortedWeight(null); + speciesTotalSortedWeight = totalSortedWeight; + model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); } + } - model.setSpeciesTotalUnsortedComputedWeight(totalUnsortedWeight); + model.setSpeciesTotalUnsortedComputedWeight(totalUnsortedWeight); - Float totalWeight = totalUnsortedWeight + speciesTotalSortedWeight; - model.setSpeciesTotalComputedWeight(totalWeight); - } + Float totalWeight = totalUnsortedWeight + speciesTotalSortedWeight; + model.setSpeciesTotalComputedWeight(totalWeight); speciesUI.getTable().repaint(); } @@ -226,7 +215,7 @@ } } else if (categoryWeight < sum) { - errorMessage = _("tutti.action.computeWeights.error.incoherentParentCategoryWeight"); + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentParentCategoryWeight")); } else { boolean subSample = categoryWeight > sum; @@ -261,7 +250,7 @@ } if (categoryWeight == null && rowWeight != null) { - errorMessage = _("tutti.action.computeWeights.error.incoherentRowWeightCategory"); + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentRowWeightCategory")); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -275,13 +264,13 @@ // if the weight of the frequencies is different from the category // weight, then set the weight of the sample if (frequencyWeight > categoryWeight) { - errorMessage = _("tutti.action.computeWeights.error.incoherentCategoryWeight"); + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentCategoryWeight")); } else if (rowWeight == null) { row.setComputedWeight(frequencyWeight); } else if (!rowWeight.equals(frequencyWeight)) { - errorMessage = _("tutti.action.computeWeights.error.incoherentRowWeightFrequency"); + throw new TuttiBusinessException(_("tutti.action.computeWeights.error.incoherentRowWeightFrequency")); } result = categoryWeight; @@ -297,14 +286,4 @@ return result; } -// @Override -// protected void releaseAction() { -// if (errorMessage != null) { -// error = new Exception(errorMessage); -// } else { -// super.releaseAction(); -// } -// errorMessage = null; -// } - }