m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java9
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java54
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html21
-rw-r--r--src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/contactsForm.html9
4 files changed, 88 insertions, 5 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<Value> parseCollectionAttributeValue(List values, ArrayList<String> types) throws Exception {
+ List<Value> resultValue = new ArrayList<Value>();
+ String currentTypeString = types.get(1);
+ AttributeInput attributeInput = new AttributeInput();
+ ArrayList<String> 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<String> types) throws Exception {
+ List<Value> listResultValue = parseCollectionAttributeValue(values, types);
+ ArrayList<Value> resultValue = new ArrayList<>(listResultValue);
+
+ return new ValueList(resultValue, resultValue.iterator().next().getType());
+ }
+
+ private Value parseSetAttributeValue(List values, ArrayList<String> types) throws Exception {
+ List<Value> listResultValue = parseCollectionAttributeValue(values, types);
+ HashSet<Value> 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<String> 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<String> 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;
}
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 @@
<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>
</div>
<div class="form-group">
- <label for="Textarea1">Enter attribute value as a Json</label>
+ <label for="TypeSelect1">Enter optional complex type</label>
+ <input type="text" class="form-control" id="ComplexType1" rows="3" th:field="*{attributeComplexType}"/>
+ <small id="passwordHelpBlock" class="form-text text-muted">
+ 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]
+ </small>
+ </div>
+ <div class="form-group">
+ <label for="Textarea1">Enter attribute value</label>
<textarea class="form-control" id="Textarea1" rows="3" th:field="*{valueString}"></textarea>
+ <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>
+ Query: { "&queryName" : "query" } <br>
+ List: [ 1, 2, 3 ] <br>
+ Set: [ [1, 2], [3, 4], [5, 6] ] <br>
+ </small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
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 @@
<head>
<meta charset="UTF-8">
- <title>Query form</title>
+ <title>Contacts query form</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
@@ -13,8 +13,13 @@
<div id="queryForm">
<form action="#" th:action="@{/contacts}" th:object="${contactsObject}" method="post">
<div class="form-group">
- <label for="Textarea1">Enter contacts as a Json map with string key and integer list as value</label>
+ <label for="Textarea1">Enter contacts</label>
<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 ] }
+ </small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>