From 852fe8974c9bf4fc6da70256233b092c9e8cca7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 24 Nov 2019 21:51:53 +0100 Subject: Improve attribute parsing on submission --- .../mimuw/cloudatlas/client/ClientController.java | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java index 148fb8d..9415888 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -178,6 +178,17 @@ public class ClientController { return new ValueSet(resultValue, resultValue.iterator().next().getType()); } + private Long parseIntegerAsLong(String value) { + Double doubleVal; + + try { + doubleVal = Double.parseDouble(value); + return doubleVal.longValue(); + } catch (NumberFormatException e) { + return Long.parseLong(value); + } + } + private Value parseAttributeValue(AttributeInput attributeObject) throws Exception { Gson gson = new Gson(); Value attributeValue = null; @@ -197,17 +208,21 @@ public class ClientController { attributeValue = new ValueDouble(Double.parseDouble(attributeObject.getValueString())); break; case "Int": - Double tempDouble = Double.parseDouble(attributeObject.getValueString()); - attributeValue = new ValueInt(tempDouble.longValue()); + attributeValue = new ValueInt(parseIntegerAsLong(attributeObject.getValueString())); break; case "String": attributeValue = new ValueString(attributeObject.getValueString()); break; case "Time": - attributeValue = new ValueTime(Long.parseLong(attributeObject.getValueString())); + attributeValue = new ValueTime(parseIntegerAsLong(attributeObject.getValueString())); break; case "Duration": - attributeValue = new ValueDuration(attributeObject.getValueString()); + if (attributeObject.getValueString().matches("\\d+")) { + attributeValue = new ValueDuration(parseIntegerAsLong(attributeObject.getValueString())); + } else { + String valDuration = attributeObject.getValueString().trim(); + attributeValue = new ValueDuration(valDuration); + } break; case "Contact": DataStringInput contactsString = new DataStringInput(); -- cgit v1.2.3