From a0f630f257300404d647ae418056c3bd55385dfe Mon Sep 17 00:00:00 2001 From: sfeutrie Date: Thu, 28 Feb 2019 15:08:07 +0100 Subject: [PATCH] Il est désormais possible de visualiser l'état du réseau de capteurs --- PFE06/src/main/java/com/PFE/ServerManager/MainController.java | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java | 1 + PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PFE06/src/main/resources/application.properties | 2 +- PFE06/src/main/resources/templates/all.html | 2 ++ PFE06/src/main/resources/templates/history.html | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ PFE06/src/main/resources/templates/home.html | 2 ++ PFE06/src/main/resources/templates/registration.html | 2 ++ PFE06/src/main/resources/templates/update.html | 3 +++ PFE06/src/main/resources/templates/upload.html | 2 ++ 10 files changed, 260 insertions(+), 4 deletions(-) create mode 100644 PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java create mode 100644 PFE06/src/main/resources/templates/history.html diff --git a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java index 450e253..cc9f45a 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java @@ -12,6 +12,10 @@ import org.springframework.web.servlet.ModelAndView; import java.io.*; import java.sql.Timestamp; import java.text.ParseException; +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; import java.util.*; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -26,7 +30,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Locale; @Controller @MultipartConfig(fileSizeThreshold = 100000000) //à changer, taille max des fichiers @@ -262,7 +265,6 @@ public class MainController { } - @GetMapping(path="/login") public ModelAndView login() { ModelAndView modelAndView = new ModelAndView(); @@ -274,7 +276,6 @@ public class MainController { public ModelAndView getAllUsers() { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("all"); - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Customer customer = customerRepository.findByEmail(auth.getName()); modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); @@ -286,6 +287,85 @@ public class MainController { return modelAndView; } + public static List> getSensorsUsed(List nodes) { + Yaml yaml = new Yaml(new Constructor(UpdateYAML.class)); + InputStream inputStream = null; + List updateYAMLS = new ArrayList<>(); + List state_sensor = new ArrayList<>(); + File dir = new File("toflash"); + if(dir.isDirectory()) { + String s[] = dir.list(); + for (int i = 0; i < s.length; i++) { + if(s[i].endsWith("yml.started")) { + state_sensor.add(i,"started"); + } + else{ + state_sensor.add(i,"programmed"); + } + try { + inputStream = new FileInputStream(new File("toflash/" + s[i])); + UpdateYAML update = yaml.load(inputStream); + updateYAMLS.add(update); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } + List> table = new ArrayList<>(); + System.out.println("size = " + updateYAMLS.size()); + int i=0, j=0, k=0; + + for(Node node : nodes){ + table.add(new ArrayList<>()); + for(Sensor sensor : node.getSensors()){ + for(UpdateYAML update : updateYAMLS) { + for(String sensorUpdate : update.getNodesSplited()){ + if(sensor.getName().equals(sensorUpdate)){ + DateTimeFormatter formatter_date = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm"); + DateTimeFormatter formatter_time = DateTimeFormatter.ofPattern("HH:mm"); + LocalDateTime updateDate = LocalDateTime.parse(update.getDate(),formatter_date); + LocalDateTime now = LocalDateTime.now(); + if(state_sensor.get(k).equals("started")){ + System.out.println("Time : " + update.getTime()); + System.out.println("duration between in minutes " + Duration.between(now,updateDate).toMinutes()); + LocalTime duration = LocalTime.parse(update.getTime(),formatter_time); + updateDate = updateDate.plusMinutes(duration.getMinute()); + updateDate = updateDate.plusHours(duration.getHour()); + table.get(i).add(j,"utilisé (disponible dans " + Duration.between(now,updateDate).toHours() + "h " + (Duration.between(now,updateDate).toMinutes())%60 + "min)"); + } + else if(state_sensor.get(k).equals("programmed")){ + table.get(i).add(j,"programmé (débute dans " + Duration.between(now,updateDate).toHours() + "h " + (Duration.between(now,updateDate).toMinutes())%60 + "min)"); + } + } + } + k++; + } + k=0; + if(table.get(i).size()==j){ + System.out.println("fonctionne"); + table.get(i).add(j,"disponible"); + } + j++; + } + j=0; + i++; + } + System.out.println("table : " + table); + return table; + } + + @GetMapping(path="/history") + public ModelAndView displayHistory() { + ModelAndView modelAndView = new ModelAndView(); + modelAndView.setViewName("history"); + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + Customer customer = customerRepository.findByEmail(auth.getName()); + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); + modelAndView.addObject("customerRole", customer.getRole()); + modelAndView.addObject("nodes", nodeRepository.findAll()); + modelAndView.addObject("is_used", getSensorsUsed(nodeRepository.findAll())); + return modelAndView; + } public static String findFile(String filename) { File dir = new File("files"); diff --git a/PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java b/PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java index 95669a9..911dbe2 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java @@ -34,6 +34,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { http .authorizeRequests() .antMatchers("/home").hasAnyAuthority("USER","ADMIN") + .antMatchers("/history").hasAnyAuthority("USER","ADMIN") .antMatchers("/registration").hasAuthority("ADMIN") .antMatchers("/config").hasAuthority("ADMIN") .antMatchers("/all").hasAuthority("ADMIN") diff --git a/PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java b/PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java new file mode 100644 index 0000000..4995936 --- /dev/null +++ b/PFE06/src/main/java/com/PFE/ServerManager/UpdateYAML.java @@ -0,0 +1,80 @@ +package com.PFE.ServerManager; + +import java.util.HashSet; +import java.util.Set; + +public class UpdateYAML { + + private String date; + private String file; + private Set nodes; + private String exp_id; + private String name; + private String time; + private String arch; + private String dir; + + public void setDate(String date) { + this.date = date; + } + public String getDate() { + return date; + } + + public void setFile(String file) { + this.file = file; + } + public String getFile() { + return file; + } + + public void setNodes(Set nodes) { + this.nodes = nodes; + } + public Set getNodes() { + return nodes; + } + public Set getNodesSplited() { + Set nodesSplited = new HashSet<>(); + for(String node : nodes){ + nodesSplited.add(node.split("@")[0]); + } + System.out.println(nodesSplited); + return nodesSplited; + } + + public void setArch(String arch) { + this.arch = arch; + } + public String getArch() { + return arch; + } + + public void setExp_id(String exp_id) { + this.exp_id = exp_id; + } + public String getExp_id() { + return exp_id; + } + + public void setDir(String dir) { + this.dir = dir; + } + public String getDir() { + return dir; + } + + public void setName(String name) { + this.name = name; + } + public String getName() { + return name; + } + + public void setTime(String time) { + this.time = time; + } + public String getTime() { + return time; + } +} diff --git a/PFE06/src/main/resources/application.properties b/PFE06/src/main/resources/application.properties index bd2766a..30caaa3 100644 --- a/PFE06/src/main/resources/application.properties +++ b/PFE06/src/main/resources/application.properties @@ -14,7 +14,7 @@ spring.datasource.username=postgres spring.datasource.password=glopglop # montre les communications JPA avec la BDD -spring.jpa.show-sql = true +# spring.jpa.show-sql = true # exécute le fichier data.sql pour préciser le role ADMIN spring.datasource.initialization-mode=always diff --git a/PFE06/src/main/resources/templates/all.html b/PFE06/src/main/resources/templates/all.html index 9c2dd6a..ab4a779 100644 --- a/PFE06/src/main/resources/templates/all.html +++ b/PFE06/src/main/resources/templates/all.html @@ -23,9 +23,11 @@ Enregistrer des utilisateurs Liste des utilisateurs Paramétrer une mise à jour + Etat du réseau diff --git a/PFE06/src/main/resources/templates/history.html b/PFE06/src/main/resources/templates/history.html new file mode 100644 index 0000000..6ed360b --- /dev/null +++ b/PFE06/src/main/resources/templates/history.html @@ -0,0 +1,84 @@ + + + + + + + + Etat actuel du réseau + + + + + + + + +
+

Réseau

+ + + + + + + + + + + + + + + + +
NomIPArchitectureCapteursEtat
TeamIPArch +
+
+
+
+ +
+
+
+ + + + + + + diff --git a/PFE06/src/main/resources/templates/home.html b/PFE06/src/main/resources/templates/home.html index ee86a15..0443a37 100644 --- a/PFE06/src/main/resources/templates/home.html +++ b/PFE06/src/main/resources/templates/home.html @@ -28,9 +28,11 @@ Enregistrer des utilisateurs Liste des utilisateurs Paramétrer une mise à jour + Etat du réseau diff --git a/PFE06/src/main/resources/templates/registration.html b/PFE06/src/main/resources/templates/registration.html index 2e50357..2e43b80 100644 --- a/PFE06/src/main/resources/templates/registration.html +++ b/PFE06/src/main/resources/templates/registration.html @@ -22,9 +22,11 @@ Enregistrer des utilisateurs Liste des utilisateurs Paramétrer une mise à jour + Etat du réseau diff --git a/PFE06/src/main/resources/templates/update.html b/PFE06/src/main/resources/templates/update.html index 30afa8e..92de20e 100644 --- a/PFE06/src/main/resources/templates/update.html +++ b/PFE06/src/main/resources/templates/update.html @@ -28,9 +28,11 @@ Enregistrer des utilisateurs Liste des utilisateurs Paramétrer une mise à jour + Etat du réseau @@ -128,6 +130,7 @@ nodes: + -- libgit2 0.21.2