From 8fb9f91d90ecaddc8a7f06dddff44018ccc4de9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 17:36:56 +0100 Subject: Add attribute form controllers --- .../pl/edu/mimuw/cloudatlas/client/Attribute.java | 51 ++++++++++++++++++++++ .../mimuw/cloudatlas/client/ClientController.java | 11 +++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java (limited to 'src') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java new file mode 100644 index 0000000..abaa02a --- /dev/null +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/Attribute.java @@ -0,0 +1,51 @@ +package pl.edu.mimuw.cloudatlas.client; + +import pl.edu.mimuw.cloudatlas.model.Value; + +public class Attribute { + private String zoneName; + private String attributeName; + private String valueString; + private String attributeType; + private Value value; + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getAttributeName() { + return attributeName; + } + + public void setAttributeName(String attributeName) { + this.attributeName = attributeName; + } + + public String getValueString() { + return valueString; + } + + public void setValueString(String valueString) { + this.valueString = valueString; + } + + public Value getValue() { + return value; + } + + public void setValue(Value value) { + this.value = value; + } + + public String getAttributeType() { + return attributeType; + } + + public void setAttributeType(String attributeType) { + this.attributeType = attributeType; + } +} 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 31d1c06..27c7ad4 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -123,6 +123,17 @@ public class ClientController { @GetMapping("/attribs") public String attribPage(Model model) { + model.addAttribute("attributeObject", new Attribute()); + return "attribForm"; + } + + @PostMapping("/attribs") + public String attribPage(@ModelAttribute Attribute attributeObject, Model model) { + return "attribForm"; + } + + @GetMapping("/values") + public String valuesPage(Model model) { return "attribChart"; } } -- cgit v1.2.3 From d4cf12c3e8c0d80d6d6a7e8c4a62861f3e32c4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 17:37:29 +0100 Subject: Add attribute form html and move navigation categories --- .../cloudatlas/client/templates/attribForm.html | 50 ++++++++++++++++++++++ .../client/templates/fragments/navbar.html | 5 ++- .../cloudatlas/client/templates/queryForm.html | 22 +++++++--- 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html (limited to 'src') 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 new file mode 100644 index 0000000..3f10f57 --- /dev/null +++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/attribForm.html @@ -0,0 +1,50 @@ + + + + + + Query form + + + + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + + + + + + + diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/fragments/navbar.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/fragments/navbar.html index c651f74..ca83cbb 100644 --- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/fragments/navbar.html +++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/fragments/navbar.html @@ -27,7 +27,10 @@ Contacts + diff --git a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html index ac00645..08b4e89 100644 --- a/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html +++ b/src/main/resources/pl/edu/mimuw/cloudatlas/client/templates/queryForm.html @@ -10,20 +10,30 @@
-
+
+

Install query

- - + +
- - + +
+
-

+
+

Uninstall query

+
+
+ + +
+ +
-- cgit v1.2.3 From 75208adcf60b4b3a48b96be70ff9352683a37075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Thu, 21 Nov 2019 10:00:50 +0100 Subject: Refactor contact value parsing --- .../mimuw/cloudatlas/client/ClientController.java | 36 +++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src') 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 27c7ad4..922c357 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -85,26 +85,34 @@ public class ClientController { return "contactsForm"; } - @PostMapping("/contacts") - public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) { - boolean success = true; + private Set parseContactsString(ContactsString contactsInput) throws Exception { Gson gson = new Gson(); - Map contactStrings = gson.fromJson(contactsObject.getString(), Map.class); + Map contactStrings = gson.fromJson(contactsInput.getString(), Map.class); Set contactObjects = new HashSet(); ArrayList cAddr; byte[] inetArray = new byte[4]; - try { - for (Map.Entry cursor : contactStrings.entrySet()) { - cAddr = cursor.getValue(); // gson always reads numerical values as doubles - for (int i = 0; i < 4; i++) { - inetArray[i] = (byte) cAddr.get(i).doubleValue(); - } - contactObjects.add(new ValueContact( - new PathName(cursor.getKey()), - InetAddress.getByAddress(inetArray)) - ); + for (Map.Entry cursor : contactStrings.entrySet()) { + cAddr = cursor.getValue(); // gson always reads numerical values as doubles + for (int i = 0; i < 4; i++) { + inetArray[i] = (byte) cAddr.get(i).doubleValue(); } + contactObjects.add(new ValueContact( + new PathName(cursor.getKey()), + InetAddress.getByAddress(inetArray)) + ); + } + + return contactObjects; + } + + @PostMapping("/contacts") + public String contactPage(@ModelAttribute ContactsString contactsObject, Model model) { + boolean success = true; + Set contactObjects; + + try { + contactObjects = parseContactsString(contactsObject); this.api.setFallbackContacts(contactObjects); } catch (Exception e) { success = false; -- cgit v1.2.3 From ad1434856c34abdb71b0d02f5cb43a19f52abc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Thu, 21 Nov 2019 10:33:46 +0100 Subject: Fix ZMI serialization --- src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java index a311c61..7f2f604 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/model/ZMI.java @@ -27,6 +27,7 @@ package pl.edu.mimuw.cloudatlas.model; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,7 +41,7 @@ import com.esotericsoftware.kryo.io.Output; * A zone management information object. This object is a single node in a zone hierarchy. It stores zone attributes as well as * references to its father and sons in the tree. */ -public class ZMI implements Cloneable { +public class ZMI implements Cloneable, Serializable { public class NoSuchZoneException extends Exception { public NoSuchZoneException(PathName path) { super("No such zone: " + path); -- cgit v1.2.3 From f12ca8014063487bfe5c129a47390f2dde1a5b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Thu, 21 Nov 2019 10:34:41 +0100 Subject: Fix attribute form errors --- .../mimuw/cloudatlas/client/templates/attribForm.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') 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 3f10f57..0499bc8 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 @@ -11,7 +11,7 @@
-
+
@@ -23,14 +23,14 @@
-- cgit v1.2.3 From eae806191b4b018de807a6920df9cd7c04ad8404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Thu, 21 Nov 2019 10:35:08 +0100 Subject: Add attribute submission backend --- .../mimuw/cloudatlas/client/ClientController.java | 67 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'src') 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 922c357..e579a38 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,12 +1,12 @@ package pl.edu.mimuw.cloudatlas.client; import com.google.gson.Gson; +import com.sun.jdi.BooleanValue; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; import pl.edu.mimuw.cloudatlas.api.Api; -import pl.edu.mimuw.cloudatlas.model.PathName; -import pl.edu.mimuw.cloudatlas.model.ValueContact; +import pl.edu.mimuw.cloudatlas.model.*; import java.net.InetAddress; import java.net.UnknownHostException; @@ -135,9 +135,70 @@ public class ClientController { return "attribForm"; } + private Value parseAttributeValue(Attribute attributeObject) throws Exception { + Value attributeValue = null; + + switch (attributeObject.getAttributeType()) { + case "Boolean": + attributeValue = attributeObject.getValueString().toLowerCase().equals("true") ? + new ValueBoolean(true) : + new ValueBoolean(false); + break; + case "Double": + attributeValue = new ValueDouble(Double.parseDouble(attributeObject.getValueString())); + break; + case "Int": + attributeValue = new ValueInt(Long.parseLong(attributeObject.getValueString())); + break; + case "String": + attributeValue = new ValueString(attributeObject.getValueString()); + break; + case "Time": + attributeValue = new ValueTime(Long.parseLong(attributeObject.getValueString())); + break; + case "Duration": + attributeValue = new ValueDuration(attributeObject.getValueString()); + break; + case "Contact": + ContactsString contactsString = new ContactsString(); + contactsString.setString(attributeObject.getValueString()); + attributeValue = parseContactsString(contactsString).iterator().next(); + break; + case "Query": + attributeValue = new ValueQuery(attributeObject.getValueString()); + break; + default: + String errMsg = "Value type not supported: " + attributeObject.getAttributeType(); + throw new UnsupportedOperationException(errMsg); + } + + return attributeValue; + } + @PostMapping("/attribs") public String attribPage(@ModelAttribute Attribute attributeObject, Model model) { - return "attribForm"; + boolean success = true; + Value attributeValue; + + try { + attributeValue = parseAttributeValue(attributeObject); + api.setAttributeValue( + attributeObject.getZoneName(), + attributeObject.getAttributeName(), + attributeValue); + } catch (Exception e) { + success = false; + System.err.println("Client exception:"); + e.printStackTrace(); + } + + if (success) { + model.addAttribute("homeMessage", "Attribute submitted successfully"); + } else { + model.addAttribute("homeMessage", "Attribute submission failed"); + } + + return "home"; } @GetMapping("/values") -- cgit v1.2.3 From 02f98aed224580d05deb4b40eac4a11c36d39498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Thu, 21 Nov 2019 10:43:58 +0100 Subject: Fix erroneous import --- src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java | 1 - 1 file changed, 1 deletion(-) (limited to 'src') 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 e579a38..022c665 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,7 +1,6 @@ package pl.edu.mimuw.cloudatlas.client; import com.google.gson.Gson; -import com.sun.jdi.BooleanValue; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; -- cgit v1.2.3