m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main
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
parent9e678a942e98d78ad0ac81e7ffb0be551db88162 (diff)
parent63dfe423c50e9c0f82ccced10b7ca04a30ec4200 (diff)
Merge pull request #39 from m-chrzan/small_fixes_to_client
Small fixes to client
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java36
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html6
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html4
3 files changed, 28 insertions, 18 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(
diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html
index ed6dcd2..e348a11 100644
--- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html
+++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html
@@ -30,7 +30,6 @@
<option th:value="Time" th:text="Time"></option>
<option th:value="Duration" th:text="Duration"></option>
<option th:value="Contact" th:text="Contact"></option>
- <option th:value="Query" th:text="Query"></option>
<option th:value="List" th:text="List"></option>
<option th:value="Set" th:text="Set"></option>
</select>
@@ -48,9 +47,8 @@
<small id="attributeValueHelpBlock" class="form-text text-muted">
Use Json list for complex types and stick to proper format in duration and time. <br> Examples: <br>
Time: 3600 <br>
- Duration (version 1): 3600 <br>
- Duration (version 2): +0 00:00:00.001 <br>
- Contact: { "contactName" : [ 1, 1, 1, 1 ] } <br>
+ Duration: 3600 <br>
+ Contact: { "/contactName" : [ 1, 1, 1, 1 ] } <br>
Query: { "&queryName" : "query" } <br>
List: [ 1, 2, 3 ] <br>
Set: [ [1, 2], [3, 4], [5, 6] ] <br>
diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html
index 79a9f5f..ba0a3a8 100644
--- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html
+++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html
@@ -17,8 +17,8 @@
<textarea class="form-control" id="Textarea1" rows="3" th:field="*{string}"></textarea>
<small id="attributeValueHelpBlock" class="form-text text-muted">
Use Json format for entering contacts. Examples: <br>
- Contact: { "contactName" : [ 1, 1, 1, 1 ] } <br>
- Contact: { "contactName1" : [ 1, 1, 1, 1 ], "contactName2" : [ 2, 2, 2, 2 ] }
+ Contact: { "/contactName" : [ 1, 1, 1, 1 ] } <br>
+ Contact: { "/contactName1" : [ 1, 1, 1, 1 ], "/contactName2" : [ 2, 2, 2, 2 ] }
</small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>