Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe

Commits:

21 changed files:

Changes:

  • client/src/main/java/fr/ird/observe/client/ui/actions/content/ShowTechnicalInformationsAction.java
    1 1
     package fr.ird.observe.client.ui.actions.content;
    
    2 2
     
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Client
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    3 25
     import fr.ird.observe.client.ObserveSwingApplicationContext;
    
    4 26
     import fr.ird.observe.client.ui.ObserveKeyStrokes;
    
    5 27
     import fr.ird.observe.client.ui.ObserveMainUI;
    

  • client/src/main/java/fr/ird/observe/client/ui/content/ContentUIInitializer.java
    ... ... @@ -52,8 +52,8 @@ import fr.ird.observe.dto.reference.DataDtoReference;
    52 52
     import fr.ird.observe.dto.reference.ReferentialDtoReference;
    
    53 53
     import org.apache.commons.lang3.BooleanUtils;
    
    54 54
     import org.apache.commons.lang3.StringUtils;
    
    55
    -import org.apache.logging.log4j.Logger;
    
    56 55
     import org.apache.logging.log4j.LogManager;
    
    56
    +import org.apache.logging.log4j.Logger;
    
    57 57
     import org.jdesktop.swingx.JXDatePicker;
    
    58 58
     import org.jdesktop.swingx.JXMonthView;
    
    59 59
     import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
    
    ... ... @@ -63,6 +63,7 @@ import org.nuiton.jaxx.runtime.swing.editor.EnumEditor;
    63 63
     import org.nuiton.jaxx.runtime.swing.renderer.DecoratorListCellRenderer;
    
    64 64
     import org.nuiton.jaxx.runtime.swing.renderer.EnumEditorRenderer;
    
    65 65
     import org.nuiton.jaxx.validator.JAXXValidator;
    
    66
    +import org.nuiton.jaxx.validator.swing.SwingValidator;
    
    66 67
     import org.nuiton.jaxx.validator.swing.SwingValidatorUtil;
    
    67 68
     import org.nuiton.jaxx.widgets.datetime.DateTimeEditor;
    
    68 69
     import org.nuiton.jaxx.widgets.datetime.TimeEditor;
    
    ... ... @@ -346,6 +347,10 @@ public class ContentUIInitializer<E extends IdDto, UI extends ContentUI<E, UI>>
    346 347
             editor.setConfig(new TemperatureEditorConfig(TemperatureFormat.C, getBean(), label.getText(), propertyName));
    
    347 348
             editor.init(label);
    
    348 349
     
    
    350
    +        editor.getModel().addPropertyChangeListener("format", e -> {
    
    351
    +            ((SwingValidator<?>) ui.getObjectById("validator")).doValidate();
    
    352
    +        });
    
    353
    +
    
    349 354
         }
    
    350 355
     
    
    351 356
         private void init(JLabel editor) {
    

  • client/src/main/java/fr/ird/observe/client/ui/content/data/longline/ActivityLonglineUIHandler.java
    ... ... @@ -251,7 +251,7 @@ class ActivityLonglineUIHandler extends ContentOpenableUIHandler<ActivityLonglin
    251 251
     
    
    252 252
             ClientValidationContext validationContext = ObserveSwingApplicationContext.get().getValidationContext();
    
    253 253
             validationContext.setCoordinatesEditor("coordinate", getUi().getCoordinatesEditor());
    
    254
    -
    
    254
    +        validationContext.setTemperatureEditorModel("seaSurfaceTemperature", getUi().getSeaSurfaceTemperature().getModel());
    
    255 255
         }
    
    256 256
     
    
    257 257
         @Override
    

  • client/src/main/java/fr/ird/observe/client/ui/content/data/seine/ActivitySeineUIHandler.java
    ... ... @@ -140,7 +140,7 @@ class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySeineDto,
    140 140
     
    
    141 141
             ClientValidationContext validationContext = ObserveSwingApplicationContext.get().getValidationContext();
    
    142 142
             validationContext.setCoordinatesEditor("coordinate", getUi().getCoordinatesEditor());
    
    143
    -
    
    143
    +        validationContext.setTemperatureEditorModel("seaSurfaceTemperature", getUi().getSeaSurfaceTemperature().getModel());
    
    144 144
         }
    
    145 145
     
    
    146 146
         @Override
    

  • client/src/main/java/fr/ird/observe/client/validation/ClientValidationContext.java
    ... ... @@ -8,12 +8,12 @@
    8 8
      * it under the terms of the GNU General Public License as
    
    9 9
      * published by the Free Software Foundation, either version 3 of the
    
    10 10
      * License, or (at your option) any later version.
    
    11
    - * 
    
    11
    + *
    
    12 12
      * This program is distributed in the hope that it will be useful,
    
    13 13
      * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    14 14
      * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    15 15
      * GNU General Public License for more details.
    
    16
    - * 
    
    16
    + *
    
    17 17
      * You should have received a copy of the GNU General Public
    
    18 18
      * License along with this program.  If not, see
    
    19 19
      * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    ... ... @@ -39,6 +39,7 @@ import fr.ird.observe.services.ObserveServicesProvider;
    39 39
     import fr.ird.observe.services.validation.ValidationContext;
    
    40 40
     import fr.ird.observe.services.validation.ValidationDataContext;
    
    41 41
     import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditor;
    
    42
    +import org.nuiton.jaxx.widgets.temperature.TemperatureEditorModel;
    
    42 43
     
    
    43 44
     import java.util.List;
    
    44 45
     import java.util.Map;
    
    ... ... @@ -52,6 +53,9 @@ import java.util.function.Supplier;
    52 53
      */
    
    53 54
     public class ClientValidationContext extends ValidationContext {
    
    54 55
     
    
    56
    +    private Map<String, CoordinatesEditor> coordinatesEditors = new TreeMap<>();
    
    57
    +    private Map<String, TemperatureEditorModel> temperatureEditorModels = new TreeMap<>();
    
    58
    +
    
    55 59
         public ClientValidationContext(ClientConfig config, ValidationDataContext validationDataContext) {
    
    56 60
             super(validationDataContext,
    
    57 61
                   ObserveSwingApplicationContext.get().getDecoratorService(),
    
    ... ... @@ -118,14 +122,13 @@ public class ClientValidationContext extends ValidationContext {
    118 122
         public void reset() {
    
    119 123
             super.reset();
    
    120 124
             coordinatesEditors.clear();
    
    125
    +        temperatureEditorModels.clear();
    
    121 126
         }
    
    122 127
     
    
    123 128
         public ObserveOpenDataManager getOpenDataManager() {
    
    124 129
             return ObserveSwingApplicationContext.get().getOpenDataManager();
    
    125 130
         }
    
    126 131
     
    
    127
    -    private Map<String, CoordinatesEditor> coordinatesEditors = new TreeMap<>();
    
    128
    -
    
    129 132
         public Map<String, CoordinatesEditor> getCoordinatesEditors() {
    
    130 133
             return coordinatesEditors;
    
    131 134
         }
    
    ... ... @@ -138,4 +141,16 @@ public class ClientValidationContext extends ValidationContext {
    138 141
             coordinatesEditors.put(name, editor);
    
    139 142
         }
    
    140 143
     
    
    144
    +    public Map<String, TemperatureEditorModel> getTemperatureEditorModels() {
    
    145
    +        return temperatureEditorModels;
    
    146
    +    }
    
    147
    +
    
    148
    +    public TemperatureEditorModel getTemperatureEditorModel(String name) {
    
    149
    +        return temperatureEditorModels.get(name);
    
    150
    +    }
    
    151
    +
    
    152
    +    public void setTemperatureEditorModel(String name, TemperatureEditorModel editor) {
    
    153
    +        temperatureEditorModels.put(name, editor);
    
    154
    +    }
    
    155
    +
    
    141 156
     }

  • dto/src/main/java/fr/ird/observe/dto/data/longline/TripLonglineDto.java
    1
    +package fr.ird.observe.dto.data.longline;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Dto
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.google.common.collect.Iterables;
    
    26
    +import fr.ird.observe.dto.IdHelper;
    
    27
    +import org.apache.logging.log4j.LogManager;
    
    28
    +import org.apache.logging.log4j.Logger;
    
    29
    +
    
    30
    +public class TripLonglineDto extends GeneratedTripLonglineDto {
    
    31
    +
    
    32
    +    private static final Logger log = LogManager.getLogger(TripLonglineDto.class);
    
    33
    +    private static final long serialVersionUID = 3977866185675257699L;
    
    34
    +
    
    35
    +    public TripLonglineActivityDto getPreviousActivity(String activitySeineId) {
    
    36
    +
    
    37
    +        TripLonglineActivityDto previous = null;
    
    38
    +
    
    39
    +        if (activitySeineId != null) {
    
    40
    +
    
    41
    +            int currentPosition = Iterables.indexOf(getActivityLongline(), IdHelper.newIdPredicate(activitySeineId)::test);
    
    42
    +            if (currentPosition >= 1) {
    
    43
    +                previous = Iterables.get(getActivityLongline(), currentPosition - 1);
    
    44
    +            }
    
    45
    +        }
    
    46
    +
    
    47
    +        if (previous != null) {
    
    48
    +            log.debug("previous activity " + previous.getTimeStamp());
    
    49
    +
    
    50
    +        } else {
    
    51
    +            log.debug("no previous activity for " + activityLongline);
    
    52
    +        }
    
    53
    +
    
    54
    +        return previous;
    
    55
    +    }
    
    56
    +}

  • dto/src/main/models/Observe.model
    ... ... @@ -348,6 +348,7 @@ activityLongline + {*} data.longline.TripLonglineActivity | ordered unique
    348 348
     
    
    349 349
     data.longline.TripLonglineActivity > data.Data
    
    350 350
     timeStamp + {*:1} Date
    
    351
    +seaSurfaceTemperature + {*:1} Float
    
    351 352
     
    
    352 353
     data.longline.TripLonglineGearUse > data.Data | form=data.longline.GearUseFeaturesLongline
    
    353 354
     gearUseFeaturesLongline + {*} data.longline.GearUseFeaturesLongline | ordered
    

  • persistence/src/main/java/fr/ird/observe/binder/data/longline/TripLonglineActivityEntityDtoBinder.java
    ... ... @@ -53,6 +53,6 @@ public class TripLonglineActivityEntityDtoBinder extends DataEntityDtoBinderSupp
    53 53
             copyEntityDataFieldsToDto(entity, dto);
    
    54 54
     
    
    55 55
             dto.setTimeStamp(entity.getTimeStamp());
    
    56
    -
    
    56
    +        dto.setSeaSurfaceTemperature(entity.getSeaSurfaceTemperature());
    
    57 57
         }
    
    58 58
     }

  • persistence/src/main/java/fr/ird/observe/binder/data/seine/ActivitySeineStubEntityDtoBinder.java
    ... ... @@ -52,6 +52,7 @@ public class ActivitySeineStubEntityDtoBinder extends DataEntityDtoBinderSupport
    52 52
             dto.setLastUpdateDate(entity.getLastUpdateDate());
    
    53 53
             dto.setLatitude(entity.getLatitude());
    
    54 54
             dto.setLongitude(entity.getLongitude());
    
    55
    +        dto.setSeaSurfaceTemperature(entity.getSeaSurfaceTemperature());
    
    55 56
     
    
    56 57
             boolean isFindeVeille = entity.getVesselActivitySeine() != null
    
    57 58
                     && ActivitySeineImpl.ACTIVITY_FIN_DE_VEILLE.equals(entity.getVesselActivitySeine().getCode());
    

  • services/pom.xml
    ... ... @@ -157,6 +157,10 @@
    157 157
           <groupId>io.ultreia.java4all.topia</groupId>
    
    158 158
           <artifactId>service-script</artifactId>
    
    159 159
         </dependency>
    
    160
    +    <dependency>
    
    161
    +      <groupId>io.ultreia.java4all.jaxx</groupId>
    
    162
    +      <artifactId>jaxx-widgets-temperature</artifactId>
    
    163
    +    </dependency>
    
    160 164
     
    
    161 165
       </dependencies>
    
    162 166
     
    

  • services/src/main/java/fr/ird/observe/services/validation/validators/TemperatureBoundFieldValidator.java
    1
    +package fr.ird.observe.services.validation.validators;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Services API
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.opensymphony.xwork2.validator.ValidationException;
    
    26
    +import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
    
    27
    +import org.nuiton.jaxx.widgets.temperature.I18nEnumHelper;
    
    28
    +import org.nuiton.jaxx.widgets.temperature.TemperatureEditorModel;
    
    29
    +import org.nuiton.jaxx.widgets.temperature.TemperatureFormat;
    
    30
    +
    
    31
    +import java.util.Map;
    
    32
    +
    
    33
    +/**
    
    34
    + * To validate that the temperature is in correct bound.
    
    35
    + * <p>
    
    36
    + * Created by tchemit on 22/09/2018.
    
    37
    + *
    
    38
    + * @author Tony Chemit - dev@tchemit.fr
    
    39
    + */
    
    40
    +public class TemperatureBoundFieldValidator extends FieldValidatorSupport {
    
    41
    +
    
    42
    +    /**
    
    43
    +     * Default temperature format (min and max are based on this format).
    
    44
    +     */
    
    45
    +    private TemperatureFormat defaultTemperatureFormat;
    
    46
    +    /**
    
    47
    +     * Min temperature.
    
    48
    +     */
    
    49
    +    private Float min;
    
    50
    +    /**
    
    51
    +     * Max temperature.
    
    52
    +     */
    
    53
    +    private Float max;
    
    54
    +
    
    55
    +    public void setDefaultTemperatureFormat(String defaultTemperatureFormat) {
    
    56
    +        this.defaultTemperatureFormat = TemperatureFormat.valueOf(defaultTemperatureFormat);
    
    57
    +    }
    
    58
    +
    
    59
    +    public void setMin(String min) {
    
    60
    +        this.min = Float.valueOf(min);
    
    61
    +    }
    
    62
    +
    
    63
    +    public void setMax(String max) {
    
    64
    +        this.max = Float.valueOf(max);
    
    65
    +    }
    
    66
    +
    
    67
    +    @Override
    
    68
    +    public void validate(Object object) throws ValidationException {
    
    69
    +
    
    70
    +        if (min == null) {
    
    71
    +            throw new ValidationException("No parameter 'min' filled");
    
    72
    +        }
    
    73
    +        if (max == null) {
    
    74
    +            throw new ValidationException("No parameter 'max' filled");
    
    75
    +        }
    
    76
    +        if (min >= max) {
    
    77
    +            throw new ValidationException(String.format("No parameter 'min' (%s) is greater than 'max' (%s)", min, max));
    
    78
    +        }
    
    79
    +        String fieldName = getFieldName();
    
    80
    +        if (fieldName == null) {
    
    81
    +            throw new ValidationException("No parameter 'fieldName' filled");
    
    82
    +        }
    
    83
    +        Float temperature = (Float) getFieldValue(fieldName, object);
    
    84
    +        if (temperature == null) {
    
    85
    +            return;
    
    86
    +        }
    
    87
    +
    
    88
    +        @SuppressWarnings("unchecked") Map<String, TemperatureEditorModel> map = (Map<String, TemperatureEditorModel>) getFieldValue("temperatureEditorModels", object);
    
    89
    +        TemperatureFormat temperatureFormat = defaultTemperatureFormat;
    
    90
    +        if (map != null) {
    
    91
    +
    
    92
    +            TemperatureEditorModel temperatureEditorModel = map.get(fieldName);
    
    93
    +            //FIXME une validation est lancé dans l'ui alors que l'on ne devrait pas et on a pas ce composant alors
    
    94
    +            if (temperatureEditorModel != null) {
    
    95
    +                temperatureFormat = temperatureEditorModel.getFormat();
    
    96
    +            }
    
    97
    +        }
    
    98
    +
    
    99
    +        if (temperature < min || temperature > max) {
    
    100
    +            float min;
    
    101
    +            float max;
    
    102
    +            if (temperatureFormat.equals(defaultTemperatureFormat)) {
    
    103
    +                min = this.min;
    
    104
    +                max = this.max;
    
    105
    +            } else {
    
    106
    +                min = defaultTemperatureFormat.convert(this.min, temperatureFormat);
    
    107
    +                max = defaultTemperatureFormat.convert(this.max, temperatureFormat);
    
    108
    +            }
    
    109
    +            stack.set(fieldName + "Bound", new TemperatureResult(min, max, I18nEnumHelper.getLabel(temperatureFormat)));
    
    110
    +            try {
    
    111
    +                addFieldError(fieldName, object);
    
    112
    +            } finally {
    
    113
    +                stack.pop();
    
    114
    +            }
    
    115
    +        }
    
    116
    +
    
    117
    +    }
    
    118
    +
    
    119
    +    @Override
    
    120
    +    public String getValidatorType() {
    
    121
    +        return "temperatureBound";
    
    122
    +    }
    
    123
    +
    
    124
    +    static class TemperatureResult {
    
    125
    +        private final float min;
    
    126
    +        private final float max;
    
    127
    +        private final String format;
    
    128
    +
    
    129
    +        TemperatureResult(float min, float max, String format) {
    
    130
    +            this.min = min;
    
    131
    +            this.max = max;
    
    132
    +            this.format = format;
    
    133
    +        }
    
    134
    +
    
    135
    +        public float getMin() {
    
    136
    +            return min;
    
    137
    +        }
    
    138
    +
    
    139
    +        public float getMax() {
    
    140
    +            return max;
    
    141
    +        }
    
    142
    +
    
    143
    +        public String getFormat() {
    
    144
    +            return format;
    
    145
    +        }
    
    146
    +    }
    
    147
    +
    
    148
    +}
    
    149
    +

  • services/src/main/java/fr/ird/observe/services/validation/validators/TemperatureCompareFieldValidator.java
    1
    +package fr.ird.observe.services.validation.validators;
    
    2
    +
    
    3
    +/*-
    
    4
    + * #%L
    
    5
    + * ObServe :: Services API
    
    6
    + * %%
    
    7
    + * Copyright (C) 2008 - 2018 IRD, Code Lutin, Ultreia.io
    
    8
    + * %%
    
    9
    + * This program is free software: you can redistribute it and/or modify
    
    10
    + * it under the terms of the GNU General Public License as
    
    11
    + * published by the Free Software Foundation, either version 3 of the
    
    12
    + * License, or (at your option) any later version.
    
    13
    + *
    
    14
    + * This program is distributed in the hope that it will be useful,
    
    15
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    16
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    
    17
    + * GNU General Public License for more details.
    
    18
    + *
    
    19
    + * You should have received a copy of the GNU General Public
    
    20
    + * License along with this program.  If not, see
    
    21
    + * <http://www.gnu.org/licenses/gpl-3.0.html>.
    
    22
    + * #L%
    
    23
    + */
    
    24
    +
    
    25
    +import com.opensymphony.xwork2.validator.ValidationException;
    
    26
    +import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;
    
    27
    +import io.ultreia.java4all.lang.Numbers;
    
    28
    +import org.nuiton.jaxx.widgets.temperature.I18nEnumHelper;
    
    29
    +import org.nuiton.jaxx.widgets.temperature.TemperatureEditorModel;
    
    30
    +import org.nuiton.jaxx.widgets.temperature.TemperatureFormat;
    
    31
    +
    
    32
    +import java.util.Map;
    
    33
    +
    
    34
    +/**
    
    35
    + * To validate that the temperature is in correct bound.
    
    36
    + * <p>
    
    37
    + * Created by tchemit on 22/09/2018.
    
    38
    + *
    
    39
    + * @author Tony Chemit - dev@tchemit.fr
    
    40
    + */
    
    41
    +public class TemperatureCompareFieldValidator extends FieldValidatorSupport {
    
    42
    +
    
    43
    +    /**
    
    44
    +     * Name of the field to compare against.
    
    45
    +     */
    
    46
    +    private String compareFieldName;
    
    47
    +
    
    48
    +    /**
    
    49
    +     * Default temperature format (max are based on this format).
    
    50
    +     */
    
    51
    +    private TemperatureFormat defaultTemperatureFormat;
    
    52
    +    /**
    
    53
    +     * Compare temperature format (compare temperature is base on this format).
    
    54
    +     */
    
    55
    +    private TemperatureFormat compareTemperatureFormat;
    
    56
    +    /**
    
    57
    +     * Max temperature.
    
    58
    +     */
    
    59
    +    private Float max;
    
    60
    +
    
    61
    +    public void setDefaultTemperatureFormat(String defaultTemperatureFormat) {
    
    62
    +        this.defaultTemperatureFormat = TemperatureFormat.valueOf(defaultTemperatureFormat);
    
    63
    +    }
    
    64
    +
    
    65
    +    public void setCompareTemperatureFormat(String compareTemperatureFormat) {
    
    66
    +        this.compareTemperatureFormat = TemperatureFormat.valueOf(compareTemperatureFormat);
    
    67
    +    }
    
    68
    +
    
    69
    +    public void setMax(String max) {
    
    70
    +        this.max = Float.valueOf(max);
    
    71
    +    }
    
    72
    +
    
    73
    +    public void setCompareFieldName(String compareFieldName) {
    
    74
    +        this.compareFieldName = compareFieldName;
    
    75
    +    }
    
    76
    +
    
    77
    +    @Override
    
    78
    +    public void validate(Object object) throws ValidationException {
    
    79
    +
    
    80
    +        String fieldName = getFieldName();
    
    81
    +        if (fieldName == null) {
    
    82
    +            throw new ValidationException("No parameter 'fieldName' filled");
    
    83
    +        }
    
    84
    +        if (compareFieldName == null) {
    
    85
    +            throw new ValidationException("No parameter 'compareFieldName' filled");
    
    86
    +        }
    
    87
    +        if (max == null) {
    
    88
    +            throw new ValidationException("No parameter 'max' filled");
    
    89
    +        }
    
    90
    +        Float temperature = (Float) getFieldValue(fieldName, object);
    
    91
    +        if (temperature == null) {
    
    92
    +            return;
    
    93
    +        }
    
    94
    +        Float againstTemperature = (Float) getFieldValue(compareFieldName, object);
    
    95
    +        if (againstTemperature == null) {
    
    96
    +            return;
    
    97
    +        }
    
    98
    +        @SuppressWarnings("unchecked") Map<String, TemperatureEditorModel> map = (Map<String, TemperatureEditorModel>) getFieldValue("temperatureEditorModels", object);
    
    99
    +        TemperatureFormat temperatureFormat = defaultTemperatureFormat;
    
    100
    +        if (map != null) {
    
    101
    +
    
    102
    +            TemperatureEditorModel temperatureEditorModel = map.get(fieldName);
    
    103
    +            //FIXME une validation est lancé dans l'ui alors que l'on ne devrait pas et on a pas ce composant alors
    
    104
    +            if (temperatureEditorModel != null) {
    
    105
    +                temperatureFormat = temperatureEditorModel.getFormat();
    
    106
    +            }
    
    107
    +        }
    
    108
    +
    
    109
    +        if (Math.abs(temperature - againstTemperature) > max) {
    
    110
    +            float max;
    
    111
    +            if (temperatureFormat.equals(defaultTemperatureFormat)) {
    
    112
    +                max = this.max;
    
    113
    +            } else {
    
    114
    +                max = Numbers.roundOneDigit(defaultTemperatureFormat.convert(this.max, temperatureFormat) - 32);
    
    115
    +            }
    
    116
    +            if (!temperatureFormat.equals(compareTemperatureFormat)) {
    
    117
    +                againstTemperature = compareTemperatureFormat.convert(againstTemperature, temperatureFormat);
    
    118
    +            }
    
    119
    +            stack.set(fieldName + "Compare", new TemperatureResult(max, againstTemperature, I18nEnumHelper.getLabel(temperatureFormat)));
    
    120
    +            try {
    
    121
    +                addFieldError(fieldName, object);
    
    122
    +            } finally {
    
    123
    +                stack.pop();
    
    124
    +            }
    
    125
    +        }
    
    126
    +
    
    127
    +    }
    
    128
    +
    
    129
    +    @Override
    
    130
    +    public String getValidatorType() {
    
    131
    +        return "temperatureCompare";
    
    132
    +    }
    
    133
    +
    
    134
    +    static class TemperatureResult {
    
    135
    +        private final float max;
    
    136
    +        private final Float againstTemperature;
    
    137
    +        private final String format;
    
    138
    +
    
    139
    +        TemperatureResult(float max, Float againstTemperature, String format) {
    
    140
    +            this.max = max;
    
    141
    +            this.againstTemperature = againstTemperature;
    
    142
    +            this.format = format;
    
    143
    +        }
    
    144
    +
    
    145
    +        public Float getAgainstTemperature() {
    
    146
    +            return againstTemperature;
    
    147
    +        }
    
    148
    +
    
    149
    +        public float getMax() {
    
    150
    +            return max;
    
    151
    +        }
    
    152
    +
    
    153
    +        public String getFormat() {
    
    154
    +            return format;
    
    155
    +        }
    
    156
    +    }
    
    157
    +
    
    158
    +}
    
    159
    +

  • validation/pom.xml
    ... ... @@ -191,6 +191,11 @@
    191 191
                 <artifactId>jaxx-widgets-gis</artifactId>
    
    192 192
                 <version>${lib.version.java4all.jaxx}</version>
    
    193 193
               </dependency>
    
    194
    +          <dependency>
    
    195
    +            <groupId>io.ultreia.java4all.jaxx</groupId>
    
    196
    +            <artifactId>jaxx-widgets-temperature</artifactId>
    
    197
    +            <version>${lib.version.java4all.jaxx}</version>
    
    198
    +          </dependency>
    
    194 199
               <dependency>
    
    195 200
                 <groupId>org.javassist</groupId>
    
    196 201
                 <artifactId>javassist</artifactId>
    

  • validation/src/main/resources/fr/ird/observe/dto/data/longline/ActivityLonglineDto-create-error-validation.xml
    ... ... @@ -77,16 +77,14 @@
    77 77
       <field name="seaSurfaceTemperature">
    
    78 78
     
    
    79 79
         <!-- temperature surface non saisie ||  12.0 <= temperature surface  <= 35.0 -->
    
    80
    -    <field-validator type="fieldexpressionwithparams" short-circuit="true">
    
    81
    -      <param name="doubleParams">min:12.0|max:35.0</param>
    
    82
    -      <param name="expression">
    
    83
    -        <![CDATA[ seaSurfaceTemperature == null || (doubles.min <= seaSurfaceTemperature && seaSurfaceTemperature <= doubles.max)]]>
    
    84
    -      </param>
    
    80
    +    <field-validator type="temperatureBound" short-circuit="true">
    
    81
    +      <param name="min">12.0</param>
    
    82
    +      <param name="max">35.0</param>
    
    83
    +      <param name="defaultTemperatureFormat">C</param>
    
    85 84
           <message>
    
    86
    -        observe.validation.activity.bound.seaSurfaceTemperature##${doubles.min}##${doubles.max}
    
    85
    +        observe.validation.activity.bound.seaSurfaceTemperature##${seaSurfaceTemperatureBound.min}##${seaSurfaceTemperatureBound.max}##${seaSurfaceTemperatureBound.format}
    
    87 86
           </message>
    
    88 87
         </field-validator>
    
    89
    -
    
    90 88
       </field>
    
    91 89
     
    
    92 90
       <field name="quadrant">
    

  • validation/src/main/resources/fr/ird/observe/dto/data/longline/ActivityLonglineDto-update-error-validation.xml
    ... ... @@ -62,13 +62,22 @@
    62 62
       <field name="seaSurfaceTemperature">
    
    63 63
     
    
    64 64
         <!-- temperature surface non saisie ||  12.0 <= temperature surface  <= 35.0 -->
    
    65
    -    <field-validator type="fieldexpressionwithparams" short-circuit="true">
    
    66
    -      <param name="doubleParams">min:12.0|max:35.0</param>
    
    67
    -      <param name="expression">
    
    68
    -        <![CDATA[ seaSurfaceTemperature == null || (doubles.min <= seaSurfaceTemperature && seaSurfaceTemperature <= doubles.max)]]>
    
    69
    -      </param>
    
    65
    +    <field-validator type="temperatureBound" short-circuit="true">
    
    66
    +      <param name="min">12.0</param>
    
    67
    +      <param name="max">35.0</param>
    
    68
    +      <param name="defaultTemperatureFormat">C</param>
    
    69
    +      <message>
    
    70
    +        observe.validation.activity.bound.seaSurfaceTemperature##${seaSurfaceTemperatureBound.min}##${seaSurfaceTemperatureBound.max}##${seaSurfaceTemperatureBound.format}
    
    71
    +      </message>
    
    72
    +    </field-validator>
    
    73
    +    <!-- coherence temperature surface (delta de 12° par rapport a celle de l'activity precedente) -->
    
    74
    +    <field-validator type="temperatureCompare" short-circuit="true">
    
    75
    +      <param name="max">12.0</param>
    
    76
    +      <param name="defaultTemperatureFormat">C</param>
    
    77
    +      <param name="compareTemperatureFormat">C</param>
    
    78
    +      <param name="compareFieldName">currentTrip.getPreviousActivity(id).seaSurfaceTemperature</param>
    
    70 79
           <message>
    
    71
    -        observe.validation.activity.bound.seaSurfaceTemperature##${doubles.min}##${doubles.max}
    
    80
    +        observe.validation.activity.invalid.seaSurfaceTemperature##${seaSurfaceTemperatureCompare.againstTemperature}##${currentTrip.getPreviousActivity(id).timeStamp}##${seaSurfaceTemperatureCompare.max}##${seaSurfaceTemperatureCompare.format}
    
    72 81
           </message>
    
    73 82
         </field-validator>
    
    74 83
     
    

  • validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-create-error-validation.xml
    ... ... @@ -251,28 +251,12 @@
    251 251
       <field name="seaSurfaceTemperature">
    
    252 252
     
    
    253 253
         <!-- temperature surface non saisie ||  12.0 <= temperature surface  <= 35.0 -->
    
    254
    -    <field-validator type="fieldexpressionwithparams" short-circuit="true">
    
    255
    -      <param name="doubleParams">min:12.0|max:35.0</param>
    
    256
    -      <param name="expression">
    
    257
    -        <![CDATA[ seaSurfaceTemperature == null || (doubles.min <= seaSurfaceTemperature && seaSurfaceTemperature <= doubles.max)]]>
    
    258
    -      </param>
    
    259
    -      <message>
    
    260
    -        observe.validation.activity.bound.seaSurfaceTemperature##${doubles.min}##${doubles.max}
    
    261
    -      </message>
    
    262
    -    </field-validator>
    
    263
    -
    
    264
    -    <!-- coherence temperature surface (delta de 12° par rapport a celle de l'activity precedente) -->
    
    265
    -    <field-validator type="fieldexpression">
    
    266
    -      <param name="expression"><![CDATA[
    
    267
    -                seaSurfaceTemperature == null || previousActivity == null || previousActivity.seaSurfaceTemperature == null ||
    
    268
    -                (previousActivity.seaSurfaceTemperature > seaSurfaceTemperature ?
    
    269
    -                previousActivity.seaSurfaceTemperature - seaSurfaceTemperature <= 12.0
    
    270
    -                :  seaSurfaceTemperature - previousActivity.seaSurfaceTemperature <= 12.0
    
    271
    -                )
    
    272
    -             ]]>
    
    273
    -      </param>
    
    254
    +    <field-validator type="temperatureBound" short-circuit="true">
    
    255
    +      <param name="min">12.0</param>
    
    256
    +      <param name="max">35.0</param>
    
    257
    +      <param name="defaultTemperatureFormat">C</param>
    
    274 258
           <message>
    
    275
    -        observe.validation.activity.invalid.seaSurfaceTemperature##${seaSurfaceTemperature}##${previousActivity.seaSurfaceTemperature}##${previousActivity.time}
    
    259
    +        observe.validation.activity.bound.seaSurfaceTemperature##${seaSurfaceTemperatureBound.min}##${seaSurfaceTemperatureBound.max}##${seaSurfaceTemperatureBound.format}
    
    276 260
           </message>
    
    277 261
         </field-validator>
    
    278 262
     
    

  • validation/src/main/resources/fr/ird/observe/dto/data/seine/ActivitySeineDto-update-error-validation.xml
    ... ... @@ -180,28 +180,22 @@
    180 180
       <field name="seaSurfaceTemperature">
    
    181 181
     
    
    182 182
         <!-- temperature surface non saisie ||  12.0 <= temperature surface  <= 35.0 -->
    
    183
    -    <field-validator type="fieldexpressionwithparams" short-circuit="true">
    
    184
    -      <param name="doubleParams">min:12.0|max:35.0</param>
    
    185
    -      <param name="expression">
    
    186
    -        <![CDATA[ seaSurfaceTemperature == null || (doubles.min <= seaSurfaceTemperature && seaSurfaceTemperature <= doubles.max)]]>
    
    187
    -      </param>
    
    183
    +    <field-validator type="temperatureBound" short-circuit="true">
    
    184
    +      <param name="min">12.0</param>
    
    185
    +      <param name="max">35.0</param>
    
    186
    +      <param name="defaultTemperatureFormat">C</param>
    
    188 187
           <message>
    
    189
    -        observe.validation.activity.bound.seaSurfaceTemperature##${doubles.min}##${doubles.max}
    
    188
    +        observe.validation.activity.bound.seaSurfaceTemperature##${seaSurfaceTemperatureBound.min}##${seaSurfaceTemperatureBound.max}##${seaSurfaceTemperatureBound.format}
    
    190 189
           </message>
    
    191 190
         </field-validator>
    
    192
    -
    
    193 191
         <!-- coherence temperature surface (delta de 12° par rapport a celle de l'activity precedente) -->
    
    194
    -    <field-validator type="fieldexpression">
    
    195
    -      <param name="expression"><![CDATA[
    
    196
    -                seaSurfaceTemperature == null || previousActivity == null || previousActivity.seaSurfaceTemperature == null ||
    
    197
    -                (previousActivity.seaSurfaceTemperature > seaSurfaceTemperature ?
    
    198
    -                previousActivity.seaSurfaceTemperature - seaSurfaceTemperature <= 12.0
    
    199
    -                :  seaSurfaceTemperature - previousActivity.seaSurfaceTemperature <= 12.0
    
    200
    -                )
    
    201
    -             ]]>
    
    202
    -      </param>
    
    192
    +    <field-validator type="temperatureCompare" short-circuit="true">
    
    193
    +      <param name="max">12.0</param>
    
    194
    +      <param name="defaultTemperatureFormat">C</param>
    
    195
    +      <param name="compareTemperatureFormat">C</param>
    
    196
    +      <param name="compareFieldName">currentRoute.getPreviousActivity(id).seaSurfaceTemperature</param>
    
    203 197
           <message>
    
    204
    -        observe.validation.activity.invalid.seaSurfaceTemperature##${seaSurfaceTemperature}##${previousActivity.seaSurfaceTemperature}##${previousActivity.time}
    
    198
    +        observe.validation.activity.invalid.seaSurfaceTemperature##${seaSurfaceTemperatureCompare.againstTemperature}##${currentRoute.getPreviousActivity(id).time}##${seaSurfaceTemperatureCompare.max}##${seaSurfaceTemperatureCompare.format}
    
    205 199
           </message>
    
    206 200
         </field-validator>
    
    207 201
     
    

  • validation/src/main/resources/i18n/validation_en_GB.properties
    ... ... @@ -325,7 +325,7 @@ observe.common.WindDto.speedRange=Speed range
    325 325
     observe.common.WindDto.waveHeight=Wave weight
    
    326 326
     observe.validation.activity.bound.latitude=Latitude must be between %1$s and %2$s.
    
    327 327
     observe.validation.activity.bound.longitude=Longitude must be between %1$s and %2$s.
    
    328
    -observe.validation.activity.bound.seaSurfaceTemperature=Temperature must be between %1$s and %2$s.
    
    328
    +observe.validation.activity.bound.seaSurfaceTemperature=Temperature must be between %1$s%3$s and %2$s%3$s.
    
    329 329
     observe.validation.activity.bound.vesselSpeed=Vessel speed must be between %1$s and %2$s.
    
    330 330
     observe.validation.activity.comment.tobig=Comment size is bound to 1024 characters.
    
    331 331
     observe.validation.activity.desactivated.currentFpaZone=Selected current Fpa zone is disabled.
    
    ... ... @@ -340,7 +340,7 @@ observe.validation.activity.desactivated.vesselActivity=Selected vessel activity
    340 340
     observe.validation.activity.desactivated.wind=Selected wind is disabled.
    
    341 341
     observe.validation.activity.duplicated.time=There is already another activity at this time.
    
    342 342
     observe.validation.activity.invalid.quadrant=Quadrant is not coherent with ocean (%1$s) of trip (indian\: 1,2, atlantic 1,2,3,4).
    
    343
    -observe.validation.activity.invalid.seaSurfaceTemperature=Sea temperature (%1$s) can't vary to more than 12° from surface temperature (%2$s) of the previous activity %3$s.
    
    343
    +observe.validation.activity.invalid.seaSurfaceTemperature=Sea temperature can't vary to more than %3$s%4$s from surface temperature (%1$s%4$s) of the previous activity %2$s.
    
    344 344
     observe.validation.activity.invalid.speed=Activity speed is %s nb, which is more than the maximum authorized which is %s nd.
    
    345 345
     observe.validation.activity.null.dcp=No floating object selected.
    
    346 346
     observe.validation.activity.null.fpaZone=Fpa zone is not filled.
    

  • validation/src/main/resources/i18n/validation_es_ES.properties
    ... ... @@ -327,7 +327,7 @@ observe.common.WindDto.speedRange=Texto velocidad del viento
    327 327
     observe.common.WindDto.waveHeight=Texto descriptivo de «altura media de la ola»
    
    328 328
     observe.validation.activity.bound.latitude=La latitud dada debe estar comprendida entre %1$s y %2$s.
    
    329 329
     observe.validation.activity.bound.longitude=La longitud dada debe estar comprendida entre %1$s y %2$s.
    
    330
    -observe.validation.activity.bound.seaSurfaceTemperature=La temperatura debe estar comprendida entre %1$s y %2$s.
    
    330
    +observe.validation.activity.bound.seaSurfaceTemperature=La temperatura debe estar comprendida entre %1$s%3$s y %2$s%3$s.
    
    331 331
     observe.validation.activity.bound.vesselSpeed=La Velocidad del viento estar comprendida entre %1$s y %2$s.
    
    332 332
     observe.validation.activity.comment.tobig=La longitud del campo comentarios está limitada a 1024 carácteres.
    
    333 333
     observe.validation.activity.desactivated.currentFpaZone=La zona actual debe ser desactivada
    
    ... ... @@ -342,7 +342,7 @@ observe.validation.activity.desactivated.vesselActivity=Actividad del barco sele
    342 342
     observe.validation.activity.desactivated.wind=La fuerza del viento seleccionada está desactivada.
    
    343 343
     observe.validation.activity.duplicated.time=Ya existe una actividad a esa hora.
    
    344 344
     observe.validation.activity.invalid.quadrant=El cuadrante no es coherente con el informe del oceano (%1$s) de la marea (indico \: 1,2, atlantico \: 1, 2, 3, 4)
    
    345
    -observe.validation.activity.invalid.seaSurfaceTemperature=La temperatura superficial (%1$s) no puede variar mas de 12° con respecto a la temperatura superficial (%2$s) de la actividad anterio %3$s.
    
    345
    +observe.validation.activity.invalid.seaSurfaceTemperature=La temperatura superficial no puede variar mas de %3$s%4$s con respecto a la temperatura superficial (%1$s%4$s) de la actividad anterio %2$s.
    
    346 346
     observe.validation.activity.invalid.speed=La velocidad de la actividad actual es %s nudos, mientras que la velocidad máxima es %s nudos.
    
    347 347
     observe.validation.activity.null.dcp=No se ha introducido objeto flotante.
    
    348 348
     observe.validation.activity.null.fpaZone=La selección de una zona FPA es obligatoria.
    

  • validation/src/main/resources/i18n/validation_fr_FR.properties
    ... ... @@ -325,7 +325,7 @@ observe.common.WindDto.speedRange=Libellé vitesse vent
    325 325
     observe.common.WindDto.waveHeight=Libellé Hauteur moyenne vagues
    
    326 326
     observe.validation.activity.bound.latitude=La latitude doit être comprise entre %1$s et %2$s.
    
    327 327
     observe.validation.activity.bound.longitude=La longitude doit être comprise entre %1$s et %2$s.
    
    328
    -observe.validation.activity.bound.seaSurfaceTemperature=La température doit être comprise entre %1$s et %2$s.
    
    328
    +observe.validation.activity.bound.seaSurfaceTemperature=La température doit être comprise entre %1$s%3$s et %2$s%3$s.
    
    329 329
     observe.validation.activity.bound.vesselSpeed=La vitesse navire doit être comprise entre %1$s et %2$s.
    
    330 330
     observe.validation.activity.comment.tobig=La taille du commentaire est limitée à 1024 caractères.
    
    331 331
     observe.validation.activity.desactivated.currentFpaZone=La zone courante est désactivée.
    
    ... ... @@ -340,7 +340,7 @@ observe.validation.activity.desactivated.vesselActivity=L'activité bateau séle
    340 340
     observe.validation.activity.desactivated.wind=Le vent Beaufort sélectionné est désactivé.
    
    341 341
     observe.validation.activity.duplicated.time=Il existe déjà une autre activité à cette heure.
    
    342 342
     observe.validation.activity.invalid.quadrant=Le quadrant n'est pas cohérent par rapport à l'océan (%1$s) de la marée (indien \: 1
    
    343
    -observe.validation.activity.invalid.seaSurfaceTemperature=La température surface (%1$s) ne peut pas varier de plus de 12° par rapport à la température surface (%2$s) de l'activité précédente %3$s.
    
    343
    +observe.validation.activity.invalid.seaSurfaceTemperature=La température surface ne peut pas varier de plus de %3$s%4$s par rapport à la température surface (%1$s%4$s) de l'activité précédente %2$s.
    
    344 344
     observe.validation.activity.invalid.speed=La vitesse de l'activité courante est de %s nd, alors que la vitesse maximale autorisée est %s nd
    
    345 345
     observe.validation.activity.null.dcp=Aucun objet flottant saisi.
    
    346 346
     observe.validation.activity.null.fpaZone=La sélection d'une zone FPA est obligatoire.
    

  • validation/src/main/resources/validators.xml
    ... ... @@ -69,5 +69,7 @@
    69 69
         <validator name="referentialCode" class="fr.ird.observe.services.validation.validators.ReferentialCodeValidator"/>
    
    70 70
         <validator name="nonTargetCatchObservedSystem" class="fr.ird.observe.services.validation.validators.NonTargetCatchObservedSystemValidator"/>
    
    71 71
         <validator name="activitySeine_observedSystem" class="fr.ird.observe.services.validation.validators.ActivitySeineObservedSystemValidator"/>
    
    72
    +  <validator name="temperatureBound" class="fr.ird.observe.services.validation.validators.TemperatureBoundFieldValidator"/>
    
    73
    +  <validator name="temperatureCompare" class="fr.ird.observe.services.validation.validators.TemperatureCompareFieldValidator"/>
    
    72 74
     
    
    73 75
     </validators>