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 --- .../pl/edu/mimuw/cloudatlas/client/Client.java | 11 ++------- .../mimuw/cloudatlas/client/ClientController.java | 28 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'src/main/java/pl/edu') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java index 96fe14f..5e71754 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java @@ -1,5 +1,6 @@ package pl.edu.mimuw.cloudatlas.client; +import org.springframework.context.annotation.Bean; import pl.edu.mimuw.cloudatlas.api.Api; import java.rmi.registry.LocateRegistry; @@ -29,14 +30,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Client { public static void main(String[] args) { - try { - Registry registry = LocateRegistry.getRegistry("localhost"); - Api api = (Api) registry.lookup("Api"); - - SpringApplication.run(Client.class, args); - } catch (Exception e) { - System.err.println("Client exception:"); - e.printStackTrace(); - } + SpringApplication.run(Client.class, args); } } 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