m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas/client
diff options
context:
space:
mode:
authorMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-21 10:35:08 +0100
committerMagdalena Grodzińska <mag.grodzinska@gmail.com>2019-11-21 10:35:08 +0100
commiteae806191b4b018de807a6920df9cd7c04ad8404 (patch)
tree95aac7ce20ec09b295f1640cab68e855846faa9b /src/main/java/pl/edu/mimuw/cloudatlas/client
parentf12ca8014063487bfe5c129a47390f2dde1a5b40 (diff)
Add attribute submission backend
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/client')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java67
1 files changed, 64 insertions, 3 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 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")