From a5af445acaf16660c28f6012be15c17915efc874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Wed, 20 Nov 2019 11:38:26 +0100 Subject: Add api call to client query installation --- .../mimuw/cloudatlas/client/ClientController.java | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java') 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 62f77ee..f6b1524 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java @@ -1,8 +1,16 @@ package pl.edu.mimuw.cloudatlas.client; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.stereotype.Controller; +import pl.edu.mimuw.cloudatlas.api.Api; + +import javax.annotation.PostConstruct; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; /* should enable reading attribute values stored by the agent @@ -17,6 +25,17 @@ plotting the attributes with numeric values as real-time graphs. @Controller public class ClientController { + private Api api; + + ClientController() { + try { + Registry registry = LocateRegistry.getRegistry("localhost"); + this.api = (Api) registry.lookup("Api"); + } catch (Exception e) { + System.err.println("Client exception:"); + e.printStackTrace(); + } + } @GetMapping("/") public String homePage(Model model) { @@ -31,7 +50,14 @@ public class ClientController { } @PostMapping("/query") - public String submitQuery(@ModelAttribute Query queryObject, Model model) { + public String submitQuery(@ModelAttribute Query queryObject, Model model) { + try { + this.api.installQuery(queryObject.getName(), queryObject.getValue()); + } catch (Exception e) { + System.err.println("Client exception:"); + e.printStackTrace(); + } + model.addAttribute("homeMessage", "Query submitted successfully"); return "home"; } -- cgit v1.2.3