From a657f79f49668bf84929325beed7d885ffb64715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 24 Nov 2019 15:24:46 +0100 Subject: Extend submission forms --- .../cloudatlas/client/templates/attribForm.html | 21 ++++++++++++++++++++- .../cloudatlas/client/templates/contactsForm.html | 9 +++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) 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 0499bc8..ed6dcd2 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 @@ -31,11 +31,30 @@ + +
- + + + + If set or list was chosen in the previous option, please enter whole nested type as a comma-separated list, including wrapper type speccified above. Example: [List, Set, String] + +
+
+ + + Use Json list for complex types and stick to proper format in duration and time.
Examples:
+ Time: 3600
+ Duration (version 1): 3600
+ Duration (version 2): +0 00:00:00.001
+ Contact: { "contactName" : [ 1, 1, 1, 1 ] }
+ Query: { "&queryName" : "query" }
+ List: [ 1, 2, 3 ]
+ Set: [ [1, 2], [3, 4], [5, 6] ]
+
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 40af9b4..79a9f5f 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 @@ -3,7 +3,7 @@ - Query form + Contacts query form @@ -13,8 +13,13 @@
- + + + Use Json format for entering contacts. Examples:
+ Contact: { "contactName" : [ 1, 1, 1, 1 ] }
+ Contact: { "contactName1" : [ 1, 1, 1, 1 ], "contactName2" : [ 2, 2, 2, 2 ] } +
-- cgit v1.2.3 From f5be9e9bc2ea02713a32df99ef49d1a7e98ee450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Sun, 24 Nov 2019 20:16:37 +0100 Subject: Add complex type handling for attribute submissions to client --- .../mimuw/cloudatlas/client/AttributeInput.java | 9 ++++ .../mimuw/cloudatlas/client/ClientController.java | 54 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java index 58e1a30..b34468b 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java @@ -7,6 +7,7 @@ public class AttributeInput { private String attributeName; private String valueString; private String attributeType; + private String attributeComplexType; private Value value; public String getZoneName() { @@ -48,4 +49,12 @@ public class AttributeInput { public void setAttributeType(String attributeType) { this.attributeType = attributeType; } + + public String getAttributeComplexType() { + return attributeComplexType; + } + + public void setAttributeComplexType(String attributeComplexType) { + this.attributeComplexType = attributeComplexType; + } } 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 ae649c0..80a331e 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -142,7 +142,43 @@ public class ClientController { return "attribForm"; } + private List parseCollectionAttributeValue(List values, ArrayList types) throws Exception { + List resultValue = new ArrayList(); + String currentTypeString = types.get(1); + AttributeInput attributeInput = new AttributeInput(); + ArrayList newTypes = new ArrayList<>(types.subList(1, types.size())); + + for (int i = 0; i < values.size(); i++) { + if (currentTypeString.equals("List")) { + resultValue.add(parseListAttributeValue((List) values.get(i), newTypes)); + } else if (currentTypeString.equals("Set")) { + resultValue.add(parseSetAttributeValue((List) values.get(i), newTypes)); + } else { + attributeInput.setAttributeType(currentTypeString); + attributeInput.setValueString(values.get(i).toString()); + resultValue.add(parseAttributeValue(attributeInput)); + } + } + + return resultValue; + } + + private Value parseListAttributeValue(List values, ArrayList types) throws Exception { + List listResultValue = parseCollectionAttributeValue(values, types); + ArrayList resultValue = new ArrayList<>(listResultValue); + + return new ValueList(resultValue, resultValue.iterator().next().getType()); + } + + private Value parseSetAttributeValue(List values, ArrayList types) throws Exception { + List listResultValue = parseCollectionAttributeValue(values, types); + HashSet resultValue = new HashSet<>(listResultValue); + + return new ValueSet(resultValue, resultValue.iterator().next().getType()); + } + private Value parseAttributeValue(AttributeInput attributeObject) throws Exception { + Gson gson = new Gson(); Value attributeValue = null; switch (attributeObject.getAttributeType()) { @@ -155,7 +191,8 @@ public class ClientController { attributeValue = new ValueDouble(Double.parseDouble(attributeObject.getValueString())); break; case "Int": - attributeValue = new ValueInt(Long.parseLong(attributeObject.getValueString())); + Double tempDouble = Double.parseDouble(attributeObject.getValueString()); + attributeValue = new ValueInt(tempDouble.longValue()); break; case "String": attributeValue = new ValueString(attributeObject.getValueString()); @@ -172,8 +209,21 @@ public class ClientController { 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 parsedListTypes = new ArrayList<>(Arrays.asList( + attributeObject.getAttributeComplexType().replaceAll("\\s","").split(","))); + attributeValue = parseListAttributeValue(parsedListValue, parsedListTypes); + break; + case "Set": + List parsedSetValue = gson.fromJson(attributeObject.getValueString(), List.class); + ArrayList parsedSetTypes = new ArrayList<>(Arrays.asList( + attributeObject.getAttributeComplexType(). replaceAll("\\s","").split(","))); + attributeValue = parseSetAttributeValue(parsedSetValue, parsedSetTypes); + break; default: String errMsg = "Value type not supported: " + attributeObject.getAttributeType(); throw new UnsupportedOperationException(errMsg); @@ -329,7 +379,7 @@ public class ClientController { String jsonAttributes = ""; Gson gson = new Gson(); jsonAttributes = gson.toJson(valuesTable); - System.out.println(jsonAttributes); + // System.out.println(jsonAttributes); return jsonAttributes; } -- cgit v1.2.3