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:58:39 +0100
committerGitHub <noreply@github.com>2019-11-24 21:58:39 +0100
commite24fbbecfb9b631d9467b204a1b87c593746886b (patch)
tree57758d0a3b45e6d3555a6821a657cd4c781e18bf /src/main/java
parent9e678a942e98d78ad0ac81e7ffb0be551db88162 (diff)
parent63dfe423c50e9c0f82ccced10b7ca04a30ec4200 (diff)
Merge pull request #39 from m-chrzan/small_fixes_to_client
Small fixes to client
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java36
1 files changed, 24 insertions, 12 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 fe958ae..557ba39 100644
--- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java
@@ -172,6 +172,7 @@ public class ClientController {
String currentTypeString = types.get(1);
AttributeInput attributeInput = new AttributeInput();
ArrayList<String> newTypes = new ArrayList<>(types.subList(1, types.size()));
+ Gson gson = new Gson();
for (int i = 0; i < values.size(); i++) {
if (currentTypeString.equals("List")) {
@@ -180,7 +181,7 @@ public class ClientController {
resultValue.add(parseSetAttributeValue((List) values.get(i), newTypes));
} else {
attributeInput.setAttributeType(currentTypeString);
- attributeInput.setValueString(values.get(i).toString());
+ attributeInput.setValueString(gson.toJson(values.get(i)));
resultValue.add(parseAttributeValue(attributeInput));
}
}
@@ -202,41 +203,52 @@ 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;
switch (attributeObject.getAttributeType()) {
case "Boolean":
- attributeValue = attributeObject.getValueString().toLowerCase().equals("true") ?
- new ValueBoolean(true) :
- new ValueBoolean(false);
+ if (attributeObject.getValueString().toLowerCase().equals("true")) {
+ attributeValue = new ValueBoolean(true);
+ } else if (attributeObject.getValueString().toLowerCase().equals("false")) {
+ attributeValue = new ValueBoolean(false);
+ } else {
+ String errMsg = "Incorrect boolean value: " + attributeObject.getValueString();
+ throw new UnsupportedOperationException(errMsg);
+ }
break;
case "Double":
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());
+ attributeValue = new ValueDuration(parseIntegerAsLong(attributeObject.getValueString()));
break;
case "Contact":
DataStringInput contactsString = new DataStringInput();
contactsString.setString(attributeObject.getValueString());
attributeValue = parseContactsString(contactsString).iterator().next();
break;
- case "Query":
- Map parsedQuery = gson.fromJson(attributeObject.getValueString(), Map.class);
- attributeValue = new ValueQuery(attributeObject.getValueString());
- break;
case "List":
List parsedListValue = gson.fromJson(attributeObject.getValueString(), List.class);
ArrayList<String> parsedListTypes = new ArrayList<>(Arrays.asList(