From 0e18634e1aa600409c111f78e3d49676f093a859 Mon Sep 17 00:00:00 2001 From: sfeutrie Date: Mon, 14 Jan 2019 14:46:24 +0100 Subject: [PATCH] modifications mineures de méthodes --- PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java | 30 +++--------------------------- PFE06/src/main/java/com/PFE/ServerManager/Customer.java | 15 +++++++++++---- PFE06/src/main/java/com/PFE/ServerManager/MainController.java | 7 +++---- PFE06/src/main/java/com/PFE/ServerManager/Role.java | 1 + PFE06/src/main/java/com/PFE/ServerManager/Team.java | 24 ++++++++++++++++++------ 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java b/PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java index 02c5d51..f651baa 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java @@ -8,8 +8,6 @@ import org.yaml.snakeyaml.constructor.Constructor; import javax.annotation.PostConstruct; import java.io.*; -import java.util.*; - @Component public class AppConfig { @@ -58,43 +56,21 @@ public class AppConfig { Customer n = new Customer(); n.setEmail(conf.getAdminEmail()); n.setPassword(bCryptPasswordEncoder.encode(conf.getAdminPassword())); - n.setId((int)(customerRepository.count() + 1)); + n.setCustomerId((int)(customerRepository.count() + 1)); n.setActive(1); Customer temp = customerRepository.findByEmail(conf.getAdminEmail()); Role userRole = roleRepository.findByRole("ADMIN"); - n.setRoles(new HashSet<>(Arrays.asList(userRole))); - - ////////////////////////////////////////// - /* - Customer p = new Customer(); - p.setEmail("admin@admin.fr"); - p.setPassword(bCryptPasswordEncoder.encode("azerty")); - p.setId((int)(customerRepository.count() + 2)); - p.setActive(1); - - Role userRole2 = roleRepository.findByRole("USER"); - p.setRoles(new HashSet<>(Arrays.asList(userRole2))); - customerRepository.save(p); - */ - /////////////////////////////////// + n.addRole(userRole); if(temp == null) { customerRepository.save(n); - } - /* Partie sur les groupes */ Team g = new Team(); g.setTeamId((int)(teamRepository.count() +1)); g.setTeam("Labo1"); - Set tempC = new HashSet<>(); - tempC.add(n); - //tempC.add(p); - g.setCustomers(tempC); - //g.setCustomers(new HashSet<>(Arrays.asList(n, p))); + g.addCustomer(n); teamRepository.save(g); - ////////////////////////// - } } \ No newline at end of file diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Customer.java b/PFE06/src/main/java/com/PFE/ServerManager/Customer.java index 5858e4c..da315ab 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/Customer.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/Customer.java @@ -1,6 +1,7 @@ package com.PFE.ServerManager; import javax.persistence.*; +import java.util.HashSet; import java.util.Set; @Entity @@ -35,7 +36,16 @@ public class Customer{ public void setRoles(Set roles) { this.roles = roles; } + public void addRole(Role role){ + if(roles == null){ + roles = new HashSet<>(); + } + this.roles.add(role); + } public Set getRoles() { return roles; } + public String getRole(){ + return roles.iterator().next().getRole(); + } public void setUpdate(Set update) { this.update = update; @@ -44,10 +54,7 @@ public class Customer{ return update; } - public String getRole(){ - return roles.iterator().next().getRole(); - } - public void setId(Integer id) { + public void setCustomerId(Integer id) { this.customerId = id; } public Integer getCustomerId() { return customerId; } diff --git a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java index 936dadc..b8b1f55 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java @@ -76,7 +76,7 @@ public class MainController { Customer customer = customerRepository.findByEmail(auth.getName()); modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); modelAndView.addObject("customerRole", customer.getRole()); - modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdate()); + modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdates()); List nodes = nodeRepository.findAll(); modelAndView.addObject("nodes", nodes); @@ -98,7 +98,6 @@ public class MainController { modelAndView.addObject("customerFiles", filesName); modelAndView.setViewName("update"); - return modelAndView; } @@ -125,11 +124,11 @@ public class MainController { Customer n = new Customer(); n.setEmail(email); n.setPassword(bCryptPasswordEncoder.encode(password)); - n.setId((int)(customerRepository.count() + 1)); + n.setCustomerId((int)(customerRepository.count() + 1)); n.setActive(1); Customer temp = customerRepository.findByEmail(email); Role userRole = roleRepository.findByRole(role); - n.setRoles(new HashSet(Arrays.asList(userRole))); + n.addRole(userRole); //utilisé uniquement pour continuer à afficher l'utilisateur connecté// Authentication auth = SecurityContextHolder.getContext().getAuthentication(); diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Role.java b/PFE06/src/main/java/com/PFE/ServerManager/Role.java index b53b626..34f6403 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/Role.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/Role.java @@ -23,4 +23,5 @@ public class Role { public void setRoleId(Integer roleId) { this.roleId = roleId; } public Integer getRoleId() { return roleId; } + } \ No newline at end of file diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Team.java b/PFE06/src/main/java/com/PFE/ServerManager/Team.java index 169471e..8ea9fed 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/Team.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/Team.java @@ -1,6 +1,7 @@ package com.PFE.ServerManager; import javax.persistence.*; +import java.util.HashSet; import java.util.Set; @Entity @@ -18,7 +19,7 @@ public class Team { @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "team_update", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "updateId")) - private Set update; + private Set updates; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "team_customer", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "customerId")) @@ -45,12 +46,23 @@ public class Team { public Set getCustomers() { return customers; } + public void addCustomer(Customer customer){ + if(updates == null){ + updates = new HashSet<>(); + } + this.customers.add(customer); + } - public void setUpdate(Set update) { - this.update = update; + public void setUpdates(Set updates) { + this.updates = updates; + } + public Set getUpdates() { + return updates; } - public Set getUpdate() { - return update; + public void addUpdate(Update update){ + if(updates == null) { + updates = new HashSet<>(); + } + this.updates.add(update); } - public void addUpdate(Update update){this.update.add(update);} } -- libgit2 0.21.2