diff options
author | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2019-11-20 11:38:26 +0100 |
---|---|---|
committer | Magdalena Grodzińska <mag.grodzinska@gmail.com> | 2019-11-20 11:41:21 +0100 |
commit | a5af445acaf16660c28f6012be15c17915efc874 (patch) | |
tree | 9ecd8e58cb7b8dde3353828ebbdfe9fa4800a5b9 /src/main/java | |
parent | 562b0d451d9a58188a279844efe0efc548ac8f1f (diff) |
Add api call to client query installation
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/client/Client.java | 11 | ||||
-rw-r--r-- | src/main/java/pl/edu/mimuw/cloudatlas/client/ClientController.java | 28 |
2 files changed, 29 insertions, 10 deletions
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"; } |