m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-24 21:51:53 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-24 21:51:53 +0100
commit852fe8974c9bf4fc6da70256233b092c9e8cca7e (patch)
tree634a1511b713d48c6309265d7e1794824dbbfc80 /src/main/java
parent1fbbfd3dd52146e64511552a2dbb5f35c62771c9 (diff)
Improve attribute parsing on submission
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java23
1 files changed, 19 insertions, 4 deletions
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();