branch develop updated (ac9c4fd -> 8aa7a78)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git from ac9c4fd Livrable #8237 Merge branch 'feature/8237' into develop new 1189c34 Utilisation de l'unité adaptée new 24cdd12 Nettoyage code new 6f4a2d9 Correction des unités lors de la sauvegarde d'un lot (code en double en fait avec deux fois une conversion d'unité) new 5f78949 Revue du service de validation en utilisant plusieurs exceptions typées new 76a3dcb Revue de l'action d'élévation des poids en utilisant les exceptions typées new d009b59 Revue des arrondis et amélioration des messages d'erreur lors de l'élvation des poids new eeda20b correction de la comparaison des unités (See #8151) new 052b8db Revue de l'API des WeightUnits pour ne plus utiliser Weights (trop d'incertitude sur l'unité utilisée) new 0652ce9 Nettoyage sur le service de nettoyage de poids + dernière revue des exceptions du service d'élévation new aabaad2 Utilisation nouvelle API des poids new 16c957f Correction des mauvaises unités utilisés dans les écran «espèces» new 1d8372e Meilleure utilisation des unités dans les interfaces graphiques et revue des ComputableDataEditor new 8aa7a78 Livrable #8151 Merge branch 'feature/8151' into develop The 13 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 8aa7a78472aaf629ebb5055e8b9627894226d5e8 Merge: ac9c4fd 1d8372e Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:47:23 2016 +0200 Livrable #8151 Merge branch 'feature/8151' into develop commit 1d8372e00613df5b64cc99f21c9c6eeb27d1a33a Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:47:17 2016 +0200 Meilleure utilisation des unités dans les interfaces graphiques et revue des ComputableDataEditor commit 16c957fa9ebb87c8cb12588d1a2dc947e53916b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:46:18 2016 +0200 Correction des mauvaises unités utilisés dans les écran «espèces» commit aabaad218482d762456aeb508ff60b3aeddc39ed Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:41:21 2016 +0200 Utilisation nouvelle API des poids commit 0652ce95303ad072ad0cc2d9516385587f313aae Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:40:58 2016 +0200 Nettoyage sur le service de nettoyage de poids + dernière revue des exceptions du service d'élévation commit 052b8db713f41679a76955c6cc2d5cc47cb81d8e Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:37:53 2016 +0200 Revue de l'API des WeightUnits pour ne plus utiliser Weights (trop d'incertitude sur l'unité utilisée) commit eeda20b0fdc2df798d0707ca74db9b767c565cf1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 16:45:10 2016 +0200 correction de la comparaison des unités (See #8151) commit d009b59733c95f144899fcdd27d1f92a2be55370 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 16:14:30 2016 +0200 Revue des arrondis et amélioration des messages d'erreur lors de l'élvation des poids commit 76a3dcb83f44f9f01c902f796ff4966704a668bb Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:52:44 2016 +0200 Revue de l'action d'élévation des poids en utilisant les exceptions typées commit 5f78949897144b289f11804f468d3d0760e5baef Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:52:10 2016 +0200 Revue du service de validation en utilisant plusieurs exceptions typées commit 6f4a2d925f17a6670ccd524884d32ded62015c84 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:16:18 2016 +0200 Correction des unités lors de la sauvegarde d'un lot (code en double en fait avec deux fois une conversion d'unité) commit 24cdd122c0786a892735eaf6183b6745a44026cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:15:29 2016 +0200 Nettoyage code commit 1189c34477f082ad7d8ec9525b92907baa7b3979 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 12 18:23:03 2016 +0200 Utilisation de l'unité adaptée Summary of changes: .../java/fr/ifremer/tutti/type/WeightUnit.java | 77 ++- .../main/java/fr/ifremer/tutti/util/Weights.java | 127 ++--- .../service/TuttiValidationDataContextSupport.java | 6 +- .../catches/BenthosWeightComputingException.java | 121 +++++ .../catches/CatchWeightComputingException.java | 40 ++ .../MarineLitterWeightComputingException.java | 40 ++ .../catches/SpeciesWeightComputingException.java | 121 +++++ .../catches/TuttiWeightComputingException.java | 20 +- .../service/catches/WeightCleaningService.java | 294 +++++------ .../service/catches/WeightComputingService.java | 556 ++++++++++----------- .../fr/ifremer/tutti/service/csv/TuttiCsvUtil.java | 3 +- .../toconfirmreport/ToConfirmReportService.java | 5 +- .../consumer/CsvConsumerForCatch.java | 4 +- .../producer/CsvProducerForCatch.java | 5 +- .../service/psionimport/PsionImportModel.java | 10 +- .../tutti/service/pupitri/PupitriImportResult.java | 2 +- .../service/pupitri/PupitriImportService.java | 4 +- .../data/SpeciesBatch-edit-error-validation.xml | 6 +- .../SpeciesBatch-validate-fatal-validation.xml | 2 +- .../resources/i18n/tutti-service_en_GB.properties | 5 + .../resources/i18n/tutti-service_fr_FR.properties | 35 +- .../fr/ifremer/tutti/ui/swing/content/Common.jcss | 3 + .../operation/catches/EditCatchesSvgHandler.java | 5 +- .../operation/catches/EditCatchesUIHandler.java | 4 +- .../operation/catches/EditCatchesUIModel.java | 13 +- .../catches/actions/ComputeBatchWeightsAction.java | 221 ++++---- .../catches/marinelitter/MarineLitterBatchUI.jaxx | 2 +- .../catches/marinelitter/MarineLitterBatchUI.jcss | 1 - .../marinelitter/MarineLitterBatchUIHandler.java | 40 +- .../marinelitter/MarineLitterBatchUIModel.java | 15 +- .../create/CreateMarineLitterBatchUI.jaxx | 2 +- .../create/CreateMarineLitterBatchUI.jcss | 1 - .../create/CreateMarineLitterBatchUIHandler.java | 5 +- .../create/CreateMarineLitterBatchUIModel.java | 12 +- .../catches/species/BenthosBatchUISupportImpl.java | 17 - .../catches/species/SpeciesBatchUISupportImpl.java | 7 - .../species/SpeciesOrBenthosBatchUISupport.java | 7 +- .../species/create/CreateSpeciesBatchUI.jaxx | 6 +- .../species/create/CreateSpeciesBatchUI.jcss | 3 - .../create/CreateSpeciesBatchUIHandler.java | 49 +- .../species/create/CreateSpeciesBatchUIModel.java | 8 +- .../catches/species/edit/SpeciesBatchUI.jaxx | 12 +- .../catches/species/edit/SpeciesBatchUI.jcss | 6 - .../species/edit/SpeciesBatchUIHandler.java | 49 +- .../frequency/SpeciesFrequencyRowModel.java | 11 +- .../frequency/SpeciesFrequencyTableModel.java | 4 +- .../species/frequency/SpeciesFrequencyUI.jaxx | 2 +- .../species/frequency/SpeciesFrequencyUI.jcss | 1 - .../frequency/SpeciesFrequencyUIHandler.java | 4 +- .../species/frequency/SpeciesFrequencyUIModel.java | 6 +- .../catches/species/split/SplitSpeciesBatchUI.jaxx | 4 +- .../catches/species/split/SplitSpeciesBatchUI.jcss | 2 - .../species/split/SplitSpeciesBatchUIHandler.java | 4 +- .../species/split/SplitSpeciesBatchUIModel.java | 14 +- .../ui/swing/util/AbstractTuttiUIHandler.java | 54 +- .../util/computable/ComputableDataEditor.jaxx | 3 +- .../computable/ComputableDataEditorHandler.java | 26 +- .../util/computable/ComputableDataTableCell.java | 103 ++-- 58 files changed, 1167 insertions(+), 1042 deletions(-) create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 1189c34477f082ad7d8ec9525b92907baa7b3979 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Apr 12 18:23:03 2016 +0200 Utilisation de l'unité adaptée --- .../operation/catches/species/frequency/SpeciesFrequencyUI.jcss | 2 +- .../operation/catches/species/frequency/SpeciesFrequencyUIModel.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss index b8b3021..5764b9d 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss @@ -448,7 +448,7 @@ ComputableDataEditor { labelFor: {totalWeightField}; enabled: {model.getTotalWeight() != null}; _help: {"tutti.editSpeciesFrequencies.field.totalWeight.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; + _addWeightUnit: {model.getWeightUnit()}; } #totalWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java index da6a793..f0f9d67 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java @@ -379,6 +379,10 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa setIndividualObservationRowsInError(new HashSet<>()); } + public WeightUnit getWeightUnit() { + return weightUnit; + } + public boolean isInitBatchEdition() { return initBatchEdition; } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 24cdd122c0786a892735eaf6183b6745a44026cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:15:29 2016 +0200 Nettoyage code --- .../catches/species/BenthosBatchUISupportImpl.java | 17 ----------------- .../catches/species/SpeciesBatchUISupportImpl.java | 7 ------- .../catches/species/SpeciesOrBenthosBatchUISupport.java | 7 ++++++- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/BenthosBatchUISupportImpl.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/BenthosBatchUISupportImpl.java index 9cc5dec..f46815a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/BenthosBatchUISupportImpl.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/BenthosBatchUISupportImpl.java @@ -50,31 +50,14 @@ import static org.nuiton.i18n.I18n.n; */ public class BenthosBatchUISupportImpl extends SpeciesOrBenthosBatchUISupport { - public static final String PROPERTY_TOTAL_COMPUTED_WEIGHT = "totalComputedWeight"; - public static final String PROPERTY_TOTAL_SORTED_WEIGHT = "totalSortedWeight"; -// public static final String PROPERTY_TOTAL_SORTED_COMPUTED_WEIGHT = "totalSortedComputedWeight"; - public static final String PROPERTY_TOTAL_UNSORTED_COMPUTED_WEIGHT = "totalUnsortedComputedWeight"; - public static final String PROPERTY_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT = "totalSampleSortedComputedWeight"; -// public static final String PROPERTY_TOTAL_INERT_COMPUTED_WEIGHT = "totalInertComputedWeight"; - public static final String PROPERTY_TOTAL_INERT_WEIGHT = "totalInertWeight"; -// public static final String PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT = "totalLivingNotItemizedComputedWeight"; - public static final String PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT = "totalLivingNotItemizedWeight"; -// public static final String PROPERTY_DISTINCT_SORTED_SPECIES_COUNT = "distinctSortedSpeciesCount"; -// public static final String PROPERTY_DISTINCT_UNSORTED_SPECIES_COUNT = "distinctUnsortedSpeciesCount"; - protected static final Map<String, String> CATCHES_UI_MODEL_PROPERTIES_MAPPING = ImmutableMap.<String, String>builder() .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_COMPUTED_WEIGHT, PROPERTY_TOTAL_COMPUTED_WEIGHT) .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_WEIGHT, PROPERTY_TOTAL_SORTED_WEIGHT) -// .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SORTED_COMPUTED_WEIGHT, PROPERTY_TOTAL_SORTED_COMPUTED_WEIGHT) .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_UNSORTED_COMPUTED_WEIGHT, PROPERTY_TOTAL_UNSORTED_COMPUTED_WEIGHT) .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT, PROPERTY_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT) -// .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_INERT_COMPUTED_WEIGHT, PROPERTY_TOTAL_INERT_COMPUTED_WEIGHT) .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_INERT_WEIGHT, PROPERTY_TOTAL_INERT_WEIGHT) -// .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT, PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_COMPUTED_WEIGHT) .put(EditCatchesUIModel.PROPERTY_BENTHOS_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT, PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT) -// .put(EditCatchesUIModel.PROPERTY_BENTHOS_DISTINCT_SORTED_SPECIES_COUNT, PROPERTY_DISTINCT_SORTED_SPECIES_COUNT) -// .put(EditCatchesUIModel.PROPERTY_BENTHOS_DISTINCT_UNSORTED_SPECIES_COUNT, PROPERTY_DISTINCT_UNSORTED_SPECIES_COUNT) .build(); public BenthosBatchUISupportImpl(TuttiUIContext context, EditCatchesUIModel catchesUIModel, WeightUnit weightUnit) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUISupportImpl.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUISupportImpl.java index 8bba93e..28faded 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUISupportImpl.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUISupportImpl.java @@ -50,13 +50,6 @@ import static org.nuiton.i18n.I18n.n; */ public class SpeciesBatchUISupportImpl extends SpeciesOrBenthosBatchUISupport { - public static final String PROPERTY_TOTAL_COMPUTED_WEIGHT = "totalComputedWeight"; - public static final String PROPERTY_TOTAL_SORTED_WEIGHT = "totalSortedWeight"; - public static final String PROPERTY_TOTAL_UNSORTED_COMPUTED_WEIGHT = "totalUnsortedComputedWeight"; - public static final String PROPERTY_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT = "totalSampleSortedComputedWeight"; - public static final String PROPERTY_TOTAL_INERT_WEIGHT = "totalInertWeight"; - public static final String PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT = "totalLivingNotItemizedWeight"; - protected static final Map<String, String> CATCHES_UI_MODEL_PROPERTIES_MAPPING = ImmutableMap.<String, String>builder() .put(EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_COMPUTED_WEIGHT, PROPERTY_TOTAL_COMPUTED_WEIGHT) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesOrBenthosBatchUISupport.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesOrBenthosBatchUISupport.java index d9f2de7..96b60bc 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesOrBenthosBatchUISupport.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesOrBenthosBatchUISupport.java @@ -54,8 +54,13 @@ import java.util.Map; public abstract class SpeciesOrBenthosBatchUISupport { public static final String SPECIES = "SPECIES"; - public static final String BENTHOS = "BENTHOS"; + public static final String PROPERTY_TOTAL_COMPUTED_WEIGHT = "totalComputedWeight"; + public static final String PROPERTY_TOTAL_SORTED_WEIGHT = "totalSortedWeight"; + public static final String PROPERTY_TOTAL_UNSORTED_COMPUTED_WEIGHT = "totalUnsortedComputedWeight"; + public static final String PROPERTY_TOTAL_SAMPLE_SORTED_COMPUTED_WEIGHT = "totalSampleSortedComputedWeight"; + public static final String PROPERTY_TOTAL_INERT_WEIGHT = "totalInertWeight"; + public static final String PROPERTY_TOTAL_LIVING_NOT_ITEMIZED_WEIGHT = "totalLivingNotItemizedWeight"; protected final TuttiUIContext context; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 6f4a2d925f17a6670ccd524884d32ded62015c84 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:16:18 2016 +0200 Correction des unités lors de la sauvegarde d'un lot (code en double en fait avec deux fois une conversion d'unité) --- .../species/edit/SpeciesBatchUIHandler.java | 27 ++++------------------ 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java index db45cbd..ec90dba 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java @@ -1245,39 +1245,20 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec public void saveRow(SpeciesBatchRowModel row) { - FishingOperation fishingOperation = getModel().getFishingOperation(); - Preconditions.checkNotNull(fishingOperation); - + Preconditions.checkNotNull(row); Preconditions.checkNotNull(row.getSpecies()); - SampleCategory<?> sampleCategory = row.getFinestCategory(); - Preconditions.checkNotNull(sampleCategory); - Preconditions.checkNotNull(sampleCategory.getCategoryId()); - Preconditions.checkNotNull(sampleCategory.getCategoryValue()); SpeciesBatch catchBean = row.toEntity(); - WeightUnit weightUnit = getWeightUnit(); - - // convert weight - Float weight = catchBean.getWeight(); - catchBean.setWeight(weightUnit.toEntity(weight)); - + FishingOperation fishingOperation = getModel().getFishingOperation(); + Preconditions.checkNotNull(fishingOperation); catchBean.setFishingOperation(fishingOperation); SpeciesBatchRowModel parent = row.getParentBatch(); if (parent != null) { - //FIXME Check no need to convert parent weight ? :( catchBean.setParentBatch(parent.toEntity()); } - // apply sample category - catchBean.setSampleCategoryId(sampleCategory.getCategoryId()); - catchBean.setSampleCategoryValue(sampleCategory.getCategoryValue()); - - // convert sample category weight - Float categoryWeight = sampleCategory.getCategoryWeight(); - catchBean.setSampleCategoryWeight(weightUnit.toEntity(categoryWeight)); - if (TuttiEntities.isNew(catchBean)) { Integer parentBatchId = null; @@ -1309,7 +1290,7 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec frequency = speciesOrBenthosBatchUISupport.saveBatchFrequencies(catchBean.getIdAsInt(), frequency); // push it back to row model - frequencyRows = SpeciesFrequencyRowModel.fromEntity(weightUnit, frequency); + frequencyRows = SpeciesFrequencyRowModel.fromEntity(getWeightUnit(), frequency); row.setFrequency(frequencyRows); List<IndividualObservationBatchRowModel> obsRows = row.getIndividualObservation() -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 5f78949897144b289f11804f468d3d0760e5baef Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:52:10 2016 +0200 Revue du service de validation en utilisant plusieurs exceptions typées --- .../catches/BenthosWeightComputingException.java | 17 + .../catches/CatchWeightComputingException.java | 14 + .../MarineLitterWeightComputingException.java | 17 + .../catches/SpeciesWeightComputingException.java | 17 + .../catches/TuttiWeightComputingException.java | 20 +- .../service/catches/WeightComputingService.java | 462 ++++++++++----------- 6 files changed, 295 insertions(+), 252 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java new file mode 100644 index 0000000..3d85185 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java @@ -0,0 +1,17 @@ +package fr.ifremer.tutti.service.catches; + +/** + * Created on 13/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class BenthosWeightComputingException extends TuttiWeightComputingException { + + public BenthosWeightComputingException(String message) { + super(message); + } + + public BenthosWeightComputingException(String message, String property, int index) { + super(message, property, index); + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java new file mode 100644 index 0000000..997281a --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java @@ -0,0 +1,14 @@ +package fr.ifremer.tutti.service.catches; + +/** + * Created on 13/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class CatchWeightComputingException extends TuttiWeightComputingException { + + public CatchWeightComputingException(String message) { + super(message); + } + +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java new file mode 100644 index 0000000..6c22618 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java @@ -0,0 +1,17 @@ +package fr.ifremer.tutti.service.catches; + +/** + * Created on 13/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class MarineLitterWeightComputingException extends TuttiWeightComputingException { + + public MarineLitterWeightComputingException(String message) { + super(message); + } + + public MarineLitterWeightComputingException(String message, String property, int index) { + super(message, property, index); + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java new file mode 100644 index 0000000..42ba734 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java @@ -0,0 +1,17 @@ +package fr.ifremer.tutti.service.catches; + +/** + * Created on 13/04/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class SpeciesWeightComputingException extends TuttiWeightComputingException { + + public SpeciesWeightComputingException(String message) { + super(message); + } + + public SpeciesWeightComputingException(String message, String property, int index) { + super(message, property, index); + } +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingException.java index ba21ade..4d06191 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingException.java @@ -24,6 +24,8 @@ package fr.ifremer.tutti.service.catches; import org.nuiton.jaxx.application.ApplicationBusinessException; +import java.util.Optional; + /** * @author Kevin Morin - kmorin@codelutin.com * @since 2.0 @@ -34,21 +36,23 @@ public class TuttiWeightComputingException extends ApplicationBusinessException protected String property; - protected int index; + protected Integer index; + + protected TuttiWeightComputingException(String message) { + this(message, null, null); + } - public TuttiWeightComputingException(String message, - String property, - int index) { + protected TuttiWeightComputingException(String message, String property, Integer index) { super(message); this.property = property; this.index = index; } - public String getProperty() { - return property; + public Optional<String> getProperty() { + return Optional.ofNullable(property); } - public int getIndex() { - return index; + public Optional<Integer> getIndex() { + return Optional.ofNullable(index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index 4ef90a9..3896b7d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -38,9 +38,11 @@ import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.util.Numbers; import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.jaxx.application.ApplicationBusinessException; +import org.apache.commons.lang3.tuple.Pair; +import org.nuiton.decorator.Decorator; import org.nuiton.validator.NuitonValidatorResult; +import java.io.Serializable; import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -57,12 +59,17 @@ public class WeightComputingService extends AbstractTuttiService { protected DecoratorService decoratorService; + private Decorator<Species> speciesDecorator; + + private int currentSpeciesRowIndex; + private int currentBenthosRowIndex; + @Override public void setServiceContext(TuttiServiceContext context) { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); validationService = getService(ValidationService.class); - decoratorService = getService(DecoratorService.class);; + decoratorService = getService(DecoratorService.class); } /** @@ -83,106 +90,78 @@ public class WeightComputingService extends AbstractTuttiService { Float speciesTotalComputedUnsortedWeight = 0f; if (rootSpeciesBatch != null) { - List<SpeciesBatch> speciesBatches = rootSpeciesBatch.getChildren(); - for (SpeciesBatch row : speciesBatches) { - Float weight = Numbers.getValueOrComputedValue( - row.getSampleCategoryWeight(), - row.getSampleCategoryComputedWeight()); - if (weight == null) { - break; - } - - if (persistenceService.isVracBatch(row)) { - speciesTotalComputedSortedWeight += weight; - } else { - speciesTotalComputedUnsortedWeight += weight; - } - } + Pair<Float, Float> pair = computeTotalComputedSortedAndUnsortedWeights(rootSpeciesBatch); + speciesTotalComputedSortedWeight = pair.getLeft(); + speciesTotalComputedUnsortedWeight = pair.getRight(); } - Number inertWeight = catchBatch.getSpeciesTotalInertWeight(); - if (inertWeight != null) { - speciesTotalComputedSortedWeight += inertWeight.floatValue(); + Float speciesInertWeight = catchBatch.getSpeciesTotalInertWeight(); + if (speciesInertWeight != null) { + speciesTotalComputedSortedWeight += speciesInertWeight; } else { catchBatch.setSpeciesTotalInertComputedWeight(0f); } - Number livingNotItemizedWeight = catchBatch.getSpeciesTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - speciesTotalComputedSortedWeight += livingNotItemizedWeight.floatValue(); + Float speciesLivingNotItemizedWeight = catchBatch.getSpeciesTotalLivingNotItemizedWeight(); + if (speciesLivingNotItemizedWeight != null) { + speciesTotalComputedSortedWeight += speciesLivingNotItemizedWeight; } else { catchBatch.setSpeciesTotalLivingNotItemizedComputedWeight(0f); } - catchBatch.setSpeciesTotalSampleSortedComputedWeight(speciesTotalComputedSortedWeight); + catchBatch.setSpeciesTotalSampleSortedComputedWeight(WeightUnit.KG.round(speciesTotalComputedSortedWeight)); Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); if (speciesTotalSortedWeight == null) { speciesTotalSortedWeight = speciesTotalComputedSortedWeight; - catchBatch.setSpeciesTotalSortedComputedWeight( - WeightUnit.KG.round(speciesTotalSortedWeight)); + catchBatch.setSpeciesTotalSortedComputedWeight(WeightUnit.KG.round(speciesTotalSortedWeight)); - } else if (speciesTotalSortedWeight < speciesTotalComputedSortedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); + } else if (Weights.isSmallerWeight(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { + throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); } - catchBatch.setSpeciesTotalUnsortedComputedWeight( - WeightUnit.KG.round(speciesTotalComputedUnsortedWeight)); + catchBatch.setSpeciesTotalUnsortedComputedWeight(WeightUnit.KG.round(speciesTotalComputedUnsortedWeight)); if (speciesTotalSortedWeight == null) { speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); } - // Benthos Float benthosTotalComputedSortedWeight = 0f; Float benthosTotalComputedUnsortedWeight = 0f; if (rootBenthosBatch != null) { - List<SpeciesBatch> benthosBatches = rootBenthosBatch.getChildren(); - for (SpeciesBatch row : benthosBatches) { - Float weight = Numbers.getValueOrComputedValue( - row.getSampleCategoryWeight(), - row.getSampleCategoryComputedWeight()); - if (weight == null) { - break; - } - if (persistenceService.isVracBatch(row)) { - benthosTotalComputedSortedWeight += weight; - } else { - benthosTotalComputedUnsortedWeight += weight; - } - } + Pair<Float, Float> pair = computeTotalComputedSortedAndUnsortedWeights(rootBenthosBatch); + benthosTotalComputedSortedWeight = pair.getLeft(); + benthosTotalComputedUnsortedWeight = pair.getRight(); + } - inertWeight = catchBatch.getBenthosTotalInertWeight(); - if (inertWeight != null) { - benthosTotalComputedSortedWeight += inertWeight.floatValue(); + Float benthosInertWeight = catchBatch.getBenthosTotalInertWeight(); + if (benthosInertWeight != null) { + benthosTotalComputedSortedWeight += benthosInertWeight; } else { catchBatch.setBenthosTotalInertComputedWeight(0f); } - livingNotItemizedWeight = catchBatch.getBenthosTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - benthosTotalComputedSortedWeight += livingNotItemizedWeight.floatValue(); + Float benthosLivingNotItemizedWeight = catchBatch.getBenthosTotalLivingNotItemizedWeight(); + if (benthosLivingNotItemizedWeight != null) { + benthosTotalComputedSortedWeight += benthosLivingNotItemizedWeight; } else { catchBatch.setBenthosTotalLivingNotItemizedComputedWeight(0f); } - catchBatch.setBenthosTotalSampleSortedComputedWeight( - WeightUnit.KG.round(benthosTotalComputedSortedWeight)); + catchBatch.setBenthosTotalSampleSortedComputedWeight(WeightUnit.KG.round(benthosTotalComputedSortedWeight)); Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); if (benthosTotalSortedWeight == null) { benthosTotalSortedWeight = benthosTotalComputedSortedWeight; - catchBatch.setBenthosTotalSortedComputedWeight( - WeightUnit.KG.round(benthosTotalSortedWeight)); + catchBatch.setBenthosTotalSortedComputedWeight(WeightUnit.KG.round(benthosTotalSortedWeight)); - } else if (benthosTotalSortedWeight < benthosTotalComputedSortedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); + } else if (Weights.isSmallerWeight(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { + throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); } - catchBatch.setBenthosTotalUnsortedComputedWeight( - WeightUnit.KG.round(benthosTotalComputedUnsortedWeight)); + catchBatch.setBenthosTotalUnsortedComputedWeight(WeightUnit.KG.round(benthosTotalComputedUnsortedWeight)); if (benthosTotalSortedWeight == null) { benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); @@ -203,22 +182,20 @@ public class WeightComputingService extends AbstractTuttiService { } } if (marineLitterTotalComputedWeight != null) { - catchBatch.setMarineLitterTotalComputedWeight( - WeightUnit.KG.round(marineLitterTotalComputedWeight)); + catchBatch.setMarineLitterTotalComputedWeight(WeightUnit.KG.round(marineLitterTotalComputedWeight)); } Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); if (marineLitterTotalWeight == null) { marineLitterTotalWeight = marineLitterTotalComputedWeight; - } else if (marineLitterTotalComputedWeight != null && marineLitterTotalWeight < marineLitterTotalComputedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal")); + } else if (marineLitterTotalComputedWeight != null && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { + throw new MarineLitterWeightComputingException(t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal")); } // nothing to do with the marine litter weight, it is an isolated weight // Catch - Float totalUnsortedWeight = catchBatch.getSpeciesTotalUnsortedComputedWeight() + - catchBatch.getBenthosTotalUnsortedComputedWeight(); + Float totalUnsortedWeight = catchBatch.getSpeciesTotalUnsortedComputedWeight() + catchBatch.getBenthosTotalUnsortedComputedWeight(); Float totalSortedSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; @@ -230,28 +207,22 @@ public class WeightComputingService extends AbstractTuttiService { if (rejectedWeight == null && totalWeight != null) { if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight)) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); } //FIXME voir avec Vincent si on calcule le poids rejeté - catchBatch.setCatchTotalRejectedComputedWeight( - WeightUnit.KG.round(totalWeight - - totalUnsortedWeight - - totalSortedSortedWeight)); + catchBatch.setCatchTotalRejectedComputedWeight(WeightUnit.KG.round(totalWeight - totalUnsortedWeight - totalSortedSortedWeight)); } else if (totalWeight == null) { if (rejectedWeight == null) { rejectedWeight = 0f; catchBatch.setCatchTotalRejectedComputedWeight(0f); } - catchBatch.setCatchTotalComputedWeight( - WeightUnit.KG.round(totalUnsortedWeight - + totalSortedSortedWeight - + rejectedWeight)); + catchBatch.setCatchTotalComputedWeight(WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)); } else if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); } Float totalSortedWeight = totalSortedSortedWeight; @@ -275,8 +246,6 @@ public class WeightComputingService extends AbstractTuttiService { catchBatch.setBenthosTotalComputedWeight(WeightUnit.KG.round(benthosTotalWeight)); } - private int currentSpeciesRowIndex; - public BatchContainer<SpeciesBatch> getComputedSpeciesBatches(Integer operationId) { BatchContainer<SpeciesBatch> rootSpeciesBatch = null; @@ -286,44 +255,35 @@ public class WeightComputingService extends AbstractTuttiService { currentSpeciesRowIndex = 0; if (rootSpeciesBatch != null) { - List<SpeciesBatch> roots = rootSpeciesBatch.getChildren(); - - for (SpeciesBatch batch : roots) { - computeSpeciesBatch(batch); - } + rootSpeciesBatch.getChildren().forEach(this::computeSpeciesBatch); } } return rootSpeciesBatch; - } - protected String getCategoryLabel(Integer sampleCategoryId) { - SampleCategoryModelEntry category = - context.getSampleCategoryModel().getCategoryById(sampleCategoryId); - return category.getLabel(); } public Float computeSpeciesBatch(SpeciesBatch batch) { + Float result = null; int thisIndex = currentSpeciesRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); - String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); + String species = decorateSpecies(batch.getSpecies()); + String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditSpeciesBatch(batch); if (!validation.isValid()) { List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw new SpeciesWeightComputingException(t(messages.get(0), + species, + categoryLabel, + categoryValue, + batch.getWeight(), + batch.getSampleCategoryWeight()), + SpeciesBatch.PROPERTY_WEIGHT, + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -339,22 +299,22 @@ public class WeightComputingService extends AbstractTuttiService { } sum += weight; } + sum = WeightUnit.KG.round(sum); if (sum != null) { if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(WeightUnit.KG.round(sum)); + batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + categoryWeight, + sum), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } else { sum = categoryWeight; @@ -370,40 +330,23 @@ public class WeightComputingService extends AbstractTuttiService { if (CollectionUtils.isNotEmpty(frequencies)) { // if there are frequencies, then compute their weight - Float frequencyWeight = 0f; - for (SpeciesBatchFrequency frequency : frequencies) { - Float w = frequency.getWeight(); - if (w == null) { - - // can't sum when a null value appears - frequencyWeight = null; - break; - - } else if (frequencyWeight != null) { - - // still can sum weights - frequencyWeight += w; - } - } - frequencyWeight = WeightUnit.KG.round(frequencyWeight); + Float frequencyWeight = sumFrequenciesWeight(frequencies); if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null - && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - frequencyWeight, - rowWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", + species, + categoryLabel, + categoryValue, + frequencyWeight, + rowWeight), + SpeciesBatch.PROPERTY_WEIGHT, + thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -411,8 +354,7 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null - && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample @@ -420,15 +362,14 @@ public class WeightComputingService extends AbstractTuttiService { String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + frequencyWeight, + categoryWeight), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -441,11 +382,7 @@ public class WeightComputingService extends AbstractTuttiService { } // compute number from frequencies - Integer frequencyNumber = 0; - for (SpeciesBatchFrequency frequency : frequencies) { - Integer c = frequency.getNumber(); - frequencyNumber += c; - } + Integer frequencyNumber = sumFrequenciesNumber(frequencies); batch.setComputedNumber(frequencyNumber); } else { @@ -456,38 +393,33 @@ public class WeightComputingService extends AbstractTuttiService { String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.noWeight", + species, + categoryLabel, + categoryValue), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } return WeightUnit.KG.round(result); } - private int currentBenthosRowIndex; - public BatchContainer<SpeciesBatch> getComputedBenthosBatches(Integer operationId) { BatchContainer<SpeciesBatch> rootBenthosBatch = null; if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { + rootBenthosBatch = persistenceService.getRootBenthosBatch(operationId, false); currentBenthosRowIndex = 0; if (rootBenthosBatch != null) { - List<SpeciesBatch> roots = rootBenthosBatch.getChildren(); - - for (SpeciesBatch batch : roots) { - computeBenthosBatch(batch); - } + rootBenthosBatch.getChildren().forEach(this::computeBenthosBatch); } } return rootBenthosBatch; + } public Float computeBenthosBatch(SpeciesBatch batch) { @@ -495,23 +427,22 @@ public class WeightComputingService extends AbstractTuttiService { int thisIndex = currentBenthosRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); - String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); + String species = decorateSpecies(batch.getSpecies()); + String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditBenthosBatch(batch); if (!validation.isValid()) { List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw new BenthosWeightComputingException(t(messages.get(0), + species, + categoryLabel, + categoryValue, + batch.getWeight(), + batch.getSampleCategoryWeight()), + SpeciesBatch.PROPERTY_WEIGHT, + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -527,24 +458,23 @@ public class WeightComputingService extends AbstractTuttiService { } sum += weight; } + sum = WeightUnit.KG.round(sum); if (sum != null) { if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(WeightUnit.KG.round(sum)); + batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); + String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + categoryWeight, + sum), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } else { sum = categoryWeight; @@ -561,33 +491,16 @@ public class WeightComputingService extends AbstractTuttiService { if (CollectionUtils.isNotEmpty(frequencies)) { // if there are frequencies, then compute their weight - Float frequencyWeight = 0f; - for (SpeciesBatchFrequency frequency : frequencies) { - Float w = frequency.getWeight(); - if (w == null) { - - // can't sum when a null value appears - frequencyWeight = null; - break; - - } else if (frequencyWeight != null) { - - // still can sum weights - frequencyWeight += w; - } - } - frequencyWeight = WeightUnit.KG.round(frequencyWeight); + Float frequencyWeight = sumFrequenciesWeight(frequencies); if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null - && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); + String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( + throw new BenthosWeightComputingException( t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", species, categoryLabel, @@ -603,25 +516,22 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null - && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); + String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + frequencyWeight, + categoryWeight), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -634,11 +544,7 @@ public class WeightComputingService extends AbstractTuttiService { } // compute number from frequencies - Integer frequencyNumber = 0; - for (SpeciesBatchFrequency frequency : frequencies) { - Integer c = frequency.getNumber(); - frequencyNumber += c; - } + Integer frequencyNumber = sumFrequenciesNumber(frequencies); batch.setComputedNumber(frequencyNumber); } else { result = categoryWeight; @@ -646,26 +552,23 @@ public class WeightComputingService extends AbstractTuttiService { } if (Weights.isNullOrZero(result)) { - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); + String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.noWeight", + species, + categoryLabel, + categoryValue), + SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, + thisIndex); } return WeightUnit.KG.round(result); + } - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, - Float marineLitterweight) { + public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, Float marineLitterweight) { - BatchContainer<MarineLitterBatch> rootMarineLitterBatch = - persistenceService.getRootMarineLitterBatch(fishingOperationId); + BatchContainer<MarineLitterBatch> rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); if (rootMarineLitterBatch != null) { boolean checkWeight = marineLitterweight == null; @@ -675,14 +578,85 @@ public class WeightComputingService extends AbstractTuttiService { MarineLitterBatch batch = children.get(i); if (checkWeight && Weights.isNullOrZero(batch.getWeight())) { - throw new TuttiWeightComputingException( - t("tutti.validator.warning.marineLitter.weight.required"), - MarineLitterBatch.PROPERTY_WEIGHT, - i); + throw new MarineLitterWeightComputingException(t("tutti.validator.warning.marineLitter.weight.required"), + MarineLitterBatch.PROPERTY_WEIGHT, + i); } } } return rootMarineLitterBatch; + + } + + private Pair<Float, Float> computeTotalComputedSortedAndUnsortedWeights(BatchContainer<SpeciesBatch> rootSpeciesBatch) { + + Float speciesTotalComputedSortedWeight = 0f; + Float speciesTotalComputedUnsortedWeight = 0f; + + for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { + Float weight = Numbers.getValueOrComputedValue( + speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); + if (weight == null) { + break; + } + + if (persistenceService.isVracBatch(speciesBatch)) { + speciesTotalComputedSortedWeight += weight; + } else { + speciesTotalComputedUnsortedWeight += weight; + } + + } + + return Pair.of(speciesTotalComputedSortedWeight, speciesTotalComputedUnsortedWeight); + + } + + private String getCategoryLabel(Integer sampleCategoryId) { + SampleCategoryModelEntry category = context.getSampleCategoryModel().getCategoryById(sampleCategoryId); + return category.getLabel(); + } + + private Integer sumFrequenciesNumber(List<SpeciesBatchFrequency> frequencies) { + Integer frequencyNumber = 0; + for (SpeciesBatchFrequency frequency : frequencies) { + Integer c = frequency.getNumber(); + frequencyNumber += c; + } + return frequencyNumber; + } + + private Float sumFrequenciesWeight(List<SpeciesBatchFrequency> frequencies) { + Float frequencyWeight = 0f; + for (SpeciesBatchFrequency frequency : frequencies) { + Float w = frequency.getWeight(); + if (w == null) { + + // can't sum when a null value appears + frequencyWeight = null; + break; + + } else if (frequencyWeight != null) { + + // still can sum weights + frequencyWeight += w; + } + } + frequencyWeight = WeightUnit.KG.round(frequencyWeight); + return frequencyWeight; } + + private String decorateSpecies(Species species) { + if (speciesDecorator == null) { + speciesDecorator = decoratorService.getDecoratorByType(Species.class); + } + return speciesDecorator.toString(species); + } + + private String decorateCategoryValue(Serializable sampleCategoryValue) { + return decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue); + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 76a3dcb83f44f9f01c902f796ff4966704a668bb Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 11:52:44 2016 +0200 Revue de l'action d'élévation des poids en utilisant les exceptions typées --- .../catches/actions/ComputeBatchWeightsAction.java | 221 +++++++++------------ 1 file changed, 94 insertions(+), 127 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java index a976727..0432426 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/actions/ComputeBatchWeightsAction.java @@ -30,6 +30,10 @@ import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategory; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.catches.BenthosWeightComputingException; +import fr.ifremer.tutti.service.catches.CatchWeightComputingException; +import fr.ifremer.tutti.service.catches.MarineLitterWeightComputingException; +import fr.ifremer.tutti.service.catches.SpeciesWeightComputingException; import fr.ifremer.tutti.service.catches.TuttiWeightComputingException; import fr.ifremer.tutti.service.catches.WeightCleaningService; import fr.ifremer.tutti.service.catches.WeightComputingService; @@ -55,6 +59,7 @@ import javax.swing.JOptionPane; import javax.swing.table.TableColumn; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -64,22 +69,22 @@ import static org.nuiton.i18n.I18n.t; * @since 1.0 */ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { - + protected final WeightCleaningService cleaningService; + protected final PersistenceService persistenceService; protected List<SpeciesBatchRowModel> speciesBatchRows; - protected List<SpeciesBatchRowModel> benthosBatchRows; protected CatchBatch catchBatch; protected Boolean modified; - protected Integer tabInError; public ComputeBatchWeightsAction(EditCatchesUIHandler handler) { super(handler, true); this.cleaningService = getContext().getWeightCleaningService(); + this.persistenceService = getContext().getPersistenceService(); } @Override @@ -125,9 +130,8 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo @Override public void doAction() throws Exception { - PersistenceService persistenceService = getContext().getPersistenceService(); - WeightComputingService weightComputingService = getContext().getWeightComputingService(); + WeightComputingService computingService = getContext().getWeightComputingService(); EditCatchesUIModel model = getModel(); Integer operationId = model.getFishingOperation().getIdAsInt(); @@ -136,61 +140,33 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo // Compute species batches // --------- - Float totalSpeciesSortedWeight; - BatchContainer<SpeciesBatch> computedSpeciesBatches; - - try { - computedSpeciesBatches = weightComputingService.getComputedSpeciesBatches(operationId); - if (computedSpeciesBatches == null) { - totalSpeciesSortedWeight = 0f; - } else { - totalSpeciesSortedWeight = computeSpeciesBatches(persistenceService, computedSpeciesBatches, speciesBatchRows = new ArrayList<>()); - } - - } catch (TuttiWeightComputingException e) { - - tabInError = 1; - throw e; + BatchContainer<SpeciesBatch> computedSpeciesBatches = computingService.getComputedSpeciesBatches(operationId); + Float totalSpeciesSortedWeight; + if (computedSpeciesBatches == null) { + totalSpeciesSortedWeight = 0f; + } else { + totalSpeciesSortedWeight = computeSpeciesBatches(getSpeciesBatchUI(), computedSpeciesBatches, speciesBatchRows = new ArrayList<>()); } // --------- // Compute benthos batches // --------- - Float totalBenthosSortedWeight; - BatchContainer<SpeciesBatch> computedBenthosBatches; - - try { - computedBenthosBatches = weightComputingService.getComputedBenthosBatches(operationId); - if (computedBenthosBatches == null) { - totalBenthosSortedWeight = 0f; - } else { - totalBenthosSortedWeight = computeSpeciesBatches(persistenceService, computedBenthosBatches, benthosBatchRows = new ArrayList<>()); - } - - } catch (TuttiWeightComputingException e) { - - tabInError = 2; - throw e; + BatchContainer<SpeciesBatch> computedBenthosBatches = computingService.getComputedBenthosBatches(operationId); + Float totalBenthosSortedWeight; + if (computedBenthosBatches == null) { + totalBenthosSortedWeight = 0f; + } else { + totalBenthosSortedWeight = computeSpeciesBatches(getBenthosBatchUI(), computedBenthosBatches, benthosBatchRows = new ArrayList<>()); } // --------- // Compute marine litter batches // --------- - BatchContainer<MarineLitterBatch> computedMarineLitterBatches; - try { - computedMarineLitterBatches = - weightComputingService.getComputedMarineLitterBatches(operationId, model.getMarineLitterTotalWeight()); - - } catch (TuttiWeightComputingException e) { - - tabInError = 3; - throw e; - - } + BatchContainer<MarineLitterBatch> computedMarineLitterBatches = computingService.getComputedMarineLitterBatches(operationId, model.getMarineLitterTotalWeight()); modified = model.isModify(); catchBatch = model.toEntity(); @@ -271,10 +247,10 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo } } - weightComputingService.computeCatchBatchWeights(catchBatch, - computedSpeciesBatches, - computedBenthosBatches, - computedMarineLitterBatches); + computingService.computeCatchBatchWeights(catchBatch, + computedSpeciesBatches, + computedBenthosBatches, + computedMarineLitterBatches); } @@ -285,16 +261,6 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo afterAction(); getUI().repaint(); - //TCHEMIT-2015-04-27 Plus besoin car le champs qui posait problème n'existe plus -// // see http://forge.codelutin.com/issues/3853 -// SwingUtilities.invokeLater( -// new Runnable() { -// @Override -// public void run() { -// getUI().getComputeSpeciesBatchButton().requestFocus(); -// } -// } -// ); } protected void afterAction() { @@ -372,31 +338,43 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo afterAction(); - if (error instanceof TuttiWeightComputingException) { + if (error instanceof CatchWeightComputingException) { - // elevation error - TuttiWeightComputingException e = (TuttiWeightComputingException) error; + getUI().getTabPane().setSelectedIndex(0); - getUI().getTabPane().setSelectedIndex(tabInError); + } - switch (tabInError) { + if (error instanceof SpeciesWeightComputingException) { - case 1: - // species error - treatSpeciesBatchError(e, getSpeciesBatchUI().getModel()); + SpeciesWeightComputingException e = (SpeciesWeightComputingException) error; - break; + getUI().getTabPane().setSelectedIndex(1); - case 2: + treatSpeciesBatchError(getSpeciesBatchUI(), e); - // benthos error - treatSpeciesBatchError(e, getBenthosBatchUI().getModel()); + } - break; + if (error instanceof BenthosWeightComputingException) { + + BenthosWeightComputingException e = (BenthosWeightComputingException) error; + + getUI().getTabPane().setSelectedIndex(2); + + treatSpeciesBatchError(getBenthosBatchUI(), e); + + } - case 3: - // marine litter error - JTables.doSelectCell(getUI().getMarineLitterTabContent().getTable(), e.getIndex(), 3); + if (error instanceof MarineLitterWeightComputingException) { + + MarineLitterWeightComputingException e = (MarineLitterWeightComputingException) error; + + getUI().getTabPane().setSelectedIndex(3); + + Optional<Integer> optionalRowIndex = e.getIndex(); + + if (optionalRowIndex.isPresent()) { + + JTables.doSelectCell(getUI().getMarineLitterTabContent().getTable(), optionalRowIndex.get(), 3); } @@ -408,13 +386,13 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo //-- Internal methods --// //------------------------------------------------------------------------// - protected Float computeSpeciesBatches(PersistenceService persistenceService, BatchContainer<SpeciesBatch> computedSpeciesBatches, List<SpeciesBatchRowModel> speciesBatchRows) { + protected Float computeSpeciesBatches(SpeciesBatchUI ui, BatchContainer<SpeciesBatch> computedSpeciesBatches, List<SpeciesBatchRowModel> speciesBatchRows) { + Float totalSortedWeight = 0f; - List<SpeciesBatch> children = computedSpeciesBatches.getChildren(); - for (SpeciesBatch batch : children) { - SpeciesBatchRowModel row = getSpeciesBatchUI().getHandler().loadBatch(batch, null, speciesBatchRows); - if (persistenceService.isVracBatch(row)) { + for (SpeciesBatch speciesBatch : computedSpeciesBatches.getChildren()) { + SpeciesBatchRowModel row = ui.getHandler().loadBatch(speciesBatch, null, speciesBatchRows); + if (persistenceService.isVracBatch(speciesBatch)) { SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); Float weight = Numbers.getValueOrComputedValue(sampleCategory.getCategoryWeight(), sampleCategory.getComputedWeight()); totalSortedWeight += weight; @@ -422,58 +400,47 @@ public class ComputeBatchWeightsAction extends LongActionSupport<EditCatchesUIMo } return totalSortedWeight; + } -// protected Float computeBenthosBatches(PersistenceService persistenceService, BatchContainer<SpeciesBatch> computedBenthosBatches) { -// Float totalSortedWeight = 0f; -// -// if (computedBenthosBatches != null) { -// benthosBatchRows = new ArrayList<>(); -// List<SpeciesBatch> children = computedBenthosBatches.getChildren(); -// for (SpeciesBatch batch : children) { -// SpeciesBatchRowModel row = getBenthosBatchUI().getHandler().loadBatch(batch, null, benthosBatchRows); -// -// if (persistenceService.isVracBatch(row)) { -// SampleCategory<?> sampleCategory = row.getFirstSampleCategory(); -// Float weight = Numbers.getValueOrComputedValue(sampleCategory.getCategoryWeight(), -// sampleCategory.getComputedWeight()); -// totalSortedWeight += weight; -// } -// } -//// getUI().getBenthosTabContent().getModel().setRows(benthosBatchRows); -// -// } -// return totalSortedWeight; -// } - - protected void treatSpeciesBatchError(TuttiWeightComputingException e, SpeciesBatchUIModel speciesBatchUIModel) { - - int index = e.getIndex(); - - SpeciesBatchRowModel row; - - if (speciesBatchUIModel.getSpeciesSortMode() != SpeciesSortMode.NONE) { - - // must resort rows in natural order (in service we use this order) - List<SpeciesBatchRowModel> rows = new ArrayList<>(speciesBatchUIModel.getRows()); - SpeciesBatchNaturalOrderComparator.sort(rows); - // get the row - row = rows.get(index); - // get the correct rowIndex in the sorted list - index = speciesBatchUIModel.getRows().indexOf(row); + protected void treatSpeciesBatchError(SpeciesBatchUI ui, TuttiWeightComputingException e) { - } else { + Optional<Integer> optionalRowIndex = e.getIndex(); - // correct order can directly get row from list - List<SpeciesBatchRowModel> rows = speciesBatchUIModel.getRows(); - row = rows.get(index); + Optional<String> optionalProperty = e.getProperty(); - } + if (optionalRowIndex.isPresent() && optionalProperty.isPresent()) { + + SpeciesBatchUIModel speciesBatchUIModel = ui.getModel(); + + Integer index = optionalRowIndex.get(); + + SpeciesBatchRowModel row; + + if (SpeciesSortMode.NONE != speciesBatchUIModel.getSpeciesSortMode()) { + + // must resort rows in natural order (in service we use this order) + List<SpeciesBatchRowModel> rows = new ArrayList<>(speciesBatchUIModel.getRows()); + SpeciesBatchNaturalOrderComparator.sort(rows); + // get the row + row = rows.get(index); + // get the correct rowIndex in the sorted list + index = speciesBatchUIModel.getRows().indexOf(row); - JXTable table = getSpeciesBatchUI().getTable(); - SpeciesBatchTableModel tableModel = (SpeciesBatchTableModel) table.getModel(); - Set<SampleCategoryColumnIdentifier> sampleCols = tableModel.getSampleCols(); - selectBatchCell(table, index, row, e.getProperty(), sampleCols, SpeciesBatchTableModel.WEIGHT); + } else { + + // correct order can directly get row from list + List<SpeciesBatchRowModel> rows = speciesBatchUIModel.getRows(); + row = rows.get(index); + + } + + JXTable table = ui.getTable(); + SpeciesBatchTableModel tableModel = (SpeciesBatchTableModel) table.getModel(); + Set<SampleCategoryColumnIdentifier> sampleCols = tableModel.getSampleCols(); + selectBatchCell(table, index, row, optionalProperty.get(), sampleCols, SpeciesBatchTableModel.WEIGHT); + + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit d009b59733c95f144899fcdd27d1f92a2be55370 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 16:14:30 2016 +0200 Revue des arrondis et amélioration des messages d'erreur lors de l'élvation des poids --- .../catches/BenthosWeightComputingException.java | 109 ++++++++- .../catches/CatchWeightComputingException.java | 30 ++- .../MarineLitterWeightComputingException.java | 28 ++- .../catches/SpeciesWeightComputingException.java | 109 ++++++++- .../service/catches/WeightComputingService.java | 257 +++++++++++---------- .../data/SpeciesBatch-edit-error-validation.xml | 6 +- .../SpeciesBatch-validate-fatal-validation.xml | 2 +- .../resources/i18n/tutti-service_en_GB.properties | 5 + .../resources/i18n/tutti-service_fr_FR.properties | 35 +-- 9 files changed, 432 insertions(+), 149 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java index 3d85185..f869c3a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,111 @@ package fr.ifremer.tutti.service.catches; */ public class BenthosWeightComputingException extends TuttiWeightComputingException { - public BenthosWeightComputingException(String message) { + public static BenthosWeightComputingException forValidationMessage(WeightUnit weightUnit, + String message, + String species, + String categoryLabel, + String categoryValue, + Float weight, + Float sampleCategoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t(message, + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(weight) + unitShortLabel, + weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + ); + throw new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + + } + + public static BenthosWeightComputingException forIncoherentTotalSorted(WeightUnit weightUnit, + Float speciesTotalSortedWeight, + Float speciesTotalComputedSortedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted", + weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, + weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage); + + } + + public static BenthosWeightComputingException forIncoherentParentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float categoryWeight, + Float sum, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(categoryWeight) + unitShortLabel, + weightUnit.fromEntity(sum) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float rowWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(rowWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float categoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(categoryWeight) + unitShortLabel); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static BenthosWeightComputingException forNoWeight(String species, + String categoryLabel, + String categoryValue, + int thisIndex) { + + String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.noWeight", + species, + categoryLabel, + categoryValue); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + + private BenthosWeightComputingException(String message) { super(message); } - public BenthosWeightComputingException(String message, String property, int index) { + private BenthosWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java index 997281a..01519cf 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java @@ -1,5 +1,9 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,7 +11,31 @@ package fr.ifremer.tutti.service.catches; */ public class CatchWeightComputingException extends TuttiWeightComputingException { - public CatchWeightComputingException(String message) { + public static CatchWeightComputingException forIncoherentTotal(WeightUnit weightUnit, + Float totalWeight, + Float computedTotalWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotal", + weightUnit.fromEntity(totalWeight) + unitShortLabel, + weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + return new CatchWeightComputingException(errorMessage); + + } + + public static CatchWeightComputingException forIncoherentTotalWithRejected(WeightUnit weightUnit, + Float totalWeight, + Float computedTotalWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotalWithRejected", + weightUnit.fromEntity(totalWeight) + unitShortLabel, + weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + return new CatchWeightComputingException(errorMessage); + + } + + private CatchWeightComputingException(String message) { super(message); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java index 6c22618..a83a498 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,30 @@ package fr.ifremer.tutti.service.catches; */ public class MarineLitterWeightComputingException extends TuttiWeightComputingException { - public MarineLitterWeightComputingException(String message) { + public static MarineLitterWeightComputingException forNoWeight(int index) { + + String errorMessage = t("tutti.validator.warning.marineLitter.weight.required"); + return new MarineLitterWeightComputingException(errorMessage, MarineLitterBatch.PROPERTY_WEIGHT, index); + + } + + public static MarineLitterWeightComputingException forIncoherentTotal(WeightUnit weightUnit, + Float marineLitterTotalWeight, + Float marineLitterTotalComputedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal", + weightUnit.fromEntity(marineLitterTotalWeight) + unitShortLabel, + weightUnit.fromEntity(marineLitterTotalComputedWeight) + unitShortLabel); + return new MarineLitterWeightComputingException(errorMessage); + + } + + private MarineLitterWeightComputingException(String message) { super(message); } - public MarineLitterWeightComputingException(String message, String property, int index) { + private MarineLitterWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java index 42ba734..4e734cd 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java @@ -1,5 +1,10 @@ package fr.ifremer.tutti.service.catches; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.type.WeightUnit; + +import static org.nuiton.i18n.I18n.t; + /** * Created on 13/04/16. * @@ -7,11 +12,111 @@ package fr.ifremer.tutti.service.catches; */ public class SpeciesWeightComputingException extends TuttiWeightComputingException { - public SpeciesWeightComputingException(String message) { + public static SpeciesWeightComputingException forValidationMessage(WeightUnit weightUnit, + String message, + String species, + String categoryLabel, + String categoryValue, + Float weight, + Float sampleCategoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t(message, + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(weight) + unitShortLabel, + weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + ); + throw new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + + } + + public static SpeciesWeightComputingException forIncoherentTotalSorted(WeightUnit weightUnit, + Float speciesTotalSortedWeight, + Float speciesTotalComputedSortedWeight) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted", + weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, + weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage); + + } + + public static SpeciesWeightComputingException forIncoherentParentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float categoryWeight, + Float sum, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(categoryWeight) + unitShortLabel, + weightUnit.fromEntity(sum) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float rowWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(rowWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, + String species, + String categoryLabel, + String categoryValue, + Float frequencyWeight, + Float categoryWeight, + int thisIndex) { + + String unitShortLabel = weightUnit.getShortLabel(); + String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", + species, + categoryLabel, + categoryValue, + weightUnit.fromEntity(frequencyWeight) + unitShortLabel, + weightUnit.fromEntity(categoryWeight) + unitShortLabel); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + public static SpeciesWeightComputingException forNoWeight(String species, + String categoryLabel, + String categoryValue, + int thisIndex) { + + String errorMessage = t("tutti.service.operations.computeWeights.error.species.noWeight", + species, + categoryLabel, + categoryValue); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } + + + private SpeciesWeightComputingException(String message) { super(message); } - public SpeciesWeightComputingException(String message, String property, int index) { + private SpeciesWeightComputingException(String message, String property, int index) { super(message, property, index); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index 3896b7d..466cfc8 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -45,8 +45,6 @@ import org.nuiton.validator.NuitonValidatorResult; import java.io.Serializable; import java.util.List; -import static org.nuiton.i18n.I18n.t; - /** * @author Kevin Morin - kmorin@codelutin.com * @since 1.3 @@ -117,7 +115,11 @@ public class WeightComputingService extends AbstractTuttiService { catchBatch.setSpeciesTotalSortedComputedWeight(WeightUnit.KG.round(speciesTotalSortedWeight)); } else if (Weights.isSmallerWeight(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); + + throw SpeciesWeightComputingException.forIncoherentTotalSorted(getSpeciesWeightUnit(), + speciesTotalSortedWeight, + speciesTotalComputedSortedWeight); + } catchBatch.setSpeciesTotalUnsortedComputedWeight(WeightUnit.KG.round(speciesTotalComputedUnsortedWeight)); @@ -159,7 +161,12 @@ public class WeightComputingService extends AbstractTuttiService { catchBatch.setBenthosTotalSortedComputedWeight(WeightUnit.KG.round(benthosTotalSortedWeight)); } else if (Weights.isSmallerWeight(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); + + throw BenthosWeightComputingException.forIncoherentTotalSorted( + getBenthosWeightUnit(), + benthosTotalSortedWeight, + benthosTotalComputedSortedWeight); + } catchBatch.setBenthosTotalUnsortedComputedWeight(WeightUnit.KG.round(benthosTotalComputedUnsortedWeight)); @@ -171,8 +178,8 @@ public class WeightComputingService extends AbstractTuttiService { Float marineLitterTotalComputedWeight = 0f; if (rootMarineLitterBatch != null) { - List<MarineLitterBatch> marineLitterBatches = rootMarineLitterBatch.getChildren(); - for (MarineLitterBatch row : marineLitterBatches) { + + for (MarineLitterBatch row : rootMarineLitterBatch.getChildren()) { Float rowWeight = row.getWeight(); if (rowWeight == null) { marineLitterTotalComputedWeight = null; @@ -180,17 +187,24 @@ public class WeightComputingService extends AbstractTuttiService { } marineLitterTotalComputedWeight += rowWeight; } + } if (marineLitterTotalComputedWeight != null) { - catchBatch.setMarineLitterTotalComputedWeight(WeightUnit.KG.round(marineLitterTotalComputedWeight)); + + marineLitterTotalComputedWeight = WeightUnit.KG.round(marineLitterTotalComputedWeight); + catchBatch.setMarineLitterTotalComputedWeight(marineLitterTotalComputedWeight); + } Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); - if (marineLitterTotalWeight == null) { - marineLitterTotalWeight = marineLitterTotalComputedWeight; + if (marineLitterTotalWeight != null + && marineLitterTotalComputedWeight != null + && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { + + throw MarineLitterWeightComputingException.forIncoherentTotal(getMarineLitterWeightUnit(), + marineLitterTotalWeight, + marineLitterTotalComputedWeight); - } else if (marineLitterTotalComputedWeight != null && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { - throw new MarineLitterWeightComputingException(t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal")); } // nothing to do with the marine litter weight, it is an isolated weight @@ -206,8 +220,14 @@ public class WeightComputingService extends AbstractTuttiService { Float rejectedWeight = catchBatch.getCatchTotalRejectedWeight(); if (rejectedWeight == null && totalWeight != null) { - if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight)) { - throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + + Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight); + + if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + + throw CatchWeightComputingException.forIncoherentTotal(getCatchWeightUnit(), + totalWeight, + computedTotalWeight); } @@ -221,8 +241,16 @@ public class WeightComputingService extends AbstractTuttiService { } catchBatch.setCatchTotalComputedWeight(WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)); - } else if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight)) { - throw new CatchWeightComputingException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); + } else { + + Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight); + if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + + throw CatchWeightComputingException.forIncoherentTotalWithRejected(getCatchWeightUnit(), + totalWeight, + computedTotalWeight); + } + } Float totalSortedWeight = totalSortedSortedWeight; @@ -269,21 +297,20 @@ public class WeightComputingService extends AbstractTuttiService { int thisIndex = currentSpeciesRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decorateSpecies(batch.getSpecies()); - String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditSpeciesBatch(batch); if (!validation.isValid()) { + List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new SpeciesWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forValidationMessage( + getSpeciesWeightUnit(), + messages.get(0), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + batch.getWeight(), + batch.getSampleCategoryWeight(), + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -306,15 +333,15 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + + throw SpeciesWeightComputingException.forIncoherentParentCategoryWeight( + getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + categoryWeight, + sum, + thisIndex); } else { sum = categoryWeight; @@ -337,16 +364,13 @@ public class WeightComputingService extends AbstractTuttiService { } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - frequencyWeight, - rowWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forIncoherentRowWeightFrequency(getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + rowWeight, + thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -360,16 +384,13 @@ public class WeightComputingService extends AbstractTuttiService { // weight, then set the weight of the sample if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forIncoherentCategoryWeight(getSpeciesWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + categoryWeight, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -391,14 +412,10 @@ public class WeightComputingService extends AbstractTuttiService { } if (Weights.isNullOrZero(result)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new SpeciesWeightComputingException(t("tutti.service.operations.computeWeights.error.species.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw SpeciesWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + thisIndex); } return WeightUnit.KG.round(result); @@ -423,26 +440,24 @@ public class WeightComputingService extends AbstractTuttiService { } public Float computeBenthosBatch(SpeciesBatch batch) { + Float result = null; int thisIndex = currentBenthosRowIndex++; Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); - String species = decorateSpecies(batch.getSpecies()); - String categoryValue = decorateCategoryValue(batch.getSampleCategoryValue()); NuitonValidatorResult validation = validationService.validateEditBenthosBatch(batch); if (!validation.isValid()) { List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new BenthosWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forValidationMessage(getBenthosWeightUnit(), + messages.get(0), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + batch.getWeight(), + batch.getSampleCategoryWeight(), + thisIndex); } List<SpeciesBatch> children = batch.getChildBatchs(); @@ -465,16 +480,14 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(sum); } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + + throw BenthosWeightComputingException.forIncoherentParentCategoryWeight(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + categoryWeight, + sum, + thisIndex); } else { sum = categoryWeight; @@ -498,17 +511,13 @@ public class WeightComputingService extends AbstractTuttiService { } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - rowWeight, - categoryWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forIncoherentRowWeightFrequency(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + rowWeight, + categoryWeight, + thisIndex); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -522,16 +531,13 @@ public class WeightComputingService extends AbstractTuttiService { // weight, then set the weight of the sample if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forIncoherentCategoryWeight(getBenthosWeightUnit(), + decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + frequencyWeight, + categoryWeight, + thisIndex); } else if (rowWeight == null) { batch.setComputedWeight(frequencyWeight); @@ -552,35 +558,29 @@ public class WeightComputingService extends AbstractTuttiService { } if (Weights.isNullOrZero(result)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new BenthosWeightComputingException(t("tutti.service.operations.computeWeights.error.benthos.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); + throw BenthosWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), + getCategoryLabel(batch.getSampleCategoryId()), + decorateCategoryValue(batch.getSampleCategoryValue()), + thisIndex); } return WeightUnit.KG.round(result); } - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, Float marineLitterweight) { + public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(Integer fishingOperationId, Float marineLitterWeight) { BatchContainer<MarineLitterBatch> rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); if (rootMarineLitterBatch != null) { - boolean checkWeight = marineLitterweight == null; + boolean checkWeight = marineLitterWeight == null; List<MarineLitterBatch> children = rootMarineLitterBatch.getChildren(); for (int i = 0; i < children.size(); i++) { MarineLitterBatch batch = children.get(i); if (checkWeight && Weights.isNullOrZero(batch.getWeight())) { - throw new MarineLitterWeightComputingException(t("tutti.validator.warning.marineLitter.weight.required"), - MarineLitterBatch.PROPERTY_WEIGHT, - i); + throw MarineLitterWeightComputingException.forNoWeight(i); } } } @@ -595,9 +595,8 @@ public class WeightComputingService extends AbstractTuttiService { Float speciesTotalComputedUnsortedWeight = 0f; for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { - Float weight = Numbers.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); + Float weight = Numbers.getValueOrComputedValue(speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); if (weight == null) { break; } @@ -659,4 +658,20 @@ public class WeightComputingService extends AbstractTuttiService { return decoratorService.getDecorator(sampleCategoryValue).toString(sampleCategoryValue); } + private WeightUnit getSpeciesWeightUnit() { + return context.getConfig().getSpeciesWeightUnit(); + } + + private WeightUnit getBenthosWeightUnit() { + return context.getConfig().getBenthosWeightUnit(); + } + + private WeightUnit getMarineLitterWeightUnit() { + return context.getConfig().getMarineLitterWeightUnit(); + } + + private WeightUnit getCatchWeightUnit() { + return WeightUnit.KG; + } + } diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml index 4d96b89..fdffdbe 100644 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml +++ b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-edit-error-validation.xml @@ -30,7 +30,7 @@ <field name="species"> <field-validator type="required" short-circuit="true"> - <message>tutti.validator.error.speciesBatch.species.required</message> + <message>tutti.validator.error.speciesOrBenthosBatch.species.required</message> </field-validator> </field> @@ -39,14 +39,14 @@ <param name="expression"> <![CDATA[ !(sampleCategoryWeight == null && weight != null) ]]> </param> - <message>tutti.service.operations.computeWeights.error.species.incoherentRowWeightCategory</message> + <message>tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory</message> </field-validator> <field-validator type="fieldexpression" short-circuit="true"> <param name="expression"> <![CDATA[ weight == null || sampleCategoryWeight == null || weight <= sampleCategoryWeight ]]> </param> - <message>tutti.service.operations.computeWeights.error.species.incoherentSampleWeight</message> + <message>tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight</message> </field-validator> </field> diff --git a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml index b955bc7..c6e014f 100644 --- a/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml +++ b/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-validate-fatal-validation.xml @@ -31,7 +31,7 @@ <field name="species"> <field-validator type="temporaryReferential" short-circuit="true"> - <message>tutti.validator.error.speciesBatch.species.temporary</message> + <message>tutti.validator.error.speciesOrBenthosBatch.species.temporary</message> </field-validator> </field> diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index 67f5130..1f0e6be 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -308,6 +308,7 @@ tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted= tutti.service.operations.computeWeights.error.benthos.noWeight= tutti.service.operations.computeWeights.error.incoherentRowWeightCategory= tutti.service.operations.computeWeights.error.incoherentTotal= +tutti.service.operations.computeWeights.error.incoherentTotalWithRejected= tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal= tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight= tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight= @@ -316,6 +317,8 @@ tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequen tutti.service.operations.computeWeights.error.species.incoherentSampleWeight= tutti.service.operations.computeWeights.error.species.incoherentTotalSorted= tutti.service.operations.computeWeights.error.species.noWeight= +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory= +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight= tutti.service.operations.computeWeights.error.totalLessThanSortedAndUnsorted= tutti.service.operations.exportCatchesReport.error= tutti.service.operations.exportCatchesReport.specialRows.benthos.code= @@ -535,6 +538,8 @@ tutti.validator.error.protocol.name.required= tutti.validator.error.speciesBatch.species.required= tutti.validator.error.speciesBatch.species.temporary= tutti.validator.error.speciesBatch.vessel.temporary= +tutti.validator.error.speciesOrBenthosBatch.species.required= +tutti.validator.error.speciesOrBenthosBatch.species.temporary= tutti.validator.export.message.error= tutti.validator.export.message.warning= tutti.validator.export.operation= diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index 379dddf..1009323 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -259,27 +259,28 @@ tutti.service.multipost.import.wrongOperation.error=Opération est impossible<hr tutti.service.multipost.import.wrongSpecies.error=Espèce impossible<hr/>Les lots que vous essayez d'importer proviennent d'un autre lot \:<br/>%s tutti.service.multipost.uncompress.error=Erreur lors de la décompression de l'archive %s tutti.service.operations.cleanWeights.benthos.batch=Lot benthos -tutti.service.operations.cleanWeights.error.redundant.frequencyWeight=Le poids (%s%s) du <strong>sous-échantillon</strong> vaut la somme des poids des <strong>échantillons mesurés</strong> -tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight=Le poids (%s%s) de la catégorie <strong>%s</strong> vaut celui de la catégorie supérieure <strong>%s</strong> -tutti.service.operations.cleanWeights.error.redundant.weight=Le poids (%s%s) de <strong>sous-échantillon</strong> vaut celui de la plus fine catégorie <strong>%s</strong> +tutti.service.operations.cleanWeights.error.redundant.frequencyWeight=Le poids (%s) du <strong>sous-échantillon</strong> vaut la somme des poids des <strong>échantillons mesurés</strong> +tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight=Le poids (%s) de la catégorie <strong>%s</strong> vaut celui de la catégorie supérieure <strong>%s</strong> +tutti.service.operations.cleanWeights.error.redundant.weight=Le poids (%s) de <strong>sous-échantillon</strong> vaut celui de la plus fine catégorie <strong>%s</strong> tutti.service.operations.cleanWeights.species.batch=Lot espèce -tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%skg) est supérieur au poids de la catégorie (%skg) -tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight=Benthos - Le poids du lot de %s/%s - %s (%skg) est inférieur à la somme des poids de ses sous-catégories (%skg) +tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%s) est supérieur au poids de la catégorie (%s) +tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight=Benthos - Le poids du lot de %s/%s - %s (%s) est inférieur à la somme des poids de ses sous-catégories (%s) tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%skg) est différent du poids du sous-échantillon (%skg) +tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency=Benthos - Le poids total des mensurations du lot de %s/%s - %s (%s) est différent du poids du sous-échantillon (%s) tutti.service.operations.computeWeights.error.benthos.incoherentSampleWeight=Benthos - Le poids de sous-échantillon du lot %s/%s - %s (%skg) est supérieur au poids du lot (%skg) -tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted=Le poids total Vrac du benthos est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié +tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted=Le poids total Vrac du benthos (%s) est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié (%s) tutti.service.operations.computeWeights.error.benthos.noWeight=Benthos - Le lot de %s/%s - %s n'a pas de poids ou un poids de 0 tutti.service.operations.computeWeights.error.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.incoherentTotal=Le poids total de la capture ne correspond pas à la somme des poids totaux Vrac et Hors Vrac -tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal=Le poids total des macro-déchets est inférieur à la somme des poids des macro-déchets saisis -tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%skg) est supérieur au poids de la catégorie (%skg) -tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight=Espèces - Le poids du lot de %s/%s - %s (%skg) est inférieur à la somme des poids de ses sous-catégories (%skg) -tutti.service.operations.computeWeights.error.species.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. -tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%skg) est différent du poids du sous-échantillon (%skg) -tutti.service.operations.computeWeights.error.species.incoherentSampleWeight=Espèces - Le poids de sous-échantillon du lot %s/%s - %s (%skg) est supérieur au poids du lot (%skg) -tutti.service.operations.computeWeights.error.species.incoherentTotalSorted=Le poids total Vrac des espèces est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié +tutti.service.operations.computeWeights.error.incoherentTotal=Le poids total de la capture (%s) ne correspond pas à la somme des poids totaux Vrac et Hors Vrac (%s) +tutti.service.operations.computeWeights.error.incoherentTotalWithRejected=Le poids total de la capture (%s) ne correspond pas à la somme des poids totaux Vrac et Hors Vrac et du rejeté (%s) +tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal=Le poids total des macro-déchets (%s) est inférieur à la somme des poids des macro-déchets saisis (%s) +tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%s) est supérieur au poids de la catégorie (%s) +tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight=Espèces - Le poids du lot de %s/%s - %s (%s) est inférieur à la somme des poids de ses sous-catégories (%s) +tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency=Espèces - Le poids total des mensurations du lot de %s/%s - %s (%s) est différent du poids du sous-échantillon (%s) +tutti.service.operations.computeWeights.error.species.incoherentTotalSorted=Le poids total Vrac des espèces (%s) est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié (%s) tutti.service.operations.computeWeights.error.species.noWeight=Espèces - Le lot de %s/%s/%s n'a pas de poids ou un poids de 0 +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentRowWeightCategory=Le poids de sous-échantillon est renseigné alors que le lot n'a pas de poids. +tutti.service.operations.computeWeights.error.speciesOrBenthos.incoherentSampleWeight=Le poids de sous-échantillon du lot %s/%s - %s (%s) est supérieur au poids du lot (%s) tutti.service.operations.computeWeights.error.totalLessThanSortedAndUnsorted=Le poids total de la capture est inférieur à la somme des poids total Vrac et Hors Vrac. tutti.service.operations.exportCatchesReport.error=Erreur lors de la génération du rapport des captures tutti.service.operations.exportCatchesReport.specialRows.benthos.code=BENTHOS @@ -474,8 +475,8 @@ tutti.validator.error.program.name.required=Le nom de la série est obligatoire tutti.validator.error.program.zone.required=La zone de la série est obligatoire tutti.validator.error.protocol.name.alreadyUsed=Le nom du protocole est déjà utilisé tutti.validator.error.protocol.name.required=Le nom du protocole est obligatoire -tutti.validator.error.speciesBatch.species.required=L'espèce est obligatoire -tutti.validator.error.speciesBatch.species.temporary=La capture Espèce utilise une espèce temporaire +tutti.validator.error.speciesOrBenthosBatch.species.required=L'espèce est obligatoire +tutti.validator.error.speciesOrBenthosBatch.species.temporary=La capture utilise une espèce temporaire tutti.validator.export.message.error=\t- [ERREUR] %s tutti.validator.export.message.warning=\t- [WARNING] %s tutti.validator.export.operation=* %s \: -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit eeda20b0fdc2df798d0707ca74db9b767c565cf1 Author: Tony CHEMIT <chemit@codelutin.com> Date: Wed Apr 13 16:45:10 2016 +0200 correction de la comparaison des unités (See #8151) --- tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java index 2ff329d..5ec1a8d 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java @@ -91,10 +91,10 @@ public class Weights { public static int compareRawWeights(float v0, float v1) { float delta = v0 - v1; int result; - if (delta > 0.00001) { + if (delta > 0.00001f) { // v0 > v1 result = 1; - } else if (delta < -0.0001f) { + } else if (delta < -0.00001f) { // v0 < v1 result = -1; } else { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 052b8db713f41679a76955c6cc2d5cc47cb81d8e Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:37:53 2016 +0200 Revue de l'API des WeightUnits pour ne plus utiliser Weights (trop d'incertitude sur l'unité utilisée) --- .../java/fr/ifremer/tutti/type/WeightUnit.java | 77 ++++++++++++- .../main/java/fr/ifremer/tutti/util/Weights.java | 127 +++++---------------- 2 files changed, 101 insertions(+), 103 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java index 9849fdf..39cd373 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/type/WeightUnit.java @@ -25,6 +25,8 @@ package fr.ifremer.tutti.type; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; +import java.util.Comparator; +import java.util.Objects; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -37,9 +39,9 @@ import static org.nuiton.i18n.I18n.t; * @author Tony Chemit - chemit@codelutin.com * @since 3.2 */ -public enum WeightUnit { +public enum WeightUnit implements Comparator<Float> { - G(n("application.common.unit.g"), n("application.common.unit.short.g"), 1, "\\d{0,8}(\\.\\d{0,1})?") { + G(n("application.common.unit.g"), n("application.common.unit.short.g"), 1, "\\d{0,8}(\\.\\d{0,1})?", 0.01f) { @Override public Float fromEntity(Float weight) { return weight == null ? null : weight * 1000; @@ -51,7 +53,7 @@ public enum WeightUnit { } }, - KG(n("application.common.unit.kg"), n("application.common.unit.short.kg"), 4, "\\d{0,6}(\\.\\d{0,4})?") { + KG(n("application.common.unit.kg"), n("application.common.unit.short.kg"), 4, "\\d{0,6}(\\.\\d{0,4})?", 0.00001f) { @Override public Float fromEntity(Float weight) { return weight; @@ -72,13 +74,16 @@ public enum WeightUnit { private final String numberEditorPattern; + private final float rawPrecision; + private final DecimalFormat decimalFormat; - WeightUnit(String i18nKey, String i18nShortKey, int numberDigits, String numberEditorPattern) { + WeightUnit(String i18nKey, String i18nShortKey, int numberDigits, String numberEditorPattern, float rawPrecision) { this.i18nKey = i18nKey; this.i18nShortKey = i18nShortKey; this.numberDigits = numberDigits; this.numberEditorPattern = numberEditorPattern; + this.rawPrecision = rawPrecision; DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); symbols.setGroupingSeparator(' '); @@ -89,6 +94,28 @@ public enum WeightUnit { this.decimalFormat.setMaximumFractionDigits(numberDigits); } + @Override + public int compare(Float v0, Float v1) { + + Objects.requireNonNull(v0, "can not compare null weights"); + Objects.requireNonNull(v1, "can not compare null weights"); + + float delta = round(v0) - round(v1); + int result; + if (delta > rawPrecision) { + // v0 > v1 + result = 1; + } else if (delta < -rawPrecision) { + // v0 < v1 + result = -1; + } else { + // v0 == v1 + result = 0; + } + return result; + + } + public String getLabel() { return t(i18nKey); } @@ -139,7 +166,7 @@ public enum WeightUnit { } else { BigDecimal sumB = new BigDecimal(String.valueOf(weight)) - .setScale(getNumberDigits()+1, BigDecimal.ROUND_HALF_UP) + .setScale(numberDigits, BigDecimal.ROUND_HALF_UP) .abs(); result = sumB.floatValue(); } @@ -150,8 +177,48 @@ public enum WeightUnit { return String.format("%s (%s)", label, getShortLabel()); } + public String renderFromEntityWithShortLabel(float o) { + return round(fromEntity(o)) + getShortLabel(); + } + public String decorateTip(String tip) { String unit = t("application.common.unit"); return String.format("%s (%s %s)", tip, unit, getLabel()); } + + public boolean isNullOrZero(Float o) { + return o == null || isZero(o); + } + + public boolean isNotNullNorZero(Float o) { + return o != null && !isZero(o); + } + + public boolean isEquals(float o1, float o2) { + return compare(o1, o2) == 0; + } + + public boolean isZero(float o) { + return isEquals(o, 0f); + } + + public boolean isNotEquals(float o1, float o2) { + return compare(o1, o2) != 0; + } + + public boolean isSmallerThan(float o1, float o2) { + return compare(o1, o2) < 0; + } + + public boolean isGreaterThan(float o1, float o2) { + return compare(o1, o2) > 0; + } + + public boolean isGreaterThanZero(float o) { + return isGreaterThan(o, 0f); + } + + public boolean isSmallerThanZero(float o) { + return isSmallerThan(o, 0f); + } } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java index 5ec1a8d..95c3675 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/util/Weights.java @@ -27,8 +27,6 @@ package fr.ifremer.tutti.util; import fr.ifremer.tutti.persistence.entities.protocol.Rtp; import fr.ifremer.tutti.type.WeightUnit; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; import java.util.Objects; /** @@ -39,102 +37,35 @@ import java.util.Objects; */ public class Weights { - private static DecimalFormatSymbols symbols; - - private static DecimalFormat decimalFormat; - - public static DecimalFormatSymbols getDecimalFormatSymbols() { - if (symbols == null) { - symbols = new DecimalFormatSymbols(); - symbols.setDecimalSeparator('.'); - symbols.setGroupingSeparator(' '); - } - return symbols; - } - - public static DecimalFormat getDecimalFormat(int minDecimal, int maxDecimal) { - if (decimalFormat == null) { - decimalFormat = new DecimalFormat(); - decimalFormat.setDecimalFormatSymbols(getDecimalFormatSymbols()); - decimalFormat.setGroupingUsed(false); - } - decimalFormat.setMinimumFractionDigits(minDecimal); - decimalFormat.setMaximumFractionDigits(maxDecimal); - return decimalFormat; - } - - public static String getWeightStringValue(Float weight) { - String textValue; - if (weight != null) { - DecimalFormat weightDecimalFormat = getDecimalFormat(1, 3); - textValue = weightDecimalFormat.format(weight); - - } else { - textValue = ""; - } - return textValue; - } - - /** - * Compare two weights with rounding them to kilograms. - * - * @param v0 first weight to compare - * @param v1 second weight to compare - * @return 1 if v0 > v1, -1 if v0 < v1, 0 if v0 == v1 - */ - public static int compareWeights(float v0, float v1) { - v0 = WeightUnit.KG.round(v0); - v1 = WeightUnit.KG.round(v1); - return compareRawWeights(v0, v1); - } - - public static int compareRawWeights(float v0, float v1) { - float delta = v0 - v1; - int result; - if (delta > 0.00001f) { - // v0 > v1 - result = 1; - } else if (delta < -0.00001f) { - // v0 < v1 - result = -1; - } else { - // v0 == v1 - result = 0; - } - return result; - } - - public static boolean isSmallerWeight(float v0, float v1) { - return compareWeights(v0, v1) < 0; - } - - public static boolean isGreaterWeight(float v0, float v1) { - return compareWeights(v0, v1) > 0; - } - - public static boolean isPositive(float weight) { - return compareRawWeights(weight, 0.0f) >= 0; - } - - public static boolean isEqualWeight(float v0, float v1) { - return compareWeights(v0, v1) == 0; - } - - public static boolean isNotEqualWeight(float v0, float v1) { - return compareWeights(v0, v1) != 0; - } - - public static boolean isNullOrZero(Float weight) { - return weight == null || compareRawWeights(weight, 0.0f) == 0; - } - - public static boolean isNotZero(float weight) { - return compareRawWeights(weight, 0.0f) != 0; - } - - public static boolean isNotNullNorZero(Float number) { - return number != null && Weights.isNotZero(number); - } +// private static DecimalFormat decimalFormat; + +// public static DecimalFormat getDecimalFormat(int minDecimal, int maxDecimal) { +// if (decimalFormat == null) { +// decimalFormat = new DecimalFormat(); +// +// DecimalFormatSymbols symbols = new DecimalFormatSymbols(); +// symbols.setDecimalSeparator('.'); +// symbols.setGroupingSeparator(' '); +// +// decimalFormat.setDecimalFormatSymbols(symbols); +// decimalFormat.setGroupingUsed(false); +// } +// decimalFormat.setMinimumFractionDigits(minDecimal); +// decimalFormat.setMaximumFractionDigits(maxDecimal); +// return decimalFormat; +// } + +// public static String getWeightStringValue(Float weight) { +// String textValue; +// if (weight != null) { +// DecimalFormat weightDecimalFormat = getDecimalFormat(1, 3); +// textValue = weightDecimalFormat.format(weight); +// +// } else { +// textValue = ""; +// } +// return textValue; +// } /** * Calcul du poids <strong>(en gramme)</strong> à partir de la classe de taille et d'une définition de -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 0652ce95303ad072ad0cc2d9516385587f313aae Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:40:58 2016 +0200 Nettoyage sur le service de nettoyage de poids + dernière revue des exceptions du service d'élévation --- .../catches/BenthosWeightComputingException.java | 31 ++- .../catches/CatchWeightComputingException.java | 10 +- .../MarineLitterWeightComputingException.java | 5 +- .../catches/SpeciesWeightComputingException.java | 31 ++- .../service/catches/WeightCleaningService.java | 294 +++++++++------------ .../service/catches/WeightComputingService.java | 35 ++- 6 files changed, 175 insertions(+), 231 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java index f869c3a..c964f21 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/BenthosWeightComputingException.java @@ -21,15 +21,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float sampleCategoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t(message, species, categoryLabel, categoryValue, - weightUnit.fromEntity(weight) + unitShortLabel, - weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + weightUnit.renderFromEntityWithShortLabel(weight), + weightUnit.renderFromEntityWithShortLabel(sampleCategoryWeight) ); - throw new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } @@ -37,10 +36,9 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float speciesTotalSortedWeight, Float speciesTotalComputedSortedWeight) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted", - weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, - weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(speciesTotalSortedWeight), + weightUnit.renderFromEntityWithShortLabel(speciesTotalComputedSortedWeight)); return new BenthosWeightComputingException(errorMessage); } @@ -53,14 +51,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float sum, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", species, categoryLabel, categoryValue, - weightUnit.fromEntity(categoryWeight) + unitShortLabel, - weightUnit.fromEntity(sum) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(categoryWeight), + weightUnit.renderFromEntityWithShortLabel(sum)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, @@ -71,14 +69,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float rowWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", species, categoryLabel, categoryValue, - weightUnit.fromEntity(frequencyWeight) + unitShortLabel, - weightUnit.fromEntity(rowWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(rowWeight)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, @@ -89,14 +87,14 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti Float categoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", species, categoryLabel, categoryValue, - weightUnit.fromEntity(frequencyWeight) + unitShortLabel, - weightUnit.fromEntity(categoryWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(categoryWeight)); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static BenthosWeightComputingException forNoWeight(String species, @@ -109,6 +107,7 @@ public class BenthosWeightComputingException extends TuttiWeightComputingExcepti categoryLabel, categoryValue); return new BenthosWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java index 01519cf..5fc498d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/CatchWeightComputingException.java @@ -15,10 +15,9 @@ public class CatchWeightComputingException extends TuttiWeightComputingException Float totalWeight, Float computedTotalWeight) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotal", - weightUnit.fromEntity(totalWeight) + unitShortLabel, - weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(totalWeight), + weightUnit.renderFromEntityWithShortLabel(computedTotalWeight)); return new CatchWeightComputingException(errorMessage); } @@ -27,10 +26,9 @@ public class CatchWeightComputingException extends TuttiWeightComputingException Float totalWeight, Float computedTotalWeight) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.incoherentTotalWithRejected", - weightUnit.fromEntity(totalWeight) + unitShortLabel, - weightUnit.fromEntity(computedTotalWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(totalWeight), + weightUnit.renderFromEntityWithShortLabel(computedTotalWeight)); return new CatchWeightComputingException(errorMessage); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java index a83a498..658cefb 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/MarineLitterWeightComputingException.java @@ -23,10 +23,9 @@ public class MarineLitterWeightComputingException extends TuttiWeightComputingEx Float marineLitterTotalWeight, Float marineLitterTotalComputedWeight) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal", - weightUnit.fromEntity(marineLitterTotalWeight) + unitShortLabel, - weightUnit.fromEntity(marineLitterTotalComputedWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(marineLitterTotalWeight) , + weightUnit.renderFromEntityWithShortLabel(marineLitterTotalComputedWeight) ); return new MarineLitterWeightComputingException(errorMessage); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java index 4e734cd..c748824 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/SpeciesWeightComputingException.java @@ -21,15 +21,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float sampleCategoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t(message, species, categoryLabel, categoryValue, - weightUnit.fromEntity(weight) + unitShortLabel, - weightUnit.fromEntity(sampleCategoryWeight) + unitShortLabel + weightUnit.renderFromEntityWithShortLabel(weight), + weightUnit.renderFromEntityWithShortLabel(sampleCategoryWeight) ); - throw new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); } @@ -37,10 +36,9 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float speciesTotalSortedWeight, Float speciesTotalComputedSortedWeight) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted", - weightUnit.fromEntity(speciesTotalSortedWeight) + unitShortLabel, - weightUnit.fromEntity(speciesTotalComputedSortedWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(speciesTotalSortedWeight), + weightUnit.renderFromEntityWithShortLabel(speciesTotalComputedSortedWeight)); return new SpeciesWeightComputingException(errorMessage); } @@ -53,14 +51,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float sum, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", species, categoryLabel, categoryValue, - weightUnit.fromEntity(categoryWeight) + unitShortLabel, - weightUnit.fromEntity(sum) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(categoryWeight), + weightUnit.renderFromEntityWithShortLabel(sum)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit, @@ -71,14 +69,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float rowWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", species, categoryLabel, categoryValue, - weightUnit.fromEntity(frequencyWeight) + unitShortLabel, - weightUnit.fromEntity(rowWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(rowWeight)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit, @@ -89,14 +87,14 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti Float categoryWeight, int thisIndex) { - String unitShortLabel = weightUnit.getShortLabel(); String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", species, categoryLabel, categoryValue, - weightUnit.fromEntity(frequencyWeight) + unitShortLabel, - weightUnit.fromEntity(categoryWeight) + unitShortLabel); + weightUnit.renderFromEntityWithShortLabel(frequencyWeight), + weightUnit.renderFromEntityWithShortLabel(categoryWeight)); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } public static SpeciesWeightComputingException forNoWeight(String species, @@ -109,6 +107,7 @@ public class SpeciesWeightComputingException extends TuttiWeightComputingExcepti categoryLabel, categoryValue); return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex); + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java index 92f8ef4..9207121 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightCleaningService.java @@ -24,10 +24,7 @@ package fr.ifremer.tutti.service.catches; import com.google.common.base.Preconditions; import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; @@ -40,13 +37,13 @@ import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.type.WeightUnit; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import static fr.ifremer.tutti.service.PersistenceService.FrequencyFunction; @@ -62,8 +59,7 @@ import static org.nuiton.i18n.I18n.t; */ public class WeightCleaningService extends AbstractTuttiService { - private static final Log log = - LogFactory.getLog(WeightCleaningService.class); + private static final Log log = LogFactory.getLog(WeightCleaningService.class); protected PersistenceService persistenceService; @@ -97,53 +93,52 @@ public class WeightCleaningService extends AbstractTuttiService { benthosBatchPrefix = t("tutti.service.operations.cleanWeights.benthos.batch"); } - /** - * Check if there is some redundant weights that could be cleaned. - * - * If no warning found, then return is a empty map, otherwise all errors - * for any bad fishing operation. - * - * Result keys are fishing operation id, values are all batches in error for - * the fishing operation. - * - * @param cruiseId id of the cruise to check. - * @return map of warnings, or empty map if no error found. - */ - public Map<Integer, String> checkCruise(Integer cruiseId) { - - if (log.isDebugEnabled()) { - log.debug("Will check cruise: " + cruiseId); - } - - Map<Integer, String> result = Maps.newLinkedHashMap(); - - List<FishingOperation> allFishingOperation = - persistenceService.getAllFishingOperation(cruiseId); - - for (FishingOperation fishingOperation : allFishingOperation) { - - Integer fishingOperationId = fishingOperation.getIdAsInt(); - - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); - - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperation + - " since no catchBatch associated."); - } - continue; - } - - Multimap<String, String> errors = checkFishingOperation(fishingOperationId); - - if (!errors.isEmpty()) { - result.put(fishingOperationId, errorsToString(errors)); - } - } - return result; - } +// /** +// * Check if there is some redundant weights that could be cleaned. +// * +// * If no warning found, then return is a empty map, otherwise all errors +// * for any bad fishing operation. +// * +// * Result keys are fishing operation id, values are all batches in error for +// * the fishing operation. +// * +// * @param cruiseId id of the cruise to check. +// * @return map of warnings, or empty map if no error found. +// */ +// public Map<Integer, String> checkCruise(Integer cruiseId) { +// +// if (log.isDebugEnabled()) { +// log.debug("Will check cruise: " + cruiseId); +// } +// +// Map<Integer, String> result = new LinkedHashMap<>(); +// +// List<FishingOperation> allFishingOperation = +// persistenceService.getAllFishingOperation(cruiseId); +// +// for (FishingOperation fishingOperation : allFishingOperation) { +// +// Integer fishingOperationId = fishingOperation.getIdAsInt(); +// +// boolean withCatchBatch = +// persistenceService.isFishingOperationWithCatchBatch( +// fishingOperationId); +// +// if (!withCatchBatch) { +// if (log.isWarnEnabled()) { +// log.warn("Skip fishing operation " + fishingOperation + " since no catchBatch associated."); +// } +// continue; +// } +// +// Multimap<String, String> errors = checkFishingOperation(fishingOperationId); +// +// if (!errors.isEmpty()) { +// result.put(fishingOperationId, errorsToString(errors)); +// } +// } +// return result; +// } public String errorsToString(Multimap<String, String> errors) { StringBuilder errorsStr = new StringBuilder("<ul style=\"font-size:11\">"); @@ -170,22 +165,21 @@ public class WeightCleaningService extends AbstractTuttiService { return errorsStr.toString(); } - /** - * Clean all redundant weights for the given cruise. - * - * @param cruiseId id of the cruise to clean. - */ - public void cleanCruise(Integer cruiseId) { - - if (log.isDebugEnabled()) { - log.debug("Will clean cruise: " + cruiseId); - } - - List<Integer> allFishingOperation = - persistenceService.getAllFishingOperationIds(cruiseId); - - allFishingOperation.forEach(this::cleanFishingOperation); - } +// /** +// * Clean all redundant weights for the given cruise. +// * +// * @param cruiseId id of the cruise to clean. +// */ +// public void cleanCruise(Integer cruiseId) { +// +// if (log.isDebugEnabled()) { +// log.debug("Will clean cruise: " + cruiseId); +// } +// +// List<Integer> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); +// +// allFishingOperation.forEach(this::cleanFishingOperation); +// } /** * Check for some redundant weights in species or benthos batches of @@ -201,33 +195,26 @@ public class WeightCleaningService extends AbstractTuttiService { } Multimap<String, String> result = LinkedHashMultimap.create(); - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); if (withCatchBatch) { // check species batches - BatchContainer<SpeciesBatch> speciesBatch = - persistenceService.getRootSpeciesBatch( - fishingOperationId, true); + BatchContainer<SpeciesBatch> speciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, true); for (SpeciesBatch batch : speciesBatch.getChildren()) { - checkBatch( - speciesBatchPrefix, - speciesWeightUnit, - batch, - result, - speciesFrequencyFunction); + checkBatch(speciesBatchPrefix, + speciesWeightUnit, + batch, + result, + speciesFrequencyFunction); } // check benthos batches - BatchContainer<SpeciesBatch> benthosBatch = - persistenceService.getRootBenthosBatch( - fishingOperationId, true); + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, true); for (SpeciesBatch batch : benthosBatch.getChildren()) { @@ -237,13 +224,13 @@ public class WeightCleaningService extends AbstractTuttiService { result, benthosFrequencyFunction); } + } else { // no catch, no check if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); } } @@ -263,9 +250,7 @@ public class WeightCleaningService extends AbstractTuttiService { log.debug("Will clean fishingOperation: " + fishingOperationId); } - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); + boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId); boolean result = false; @@ -273,10 +258,8 @@ public class WeightCleaningService extends AbstractTuttiService { // clean species batches - Set<SpeciesBatch> speciesToSave = Sets.newHashSet(); - BatchContainer<SpeciesBatch> speciesBatch = - persistenceService.getRootSpeciesBatch( - fishingOperationId, true); + Set<SpeciesBatch> speciesToSave = new HashSet<>(); + BatchContainer<SpeciesBatch> speciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, true); for (SpeciesBatch batch : speciesBatch.getChildren()) { @@ -289,10 +272,8 @@ public class WeightCleaningService extends AbstractTuttiService { // clean benthos batches - Set<SpeciesBatch> benthosToSave = Sets.newHashSet(); - BatchContainer<SpeciesBatch> benthosBatch = - persistenceService.getRootBenthosBatch( - fishingOperationId, true); + Set<SpeciesBatch> benthosToSave = new HashSet<>(); + BatchContainer<SpeciesBatch> benthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, true); for (SpeciesBatch batch : benthosBatch.getChildren()) { @@ -309,8 +290,7 @@ public class WeightCleaningService extends AbstractTuttiService { result = true; - FishingOperation fishingOperation = - persistenceService.getFishingOperation(fishingOperationId); + FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId); for (SpeciesBatch toSave : speciesToSave) { toSave.setFishingOperation(fishingOperation); @@ -328,8 +308,7 @@ public class WeightCleaningService extends AbstractTuttiService { // no catch, no clean if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); + log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated."); } } @@ -337,11 +316,7 @@ public class WeightCleaningService extends AbstractTuttiService { } - protected void checkBatch(String batchPrefix, - WeightUnit weightUnit, - SpeciesBatch batch, - Multimap<String, String> result, - FrequencyFunction frequencyFunction) { + protected void checkBatch(String batchPrefix, WeightUnit weightUnit, SpeciesBatch batch, Multimap<String, String> result, FrequencyFunction frequencyFunction) { if (!batch.isChildBatchsEmpty()) { @@ -350,17 +325,7 @@ public class WeightCleaningService extends AbstractTuttiService { // check batch sample category weight (before childs) String message = checkSampleCategoryWeightRedundant(weightUnit, batch, childBatch); - - if (message != null) { - - String label = getBatchLabel(batchPrefix, weightUnit, childBatch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, childBatch, result); // check childs checkBatch(batchPrefix, weightUnit, childBatch, result, frequencyFunction); @@ -369,30 +334,12 @@ public class WeightCleaningService extends AbstractTuttiService { { // check batch weight String message = checkWeightRedundant(weightUnit, batch); - - if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, batch, result); } { // check batch frequencies weight String message = checkFrequencyWeightRedundant(weightUnit, batch, frequencyFunction); - - if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } - if (!result.containsEntry(label, message)) { - result.put(label, message); - } - } + addMessageIfNotExist(message, batchPrefix, weightUnit, batch, result); } } } @@ -417,10 +364,7 @@ public class WeightCleaningService extends AbstractTuttiService { if (message != null) { // always clean batch after cleaning childs - String label = getBatchLabel(batchPrefix, weightUnit, childBatch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, childBatch); batch.setSampleCategoryWeight(null); result.add(batch); } @@ -433,10 +377,7 @@ public class WeightCleaningService extends AbstractTuttiService { String message = checkFrequencyWeightRedundant(weightUnit, batch, frequencyFunction); if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, batch); removeWeight = true; } @@ -446,10 +387,7 @@ public class WeightCleaningService extends AbstractTuttiService { String message = checkWeightRedundant(weightUnit, batch); if (message != null) { - String label = getBatchLabel(batchPrefix, weightUnit, batch); - if (log.isInfoEnabled()) { - log.info(label + " " + message); - } + buildLabelAndLogMessage(message, batchPrefix, weightUnit, batch); removeWeight = true; } } @@ -461,11 +399,10 @@ public class WeightCleaningService extends AbstractTuttiService { result.add(batch); } } + } - protected String checkSampleCategoryWeightRedundant(WeightUnit weightUnit, - SpeciesBatch parentBatch, - SpeciesBatch batch) { + protected String checkSampleCategoryWeightRedundant(WeightUnit weightUnit, SpeciesBatch parentBatch, SpeciesBatch batch) { Preconditions.checkNotNull(parentBatch); @@ -475,12 +412,10 @@ public class WeightCleaningService extends AbstractTuttiService { Float sampleCategoryWeight = batch.getSampleCategoryWeight(); Float parentSampleCategoryWeight = parentBatch.getSampleCategoryWeight(); - if (sampleCategoryWeight != null && parentSampleCategoryWeight != null && - Weights.isEqualWeight(parentSampleCategoryWeight, sampleCategoryWeight)) { + if (sampleCategoryWeight != null && parentSampleCategoryWeight != null && WeightUnit.KG.isEquals(parentSampleCategoryWeight, sampleCategoryWeight)) { result = t("tutti.service.operations.cleanWeights.error.redundant.sampleCategoryWeight", - weightUnit.fromEntity(sampleCategoryWeight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(sampleCategoryWeight) + weightUnit.getShortLabel(), getCategoryLabel(batch), getCategoryLabel(parentBatch) ); @@ -503,13 +438,11 @@ public class WeightCleaningService extends AbstractTuttiService { // check if there is some frequencies List<SpeciesBatchFrequency> frequencies = frequencyFunction.apply(batch); - Float frequenciesWeigth = - persistenceService.countFrequenciesWeight(frequencies, true); + Float frequenciesWeigth = persistenceService.countFrequenciesWeight(frequencies, true); - if (frequenciesWeigth != null && Weights.isEqualWeight(weight, frequenciesWeigth)) { + if (frequenciesWeigth != null && WeightUnit.KG.isEquals(weight, frequenciesWeigth)) { result = t("tutti.service.operations.cleanWeights.error.redundant.frequencyWeight", - weightUnit.fromEntity(weight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(weight) + weightUnit.getShortLabel(), getCategoryLabel(batch)); } } @@ -517,8 +450,7 @@ public class WeightCleaningService extends AbstractTuttiService { return result; } - protected String checkWeightRedundant(WeightUnit weightUnit, - SpeciesBatch batch) { + protected String checkWeightRedundant(WeightUnit weightUnit, SpeciesBatch batch) { Preconditions.checkState(batch.isChildBatchsEmpty()); @@ -527,25 +459,23 @@ public class WeightCleaningService extends AbstractTuttiService { // on a leaf, check if weight is not = to the finest category weight Float weight = batch.getWeight(); Float sampleCategoryWeight = batch.getSampleCategoryWeight(); - if (weight != null && sampleCategoryWeight != null && Weights.isEqualWeight(weight, sampleCategoryWeight)) { + if (weight != null && sampleCategoryWeight != null && WeightUnit.KG.isEquals(weight, sampleCategoryWeight)) { result = t("tutti.service.operations.cleanWeights.error.redundant.weight", - weightUnit.fromEntity(weight), - weightUnit.getShortLabel(), + weightUnit.fromEntity(weight) + weightUnit.getShortLabel(), getCategoryLabel(batch)); } return result; } - protected String getBatchLabel(String type, WeightUnit weightUnit, - SpeciesBatch batch) { + protected String getBatchLabel(String type, WeightUnit weightUnit, SpeciesBatch batch) { StringBuilder sb = new StringBuilder("[ " + type); String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); sb.append(" ").append(species); - List<String> categories = Lists.newArrayList(); + List<String> categories = new ArrayList<>(); SpeciesBatch b = batch; while (b.getParentBatch() != null) { String categoryValue = decoratorService.getDecorator(b.getSampleCategoryValue()) @@ -562,9 +492,29 @@ public class WeightCleaningService extends AbstractTuttiService { } protected String getCategoryLabel(SpeciesBatch batch) { - SampleCategoryModelEntry category = - sampleCategoryModel.getCategoryById(batch.getSampleCategoryId()); + SampleCategoryModelEntry category = sampleCategoryModel.getCategoryById(batch.getSampleCategoryId()); return category.getLabel(); } + + protected String buildLabelAndLogMessage(String message, String batchPrefix, WeightUnit weightUnit, SpeciesBatch b) { + String label = getBatchLabel(batchPrefix, weightUnit, b); + if (log.isInfoEnabled()) { + log.info(label + " " + message); + } + return label; + } + + protected void addMessageIfNotExist(String message, String batchPrefix, WeightUnit weightUnit, SpeciesBatch b, Multimap<String, String> result) { + + if (message != null) { + + String label = buildLabelAndLogMessage(message, batchPrefix, weightUnit, b); + if (!result.containsEntry(label, message)) { + result.put(label, message); + } + } + + } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java index 466cfc8..901add8 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java @@ -36,7 +36,6 @@ import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.util.Numbers; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.tuple.Pair; import org.nuiton.decorator.Decorator; @@ -114,7 +113,7 @@ public class WeightComputingService extends AbstractTuttiService { speciesTotalSortedWeight = speciesTotalComputedSortedWeight; catchBatch.setSpeciesTotalSortedComputedWeight(WeightUnit.KG.round(speciesTotalSortedWeight)); - } else if (Weights.isSmallerWeight(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { + } else if (WeightUnit.KG.isSmallerThan(speciesTotalSortedWeight, speciesTotalComputedSortedWeight)) { throw SpeciesWeightComputingException.forIncoherentTotalSorted(getSpeciesWeightUnit(), speciesTotalSortedWeight, @@ -160,7 +159,7 @@ public class WeightComputingService extends AbstractTuttiService { benthosTotalSortedWeight = benthosTotalComputedSortedWeight; catchBatch.setBenthosTotalSortedComputedWeight(WeightUnit.KG.round(benthosTotalSortedWeight)); - } else if (Weights.isSmallerWeight(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { + } else if (WeightUnit.KG.isSmallerThan(benthosTotalSortedWeight, benthosTotalComputedSortedWeight)) { throw BenthosWeightComputingException.forIncoherentTotalSorted( getBenthosWeightUnit(), @@ -199,7 +198,7 @@ public class WeightComputingService extends AbstractTuttiService { Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); if (marineLitterTotalWeight != null && marineLitterTotalComputedWeight != null - && Weights.isSmallerWeight(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { + && WeightUnit.KG.isSmallerThan(marineLitterTotalWeight, marineLitterTotalComputedWeight)) { throw MarineLitterWeightComputingException.forIncoherentTotal(getMarineLitterWeightUnit(), marineLitterTotalWeight, @@ -223,7 +222,7 @@ public class WeightComputingService extends AbstractTuttiService { Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight); - if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + if (WeightUnit.KG.isNotEquals(totalWeight, computedTotalWeight)) { throw CatchWeightComputingException.forIncoherentTotal(getCatchWeightUnit(), totalWeight, @@ -244,7 +243,7 @@ public class WeightComputingService extends AbstractTuttiService { } else { Float computedTotalWeight = WeightUnit.KG.round(totalUnsortedWeight + totalSortedSortedWeight + rejectedWeight); - if (Weights.isNotEqualWeight(totalWeight, computedTotalWeight)) { + if (WeightUnit.KG.isNotEquals(totalWeight, computedTotalWeight)) { throw CatchWeightComputingException.forIncoherentTotalWithRejected(getCatchWeightUnit(), totalWeight, @@ -261,7 +260,7 @@ public class WeightComputingService extends AbstractTuttiService { Float catchRate; - if (Weights.isEqualWeight(totalSortedSortedWeight, 0f)) { + if (WeightUnit.KG.isZero(totalSortedSortedWeight)) { catchRate = 0f; } else { catchRate = totalSortedWeight / totalSortedSortedWeight; @@ -332,7 +331,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null) { batch.setSampleCategoryComputedWeight(sum); - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { + } else if (WeightUnit.KG.isSmallerThan(categoryWeight, sum)) { throw SpeciesWeightComputingException.forIncoherentParentCategoryWeight( getSpeciesWeightUnit(), @@ -362,7 +361,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && WeightUnit.KG.isNotEquals(rowWeight, frequencyWeight)) { throw SpeciesWeightComputingException.forIncoherentRowWeightFrequency(getSpeciesWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -378,11 +377,11 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && WeightUnit.KG.isNotEquals(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { + if (WeightUnit.KG.isGreaterThan(frequencyWeight, categoryWeight)) { throw SpeciesWeightComputingException.forIncoherentCategoryWeight(getSpeciesWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -410,7 +409,7 @@ public class WeightComputingService extends AbstractTuttiService { result = categoryWeight; } } - if (Weights.isNullOrZero(result)) { + if (WeightUnit.KG.isNullOrZero(result)) { throw SpeciesWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), getCategoryLabel(batch.getSampleCategoryId()), @@ -479,7 +478,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null) { batch.setSampleCategoryComputedWeight(sum); - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { + } else if (WeightUnit.KG.isSmallerThan(categoryWeight, sum)) { throw BenthosWeightComputingException.forIncoherentParentCategoryWeight(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -509,7 +508,7 @@ public class WeightComputingService extends AbstractTuttiService { if (categoryWeight == null && rowWeight != null) { // throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - } else if (rowWeight != null && frequencyWeight != null && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { + } else if (rowWeight != null && frequencyWeight != null && WeightUnit.KG.isNotEquals(rowWeight, frequencyWeight)) { throw BenthosWeightComputingException.forIncoherentRowWeightFrequency(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -525,11 +524,11 @@ public class WeightComputingService extends AbstractTuttiService { batch.setSampleCategoryComputedWeight(frequencyWeight); result = frequencyWeight; - } else if (frequencyWeight != null && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { + } else if (frequencyWeight != null && WeightUnit.KG.isNotEquals(frequencyWeight, categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { + if (WeightUnit.KG.isGreaterThan(frequencyWeight, categoryWeight)) { throw BenthosWeightComputingException.forIncoherentCategoryWeight(getBenthosWeightUnit(), decorateSpecies(batch.getSpecies()), @@ -556,7 +555,7 @@ public class WeightComputingService extends AbstractTuttiService { result = categoryWeight; } } - if (Weights.isNullOrZero(result)) { + if (WeightUnit.KG.isNullOrZero(result)) { throw BenthosWeightComputingException.forNoWeight(decorateSpecies(batch.getSpecies()), getCategoryLabel(batch.getSampleCategoryId()), @@ -579,7 +578,7 @@ public class WeightComputingService extends AbstractTuttiService { for (int i = 0; i < children.size(); i++) { MarineLitterBatch batch = children.get(i); - if (checkWeight && Weights.isNullOrZero(batch.getWeight())) { + if (checkWeight && WeightUnit.KG.isNullOrZero(batch.getWeight())) { throw MarineLitterWeightComputingException.forNoWeight(i); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit aabaad218482d762456aeb508ff60b3aeddc39ed Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:41:21 2016 +0200 Utilisation nouvelle API des poids --- .../tutti/service/TuttiValidationDataContextSupport.java | 6 ++++-- .../main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java | 3 +-- .../service/export/toconfirmreport/ToConfirmReportService.java | 5 ++--- .../service/genericformat/consumer/CsvConsumerForCatch.java | 4 ++-- .../service/genericformat/producer/CsvProducerForCatch.java | 5 +++-- .../fr/ifremer/tutti/service/psionimport/PsionImportModel.java | 10 +++++----- .../fr/ifremer/tutti/service/pupitri/PupitriImportResult.java | 2 +- .../fr/ifremer/tutti/service/pupitri/PupitriImportService.java | 4 ++-- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiValidationDataContextSupport.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiValidationDataContextSupport.java index a5b2b9f..35eb29a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiValidationDataContextSupport.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiValidationDataContextSupport.java @@ -30,7 +30,7 @@ import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; -import fr.ifremer.tutti.util.Weights; +import fr.ifremer.tutti.type.WeightUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.DateUtil; @@ -43,6 +43,8 @@ import java.util.List; /** * Data to shared by validators. * + * <strong>Be ware some of this methods are used in validation files, so do NOT remove them, even if your IDE tells you they are not used, they are!</strong> + * * @author Tony Chemit - chemit@codelutin.com * @since 1.2 */ @@ -134,7 +136,7 @@ public abstract class TuttiValidationDataContextSupport { } public final boolean isNotWeightZeroValue(Float weight) { - return Weights.isNotEqualWeight(weight, 0f); + return WeightUnit.KG.isNotNullNorZero(weight); } public final boolean isMutiRegNumberValid(String numberAsString) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java index c4365db..4e906e6 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/csv/TuttiCsvUtil.java @@ -31,7 +31,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.type.WeightUnit; -import fr.ifremer.tutti.util.Weights; import org.nuiton.csv.Common; import org.nuiton.csv.ValueFormatter; import org.nuiton.csv.ValueParserFormatter; @@ -62,7 +61,7 @@ public class TuttiCsvUtil extends Common { // if value is null then use the default value value = defaultValue; } - return Weights.getWeightStringValue(value); + return WeightUnit.KG.renderWeight(value); } @Override diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java index 401519e..88c5d27 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java @@ -38,7 +38,6 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.type.WeightUnit; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -182,10 +181,10 @@ public class ToConfirmReportService extends AbstractTuttiService { Species species = batch.getSpecies(); Float sampleCategoryWeightValue = weightUnit.fromEntity(batch.getSampleCategoryWeight()); - String sampleCategoryWeight = Weights.getWeightStringValue(sampleCategoryWeightValue); + String sampleCategoryWeight = weightUnit.renderWeight(sampleCategoryWeightValue); Float weightValue = weightUnit.fromEntity(batch.getWeight()); - String weight = Weights.getWeightStringValue(weightValue); + String weight = weightUnit.renderWeight(weightValue); String comment = batch.getComment(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java index 52a04e3..5edbf93 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java @@ -40,7 +40,7 @@ import fr.ifremer.tutti.service.genericformat.GenericFormatImportOperationContex import fr.ifremer.tutti.service.genericformat.csv.CatchModel; import fr.ifremer.tutti.service.genericformat.csv.CatchRow; import fr.ifremer.tutti.service.genericformat.csv.ExportSampleCategory; -import fr.ifremer.tutti.util.Weights; +import fr.ifremer.tutti.type.WeightUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.ImportRow; @@ -100,7 +100,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - if (bean.getFrequencyWeight() != null && Weights.isEqualWeight(bean.getFrequencyWeight(), 0f)) { + if (bean.getFrequencyWeight() != null && WeightUnit.KG.isZero(bean.getFrequencyWeight())) { // Cant have a Weight 0.0 addCheckError(row, new FrequencyWeigthNullValueException(operationContext.getFishingOperation())); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java index dba9f60..579aba7 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java @@ -35,6 +35,7 @@ import fr.ifremer.tutti.service.genericformat.GenericFormatExportOperationContex import fr.ifremer.tutti.service.genericformat.csv.CatchModel; import fr.ifremer.tutti.service.genericformat.csv.CatchRow; import fr.ifremer.tutti.service.genericformat.csv.ExportSampleCategory; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.util.Numbers; import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; @@ -529,7 +530,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { float currentRate = totalWeight / sampleWeight; - if (Weights.isNotEqualWeight(1.0f, currentRate)) { + if (WeightUnit.KG.isNotEquals(1.0f, currentRate)) { // the only case which can change the final rate finalRaisingFactor *= currentRate; @@ -543,7 +544,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { Float frequencyWeight = row.getFrequencyWeight(); Float computedFrequencyTotalWeight = row.getComputedFrequencyTotalWeight(); float currentRate = computedFrequencyTotalWeight / frequencyWeight; - if (Weights.isNotEqualWeight(1.0f, currentRate)) { + if (WeightUnit.KG.isNotEquals(1.0f, currentRate)) { // the only case which can change the final rate finalRaisingFactor *= currentRate; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java index 2c7ae1d..1c6874d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java @@ -31,7 +31,7 @@ import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.util.Weights; +import fr.ifremer.tutti.type.WeightUnit; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -156,7 +156,7 @@ public class PsionImportModel { Multimap<Species, PsionImportBatchModel> store; // --- Guess if sorted or unsorted batch --- // - if (Weights.isGreaterWeight(weight, 0) && Weights.isEqualWeight(weight, sampleWeight)) { + if (WeightUnit.KG.isGreaterThanZero(weight) && WeightUnit.KG.isEquals(weight, sampleWeight)) { store = unsortedBatchsBySpecies; if (log.isInfoEnabled()) { @@ -218,7 +218,7 @@ public class PsionImportModel { Float weight = batchModel.getWeight(); Float sampleWeight = batchModel.getSampleWeight(); - if (Weights.isEqualWeight(weight, 0) && Weights.isGreaterWeight(sampleWeight, 0)) { + if (WeightUnit.KG.isZero(weight) && WeightUnit.KG.isGreaterThanZero(sampleWeight)) { // POID = 0 et TAIL != POID : un seul poids à positionner batchModel.setWeight(sampleWeight); @@ -262,13 +262,13 @@ public class PsionImportModel { Float weight = batchModel.getWeight(); Float sampleWeight = batchModel.getSampleWeight(); - if (Weights.isEqualWeight(weight, 0) && Weights.isGreaterWeight(sampleWeight, 0)) { + if (WeightUnit.KG.isZero(weight) && WeightUnit.KG.isGreaterThanZero(sampleWeight)) { // POID = 0 et TAIL != POID : un seul poids à positionner continue; } - if (Weights.isGreaterWeight(weight, 0) && Weights.isGreaterWeight(weight, sampleWeight)) { + if (WeightUnit.KG.isGreaterThanZero(weight) && WeightUnit.KG.isGreaterThan(weight, sampleWeight)) { // POID > 0 et POID > TAIL : deux poids à positionner speciesBatchesWithDoubleWeight.add(batchModel); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java index e71f539..a302425 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportResult.java @@ -364,7 +364,7 @@ public class PupitriImportResult { melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part3", editedMelagTotalWeight, unitLabel)).append("\n"); - if (Weights.isNotEqualWeight(editedMelagTotalWeight, melagTotalWeight.floatValue())) { + if (WeightUnit.KG.isNotEquals(editedMelagTotalWeight, melagTotalWeight.floatValue())) { melagCommentBuilder.append(t("tutti.service.pupitri.import.createMelag.comment.part4", melagTotalWeight.floatValue(), unitLabel, editedMelagTotalWeight, unitLabel)).append("\n"); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java index 396af5e..28b0e9f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java @@ -286,7 +286,7 @@ public class PupitriImportService extends AbstractTuttiService { PupitriSignContext signContext = aCatch.getSignContext(signs); - if (!Weights.isNullOrZero(signContext.getWeight())) { + if (!WeightUnit.KG.isNullOrZero(signContext.getWeight())) { PupitriImportReportRow reportCatch = PupitriImportReportRow.newRow(code, name, @@ -569,7 +569,7 @@ public class PupitriImportService extends AbstractTuttiService { SpeciesBatch childBatch = createSpeciesBatch( operation, species, - Weights.isNullOrZero(catchWeight) ? null : catchWeight, + WeightUnit.KG.isNullOrZero(catchWeight) ? null : catchWeight, categoryId, splitCqv); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 16c957fa9ebb87c8cb12588d1a2dc947e53916b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:46:18 2016 +0200 Correction des mauvaises unités utilisés dans les écran «espèces» --- .../species/create/CreateSpeciesBatchUI.jaxx | 6 +-- .../species/create/CreateSpeciesBatchUI.jcss | 3 -- .../create/CreateSpeciesBatchUIHandler.java | 49 +++++++++------------- .../species/create/CreateSpeciesBatchUIModel.java | 8 +++- .../catches/species/edit/SpeciesBatchUI.jaxx | 12 +++--- .../catches/species/edit/SpeciesBatchUI.jcss | 6 --- .../species/edit/SpeciesBatchUIHandler.java | 22 +++++----- .../frequency/SpeciesFrequencyRowModel.java | 11 +++-- .../frequency/SpeciesFrequencyTableModel.java | 4 +- .../species/frequency/SpeciesFrequencyUI.jaxx | 2 +- .../species/frequency/SpeciesFrequencyUI.jcss | 1 - .../frequency/SpeciesFrequencyUIHandler.java | 4 +- .../species/frequency/SpeciesFrequencyUIModel.java | 2 +- .../catches/species/split/SplitSpeciesBatchUI.jaxx | 4 +- .../catches/species/split/SplitSpeciesBatchUI.jcss | 2 - .../species/split/SplitSpeciesBatchUIHandler.java | 4 +- .../species/split/SplitSpeciesBatchUIModel.java | 14 +++---- 17 files changed, 67 insertions(+), 87 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx index b0a022c..3bd6868 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jaxx @@ -112,7 +112,7 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Species batch weight --> <row> <cell anchor='west'> - <JLabel id='batchSampleCategoryWeightLabel'/> + <JLabel id='batchSampleCategoryWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0' columns='2'> <NumberEditor id='batchSampleCategoryWeightField' constructorParams='this'/> @@ -122,7 +122,7 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Species batch sample weight --> <row> <cell anchor='west'> - <JLabel id='batchWeightLabel'/> + <JLabel id='batchWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0' columns='2'> <NumberEditor id='batchWeightField' constructorParams='this'/> @@ -166,7 +166,7 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Sample Total weight --> <row> <cell anchor='west'> - <JLabel id='sampleWeightLabel'/> + <JLabel id='sampleWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <JTextField id='sampleWeightField'/> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jcss index 7fac441..b084806 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUI.jcss @@ -82,7 +82,6 @@ NumberEditor { toolTipText: "tutti.createSpeciesBatch.field.batchSampleCategoryWeight.tip"; labelFor: {batchSampleCategoryWeightField}; _help: {"tutti.createSpeciesBatch.field.batchSampleCategoryWeight.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; } #batchSampleCategoryWeightField { @@ -97,7 +96,6 @@ NumberEditor { toolTipText: "tutti.createSpeciesBatch.field.batchWeight.tip"; labelFor: {batchWeightField}; _help: {"tutti.createSpeciesBatch.field.batchWeight.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; } #batchWeightField { @@ -149,7 +147,6 @@ NumberEditor { toolTipText: "tutti.createSpeciesBatch.field.sampleWeight.tip"; labelFor: {sampleWeightField}; _help: {"tutti.createSpeciesBatch.field.sampleWeightField.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; } #sampleWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java index e952a1b..d32dd16 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIHandler.java @@ -32,7 +32,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.edit.SpeciesBatchUIModel; @@ -64,8 +63,7 @@ import java.util.Optional; public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<SplitSpeciesBatchRowModel, CreateSpeciesBatchUIModel, CreateSpeciesBatchUI> { /** Logger. */ - private static final Log log = - LogFactory.getLog(CreateSpeciesBatchUIHandler.class); + private static final Log log = LogFactory.getLog(CreateSpeciesBatchUIHandler.class); public static final PropertyChangeListener PROPERTY_WEIGHT_CHANGED_LISTENER = new PropertyChangeListener() { @@ -184,22 +182,13 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl * @since 2.5 */ protected CaracteristicQualitativeValue sortedValue; - - /** - * Sample categories model. - * - * @since 2.4 - */ - protected SampleCategoryModel sampleCategoryModel; - - /** - * Weight unit. - * - * @since 2.6 - */ - protected WeightUnit weightUnit; - - protected SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport; +// +// /** +// * Sample categories model. +// * +// * @since 2.4 +// */ +// protected SampleCategoryModel sampleCategoryModel; public CreateSpeciesBatchUIHandler() { super(SplitSpeciesBatchRowModel.PROPERTY_SELECTED, @@ -279,9 +268,7 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl super.beforeInit(ui); - this.speciesOrBenthosBatchUISupport = ui.getContextValue(SpeciesOrBenthosBatchUISupport.class, ui.getSpeciesOrBenthosContext()); - this.weightUnit = speciesOrBenthosBatchUISupport.getWeightUnit(); - this.sampleCategoryModel = getDataContext().getSampleCategoryModel(); + SampleCategoryModel sampleCategoryModel = getDataContext().getSampleCategoryModel(); SampleCategoryModelEntry caracteristic = sampleCategoryModel.getCategoryById(sampleCategoryModel.getFirstCategoryId()); @@ -298,6 +285,7 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl Objects.requireNonNull(vracValue, "Could not found vrac qualitative value"); sortedValue = vracValue; + SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport = ui.getContextValue(SpeciesOrBenthosBatchUISupport.class, ui.getSpeciesOrBenthosContext()); CreateSpeciesBatchUIModel model = new CreateSpeciesBatchUIModel(speciesOrBenthosBatchUISupport, sampleCategoryModel); this.ui.setContextValue(model); listModelIsModify(model); @@ -308,6 +296,8 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl initUI(this.ui); + CreateSpeciesBatchUIModel model = getModel(); + initBeanFilterableComboBox(this.ui.getSpeciesComboBox(), new ArrayList<>(), null, @@ -316,7 +306,7 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl List<SampleCategoryModelEntry> categories = new ArrayList<>(); // add all categories - categories.addAll(sampleCategoryModel.getCategory()); + categories.addAll(model.getSampleCategoryModel().getCategory()); // remove the first one (V/HV) categories.remove(0); @@ -332,7 +322,6 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl new ArrayList<>(caracteristic.getQualitativeValue()), null); - CreateSpeciesBatchUIModel model = getModel(); model.addPropertyChangeListener(CreateSpeciesBatchUIModel.PROPERTY_SPECIES, PROPERTY_SPECIES_CHANGED_LISTENER); @@ -402,7 +391,7 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl // compute which species can still be used - List<Species> allSpecies = speciesOrBenthosBatchUISupport.getReferentSpeciesWithSurveyCode(true); + List<Species> allSpecies = model.getSpeciesOrBenthosBatchUISupport().getReferentSpeciesWithSurveyCode(true); speciesToUse.addAll(allSpecies); } @@ -437,8 +426,10 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl if (log.isDebugEnabled()) { log.debug("Generate table model for category " + category); } + CreateSpeciesBatchUIModel model = getModel(); + // when generate a new table model, then reset previous rows from model - getModel().setRows(null); + model.setRows(null); Caracteristic data = null; @@ -482,14 +473,14 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl addFloatColumnToModel(columnModel, SplitSpeciesBatchTableModel.WEIGHT, - weightUnit, + model.getSpeciesOrBenthosBatchUISupport().getWeightUnit(), table); } } // create table model SplitSpeciesBatchTableModel tableModel = new SplitSpeciesBatchTableModel(columnModel, - getModel(), + model, editableCategoryValue, false); @@ -530,7 +521,7 @@ public class CreateSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spl "(can add a first empty row? " + editableCategoryValue + ")."); } - getModel().setRows(rows); + model.setRows(rows); } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java index 2cf453d..5cbc3f5 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/create/CreateSpeciesBatchUIModel.java @@ -28,6 +28,7 @@ import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SelectedCategoryAble; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.SplitSpeciesBatchRowModel; @@ -48,8 +49,7 @@ import static org.nuiton.i18n.I18n.t; */ public class CreateSpeciesBatchUIModel extends AbstractTuttiTableUIModel<CreateSpeciesBatchUIModel, SplitSpeciesBatchRowModel, CreateSpeciesBatchUIModel> implements SelectedCategoryAble { - private final static Log log = - LogFactory.getLog(CreateSpeciesBatchUIModel.class); + private final static Log log = LogFactory.getLog(CreateSpeciesBatchUIModel.class); private static final long serialVersionUID = 1L; @@ -362,4 +362,8 @@ public class CreateSpeciesBatchUIModel extends AbstractTuttiTableUIModel<CreateS public SpeciesOrBenthosBatchUISupport getSpeciesOrBenthosBatchUISupport() { return speciesOrBenthosBatchUISupport; } + + public WeightUnit getWeightUnit() { + return speciesOrBenthosBatchUISupport.getWeightUnit(); + } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jaxx index eafb22d..1251a43 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jaxx @@ -102,13 +102,13 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Poids total / Poids total vrac --> <row> <cell anchor='west'> - <JLabel id='totalWeightLabel'/> + <JLabel id='totalWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <JTextField id='totalWeightField'/> </cell> <cell anchor='west'> - <JLabel id='totalSortedWeightLabel'/> + <JLabel id='totalSortedWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <ComputableDataEditor id='totalSortedWeightField' genericType="Float" constructorParams='this'/> @@ -118,13 +118,13 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Poids échantillonné vrac / Poids total hors vrac --> <row> <cell> - <JLabel id='totalSampleSortedWeightLabel'/> + <JLabel id='totalSampleSortedWeightLabel' styleClass='labelWithUnit'/> </cell> <cell> <JTextField id='totalSampleSortedWeightField'/> </cell> <cell> - <JLabel id='totalUnsortedWeightLabel'/> + <JLabel id='totalUnsortedWeightLabel' styleClass='labelWithUnit'/> </cell> <cell> <JTextField id='totalUnsortedWeightField'/> @@ -134,13 +134,13 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Poids inerte / Poids vivant non détaillé --> <row> <cell> - <JLabel id='totalInertWeightLabel'/> + <JLabel id='totalInertWeightLabel' styleClass='labelWithUnit'/> </cell> <cell> <ComputableDataEditor id='totalInertWeightField' genericType="Float" constructorParams='this'/> </cell> <cell> - <JLabel id='totalLivingNotItemizedWeightLabel'/> + <JLabel id='totalLivingNotItemizedWeightLabel' styleClass='labelWithUnit'/> </cell> <cell> <ComputableDataEditor id='totalLivingNotItemizedWeightField' genericType="Float" constructorParams='this'/> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jcss index 9980cf3..91b485a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUI.jcss @@ -85,7 +85,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalWeight.tip"; labelFor: {totalWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalWeightField { @@ -99,7 +98,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalSortedWeight.tip"; labelFor: {totalSortedWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalSortedWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalSortedWeightField { @@ -113,7 +111,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalSampleSortedWeight.tip"; labelFor: {totalSampleSortedWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalSampleSortedWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalSampleSortedWeightField { @@ -127,7 +124,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalUnsortedWeight.tip"; labelFor: {totalUnsortedWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalUnsortedWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalUnsortedWeightField { @@ -141,7 +137,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalInertWeight.tip"; labelFor: {totalInertWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalInertWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalInertWeightField { @@ -155,7 +150,6 @@ ComputableDataEditor { toolTipText: "tutti.editSpeciesBatch.field.speciesTotalLivingNotItemizedWeight.tip"; labelFor: {totalLivingNotItemizedWeightField}; _help: {"tutti.editSpeciesBatch.field.speciesTotalLivingNotItemizedWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalLivingNotItemizedWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java index ec90dba..7f2a971 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/edit/SpeciesBatchUIHandler.java @@ -55,7 +55,6 @@ import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentCellRenderer; import fr.ifremer.tutti.ui.swing.util.comment.CommentCellEditor; import fr.ifremer.tutti.ui.swing.util.comment.CommentCellRenderer; import fr.ifremer.tutti.ui.swing.util.computable.ComputableDataTableCell; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.JTables; import jaxx.runtime.validator.swing.SwingValidator; @@ -757,10 +756,8 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec { // Weight column addColumnToModel(columnModel, - ComputableDataTableCell.newEditor( - Float.class, weightUnit, computedDataColor), - ComputableDataTableCell.newRender( - defaultRenderer, weightUnit, computedDataColor), + ComputableDataTableCell.newEditor(weightUnit, computedDataColor), + ComputableDataTableCell.newRender(defaultRenderer, weightUnit, computedDataColor), SpeciesBatchTableModel.WEIGHT, weightUnit); } @@ -983,9 +980,11 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec // Create rows in batch table model + //FIXME Weight check!!! Float parentWeight = parentBatch.getFinestCategory().getNotNullWeight(); - boolean subSample = parentWeight != null && totalRowWeight != null - && Weights.isGreaterWeight(parentWeight, totalRowWeight); + boolean subSample = parentWeight != null + && totalRowWeight != null + && getWeightUnit().isGreaterThan(parentWeight, totalRowWeight); List<SpeciesBatchRowModel> newBatches = Lists.newArrayList(); for (SplitSpeciesBatchRowModel row : rows) { if (row.isValid()) { @@ -1061,9 +1060,10 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec // re compute the sub sample property for all childs int categoryIndex = sampleCategoryModel.indexOf(sampleCategoryDef); + //FIXME Weight check!!! Float parentWeight = parentBatch.getSampleCategoryByIndex(categoryIndex - 1).getNotNullWeight(); boolean subSample = parentWeight != null && totalRowWeight != null - && Weights.isGreaterWeight(parentWeight, totalRowWeight); + && getWeightUnit().isGreaterThan(parentWeight, totalRowWeight); Set<SpeciesBatchRowModel> shell = Sets.newHashSet(); parentBatch.collectShell(shell); @@ -1199,9 +1199,11 @@ public class SpeciesBatchUIHandler extends AbstractTuttiBatchTableUIHandler<Spec batchChilds.add(childRow); } + //FIXME Weight check!!! Float rowWeight = newRow.getFinestCategory().getNotNullWeight(); - boolean subSample = rowWeight != null && childrenWeights != null - && Weights.isSmallerWeight(childrenWeights, rowWeight); + boolean subSample = rowWeight != null + && childrenWeights != null + && weightUnit.isSmallerThan(childrenWeights, rowWeight); for (SpeciesBatchRowModel childRow : batchChilds) { childRow.getFinestCategory().setSubSample(subSample); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java index cf3d7d1..0600305 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyRowModel.java @@ -30,7 +30,6 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; -import fr.ifremer.tutti.util.Weights; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -231,14 +230,14 @@ public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBa public boolean withWeight() { Float weight = getWeight(); - return Weights.isNotNullNorZero(weight); + return weightUnit.isNotNullNorZero(weight); } /** * @param weightToAdd weight (cannot be negative) to add */ public void addToWeight(float weightToAdd) { - if (!Weights.isPositive(weightToAdd)) { + if (weightUnit.isSmallerThanZero(weightToAdd)) { throw new IllegalArgumentException("you must add a positive weight"); } if (weight == null) { @@ -251,14 +250,14 @@ public class SpeciesFrequencyRowModel extends AbstractTuttiBeanUIModel<SpeciesBa * @param weightToRemove weight (cannot be negative) to remove */ public void removeFromWeight(float weightToRemove) { - if (!Weights.isPositive(weightToRemove)) { + if (weightUnit.isSmallerThanZero(weightToRemove)) { throw new IllegalArgumentException("you must remove a positive weight"); } if (weight == null) { weight = 0f; } - if (Weights.isSmallerWeight(weight, weightToRemove)) { - throw new IllegalArgumentException("the weight to remove cannot be greater than the weight"); + if (weightUnit.isSmallerThan(weight, weightToRemove)) { + throw new IllegalArgumentException("the weight to remove cannot be greater than the initial weight"); } setWeight(weightUnit.round(weight - weightToRemove)); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java index faae041..38c945c 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyTableModel.java @@ -537,7 +537,7 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp log.info("add weight to frequency (lengthStep: " + lengthStep + "): " + weight); } - Preconditions.checkState(Weights.isPositive(weight)); + Preconditions.checkState(weightUnit.isGreaterThanZero(weight)); SpeciesFrequencyRowModel row = getOrCreateRowForLengthStep(lengthStep); @@ -561,7 +561,7 @@ public class SpeciesFrequencyTableModel extends AbstractApplicationTableModel<Sp log.info("remove weight to frequency (lengthStep: " + lengthStep + "): " + weight); } - Preconditions.checkState(Weights.isPositive(weight)); + Preconditions.checkState(weightUnit.isGreaterThanZero(weight)); Optional<SpeciesFrequencyRowModel> optionalRow = getOptionalRowForLengthStep(lengthStep); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx index 340709f..aeeb4ad 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jaxx @@ -286,7 +286,7 @@ protected int getLengthStepPanelPreferedWidth() { </row> <row> <cell> - <JLabel id='totalWeightLabel'/> + <JLabel id='totalWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx="1"> <ComputableDataEditor id='totalWeightField' genericType="Float" constructorParams='this'/> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss index 5764b9d..cb41d94 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUI.jcss @@ -448,7 +448,6 @@ ComputableDataEditor { labelFor: {totalWeightField}; enabled: {model.getTotalWeight() != null}; _help: {"tutti.editSpeciesFrequencies.field.totalWeight.help"}; - _addWeightUnit: {model.getWeightUnit()}; } #totalWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java index 60371b7..644e408 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java @@ -272,8 +272,8 @@ public class SpeciesFrequencyUIHandler extends AbstractTuttiTableUIHandler<Speci weightToAdd = newValue - oldValue; } - if (weightToAdd != null) { - if (Weights.isPositive(weightToAdd)) { + if (weightUnit.isNotNullNorZero(weightToAdd)) { + if (weightUnit.isGreaterThanZero(weightToAdd)) { getTableModel().addWeightToFrequencyRow(row, weightToAdd); } else { getTableModel().removeWeightToFrequencyRow(row, -weightToAdd); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java index f0f9d67..0dc3fa4 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIModel.java @@ -656,7 +656,7 @@ public class SpeciesFrequencyUIModel extends AbstractTuttiTableUIModel<SpeciesBa Float totalWeight = getTotalWeight(); Float totalComputedWeight = getTotalComputedWeight(); return totalWeight != null && totalComputedWeight != null - && Weights.isEqualWeight(totalWeight, totalComputedWeight); + && WeightUnit.KG.isEquals(totalWeight, totalComputedWeight); } public Rtp getRtp() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx index 1831fe0..abe78be 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jaxx @@ -86,7 +86,7 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Incoming Batch Total weight --> <row> <cell anchor='west'> - <JLabel id='batchWeightLabel'/> + <JLabel id='batchWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <JTextField id='batchWeightField'/> @@ -96,7 +96,7 @@ public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; } <!-- Sample Total weight --> <row> <cell anchor='west'> - <JLabel id='sampleWeightLabel'/> + <JLabel id='sampleWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <JTextField id='sampleWeightField'/> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jcss index 2e8f900..fdda5c3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUI.jcss @@ -44,7 +44,6 @@ toolTipText: "tutti.splitSpeciesBatch.field.batchWeightField.tip"; labelFor: {batchWeightField}; _help: {"tutti.splitSpeciesBatch.field.batchWeightField.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; } #batchWeightField { @@ -59,7 +58,6 @@ toolTipText: "tutti.splitSpeciesBatch.field.sampleWeightField.tip"; labelFor: {sampleWeightField}; _help: {"tutti.splitSpeciesBatch.field.sampleWeightField.help"}; - _addWeightUnit: {handler.getConfig().getSpeciesWeightUnit()}; } #sampleWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java index 410509b..e739663 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java @@ -118,7 +118,7 @@ public class SplitSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spli } }; - protected SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport; +// protected SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport; public SplitSpeciesBatchUIHandler() { super(SplitSpeciesBatchRowModel.PROPERTY_SELECTED, @@ -204,7 +204,7 @@ public class SplitSpeciesBatchUIHandler extends AbstractTuttiTableUIHandler<Spli super.beforeInit(ui); SampleCategoryModel sampleCategoryModel = getDataContext().getSampleCategoryModel(); - this.speciesOrBenthosBatchUISupport = ui.getContextValue(SpeciesOrBenthosBatchUISupport.class, ui.getSpeciesOrBenthosContext()); + SpeciesOrBenthosBatchUISupport speciesOrBenthosBatchUISupport = ui.getContextValue(SpeciesOrBenthosBatchUISupport.class, ui.getSpeciesOrBenthosContext()); SplitSpeciesBatchUIModel model = new SplitSpeciesBatchUIModel(speciesOrBenthosBatchUISupport, sampleCategoryModel); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java index 5749cd0..df1dc2b 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIModel.java @@ -89,13 +89,6 @@ public class SplitSpeciesBatchUIModel protected SampleCategoryModel sampleCategoryModel; /** - * Weight unit. - * - * @since 2.5 - */ - protected final WeightUnit weightUnit; - - /** * Is ui in split mode ? * * @since 2.6 @@ -108,13 +101,12 @@ public class SplitSpeciesBatchUIModel SampleCategoryModel sampleCategoryModel) { super(SpeciesBatchRowModel.class, null, null); this.speciesOrBenthosBatchUISupport = speciesOrBenthosBatchUISupport; - this.weightUnit = speciesOrBenthosBatchUISupport.getWeightUnit(); this.sampleCategoryModel = sampleCategoryModel; } @Override protected SpeciesBatchRowModel newEntity() { - return new SpeciesBatchRowModel(weightUnit, sampleCategoryModel); + return new SpeciesBatchRowModel(getWeightUnit(), sampleCategoryModel); } public SpeciesOrBenthosBatchUISupport getSpeciesOrBenthosBatchUISupport() { @@ -179,4 +171,8 @@ public class SplitSpeciesBatchUIModel this.splitMode = splitMode; firePropertyChange(PROPERTY_SPLIT_MODE, oldValue, splitMode); } + + public WeightUnit getWeightUnit() { + return speciesOrBenthosBatchUISupport.getWeightUnit(); + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 1d8372e00613df5b64cc99f21c9c6eeb27d1a33a Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:47:17 2016 +0200 Meilleure utilisation des unités dans les interfaces graphiques et revue des ComputableDataEditor --- .../fr/ifremer/tutti/ui/swing/content/Common.jcss | 3 + .../operation/catches/EditCatchesSvgHandler.java | 5 +- .../operation/catches/EditCatchesUIHandler.java | 4 +- .../operation/catches/EditCatchesUIModel.java | 13 ++- .../catches/marinelitter/MarineLitterBatchUI.jaxx | 2 +- .../catches/marinelitter/MarineLitterBatchUI.jcss | 1 - .../marinelitter/MarineLitterBatchUIHandler.java | 40 +++----- .../marinelitter/MarineLitterBatchUIModel.java | 15 ++- .../create/CreateMarineLitterBatchUI.jaxx | 2 +- .../create/CreateMarineLitterBatchUI.jcss | 1 - .../create/CreateMarineLitterBatchUIHandler.java | 5 +- .../create/CreateMarineLitterBatchUIModel.java | 12 ++- .../ui/swing/util/AbstractTuttiUIHandler.java | 54 +---------- .../util/computable/ComputableDataEditor.jaxx | 3 +- .../computable/ComputableDataEditorHandler.java | 26 +++--- .../util/computable/ComputableDataTableCell.java | 103 +++++++++------------ 16 files changed, 116 insertions(+), 173 deletions(-) diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/Common.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/Common.jcss index b3d144c..23f3df2 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/Common.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/Common.jcss @@ -1,3 +1,6 @@ +.labelWithUnit { + _addWeightUnit: {model.getWeightUnit()}; +} .buttonPanel { height: 50; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesSvgHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesSvgHandler.java index a07b64f..865d6f9 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesSvgHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesSvgHandler.java @@ -38,7 +38,6 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.catches.EnterWeightUI; import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; import fr.ifremer.tutti.util.Numbers; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.JAXXUtil; import org.apache.batik.bridge.UpdateManager; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; @@ -485,7 +484,7 @@ public class EditCatchesSvgHandler { //TODO i18n ? String textContent; if (value != null) { - textContent = Weights.getWeightStringValue(value) + " " + weightUnit.getShortLabel(); + textContent = weightUnit.renderWeight(value) + " " + weightUnit.getShortLabel(); } else { textContent = null; } @@ -798,7 +797,7 @@ public class EditCatchesSvgHandler { if (denominator == null) { denominator = (Float) JavaBeanObjectUtil.getProperty(model, denominatorComputedProperty); } - if (numerator == null || denominator == null || Weights.isEqualWeight(denominator, 0f)) { + if (numerator == null || WeightUnit.KG.isNullOrZero(denominator)) { ratio = null; } else { ratio = Numbers.roundToInt(100f * numerator / denominator); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java index 9b207d9..fba8764 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java @@ -24,13 +24,13 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches; import com.google.common.collect.Sets; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.BenthosBatchUISupportImpl; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.EditSpeciesBatchPanelUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesOrBenthosBatchUISupport; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiTabContainerUIHandler; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.swing.CardLayout2Ext; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.logging.Log; @@ -96,7 +96,7 @@ public class EditCatchesUIHandler extends AbstractTuttiTabContainerUIHandler<Edi Float totalWeight = (Float) evt.getNewValue(); - if (totalWeight != null && Weights.isEqualWeight(totalWeight, 0.f)) { + if (totalWeight != null && WeightUnit.KG.isZero(totalWeight)) { // remove the totalWeight (see https://forge.codelutin.com/issues/5144) source.setCatchTotalRejectedWeight(null); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java index 412d712..c0c7494 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java @@ -37,7 +37,6 @@ import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.attachment.AttachmentModelAware; import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; -import fr.ifremer.tutti.util.Weights; import org.apache.commons.collections4.CollectionUtils; import org.nuiton.jaxx.application.swing.tab.TabContentModel; import org.nuiton.util.beans.Binder; @@ -628,10 +627,10 @@ public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, Edi Float catchTotalRejectedWeight = getCatchTotalRejectedComputedOrNotWeight().getDataOrComputedData(); Float speciesTotalSortedWeight = getSpeciesTotalSortedComputedOrNotWeight().getDataOrComputedData(); - boolean noCatchTotalRejected = catchTotalRejectedWeight == null || Weights.isEqualWeight(catchTotalRejectedWeight, 0f); - boolean noTotalUnsortedWeight = speciesTotalUnsortedComputedWeight != null && Weights.isGreaterWeight(speciesTotalUnsortedComputedWeight, 0f); + boolean noCatchTotalRejected = WeightUnit.KG.isNullOrZero(catchTotalRejectedWeight); + boolean noTotalUnsortedWeight = speciesTotalUnsortedComputedWeight != null && WeightUnit.KG.isGreaterThanZero(speciesTotalUnsortedComputedWeight); boolean speciesWeightEquals = speciesTotalSortedWeight != null && speciesTotalSampleSortedComputedWeight !=null - && Weights.isEqualWeight(speciesTotalSortedWeight, speciesTotalSampleSortedComputedWeight); + && WeightUnit.KG.isEquals(speciesTotalSortedWeight, speciesTotalSampleSortedComputedWeight); return noTotalUnsortedWeight && noCatchTotalRejected && speciesWeightEquals; } @@ -773,10 +772,10 @@ public class EditCatchesUIModel extends AbstractTuttiBeanUIModel<CatchBatch, Edi Float catchTotalRejectedWeight = getCatchTotalRejectedComputedOrNotWeight().getDataOrComputedData(); Float benthosTotalSortedWeight = getBenthosTotalSortedComputedOrNotWeight().getDataOrComputedData(); - boolean noCatchTotalRejected = catchTotalRejectedWeight == null || Weights.isEqualWeight(catchTotalRejectedWeight, 0f); - boolean noTotalUnsortedWeight = benthosTotalUnsortedComputedWeight != null && Weights.isGreaterWeight(benthosTotalUnsortedComputedWeight, 0f); + boolean noCatchTotalRejected = WeightUnit.KG.isNullOrZero(catchTotalRejectedWeight); + boolean noTotalUnsortedWeight = benthosTotalUnsortedComputedWeight != null && WeightUnit.KG.isGreaterThanZero(benthosTotalUnsortedComputedWeight); boolean benthosWeightEquals = benthosTotalSortedWeight != null && benthosTotalSampleSortedComputedWeight !=null - && Weights.isEqualWeight(benthosTotalSortedWeight, benthosTotalSampleSortedComputedWeight); + && WeightUnit.KG.isEquals(benthosTotalSortedWeight, benthosTotalSampleSortedComputedWeight); return noTotalUnsortedWeight && noCatchTotalRejected && benthosWeightEquals; diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jaxx index 2536c4b..3b6ade3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jaxx @@ -81,7 +81,7 @@ public MarineLitterBatchUI(TuttiUI<?,?> parentUI) { <!-- Poids total --> <row> <cell anchor='west'> - <JLabel id='marineLitterTotalWeightLabel'/> + <JLabel id='marineLitterTotalWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0'> <ComputableDataEditor id='marineLitterTotalWeightField' diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jcss index 969f871..d8d16b4 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUI.jcss @@ -59,7 +59,6 @@ ComputableDataEditor { toolTipText: "tutti.editMarineLitterBatch.field.marineLitterTotalWeight.tip"; labelFor: {marineLitterTotalWeightField}; _help: {"tutti.editMarineLitterBatch.field.marineLitterTotalWeight.help"}; - _addWeightUnit: {handler.getConfig().getMarineLitterWeightUnit()}; } #marineLitterTotalWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java index 6451028..1de6618 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIHandler.java @@ -59,15 +59,7 @@ import java.util.List; */ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler<MarineLitterBatchRowModel, MarineLitterBatchUIModel, MarineLitterBatchTableModel, MarineLitterBatchUI> { - private static final Log log = - LogFactory.getLog(MarineLitterBatchUIHandler.class); - - /** - * Weight unit. - * - * @since 2.5 - */ - protected WeightUnit weightUnit; + private static final Log log = LogFactory.getLog(MarineLitterBatchUIHandler.class); public MarineLitterBatchUIHandler() { super( @@ -107,7 +99,7 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler if (log.isDebugEnabled()) { log.debug("Get marineLitter batch for fishingOperation: " + - bean.getId()); + bean.getId()); } rows = Lists.newArrayList(); @@ -201,12 +193,9 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler log.debug("beforeInit: " + ui); } - weightUnit = getConfig().getMarineLitterWeightUnit(); - - EditCatchesUIModel catchesUIModel = - ui.getContextValue(EditCatchesUIModel.class); + EditCatchesUIModel catchesUIModel = ui.getContextValue(EditCatchesUIModel.class); - MarineLitterBatchUIModel model = new MarineLitterBatchUIModel(catchesUIModel); + MarineLitterBatchUIModel model = new MarineLitterBatchUIModel(catchesUIModel, getConfig().getMarineLitterWeightUnit()); ui.setContextValue(model); // propagate when value is changing @@ -229,8 +218,7 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler JXTable table = getTable(); // create table column model - DefaultTableColumnModelExt columnModel = - new DefaultTableColumnModelExt(); + DefaultTableColumnModelExt columnModel = new DefaultTableColumnModelExt(); { // Id column @@ -265,6 +253,8 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler table); } + WeightUnit weightUnit = getModel().getWeightUnit(); + { // Weight column addFloatColumnToModel(columnModel, @@ -290,8 +280,7 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler } // create table model - MarineLitterBatchTableModel tableModel = - new MarineLitterBatchTableModel(weightUnit, columnModel); + MarineLitterBatchTableModel tableModel = new MarineLitterBatchTableModel(weightUnit, columnModel); table.setModel(tableModel); table.setColumnModel(columnModel); @@ -361,11 +350,10 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler protected MarineLitterBatchRowModel loadBatch(MarineLitterBatch aBatch) { MarineLitterBatchRowModel newRow = - new MarineLitterBatchRowModel(weightUnit, aBatch); + new MarineLitterBatchRowModel(getModel().getWeightUnit(), aBatch); List<Attachment> attachments = - getPersistenceService().getAllAttachments(newRow.getObjectType(), - newRow.getObjectId()); + getPersistenceService().getAllAttachments(newRow.getObjectType(), newRow.getObjectId()); newRow.addAllAttachment(attachments); return newRow; @@ -399,8 +387,8 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler Preconditions.checkNotNull(row.getMarineLitterSizeCategory()); if (log.isInfoEnabled()) { log.info("Remove from speciesUsed: " + - decorate(row.getMarineLitterSizeCategory()) + - " - " + decorate(row.getMarineLitterCategory())); + decorate(row.getMarineLitterSizeCategory()) + + " - " + decorate(row.getMarineLitterCategory())); } MarineLitterBatchUIModel model = getModel(); model.getMarineLitterCategoriesUsed().remove(row.getMarineLitterSizeCategory(), @@ -414,8 +402,8 @@ public class MarineLitterBatchUIHandler extends AbstractTuttiBatchTableUIHandler Preconditions.checkNotNull(row.getMarineLitterSizeCategory()); if (log.isDebugEnabled()) { log.debug("Add to marineLitterCategoriesUsed: " + - decorate(row.getMarineLitterSizeCategory()) + - " - " + decorate(row.getMarineLitterCategory())); + decorate(row.getMarineLitterSizeCategory()) + + " - " + decorate(row.getMarineLitterCategory())); } MarineLitterBatchUIModel model = getModel(); model.getMarineLitterCategoriesUsed().put(row.getMarineLitterSizeCategory(), diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIModel.java index 68879c5..92fff40 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/MarineLitterBatchUIModel.java @@ -24,11 +24,12 @@ package fr.ifremer.tutti.ui.swing.content.operation.catches.marinelitter; import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.content.operation.catches.AbstractTuttiBatchUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; -import org.nuiton.jaxx.application.swing.tab.TabContentModel; import fr.ifremer.tutti.ui.swing.util.computable.ComputableData; import org.apache.commons.collections4.CollectionUtils; +import org.nuiton.jaxx.application.swing.tab.TabContentModel; import static org.nuiton.i18n.I18n.n; @@ -50,9 +51,15 @@ public class MarineLitterBatchUIModel extends AbstractTuttiBatchUIModel<MarineLi */ protected boolean removeBatchEnabled; - public MarineLitterBatchUIModel(EditCatchesUIModel catchesUIModel) { - super(catchesUIModel, - EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + private final WeightUnit weightUnit; + + public MarineLitterBatchUIModel(EditCatchesUIModel catchesUIModel, WeightUnit weightUnit) { + super(catchesUIModel, EditCatchesUIModel.PROPERTY_MARINE_LITTER_TOTAL_WEIGHT); + this.weightUnit = weightUnit; + } + + public WeightUnit getWeightUnit() { + return weightUnit; } public ComputableData<Float> getMarineLitterTotalComputedOrNotWeight() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jaxx index 4f243bd..6277a7a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jaxx @@ -98,7 +98,7 @@ public CreateMarineLitterBatchUI(EditCatchesUI parentUI) { <!-- MarineLitter weight --> <row> <cell anchor='west'> - <JLabel id='marineLitterWeightLabel'/> + <JLabel id='marineLitterWeightLabel' styleClass='labelWithUnit'/> </cell> <cell weightx='1.0' columns='2'> <NumberEditor id='marineLitterWeightField' constructorParams='this'/> diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jcss b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jcss index f384bcb..a370782 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jcss +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUI.jcss @@ -82,7 +82,6 @@ NumberEditor { toolTipText: "tutti.createMarineLitterBatch.field.weight.tip"; labelFor: {marineLitterWeightField}; _help: {"tutti.createMarineLitterBatch.field.weight.help"}; - _addWeightUnit: {handler.getConfig().getMarineLitterWeightUnit()}; } #marineLitterWeightField { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIHandler.java index 5fd2b02..ad00300 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIHandler.java @@ -43,8 +43,7 @@ import javax.swing.JComponent; public class CreateMarineLitterBatchUIHandler extends AbstractTuttiUIHandler<CreateMarineLitterBatchUIModel, CreateMarineLitterBatchUI> { /** Logger. */ - private static final Log log = - LogFactory.getLog(CreateMarineLitterBatchUIHandler.class); + private static final Log log = LogFactory.getLog(CreateMarineLitterBatchUIHandler.class); //------------------------------------------------------------------------// //-- AbstractTuttiUIHandler methods --// @@ -53,7 +52,7 @@ public class CreateMarineLitterBatchUIHandler extends AbstractTuttiUIHandler<Cre @Override public void beforeInit(CreateMarineLitterBatchUI ui) { super.beforeInit(ui); - CreateMarineLitterBatchUIModel model = new CreateMarineLitterBatchUIModel(); + CreateMarineLitterBatchUIModel model = new CreateMarineLitterBatchUIModel(getConfig().getMarineLitterWeightUnit()); ui.setContextValue(model); listModelIsModify(model); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIModel.java index ab2c334..93fea67 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/marinelitter/create/CreateMarineLitterBatchUIModel.java @@ -27,6 +27,7 @@ import com.google.common.collect.Multimap; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatchs; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiBeanUIModel; /** @@ -55,8 +56,15 @@ public class CreateMarineLitterBatchUIModel extends AbstractTuttiBeanUIModel<Cre protected final Multimap<CaracteristicQualitativeValue, CaracteristicQualitativeValue> marineLitterCategoryUsed = ArrayListMultimap.create(); - public CreateMarineLitterBatchUIModel() { + private final WeightUnit weightUnit; + + public CreateMarineLitterBatchUIModel(WeightUnit weightUnit) { super(null, null); + this.weightUnit = weightUnit; + } + + public WeightUnit getWeightUnit() { + return weightUnit; } public CaracteristicQualitativeValue getMarineLitterCategory() { @@ -118,7 +126,7 @@ public class CreateMarineLitterBatchUIModel extends AbstractTuttiBeanUIModel<Cre @Override protected CreateMarineLitterBatchUIModel newEntity() { - return new CreateMarineLitterBatchUIModel(); + return new CreateMarineLitterBatchUIModel(weightUnit); } public void reset() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java index 87b30b0..f50706a 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/AbstractTuttiUIHandler.java @@ -40,7 +40,6 @@ import fr.ifremer.tutti.ui.swing.content.MainUIHandler; import fr.ifremer.tutti.ui.swing.util.actions.ShowComboBoxPopupActions; import fr.ifremer.tutti.ui.swing.util.attachment.ButtonAttachment; import fr.ifremer.tutti.ui.swing.util.computable.ComputableDataEditor; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.swing.JAXXWidgetUtil; import jaxx.runtime.swing.editor.cell.NumberCellEditor; import jaxx.runtime.validator.swing.SwingValidator; @@ -79,8 +78,8 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.text.DecimalFormat; import java.util.List; +import java.util.Objects; import java.util.Set; import static org.nuiton.i18n.I18n.t; @@ -152,26 +151,12 @@ public abstract class AbstractTuttiUIHandler<M, UI extends TuttiUI<M, ?>> extend handler.clearValidators(); } - public String getWeightStringValue(WeightUnit weightUnit, Float weight) { - String textValue; - if (weight != null) { - - int numberDigits = weightUnit.getNumberDigits(); - - DecimalFormat weightDecimalFormat = Weights.getDecimalFormat(1, numberDigits); - textValue = weightDecimalFormat.format(weight); - - } else { - textValue = ""; - } - return textValue; - } - public String getWeightStringValue(JComponent component, Float weight) { WeightUnit weightUnit = (WeightUnit) component.getClientProperty("addWeightUnit"); - return getWeightStringValue(weightUnit, weight); + Objects.requireNonNull(weightUnit, "can't find addWeightUnit client property on component: " + component); + return weightUnit.renderWeight(weight); } @@ -437,8 +422,7 @@ public abstract class AbstractTuttiUIHandler<M, UI extends TuttiUI<M, ?>> extend // set also the number of digits (4 for kg, 1 for g) ComputableDataEditor editor = (ComputableDataEditor) labelFor; - editor.setNumberPattern(weightUnit.getNumberEditorPattern()); - editor.setDecimalNumber(weightUnit.getNumberDigits()); + editor.setWeightUnit(weightUnit); } else if (labelFor instanceof NumberEditor) { // set also the number of digits (4 for kg, 1 for g) @@ -455,36 +439,6 @@ public abstract class AbstractTuttiUIHandler<M, UI extends TuttiUI<M, ?>> extend TuttiUIUtil.initButton(getContext(), this.getUI(), abstractButton); -// Class actionType = (Class) abstractButton.getClientProperty("simpleAction"); -// if (actionType != null) { -// -// Action action = getContext().getActionFactory().createSimpleAction(this, abstractButton, actionType); -// abstractButton.setAction(action); -// -// } -// -// String actionName = abstractButton.getName(); -// Action action = abstractButton.getAction(); -// Boolean skipAction = (Boolean) abstractButton.getClientProperty("skipAction"); -// -// if (BooleanUtils.isNotTrue(skipAction) -// && abstractButton.isFocusable() -// && !(abstractButton instanceof JMenuItem) -// && !(abstractButton instanceof JCheckBox) -// && !(abstractButton instanceof JRadioButton)) { -// -// if (action == null) { -// throw new IllegalStateException("No action defined for button: " + actionName); -// } -// -// if (log.isDebugEnabled()) { -// log.debug("Register action: " + actionName); -// } -// -// abstractButton.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionName); -// abstractButton.getActionMap().put(actionName, action); -// -// } } protected void initNumberEditor(NumberEditor editor) { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditor.jaxx b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditor.jaxx index 1b976c8..7208caf 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditor.jaxx +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditor.jaxx @@ -20,12 +20,13 @@ <org.nuiton.jaxx.widgets.number.NumberEditor genericType='E extends Number'> <import> + fr.ifremer.tutti.type.WeightUnit java.awt.Color </import> <Color id='computedDataColor' javaBean='null'/> - <Integer id='decimalNumber' javaBean='null'/> + <WeightUnit id='weightUnit' javaBean='null'/> <script><![CDATA[ diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditorHandler.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditorHandler.java index 9291543..308eeba 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditorHandler.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataEditorHandler.java @@ -22,8 +22,8 @@ package fr.ifremer.tutti.ui.swing.util.computable; * #L% */ +import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.JAXXUtil; import org.nuiton.jaxx.widgets.number.NumberEditorHandler; import org.nuiton.jaxx.widgets.number.NumberEditorModel; @@ -33,7 +33,6 @@ import java.awt.Color; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeListener; -import java.text.DecimalFormat; /** * @author Kevin Morin - kmorin@codelutin.com @@ -41,7 +40,7 @@ import java.text.DecimalFormat; */ public class ComputableDataEditorHandler extends NumberEditorHandler { - protected Integer decimalNumber; + private WeightUnit weightUnit; @Override public void init() { @@ -84,10 +83,10 @@ public class ComputableDataEditorHandler extends NumberEditorHandler { } }); - ui.addPropertyChangeListener(ComputableDataEditor.PROPERTY_DECIMAL_NUMBER, - evt -> decimalNumber = (Integer) evt.getNewValue()); - - decimalNumber = ((ComputableDataEditor) ui).getDecimalNumber(); + ui.addPropertyChangeListener(ComputableDataEditor.PROPERTY_WEIGHT_UNIT, evt -> { + weightUnit = (WeightUnit) evt.getNewValue(); + ui.setNumberPattern(weightUnit.getNumberEditorPattern()); + }); super.init(); @@ -129,13 +128,18 @@ public class ComputableDataEditorHandler extends NumberEditorHandler { String modelText; Number computedData = bean.getComputedData(); -// if (ui.isUseFloat() && decimalNumber != null && computedData != null) { - if (decimalNumber != null && computedData != null) { - DecimalFormat decimalFormat = Weights.getDecimalFormat(1, decimalNumber); - modelText = decimalFormat.format(computedData); + if (weightUnit != null) { + modelText = weightUnit.renderWeight((Float) computedData); } else { modelText = JAXXUtil.getStringValue(computedData); } +// if (ui.isUseFloat() && decimalNumber != null && computedData != null) { +// if (decimalNumber != null && computedData != null) { +// DecimalFormat decimalFormat = Weights.getDecimalFormat(1, decimalNumber); +// modelText = decimalFormat.format(computedData); +// } else { +// modelText = JAXXUtil.getStringValue(computedData); +// } tf.setText(modelText); } else { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataTableCell.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataTableCell.java index b67b3b2..78934cf 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataTableCell.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/computable/ComputableDataTableCell.java @@ -24,7 +24,6 @@ package fr.ifremer.tutti.ui.swing.util.computable; import fr.ifremer.tutti.type.WeightUnit; import fr.ifremer.tutti.ui.swing.util.TuttiUI; -import fr.ifremer.tutti.util.Weights; import jaxx.runtime.JAXXUtil; import javax.swing.AbstractCellEditor; @@ -44,7 +43,6 @@ import java.awt.Font; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.io.Serializable; -import java.text.DecimalFormat; /** * Editor for TuttiComputedOrNotData @@ -55,47 +53,28 @@ import java.text.DecimalFormat; public class ComputableDataTableCell extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; - public static TableCellRenderer newRender(TableCellRenderer renderer, - WeightUnit weightUnit, - Color computedDataColor) { + public static TableCellRenderer newRender(TableCellRenderer renderer, WeightUnit weightUnit, Color computedDataColor) { - return new TuttiComputedOrNotDataTableCellRenderer(renderer, - true, - weightUnit.getNumberDigits(), - computedDataColor); + return new TuttiComputedOrNotDataTableCellRenderer(weightUnit, renderer, computedDataColor); } - public static TableCellEditor newEditor(Class type, - WeightUnit weightUnit, - Color computedDataColor) { + public static TableCellEditor newEditor(WeightUnit weightUnit, Color computedDataColor) { - return new TuttiComputedOrNotDataTableCellEditor(type, - false, - true, - weightUnit.getNumberDigits(), - weightUnit.getNumberEditorPattern(), - computedDataColor); + return new TuttiComputedOrNotDataTableCellEditor(weightUnit, computedDataColor); } - public static class TuttiComputedOrNotDataTableCellEditor - extends AbstractCellEditor - implements TableCellEditor, FocusListener, AncestorListener { + public static class TuttiComputedOrNotDataTableCellEditor extends AbstractCellEditor implements TableCellEditor, FocusListener, AncestorListener { private static final long serialVersionUID = 1L; - protected final ComputableDataEditor numberEditor; + private final ComputableDataEditor<Float> numberEditor; - protected ComputableData data; + private ComputableData<Float> data; /** constructor */ - public TuttiComputedOrNotDataTableCellEditor(Class type, - boolean useSign, - boolean useFloat, - Integer decimalNumber, - String numberPattern, - Color computedDataColor) { - - numberEditor = new ComputableDataEditor(); + public TuttiComputedOrNotDataTableCellEditor(WeightUnit weightUnit, Color computedDataColor) { + + numberEditor = new ComputableDataEditor<>(); numberEditor.setComputedDataColor(computedDataColor); numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); numberEditor.getTextField().addFocusListener(this); @@ -103,18 +82,16 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { numberEditor.getTextField().setBorder(new LineBorder(Color.GRAY, 2)); numberEditor.setSelectAllTextOnError(true); - numberEditor.setNumberPattern(numberPattern); - numberEditor.setNumberType(type); - numberEditor.setUseSign(useSign); - numberEditor.setDecimalNumber(decimalNumber); + numberEditor.setNumberType(Float.class); + numberEditor.setUseSign(false); numberEditor.init(); + numberEditor.setWeightUnit(weightUnit); } @Override - public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - data = (ComputableData) value; + data = (ComputableData<Float>) value; numberEditor.setNumberValue(data.getData()); // Check nullity and set the text that will be selected with the current value @@ -130,7 +107,7 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { } @Override - public ComputableData getCellEditorValue() { + public ComputableData<Float> getCellEditorValue() { return data; } @@ -167,7 +144,7 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { boolean result = super.stopCellEditing(); // Reset previous data to avoid keeping it on other cell edition if (result) { - data.setData(numberEditor.getModel().getNumberValue()); + data.setData((Float) numberEditor.getModel().getNumberValue()); numberEditor.setBean((Serializable) null); @@ -177,29 +154,31 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { } } - public static class TuttiComputedOrNotDataTableCellRenderer - implements TableCellRenderer { + private static class TuttiComputedOrNotDataTableCellRenderer implements TableCellRenderer { + + private final WeightUnit weightUnit; protected final TableCellRenderer delegate; - protected Integer decimalNumber; +// protected Integer decimalNumber; protected Color computedDataColor; - protected boolean useFloat; - - public TuttiComputedOrNotDataTableCellRenderer( - TableCellRenderer delegate, - boolean useFloat, - Integer decimalNumber, - Color computedDataColor) { +// protected boolean useFloat; + private TuttiComputedOrNotDataTableCellRenderer(WeightUnit weightUnit, + TableCellRenderer delegate, +// boolean useFloat, +// Integer decimalNumber, + Color computedDataColor) { + this.weightUnit = weightUnit; this.delegate = delegate; - this.useFloat = useFloat; - this.decimalNumber = decimalNumber; +// this.useFloat = useFloat; +// this.decimalNumber = decimalNumber; this.computedDataColor = computedDataColor; } + @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, @@ -207,8 +186,8 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { int row, int column) { - ComputableData data = (ComputableData) value; - Number dataValue = data.getData(); + ComputableData<Float> data = (ComputableData<Float>) value; + Float dataValue = data.getData(); Font font; Color foreground; String text; @@ -217,12 +196,15 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { font = TuttiUI.TEXTFIELD_COMPUTED_FONT; foreground = computedDataColor; - if (useFloat && decimalNumber != null && dataValue != null) { - DecimalFormat decimalFormat = Weights.getDecimalFormat(1, decimalNumber); - text = JAXXUtil.getStringValue(decimalFormat.format(dataValue)); - } else { - text = JAXXUtil.getStringValue(dataValue); - } + text = weightUnit.renderWeight(dataValue); + +// if (useFloat && decimalNumber != null && dataValue != null) { +// DecimalFormat decimalFormat = Weights.getDecimalFormat(1, decimalNumber); +// text = JAXXUtil.getStringValue(decimalFormat.format(dataValue)); +// text = weightUnit.renderWeight((Float) dataValue); +// } else { +// text = JAXXUtil.getStringValue(dataValue); +// } } else { font = TuttiUI.TEXTFIELD_NORMAL_FONT; @@ -251,4 +233,5 @@ public class ComputableDataTableCell extends DefaultTableCellRenderer { } } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See https://gitlab.nuiton.org/codelutin/tutti.git commit 8aa7a78472aaf629ebb5055e8b9627894226d5e8 Merge: ac9c4fd 1d8372e Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 14 08:47:23 2016 +0200 Livrable #8151 Merge branch 'feature/8151' into develop .../java/fr/ifremer/tutti/type/WeightUnit.java | 77 ++- .../main/java/fr/ifremer/tutti/util/Weights.java | 127 ++--- .../service/TuttiValidationDataContextSupport.java | 6 +- .../catches/BenthosWeightComputingException.java | 121 +++++ .../catches/CatchWeightComputingException.java | 40 ++ .../MarineLitterWeightComputingException.java | 40 ++ .../catches/SpeciesWeightComputingException.java | 121 +++++ .../catches/TuttiWeightComputingException.java | 20 +- .../service/catches/WeightCleaningService.java | 294 +++++------ .../service/catches/WeightComputingService.java | 556 ++++++++++----------- .../fr/ifremer/tutti/service/csv/TuttiCsvUtil.java | 3 +- .../toconfirmreport/ToConfirmReportService.java | 5 +- .../consumer/CsvConsumerForCatch.java | 4 +- .../producer/CsvProducerForCatch.java | 5 +- .../service/psionimport/PsionImportModel.java | 10 +- .../tutti/service/pupitri/PupitriImportResult.java | 2 +- .../service/pupitri/PupitriImportService.java | 4 +- .../data/SpeciesBatch-edit-error-validation.xml | 6 +- .../SpeciesBatch-validate-fatal-validation.xml | 2 +- .../resources/i18n/tutti-service_en_GB.properties | 5 + .../resources/i18n/tutti-service_fr_FR.properties | 35 +- .../fr/ifremer/tutti/ui/swing/content/Common.jcss | 3 + .../operation/catches/EditCatchesSvgHandler.java | 5 +- .../operation/catches/EditCatchesUIHandler.java | 4 +- .../operation/catches/EditCatchesUIModel.java | 13 +- .../catches/actions/ComputeBatchWeightsAction.java | 221 ++++---- .../catches/marinelitter/MarineLitterBatchUI.jaxx | 2 +- .../catches/marinelitter/MarineLitterBatchUI.jcss | 1 - .../marinelitter/MarineLitterBatchUIHandler.java | 40 +- .../marinelitter/MarineLitterBatchUIModel.java | 15 +- .../create/CreateMarineLitterBatchUI.jaxx | 2 +- .../create/CreateMarineLitterBatchUI.jcss | 1 - .../create/CreateMarineLitterBatchUIHandler.java | 5 +- .../create/CreateMarineLitterBatchUIModel.java | 12 +- .../catches/species/BenthosBatchUISupportImpl.java | 17 - .../catches/species/SpeciesBatchUISupportImpl.java | 7 - .../species/SpeciesOrBenthosBatchUISupport.java | 7 +- .../species/create/CreateSpeciesBatchUI.jaxx | 6 +- .../species/create/CreateSpeciesBatchUI.jcss | 3 - .../create/CreateSpeciesBatchUIHandler.java | 49 +- .../species/create/CreateSpeciesBatchUIModel.java | 8 +- .../catches/species/edit/SpeciesBatchUI.jaxx | 12 +- .../catches/species/edit/SpeciesBatchUI.jcss | 6 - .../species/edit/SpeciesBatchUIHandler.java | 49 +- .../frequency/SpeciesFrequencyRowModel.java | 11 +- .../frequency/SpeciesFrequencyTableModel.java | 4 +- .../species/frequency/SpeciesFrequencyUI.jaxx | 2 +- .../species/frequency/SpeciesFrequencyUI.jcss | 1 - .../frequency/SpeciesFrequencyUIHandler.java | 4 +- .../species/frequency/SpeciesFrequencyUIModel.java | 6 +- .../catches/species/split/SplitSpeciesBatchUI.jaxx | 4 +- .../catches/species/split/SplitSpeciesBatchUI.jcss | 2 - .../species/split/SplitSpeciesBatchUIHandler.java | 4 +- .../species/split/SplitSpeciesBatchUIModel.java | 14 +- .../ui/swing/util/AbstractTuttiUIHandler.java | 54 +- .../util/computable/ComputableDataEditor.jaxx | 3 +- .../computable/ComputableDataEditorHandler.java | 26 +- .../util/computable/ComputableDataTableCell.java | 103 ++-- 58 files changed, 1167 insertions(+), 1042 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm