Commit 180f54e51c502cde63d5d3d0b01c472219e7d684
1 parent
fb2a766e
Spring : ajouts mineurs
* Ajout de l'architecture des capteurs dans le fichier d'expérimentation YAML * On ne peut maintenant sélectionner que de noeuds de même architecture pour une expérience * Ajout du nom du répertoire où se trouve le fichier à compiler * Vérification des fichiers pour avertir si un fichier est déjà nommé de la même manière lors de l'upload d'un nouveau fichier * Passage de l'application sur le port 80
Showing
7 changed files
with
89 additions
and
57 deletions
Show diff stats
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -3,6 +3,7 @@ package com.PFE.ServerManager; |
3 | 3 | import org.springframework.beans.factory.annotation.Autowired; |
4 | 4 | import org.springframework.http.HttpEntity; |
5 | 5 | import org.springframework.http.HttpStatus; |
6 | +import org.springframework.http.ResponseEntity; | |
6 | 7 | import org.springframework.stereotype.Controller; |
7 | 8 | import org.springframework.web.bind.annotation.*; |
8 | 9 | import org.springframework.web.multipart.MultipartFile; |
... | ... | @@ -169,8 +170,10 @@ public class MainController { |
169 | 170 | } |
170 | 171 | |
171 | 172 | @RequestMapping(value = "/file", method = RequestMethod.POST) |
172 | - @ResponseStatus(value = HttpStatus.OK) | |
173 | - public void submit(@RequestParam MultipartFile file) { | |
173 | + public ResponseEntity submit(@RequestParam MultipartFile file) { | |
174 | + if(findFile(file.getOriginalFilename()) != null) { | |
175 | + return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); | |
176 | + } | |
174 | 177 | |
175 | 178 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
176 | 179 | Customer customer = customerRepository.findByEmail(auth.getName()); |
... | ... | @@ -203,6 +206,7 @@ public class MainController { |
203 | 206 | catch(IOException e) { |
204 | 207 | } |
205 | 208 | } |
209 | + return new ResponseEntity<String>(HttpStatus.OK); | |
206 | 210 | } |
207 | 211 | |
208 | 212 | @RequestMapping(value = "/updatenodes", method = RequestMethod.POST) |
... | ... | @@ -262,8 +266,26 @@ public class MainController { |
262 | 266 | return modelAndView; |
263 | 267 | } |
264 | 268 | |
269 | + | |
270 | + public static String findFile(String filename) { | |
271 | + File dir = new File("files"); | |
272 | + if(dir.isDirectory()){ | |
273 | + String s[] = dir.list(); | |
274 | + for(int i = 0; i < s.length; i++) { | |
275 | + File dirTemp = new File("files/" + s[i]); | |
276 | + if(dirTemp.isDirectory()) { | |
277 | + if(dirTemp.list()[0].equals(filename)) { | |
278 | + return s[i]; | |
279 | + } | |
280 | + } | |
281 | + } | |
282 | + } | |
283 | + return null; | |
284 | + } | |
285 | + | |
286 | + | |
265 | 287 | @PostMapping(path="/savemaj") |
266 | - public String saveMaj(@RequestParam String name, @RequestParam String date, @RequestParam String time, @RequestParam String nodes, @RequestParam String file){ | |
288 | + public String saveMaj(@RequestParam String name, @RequestParam String date, @RequestParam String time, @RequestParam String nodes, @RequestParam String file, @RequestParam String arch){ | |
267 | 289 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
268 | 290 | Customer customer = customerRepository.findByEmail(auth.getName()); |
269 | 291 | |
... | ... | @@ -273,6 +295,8 @@ public class MainController { |
273 | 295 | update_c.setNodes(nodes); |
274 | 296 | update_c.setFile(file); |
275 | 297 | update_c.setTime(time); |
298 | + update_c.setArch(arch); | |
299 | + update_c.setDir(findFile(update_c.getFile())); | |
276 | 300 | |
277 | 301 | updateRepository.save(update_c); // ajouter la mise a jour dans la table |
278 | 302 | |
... | ... | @@ -283,36 +307,6 @@ public class MainController { |
283 | 307 | return "redirect:/update"; |
284 | 308 | } |
285 | 309 | |
286 | - /* | |
287 | - @PostMapping(path="/runmaj") | |
288 | - public String runMaj(@RequestParam String name, @RequestParam String date, @RequestParam String nodes, @RequestParam String file){ | |
289 | - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
290 | - Customer customer = customerRepository.findByEmail(auth.getName()); | |
291 | - | |
292 | - Update update_c = new Update(); | |
293 | - update_c.setUpdate(name); | |
294 | - update_c.setDate(date); | |
295 | - update_c.setNodes(nodes); | |
296 | - update_c.setFile(file); | |
297 | - | |
298 | - Map<String, Object> data = new HashMap<String, Object>(); | |
299 | - data.put("name", update_c.getUpdate()); | |
300 | - data.put("date", update_c.getDate()); | |
301 | - data.put("file", update_c.getFile()); | |
302 | - data.put("nodes", update_c.getNodes().split(";")); | |
303 | - Yaml yaml = new Yaml(); | |
304 | - FileWriter writer = null; | |
305 | - try { | |
306 | - writer = new FileWriter("toflash/" + customer.getEmail().split("@")[0] + "_" + update_c.getUpdate() + ".yml"); | |
307 | - } catch (IOException e) { | |
308 | - e.printStackTrace(); | |
309 | - } | |
310 | - yaml.dump(data, writer); | |
311 | - | |
312 | - return "redirect:/update"; | |
313 | - } | |
314 | -*/ | |
315 | - | |
316 | 310 | @PostMapping(path="/startsavedmaj") |
317 | 311 | @ResponseStatus(value = HttpStatus.OK) |
318 | 312 | public void startSavedMaj(@RequestParam String majname){ |
... | ... | @@ -337,6 +331,8 @@ public class MainController { |
337 | 331 | data.put("date", update.getDate()); |
338 | 332 | data.put("time", update.getTime()); |
339 | 333 | data.put("file", update.getFile()); |
334 | + data.put("dir", update.getDir()); | |
335 | + data.put("arch", update.getArch()); | |
340 | 336 | data.put("nodes", update.getNodes().split(";")); |
341 | 337 | Yaml yaml = new Yaml(); |
342 | 338 | FileWriter writer = null; | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/Update.java
... | ... | @@ -22,6 +22,12 @@ public class Update { |
22 | 22 | @Column(name = "file") |
23 | 23 | private String file; |
24 | 24 | |
25 | + @Column(name = "dir") | |
26 | + private String dir; | |
27 | + | |
28 | + @Column(name = "arch") | |
29 | + private String arch; | |
30 | + | |
25 | 31 | @Column(name = "nodes") |
26 | 32 | private String nodes; |
27 | 33 | |
... | ... | @@ -58,4 +64,14 @@ public class Update { |
58 | 64 | this.file = file; |
59 | 65 | } |
60 | 66 | public String getFile() { return file; } |
67 | + | |
68 | + public void setDir(String dir) { | |
69 | + this.dir = dir; | |
70 | + } | |
71 | + public String getDir() { return dir; } | |
72 | + | |
73 | + public void setArch(String arch) { | |
74 | + this.arch = arch; | |
75 | + } | |
76 | + public String getArch() { return arch; } | |
61 | 77 | } | ... | ... |
PFE06/src/main/resources/application.properties
... | ... | @@ -12,9 +12,6 @@ spring.jpa.hibernate.ddl-auto=create-drop |
12 | 12 | spring.datasource.url=jdbc:postgresql://localhost:5432/sql_only |
13 | 13 | spring.datasource.username=postgres |
14 | 14 | spring.datasource.password=glopglop |
15 | -#spring.datasource.url=jdbc:postgresql://localhost:5432/sql_only | |
16 | -#spring.datasource.username=postgres | |
17 | -#spring.datasource.password=glopglop | |
18 | 15 | |
19 | 16 | # montre les communications JPA avec la BDD |
20 | 17 | spring.jpa.show-sql = true |
... | ... | @@ -24,4 +21,5 @@ spring.datasource.initialization-mode=always |
24 | 21 | |
25 | 22 | server.tomcat.max-http-post-size=80000000 |
26 | 23 | spring.servlet.multipart.max-file-size=80MB |
27 | -spring.servlet.multipart.max-request-size=80MB | |
28 | 24 | \ No newline at end of file |
25 | +spring.servlet.multipart.max-request-size=80MB | |
26 | +server.port=80 | |
29 | 27 | \ No newline at end of file | ... | ... |
PFE06/src/main/resources/static/js/update.js
... | ... | @@ -100,22 +100,30 @@ $(document).ready(function() { |
100 | 100 | } ); |
101 | 101 | |
102 | 102 | var nodeSet = new Set(); |
103 | + var arch = ""; | |
104 | + var first = true; | |
103 | 105 | |
104 | 106 | tableNodes.on('select', function (e, dt, type, indexes) { |
105 | 107 | var rowData = tableNodes.rows(indexes).data().toArray()[0]; |
106 | - console.log(rowData); | |
107 | 108 | nodeSet.add(rowData[3] + "@" + rowData[1]); |
108 | - console.log(nodeSet); | |
109 | + var lastArch = arch; | |
110 | + arch = rowData[2]; | |
111 | + if(first != true && lastArch != arch) | |
112 | + { | |
113 | + alert("Veuillez choisir la même architecture"); | |
114 | + tableNodes.rows().deselect(); | |
115 | + nodeSet.clear(); | |
116 | + first = true; | |
117 | + } | |
118 | + first = false; | |
109 | 119 | } ); |
110 | 120 | |
111 | 121 | tableNodes.on('deselect', function (e, dt, type, indexes) { |
112 | 122 | var rowData = tableNodes.rows(indexes).data().toArray()[0]; |
113 | 123 | nodeSet.delete(rowData[3] + "@" + rowData[1]); |
114 | - console.log(nodeSet); | |
115 | 124 | } ); |
116 | 125 | |
117 | 126 | var sendInfoMaj = function(action) { |
118 | - console.log(action); | |
119 | 127 | var form = document.createElement('form'); |
120 | 128 | form.setAttribute('action', action); |
121 | 129 | form.setAttribute('method', 'post'); |
... | ... | @@ -183,6 +191,12 @@ $(document).ready(function() { |
183 | 191 | inputvar5.setAttribute('value', majTime); |
184 | 192 | form.appendChild(inputvar5); |
185 | 193 | |
194 | + var inputvar6 = document.createElement('input'); | |
195 | + inputvar6.setAttribute('type', 'hidden'); | |
196 | + inputvar6.setAttribute('name', 'arch'); | |
197 | + inputvar6.setAttribute('value', arch); | |
198 | + form.appendChild(inputvar6); | |
199 | + | |
186 | 200 | document.body.appendChild(form); |
187 | 201 | form.submit(); |
188 | 202 | } | ... | ... |
PFE06/src/main/resources/static/js/upload.js
... | ... | @@ -73,19 +73,32 @@ $(document).ready(function() { |
73 | 73 | request.upload.onloadend = function(e) { |
74 | 74 | fileProgress.style.width = 100 + "%" |
75 | 75 | fileProgress.innerHTML = "100%"; |
76 | - var modalButton = document.getElementById("modal-button"); | |
77 | - | |
78 | - modalButton.addEventListener('click', function(e) { | |
79 | - location.reload(); | |
80 | - }) | |
81 | - | |
82 | - modalContent.innerHTML = "Upload terminé !"; | |
83 | - modalTitle.innerHTML = "Félicitations"; | |
84 | - $("#warningFilesNumber").modal() | |
85 | 76 | } |
86 | 77 | |
87 | 78 | request.onreadystatechange = function() { |
88 | 79 | if(this.readyState === XMLHttpRequest.DONE && this.status === 200) { |
80 | + var modalButton = document.getElementById("modal-button"); | |
81 | + | |
82 | + modalButton.addEventListener('click', function(e) { | |
83 | + location.reload(); | |
84 | + }) | |
85 | + | |
86 | + modalContent.innerHTML = "Upload terminé !"; | |
87 | + modalTitle.innerHTML = "Félicitations"; | |
88 | + $("#warningFilesNumber").modal() | |
89 | + formData = new FormData(); | |
90 | + } | |
91 | + | |
92 | + if(this.readyState === XMLHttpRequest.DONE && this.status === 500) { | |
93 | + var modalButton = document.getElementById("modal-button"); | |
94 | + | |
95 | + modalButton.addEventListener('click', function(e) { | |
96 | + location.reload(); | |
97 | + }) | |
98 | + | |
99 | + modalContent.innerHTML = "Un fichier du même nom existe déjà, veuillez le renommer"; | |
100 | + modalTitle.innerHTML = "Erreur"; | |
101 | + $("#warningFilesNumber").modal(); | |
89 | 102 | formData = new FormData(); |
90 | 103 | } |
91 | 104 | } | ... | ... |
PFE06/src/main/resources/templates/update.html
... | ... | @@ -179,6 +179,7 @@ nodes: |
179 | 179 | </div> |
180 | 180 | </tbody> |
181 | 181 | </table> |
182 | + | |
182 | 183 | <div class="form-team"> |
183 | 184 | <input type="text" class="form-control" id="majName" placeholder="Nom de la mise à jour" name="update" style="margin-top:20px;"> |
184 | 185 | </div> |
... | ... | @@ -188,7 +189,7 @@ nodes: |
188 | 189 | <input type="datetime-local" class="form-control" id="majDate" placeholder="Date de la mise à jour" name="date"> |
189 | 190 | </div> |
190 | 191 | <br/> |
191 | - <p>Durée de l'expérimentation</p> | |
192 | + <p>Durée de l'expérimentation (hh:mm)</p> | |
192 | 193 | <div class="form-team"> |
193 | 194 | <input type="time" class="form-control" id="majTime" placeholder="Durée" name="time"> |
194 | 195 | </div> | ... | ... |