diff --git a/src/main/java/org/caosdb/server/query/POV.java b/src/main/java/org/caosdb/server/query/POV.java index 95c50420f58c16a0bf9564f18c325024d72d5c99..89ea9ad46e6205dfe0583e8f54551effd82a2658 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);