Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
32d05ea7
by Tony Chemit at 2023-06-15T17:25:39+02:00
6 changed files:
- core/api/dto-validation/src/main/java/fr/ird/observe/dto/validation/validators/data/ps/logbook/ActivityCheckTime.java
- core/services/i18n/src/main/i18n/translations/services_en_GB.properties
- core/services/i18n/src/main/i18n/translations/services_es_ES.properties
- core/services/i18n/src/main/i18n/translations/services_fr_FR.properties
- core/services/test/src/main/resources/fixtures/fr/ird/observe/services/service/ValidateService-dataResult.json
- toolkit/api-validation/src/main/java/fr/ird/observe/validation/validators/collection/CollectionValidationWalkerContext.java
Changes:
| ... | ... | @@ -23,6 +23,7 @@ package fr.ird.observe.dto.validation.validators.data.ps.logbook; |
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | 25 | import com.opensymphony.xwork2.validator.ValidationException;
|
| 26 | +import fr.ird.observe.dto.I18nDecoratorHelper;
|
|
| 26 | 27 | import fr.ird.observe.dto.data.ps.logbook.ActivityDto;
|
| 27 | 28 | import fr.ird.observe.dto.data.ps.logbook.RouteDto;
|
| 28 | 29 | import fr.ird.observe.dto.data.ps.logbook.TimeAndNumberAware;
|
| ... | ... | @@ -64,7 +65,7 @@ public class ActivityCheckTime extends NuitonFieldValidatorSupport { |
| 64 | 65 | |
| 65 | 66 | protected void addError(CollectionValidationWalkerContext<ActivityDto, TimeAndNumberAware> context, Object object) {
|
| 66 | 67 | TimeAndNumberAware current = context.getCurrent();
|
| 67 | - setDefaultMessage(MESSAGE_KEY + String.format(MESSAGE_PARAMETERS, context.getHumanIndex(), current.getTime(), current.getNumber()));
|
|
| 68 | + setDefaultMessage(MESSAGE_KEY + String.format(MESSAGE_PARAMETERS, context.getHumanIndex(), I18nDecoratorHelper.getTimeLabel(getValidatorContext().getLocale(),current.getTime()), current.getNumber()));
|
|
| 68 | 69 | addFieldError(getFieldName(), object);
|
| 69 | 70 | }
|
| 70 | 71 |
| ... | ... | @@ -905,10 +905,10 @@ observe.data.ll.pairing.ActivityPairingResultItem.type=Observed activity |
| 905 | 905 | observe.data.pairing.ActivityPairingResultItem.computedTimeAfter=after
|
| 906 | 906 | observe.data.pairing.ActivityPairingResultItem.computedTimeBefore=before
|
| 907 | 907 | observe.data.pairing.ActivityPairingResultItem.computedTimeEquals=Same date - time
|
| 908 | -observe.data.ps.Activity.validation.invalid.time.and.number=Observation time cant' be after a previous activity if number is greater (activity at position %1$s is not correct (time %2$s, number %3$s).
|
|
| 908 | +observe.data.ps.Activity.validation.invalid.time.and.number=Observation time can't be after a previous activity if his order number is greater (activity at position %1$s is not correct (time %2$s, order number %3$s).
|
|
| 909 | 909 | observe.data.ps.Route.validation.duplicated.date=There is already another route at this date.
|
| 910 | 910 | observe.data.ps.Route.validation.invalid.quadrant=Activity quadrant at position %1$s is not consistent with trip ocean (%2$s) of trip (indian\: 1 or 2, atlantic\: 1,2,3 or 4).
|
| 911 | -observe.data.ps.Route.validation.invalid.time=Observation time cant' be after the one of the previous activity (activity at position %1$s is not correct).
|
|
| 911 | +observe.data.ps.Route.validation.invalid.time=Observation time can't be after the one of the previous activity (activity at position %1$s is not correct).
|
|
| 912 | 912 | observe.data.ps.SampleSpecies.validation.mismatch.measuredCount=Measure count (%s) must be the sum of frequencies count (%s)
|
| 913 | 913 | observe.data.ps.SampleSpecies.validation.mismatch.subSampleNumber=The sub sample number must be strictly positive if the sample is a « super sample ».
|
| 914 | 914 | observe.data.ps.common.Trip.action.move.all=Move all
|
| ... | ... | @@ -905,7 +905,7 @@ observe.data.ll.pairing.ActivityPairingResultItem.type=Observed activity \#TODO |
| 905 | 905 | observe.data.pairing.ActivityPairingResultItem.computedTimeAfter=after \#TODO
|
| 906 | 906 | observe.data.pairing.ActivityPairingResultItem.computedTimeBefore=before \#TODO
|
| 907 | 907 | observe.data.pairing.ActivityPairingResultItem.computedTimeEquals=Same date - time \#TODO
|
| 908 | -observe.data.ps.Activity.validation.invalid.time.and.number=Observation time cant' be after a previous activity if number is greater (activity at position %1$s is not correct (time %2$s, number %3$s). \#TODO
|
|
| 908 | +observe.data.ps.Activity.validation.invalid.time.and.number=Observation time can't be after a previous activity if his order number is greater (activity at position %1$s is not correct (time %2$s, order number %3$s). \#TODO
|
|
| 909 | 909 | observe.data.ps.Route.validation.duplicated.date=Ya existe otra ruta en esa fecha.
|
| 910 | 910 | observe.data.ps.Route.validation.invalid.quadrant=El cuadrante de la actividad %1$s no es coherente con el océano (%2$s) de la marea (indico \: 1,2, atlántico \: 1, 2, 3, 4)
|
| 911 | 911 | observe.data.ps.Route.validation.invalid.time=La hora de la observación de la actividad debe ser superior a la de la actividad anterior (actividad %1$s incorrecta).
|
| ... | ... | @@ -905,7 +905,7 @@ observe.data.ll.pairing.ActivityPairingResultItem.type=Activité observée |
| 905 | 905 | observe.data.pairing.ActivityPairingResultItem.computedTimeAfter=après
|
| 906 | 906 | observe.data.pairing.ActivityPairingResultItem.computedTimeBefore=avant
|
| 907 | 907 | observe.data.pairing.ActivityPairingResultItem.computedTimeEquals=Même date - heure
|
| 908 | -observe.data.ps.Activity.validation.invalid.time.and.number=L'heure d'observation d'une activité doit être supérieure à celle de l'activité précédente si son identifiant l'est (activité de position %1$s incorrecte, heure \: %2$s, identifiant \: %3$s).
|
|
| 908 | +observe.data.ps.Activity.validation.invalid.time.and.number=L'heure d'observation d'une activité doit être supérieure à celle de l'activité précédente si son numéro d'ordre l'est (activité de position %1$s incorrecte, heure \: %2$s, numéro d'ordre \: %3$s).
|
|
| 909 | 909 | observe.data.ps.Route.validation.duplicated.date=Il existe déjà une autre route à cette date.
|
| 910 | 910 | observe.data.ps.Route.validation.invalid.quadrant=Le quadrant de l’activité à la position %1$s n'est pas cohérent par rapport à l'océan (%2$s) de la marée (indien \: 1
|
| 911 | 911 | observe.data.ps.Route.validation.invalid.time=L'heure d'observation d'une activité doit être supérieure à celle de l'activité précédente (activité de position %1$s incorrecte).
|
| ... | ... | @@ -39368,6 +39368,11 @@ |
| 39368 | 39368 | "scope": "ERROR",
|
| 39369 | 39369 | "message": "Obligatoire si opération de pêche réussie"
|
| 39370 | 39370 | },
|
| 39371 | + {
|
|
| 39372 | + "fieldName": "time",
|
|
| 39373 | + "scope": "ERROR",
|
|
| 39374 | + "message": "L\u0027heure d\u0027observation d\u0027une activité doit être supérieure à celle de l\u0027activité précédente si son numéro d\u0027ordre l\u0027est (activité de position 2 incorrecte, heure : 15:12, numéro d\u0027ordre : 1)."
|
|
| 39375 | + },
|
|
| 39371 | 39376 | {
|
| 39372 | 39377 | "fieldName": "time",
|
| 39373 | 39378 | "scope": "WARNING",
|
| ... | ... | @@ -43,13 +43,13 @@ public class CollectionValidationWalkerContext<D extends ToolkitId, C extends To |
| 43 | 43 | protected final BiPredicate<CollectionValidationWalkerContext<D, C>, C> usePredicate;
|
| 44 | 44 | protected final BiPredicate<CollectionValidationWalkerContext<D, C>, C> validPredicate;
|
| 45 | 45 | protected final int size;
|
| 46 | - protected C skip;
|
|
| 46 | + protected C editing;
|
|
| 47 | 47 | protected int index = -1;
|
| 48 | 48 | protected C current;
|
| 49 | 49 | protected C previous;
|
| 50 | 50 | |
| 51 | 51 | public static <D extends ToolkitId, C extends ToolkitId> CollectionValidationWalkerContext<D, C> validate(D container, Collection<C> collection, C skip, BiPredicate<CollectionValidationWalkerContext<D, C>, C> usePredicate, BiPredicate<CollectionValidationWalkerContext<D, C>, C> validPredicate) {
|
| 52 | - return create(container, collection, usePredicate, validPredicate).map(c -> c.setSkip(skip).validate()).orElse(null);
|
|
| 52 | + return create(container, collection, usePredicate, validPredicate).map(c -> c.setEditing(skip).validate()).orElse(null);
|
|
| 53 | 53 | }
|
| 54 | 54 | |
| 55 | 55 | public static <D extends ToolkitId, C extends ToolkitId> CollectionValidationWalkerContext<D, C> validate(D container, Collection<C> collection, BiPredicate<CollectionValidationWalkerContext<D, C>, C> usePredicate, BiPredicate<CollectionValidationWalkerContext<D, C>, C> validPredicate) {
|
| ... | ... | @@ -71,13 +71,14 @@ public class CollectionValidationWalkerContext<D extends ToolkitId, C extends To |
| 71 | 71 | this.validPredicate = validPredicate;
|
| 72 | 72 | }
|
| 73 | 73 | |
| 74 | - public CollectionValidationWalkerContext<D, C> setSkip(C skip) {
|
|
| 75 | - this.skip = skip;
|
|
| 74 | + public CollectionValidationWalkerContext<D, C> setEditing(C editing) {
|
|
| 75 | + this.editing = editing;
|
|
| 76 | 76 | return this;
|
| 77 | 77 | }
|
| 78 | 78 | |
| 79 | 79 | public CollectionValidationWalkerContext<D, C> validate() {
|
| 80 | 80 | for (C current : collection) {
|
| 81 | + current = getCurrent(current);
|
|
| 81 | 82 | boolean use = addCurrent(current, usePredicate);
|
| 82 | 83 | if (use) {
|
| 83 | 84 | boolean valid = validPredicate.test(this, current);
|
| ... | ... | @@ -89,10 +90,26 @@ public class CollectionValidationWalkerContext<D extends ToolkitId, C extends To |
| 89 | 90 | return null;
|
| 90 | 91 | }
|
| 91 | 92 | |
| 93 | + private C getCurrent(C current) {
|
|
| 94 | + if (editing != null && Objects.equals(current.getId(), editing.getId())) {
|
|
| 95 | + // use editing one as current
|
|
| 96 | + return editing;
|
|
| 97 | + }
|
|
| 98 | + return current;
|
|
| 99 | + }
|
|
| 100 | + |
|
| 92 | 101 | public boolean addCurrent(C current, BiPredicate<CollectionValidationWalkerContext<D, C>, C> predicate) {
|
| 93 | 102 | index++;
|
| 94 | - if (skip != null && Objects.equals(current.getId(), skip.getId())) {
|
|
| 95 | - return false;
|
|
| 103 | + if (editing != null) {
|
|
| 104 | + if (!Objects.equals(current.getId(), editing.getId())) {
|
|
| 105 | + boolean use = predicate.test(this, current);
|
|
| 106 | + if (use) {
|
|
| 107 | + this.previous = this.current;
|
|
| 108 | + this.current = current;
|
|
| 109 | + }
|
|
| 110 | + // always return false, since we don't want to validate this entry
|
|
| 111 | + return false;
|
|
| 112 | + }
|
|
| 96 | 113 | }
|
| 97 | 114 | boolean use = predicate.test(this, current);
|
| 98 | 115 | if (use) {
|