Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
655f2efb
by Tony Chemit at 2024-09-11T15:49:54+02:00
-
b90951e3
by Tony Chemit at 2024-09-11T15:49:54+02:00
-
9670ccf7
by Tony Chemit at 2024-09-11T15:49:54+02:00
-
2aaeae8d
by Tony Chemit at 2024-09-11T15:49:55+02:00
-
97886cfb
by Tony Chemit at 2024-09-11T15:49:55+02:00
-
81566471
by Tony Chemit at 2024-09-11T15:51:04+02:00
8 changed files:
- client/core/src/main/java/fr/ird/observe/client/util/table/JXTableUtil.java
- client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/SetDetailCompositionUIInitializer.java
- client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/observation/composition/SetDetailCompositionValidatorService.java
- core/api/dto/src/main/java/fr/ird/observe/dto/data/ll/observation/SectionTemplateDto.java
- core/persistence/java/src/main/resources/META-INF/persistence/Observe/TopiaEntitySqlModel.json
- core/persistence/java/src/main/resources/fr/ird/observe/entities/data/ll/observation/BasketImpl.hbm.xml
- core/persistence/migration/src/main/java/fr/ird/observe/spi/migration/v9/DataSourceMigrationForVersion_9_4.java
- model/src/main/models/Observe/persistence/attribute/digits.properties
Changes:
| ... | ... | @@ -31,14 +31,18 @@ import io.ultreia.java4all.decoration.Decorator; |
| 31 | 31 | import org.jdesktop.swingx.JXTable;
|
| 32 | 32 | import org.jdesktop.swingx.renderer.DefaultTableRenderer;
|
| 33 | 33 | import org.jdesktop.swingx.renderer.StringValue;
|
| 34 | +import org.nuiton.jaxx.runtime.swing.SwingUtil;
|
|
| 35 | +import org.nuiton.jaxx.widgets.number.NumberCellEditor;
|
|
| 34 | 36 | |
| 35 | 37 | import javax.swing.JComponent;
|
| 36 | 38 | import javax.swing.JScrollPane;
|
| 37 | 39 | import javax.swing.JTable;
|
| 40 | +import javax.swing.border.LineBorder;
|
|
| 38 | 41 | import javax.swing.table.TableCellEditor;
|
| 39 | 42 | import javax.swing.table.TableCellRenderer;
|
| 40 | 43 | import javax.swing.table.TableColumn;
|
| 41 | 44 | import javax.swing.table.TableColumnModel;
|
| 45 | +import java.awt.Color;
|
|
| 42 | 46 | import java.awt.Component;
|
| 43 | 47 | import java.awt.Dimension;
|
| 44 | 48 | import java.util.Collection;
|
| ... | ... | @@ -221,6 +225,14 @@ public class JXTableUtil { |
| 221 | 225 | return getDefaultTableRenderer(sv, true);
|
| 222 | 226 | }
|
| 223 | 227 | |
| 228 | + public static TableCellEditor newFloat2ColumnEditor() {
|
|
| 229 | + @SuppressWarnings("unchecked") NumberCellEditor<Float> editor = (NumberCellEditor<Float>) NumberCellEditor.newFloatColumnEditor();
|
|
| 230 | + editor.getNumberEditor().setSelectAllTextOnError(true);
|
|
| 231 | + editor.getNumberEditor().getTextField().setBorder(new LineBorder(Color.GRAY, 2));
|
|
| 232 | + editor.getNumberEditor().setNumberPattern(SwingUtil.DECIMAL2_PATTERN);
|
|
| 233 | + return editor;
|
|
| 234 | + }
|
|
| 235 | + |
|
| 224 | 236 | private static DefaultTableRenderer getDefaultTableRenderer(StringValue sv, boolean useStringValue) {
|
| 225 | 237 | return getDefaultTableRenderer(sv, useStringValue, null);
|
| 226 | 238 | }
|
| ... | ... | @@ -174,8 +174,8 @@ public class SetDetailCompositionUIInitializer extends ContentSimpleUIInitialize |
| 174 | 174 | JXTableUtil.initEditors(table,
|
| 175 | 175 | null,
|
| 176 | 176 | NumberCellEditor.newIntegerColumnEditor(),
|
| 177 | - NumberCellEditor.newFloatColumnEditor(),
|
|
| 178 | - NumberCellEditor.newFloatColumnEditor());
|
|
| 177 | + JXTableUtil.newFloat2ColumnEditor(),
|
|
| 178 | + JXTableUtil.newFloat2ColumnEditor());
|
|
| 179 | 179 | |
| 180 | 180 | table.installTableKeyListener();
|
| 181 | 181 | // table.installTableFocusListener();
|
| ... | ... | @@ -92,7 +92,7 @@ public class SetDetailCompositionValidatorService { |
| 92 | 92 | Float basketFloatline1Length = basket.getFloatline1Length();
|
| 93 | 93 | if (previousBasketFloatline2Length != null
|
| 94 | 94 | && basketFloatline1Length != null
|
| 95 | - && Math.abs(previousBasketFloatline2Length - basketFloatline1Length) > 0.001f) {
|
|
| 95 | + && Math.abs(previousBasketFloatline2Length - basketFloatline1Length) > 0.01f) {
|
|
| 96 | 96 | validationContext.addMessage(basketValidator, NuitonValidatorScope.ERROR, "floatline2Length", t("observe.data.ll.observation.SetDetailComposition.basket.invalid.nextFloatline1Length", previousBasketFloatline2Length, basketFloatline1Length));
|
| 97 | 97 | }
|
| 98 | 98 | }
|
| ... | ... | @@ -25,6 +25,7 @@ package fr.ird.observe.dto.data.ll.observation; |
| 25 | 25 | import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;
|
| 26 | 26 | import io.ultreia.java4all.decoration.Decorated;
|
| 27 | 27 | import io.ultreia.java4all.jaxx.widgets.length.nautical.NauticalLengthFormat;
|
| 28 | +import io.ultreia.java4all.lang.Numbers;
|
|
| 28 | 29 | import io.ultreia.java4all.lang.Strings;
|
| 29 | 30 | |
| 30 | 31 | import java.util.ArrayList;
|
| ... | ... | @@ -72,7 +73,7 @@ public class SectionTemplateDto extends GeneratedSectionTemplateDto { |
| 72 | 73 | String[] parts = floatlineLengths.substring(0, floatlineLengths.indexOf(":")).split("/");
|
| 73 | 74 | List<Float> newLengths = new ArrayList<>(parts.length);
|
| 74 | 75 | for (String part : parts) {
|
| 75 | - Float aFloat = Float.valueOf(part);
|
|
| 76 | + float aFloat = Numbers.roundTwoDigits(Float.valueOf(part));
|
|
| 76 | 77 | newLengths.add(aFloat);
|
| 77 | 78 | }
|
| 78 | 79 | return newLengths;
|
| ... | ... | @@ -105,8 +106,8 @@ public class SectionTemplateDto extends GeneratedSectionTemplateDto { |
| 105 | 106 | Iterator<BasketDto> basketIterator = baskets.iterator();
|
| 106 | 107 | {
|
| 107 | 108 | // on first basket, using the two first lengths
|
| 108 | - floatline1 = unitFormat.convert(NauticalLengthFormat.M, lengthsIterator.next());
|
|
| 109 | - floatline2 = unitFormat.convert(NauticalLengthFormat.M,lengthsIterator.next());
|
|
| 109 | + floatline1 = Numbers.roundTwoDigits(unitFormat.convert(NauticalLengthFormat.M, lengthsIterator.next()));
|
|
| 110 | + floatline2 = Numbers.roundTwoDigits(unitFormat.convert(NauticalLengthFormat.M,lengthsIterator.next()));
|
|
| 110 | 111 | BasketDto basket = basketIterator.next();
|
| 111 | 112 | basket.setFloatline1Length(floatline1);
|
| 112 | 113 | basket.setFloatline2Length(floatline2);
|
| ... | ... | @@ -114,7 +115,7 @@ public class SectionTemplateDto extends GeneratedSectionTemplateDto { |
| 114 | 115 | while (basketIterator.hasNext()) {
|
| 115 | 116 | // floatline1 is previous floatline2
|
| 116 | 117 | floatline1 = floatline2;
|
| 117 | - floatline2 = unitFormat.convert(NauticalLengthFormat.M,lengthsIterator.next());
|
|
| 118 | + floatline2 = Numbers.roundTwoDigits(unitFormat.convert(NauticalLengthFormat.M,lengthsIterator.next()));
|
|
| 118 | 119 | BasketDto basket = basketIterator.next();
|
| 119 | 120 | basket.setFloatline1Length(floatline1);
|
| 120 | 121 | basket.setFloatline2Length(floatline2);
|
| ... | ... | @@ -664,8 +664,8 @@ |
| 664 | 664 | "settingIdentifier": "java.lang.Integer"
|
| 665 | 665 | },
|
| 666 | 666 | "decimalPropertiesScales": {
|
| 667 | - "floatline1Length": 4,
|
|
| 668 | - "floatline2Length": 4
|
|
| 667 | + "floatline1Length": 2,
|
|
| 668 | + "floatline2Length": 2
|
|
| 669 | 669 | }
|
| 670 | 670 | },
|
| 671 | 671 | "replicationOrder": [
|
| ... | ... | @@ -38,10 +38,10 @@ |
| 38 | 38 | <property name="settingIdentifier" access="field" type="java.lang.Integer" column="settingIdentifier" not-null="true"/>
|
| 39 | 39 | <property name="haulingIdentifier" access="field" type="java.lang.Integer" column="haulingIdentifier"/>
|
| 40 | 40 | <property name="floatline1Length" access="field" type="java.lang.Float">
|
| 41 | - <column name="floatline1Length" precision="6" scale="4" sql-type="numeric"/>
|
|
| 41 | + <column name="floatline1Length" precision="6" scale="2" sql-type="numeric"/>
|
|
| 42 | 42 | </property>
|
| 43 | 43 | <property name="floatline2Length" access="field" type="java.lang.Float">
|
| 44 | - <column name="floatline2Length" precision="6" scale="4" sql-type="numeric"/>
|
|
| 44 | + <column name="floatline2Length" precision="6" scale="2" sql-type="numeric"/>
|
|
| 45 | 45 | </property>
|
| 46 | 46 | <set name="branchline" order-by="settingIdentifier" lazy="true" cascade="all,delete-orphan" >
|
| 47 | 47 | <key column="basket" foreign-key="fk_ll_observation_basket_branchline" not-null="true" />
|
| ... | ... | @@ -24,11 +24,17 @@ package fr.ird.observe.spi.migration.v9; |
| 24 | 24 | |
| 25 | 25 | import com.google.auto.service.AutoService;
|
| 26 | 26 | import fr.ird.observe.spi.migration.ByMajorMigrationVersionResource;
|
| 27 | +import io.ultreia.java4all.lang.Numbers;
|
|
| 27 | 28 | import io.ultreia.java4all.util.Version;
|
| 28 | 29 | import io.ultreia.java4all.util.sql.SqlQuery;
|
| 29 | 30 | import org.nuiton.topia.service.migration.resources.MigrationVersionResource;
|
| 30 | 31 | import org.nuiton.topia.service.migration.resources.MigrationVersionResourceExecutor;
|
| 31 | 32 | |
| 33 | +import java.math.BigDecimal;
|
|
| 34 | +import java.math.RoundingMode;
|
|
| 35 | +import java.sql.ResultSet;
|
|
| 36 | +import java.sql.SQLException;
|
|
| 37 | + |
|
| 32 | 38 | /**
|
| 33 | 39 | * Created at 11/09/2024.
|
| 34 | 40 | *
|
| ... | ... | @@ -46,9 +52,48 @@ public class DataSourceMigrationForVersion_9_4 extends ByMajorMigrationVersionRe |
| 46 | 52 | @Override
|
| 47 | 53 | public void generateSqlScript(MigrationVersionResourceExecutor executor) {
|
| 48 | 54 | boolean withIds = executor.findSingleResult(SqlQuery.wrap("SELECT COUNT (*) FROM common.person", r -> r.getInt(1) > 0));
|
| 55 | + if (withIds) {
|
|
| 56 | + // See https://gitlab.com/ultreiaio/ird-observe/-/issues/2914
|
|
| 57 | + issue2914(executor);
|
|
| 58 | + }
|
|
| 59 | + }
|
|
| 49 | 60 | |
| 61 | + private void issue2914(MigrationVersionResourceExecutor executor) {
|
|
| 62 | + executor.findMultipleResult(SqlQuery.wrap("SELECT topiaId, floatline1Length, floatline2Length FROM ll_observation.Basket WHERE floatline1Length IS NOT NULL OR floatline2Length IS NOT NULL", BasketRecord::new))
|
|
| 63 | + .stream()
|
|
| 64 | + .filter(BasketRecord::isModified)
|
|
| 65 | + .map(BasketRecord::toSql)
|
|
| 66 | + .forEach(executor::writeSql);
|
|
| 50 | 67 | }
|
| 51 | 68 | |
| 69 | + private static class BasketRecord {
|
|
| 70 | + private final String id;
|
|
| 71 | + private final Float floatline1Length;
|
|
| 72 | + private final Float floatline2Length;
|
|
| 73 | + private final boolean modified;
|
|
| 74 | + |
|
| 75 | + public BasketRecord(ResultSet r) throws SQLException {
|
|
| 76 | + this.id = r.getString(1);
|
|
| 77 | + Double floatline1Length = toDouble(r.getObject(2));
|
|
| 78 | + Double floatline2Length = toDouble(r.getObject(3));
|
|
| 79 | + this.floatline1Length = floatline1Length == null ? null : Numbers.roundNDigits(floatline1Length.floatValue(), 2);
|
|
| 80 | + this.floatline2Length = floatline2Length == null ? null : Numbers.roundNDigits(floatline2Length.floatValue(), 2);
|
|
| 81 | + this.modified = (this.floatline1Length != null && this.floatline1Length.toString().equals(floatline1Length.toString())) ||
|
|
| 82 | + (this.floatline2Length != null && this.floatline2Length.toString().equals(floatline2Length.toString()));
|
|
| 83 | + }
|
|
| 84 | + |
|
| 85 | + private static Double toDouble(Object r) {
|
|
| 86 | + return r == null ? null : new BigDecimal(r.toString()).setScale(10, RoundingMode.HALF_UP).doubleValue();
|
|
| 87 | + }
|
|
| 88 | + |
|
| 89 | + public boolean isModified() {
|
|
| 90 | + return modified;
|
|
| 91 | + }
|
|
| 92 | + |
|
| 93 | + public String toSql() {
|
|
| 94 | + return String.format("UPDATE ll_observation.Basket SET floatline1Length = %s, floatline2Length = %s WHERE topiaId ='%s';", floatline1Length, floatline2Length, id);
|
|
| 95 | + }
|
|
| 96 | + }
|
|
| 52 | 97 | }
|
| 53 | 98 | |
| 54 | 99 |
| ... | ... | @@ -58,8 +58,8 @@ data.ll.observation.Activity.attribute.latitude=4 |
| 58 | 58 | data.ll.observation.Activity.attribute.longitude=4
|
| 59 | 59 | data.ll.observation.Activity.attribute.seaSurfaceTemperature=2
|
| 60 | 60 | data.ll.observation.BaitsComposition.attribute.individualWeight=3
|
| 61 | -data.ll.observation.Basket.attribute.floatline1Length=4
|
|
| 62 | -data.ll.observation.Basket.attribute.floatline2Length=4
|
|
| 61 | +data.ll.observation.Basket.attribute.floatline1Length=2
|
|
| 62 | +data.ll.observation.Basket.attribute.floatline2Length=2
|
|
| 63 | 63 | data.ll.observation.Branchline.attribute.branchlineLength=4
|
| 64 | 64 | data.ll.observation.Branchline.attribute.snapWeight=3
|
| 65 | 65 | data.ll.observation.Branchline.attribute.swivelWeight=3
|