diff options
author | Magdalena GrodziĆska <mag.grodzinska@gmail.com> | 2019-11-24 20:18:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-24 20:18:42 +0100 |
commit | bc208bbea11c4e0babdad30bd13a70ec7c3b70f1 (patch) | |
tree | f89f2ea9251ad4d153fe68710cf646ed034cfd13 /src/main/java/pl/edu/mimuw | |
parent | 020b22cd7a961b37eb23247264db5ff3246a54af (diff) | |
parent | f5be9e9bc2ea02713a32df99ef49d1a7e98ee450 (diff) |
Merge pull request #36 from m-chrzan/fix_attrib_submission_types
Fix attrib submission types
Diffstat (limited to 'src/main/java/pl/edu/mimuw')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/client/AttributeInput.java | 9 | ||||
-rw-r--r-- | src/main/java/pl/edu/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<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; } |