From c7b2ab0e42471cfea1cfc617e4a05ff920ab0c03 Mon Sep 17 00:00:00 2001 From: Daniel Hornung <d.hornung@indiscale.com> Date: Fri, 24 Jun 2022 11:58:30 +0200 Subject: [PATCH] FIX: POV.java: Fixed unit-induced value conversion. --- src/main/java/org/caosdb/server/query/POV.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/caosdb/server/query/POV.java b/src/main/java/org/caosdb/server/query/POV.java index 95c50420..89ea9ad4 100644 --- a/src/main/java/org/caosdb/server/query/POV.java +++ b/src/main/java/org/caosdb/server/query/POV.java @@ -63,6 +63,7 @@ public class POV implements EntityFilterInterface { private DateTimeInterface vDatetime; private final String aggregate; private String targetSet = null; + private String unitStr = null; private Unit unit = null; private Long stdUnitSig = null; private Double vDoubleConvertedToStdUnit = null; @@ -112,7 +113,6 @@ public class POV implements EntityFilterInterface { // parse value to int/double/datetime if (this.value != null) { - String unitStr = null; // try and parse as integer try { @@ -122,7 +122,7 @@ public class POV implements EntityFilterInterface { throw new NumberFormatException(); } final String vIntStr = m.group(1); - unitStr = m.group(2); + this.unitStr = m.group(2); this.vInt = Integer.parseInt(vIntStr); } catch (final NumberFormatException e) { this.vInt = null; @@ -138,7 +138,7 @@ public class POV implements EntityFilterInterface { throw new NumberFormatException(); } final String vDoubleStr = m.group(1); - unitStr = m.group(2); + this.unitStr = m.group(2); this.vDouble = Double.parseDouble(vDoubleStr); } catch (final NumberFormatException e) { @@ -146,16 +146,17 @@ public class POV implements EntityFilterInterface { } } - if (this.vDouble != null && unitStr != null && unitStr.length() > 0) { + if ((this.vDouble != null || this.vInt != null) + && this.unitStr != null + && this.unitStr.length() > 0) { try { - this.unit = getUnit(unitStr); + this.unit = getUnit(this.unitStr); } catch (final ParserException e) { e.printStackTrace(); throw new UnsupportedOperationException("Could not parse the unit."); } this.stdUnitSig = this.unit.normalize().getSignature(); - this.vDoubleConvertedToStdUnit = this.unit.convert(this.vDouble); } // try and parse as datetime try { @@ -285,6 +286,11 @@ public class POV implements EntityFilterInterface { } callPOV.setDouble(8, this.vDouble); } + // finally: do unit conversion + if (this.unitStr != null && this.unitStr.length() > 0) { + this.vDoubleConvertedToStdUnit = + this.unit.convert(this.vDouble != null ? this.vDouble : vDoubleSubst); + } } else { callPOV.setNull(7, INTEGER); callPOV.setNull(8, DOUBLE); -- GitLab