diff --git a/PFE06/pom.xml b/PFE06/pom.xml index d4b6ad9..93fc9ac 100644 --- a/PFE06/pom.xml +++ b/PFE06/pom.xml @@ -35,6 +35,10 @@ 1.21 + com.fasterxml.jackson.core + jackson-databind + + org.springframework.boot spring-boot-starter-web diff --git a/PFE06/src/main/java/com/PFE/ServerManager/ConfigNodes.java b/PFE06/src/main/java/com/PFE/ServerManager/ConfigNodes.java deleted file mode 100644 index 69be161..0000000 --- a/PFE06/src/main/java/com/PFE/ServerManager/ConfigNodes.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.PFE.ServerManager; - -import java.util.List; - -public class ConfigNodes { - - private List nodes; - - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = nodes; - } -} diff --git a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java index c4f8f9e..cdc304b 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java @@ -1,7 +1,7 @@ package com.PFE.ServerManager; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.repository.query.Param; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -19,6 +19,7 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; import javax.servlet.annotation.MultipartConfig; +import com.fasterxml.jackson.databind.ObjectMapper; @Controller @MultipartConfig(fileSizeThreshold = 20971520) //à changer, taille max des fichiers @@ -198,35 +199,40 @@ public class MainController { } } - @RequestMapping(value = "/config", method = RequestMethod.POST) + @RequestMapping(value = "/updatenodes", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) - public void submitConfig(@RequestParam MultipartFile file) { + public void submitConfig(HttpEntity httpEntity) { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - Customer customer = customerRepository.findByEmail(auth.getName()); - InputStream inputStream = null; + nodeRepository.deleteAll(); + String json = httpEntity.getBody(); + ObjectMapper objectMapper = new ObjectMapper(); + NodeJSON[] nodes = null; try { - inputStream = file.getInputStream(); - } - catch (IOException e) { + nodes = objectMapper.readValue(json, NodeJSON[].class); + } catch (IOException e) { e.printStackTrace(); } - nodeRepository.deleteAll(); - Yaml yaml = new Yaml(new Constructor(ConfigNodes.class)); - ConfigNodes conf = yaml.load(inputStream); - - Iterator iter = conf.getNodes().iterator(); - while (iter.hasNext()) { - NodeYAML element = iter.next(); + for (NodeJSON n : nodes) { Node node = new Node(); - node.setName(element.getName()); - node.setArch(element.getArch()); - node.setIp(element.getIp()); + node.setName(n.getName()); + node.setArch(n.getArch()); + node.setIp(n.getIp()); + List sensors = n.getSensors(); + Set sensorsReal = new HashSet(); + for(SensorJSON s : sensors) + { + Sensor ss = new Sensor(); + ss.setName(s.getName()); + sensorsReal.add(ss); + } + node.setSensors(sensorsReal); nodeRepository.save(node); } + } + @GetMapping(path="/login") public ModelAndView login() { ModelAndView modelAndView = new ModelAndView(); @@ -290,7 +296,7 @@ public class MainController { Yaml yaml = new Yaml(); FileWriter writer = null; try { - writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + update_c.getUpdate() + ".yaml"); + writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + update_c.getUpdate() + ".yml"); } catch (IOException e) { e.printStackTrace(); } @@ -313,21 +319,11 @@ public class MainController { Yaml yaml = new Yaml(); FileWriter writer = null; try { - writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + update.getUpdate() + ".yaml"); + writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + update.getUpdate() + ".yml"); } catch (IOException e) { e.printStackTrace(); } yaml.dump(data, writer); } - @GetMapping(value="/nodesconf") - public ModelAndView nodesconf() { - ModelAndView modelAndView = new ModelAndView(); - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - Customer customer = customerRepository.findByEmail(auth.getName()); - modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); - modelAndView.addObject("customerRole", customer.getRole()); - modelAndView.setViewName("nodesconf"); - return modelAndView; - } } \ No newline at end of file diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Node.java b/PFE06/src/main/java/com/PFE/ServerManager/Node.java index 54b3f75..ca20215 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/Node.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/Node.java @@ -1,6 +1,7 @@ package com.PFE.ServerManager; import javax.persistence.*; +import java.util.Set; @Entity @Table(name = "node") @@ -19,6 +20,14 @@ public class Node { @Column(name = "arch") private String arch; + @ManyToMany(cascade = CascadeType.ALL) + @JoinTable(name = "nodes_sensor", joinColumns = @JoinColumn(name = "node_id"), inverseJoinColumns = @JoinColumn(name = "sensorId")) + private Set sensors; + + public void setSensors(Set sensors) { + this.sensors = sensors; + } + public void setNode_id(Integer node_id) { this.node_id = node_id; } @@ -51,4 +60,8 @@ public class Node { return arch; } + public Set getSensors() { + return sensors; + } + } diff --git a/PFE06/src/main/java/com/PFE/ServerManager/NodeJSON.java b/PFE06/src/main/java/com/PFE/ServerManager/NodeJSON.java new file mode 100644 index 0000000..a0048a2 --- /dev/null +++ b/PFE06/src/main/java/com/PFE/ServerManager/NodeJSON.java @@ -0,0 +1,40 @@ +package com.PFE.ServerManager; + +import java.util.List; + +public class NodeJSON { + + private String name; + private String ip; + private String arch; + private List sensors; + + public void setName(String name) { + this.name = name; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public void setArch(String arch) { + this.arch = arch; + } + + public void setSensors(List sensors) { this.sensors = sensors; } + + public String getName() { + return name; + } + + public String getIp() { + return ip; + } + + public String getArch() { + return arch; + } + + public List getSensors() { return sensors; } + +} diff --git a/PFE06/src/main/java/com/PFE/ServerManager/NodeYAML.java b/PFE06/src/main/java/com/PFE/ServerManager/NodeYAML.java deleted file mode 100644 index 597d786..0000000 --- a/PFE06/src/main/java/com/PFE/ServerManager/NodeYAML.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.PFE.ServerManager; - -public class NodeYAML { - - private String name; - private String ip; - private String arch; - - public void setName(String name) { - this.name = name; - } - - public void setIp(String ip) { - this.ip = ip; - } - - public void setArch(String arch) { - this.arch = arch; - } - - public String getName() { - return name; - } - - public String getIp() { - return ip; - } - - public String getArch() { - return arch; - } - -} diff --git a/PFE06/src/main/java/com/PFE/ServerManager/NodesJSON.java b/PFE06/src/main/java/com/PFE/ServerManager/NodesJSON.java new file mode 100644 index 0000000..8ad3434 --- /dev/null +++ b/PFE06/src/main/java/com/PFE/ServerManager/NodesJSON.java @@ -0,0 +1,12 @@ +package com.PFE.ServerManager; + +import java.util.List; + +public class NodesJSON { + private List nodes; + + public void setNodes(List nodes) { this.nodes = nodes; } + + public List getNodes() { return nodes; } + +} diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Sensor.java b/PFE06/src/main/java/com/PFE/ServerManager/Sensor.java new file mode 100644 index 0000000..b66ba57 --- /dev/null +++ b/PFE06/src/main/java/com/PFE/ServerManager/Sensor.java @@ -0,0 +1,23 @@ +package com.PFE.ServerManager; + +import javax.persistence.*; + +@Entity +@Table(name = "sensor") +public class Sensor { + @Id + @Column(name = "sensorId", columnDefinition = "serial") + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer sensorId; + + @Column(name = "name") + private String name; + + public void setSensorId(Integer sensorId) { this.sensorId = sensorId; } + public Integer getSensorId() { return sensorId; } + + public void setName(String name) { + this.name = name; + } + public String getName() { return name; } +} diff --git a/PFE06/src/main/java/com/PFE/ServerManager/SensorJSON.java b/PFE06/src/main/java/com/PFE/ServerManager/SensorJSON.java new file mode 100644 index 0000000..d6f6acb --- /dev/null +++ b/PFE06/src/main/java/com/PFE/ServerManager/SensorJSON.java @@ -0,0 +1,14 @@ +package com.PFE.ServerManager; + + +public class SensorJSON { + private String name; + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/PFE06/src/main/resources/static/js/nodes.js b/PFE06/src/main/resources/static/js/nodes.js index d1248e5..5fbed4b 100644 --- a/PFE06/src/main/resources/static/js/nodes.js +++ b/PFE06/src/main/resources/static/js/nodes.js @@ -74,7 +74,18 @@ function clearAll() { allDone.addEventListener('click', function() { if(nodes.length !== 0) { - console.log(JSON.stringify(nodes)); + var xhr = new XMLHttpRequest(); + var url = "/updatenodes"; + xhr.open("POST", url, true); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.onreadystatechange = function () { + if (xhr.readyState === 4 && xhr.status === 200) { + location.reload(); + } + }; + var data = JSON.stringify(nodes); + console.log(data); + xhr.send(data); } }) diff --git a/PFE06/src/main/resources/static/js/update.js b/PFE06/src/main/resources/static/js/update.js index 38eb91a..ad2ae46 100644 --- a/PFE06/src/main/resources/static/js/update.js +++ b/PFE06/src/main/resources/static/js/update.js @@ -37,6 +37,13 @@ $(document).ready(function() { /********** Configuration file ***********/ + + + + + + + /* var configName = document.getElementById("config_name"); var configSend = document.getElementById("config_send"); var file = document.getElementById("configInputFile"); @@ -81,6 +88,8 @@ $(document).ready(function() { }) } +*/ + /********** Tableau **********/ var tableNodes = $('#nodes-table').DataTable( { @@ -94,12 +103,15 @@ $(document).ready(function() { tableNodes.on('select', function (e, dt, type, indexes) { var rowData = tableNodes.rows(indexes).data().toArray()[0]; - nodeSet.add(rowData[0]); + console.log(rowData); + nodeSet.add(rowData[0] + "@" + rowData[3]); + console.log(nodeSet); } ); tableNodes.on('deselect', function (e, dt, type, indexes) { var rowData = tableNodes.rows(indexes).data().toArray()[0]; - nodeSet.delete(rowData[0]); + nodeSet.delete(rowData[0] + "@" + rowData[3]); + console.log(nodeSet); } ); var sendInfoMaj = function(action) { diff --git a/PFE06/src/main/resources/templates/all.html b/PFE06/src/main/resources/templates/all.html index 5dd877c..9c2dd6a 100644 --- a/PFE06/src/main/resources/templates/all.html +++ b/PFE06/src/main/resources/templates/all.html @@ -63,7 +63,7 @@ Nom ID Utilisateurs - Mises à jours + Mises à jour Team diff --git a/PFE06/src/main/resources/templates/nodesconf.html b/PFE06/src/main/resources/templates/nodesconf.html deleted file mode 100644 index 788b040..0000000 --- a/PFE06/src/main/resources/templates/nodesconf.html +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - Configuration des noeuds - - - - - - - -
-

Configuration des noeuds

- -
-
- Nom -
- -
- -
-
- IP -
- -
- -
-
- Architecture -
- -
- -

Capteurs


- -
-
- Nom -
- -
- - - - -
- - - - - -
-
-
- -
-
- -
-
- -
-
-
- - -
- - - - - - - - - - - - diff --git a/PFE06/src/main/resources/templates/registration.html b/PFE06/src/main/resources/templates/registration.html index 2faaa47..5f2ea58 100644 --- a/PFE06/src/main/resources/templates/registration.html +++ b/PFE06/src/main/resources/templates/registration.html @@ -4,11 +4,10 @@ - Enregistrement de nouveaux utilisateurs - +
+ +
+ +
+ +
+ +
+

Formulaire d'ajout d'un utilisateur

-

Merci d'entrer le login et le mot de passe du nouvel utilisateur

-
-