Commit 0e18634e1aa600409c111f78e3d49676f093a859
1 parent
65f1240c
modifications mineures de méthodes
Showing
5 changed files
with
36 additions
and
41 deletions
Show diff stats
PFE06/src/main/java/com/PFE/ServerManager/AppConfig.java
@@ -8,8 +8,6 @@ import org.yaml.snakeyaml.constructor.Constructor; | @@ -8,8 +8,6 @@ import org.yaml.snakeyaml.constructor.Constructor; | ||
8 | 8 | ||
9 | import javax.annotation.PostConstruct; | 9 | import javax.annotation.PostConstruct; |
10 | import java.io.*; | 10 | import java.io.*; |
11 | -import java.util.*; | ||
12 | - | ||
13 | 11 | ||
14 | @Component | 12 | @Component |
15 | public class AppConfig { | 13 | public class AppConfig { |
@@ -58,43 +56,21 @@ public class AppConfig { | @@ -58,43 +56,21 @@ public class AppConfig { | ||
58 | Customer n = new Customer(); | 56 | Customer n = new Customer(); |
59 | n.setEmail(conf.getAdminEmail()); | 57 | n.setEmail(conf.getAdminEmail()); |
60 | n.setPassword(bCryptPasswordEncoder.encode(conf.getAdminPassword())); | 58 | n.setPassword(bCryptPasswordEncoder.encode(conf.getAdminPassword())); |
61 | - n.setId((int)(customerRepository.count() + 1)); | 59 | + n.setCustomerId((int)(customerRepository.count() + 1)); |
62 | n.setActive(1); | 60 | n.setActive(1); |
63 | 61 | ||
64 | Customer temp = customerRepository.findByEmail(conf.getAdminEmail()); | 62 | Customer temp = customerRepository.findByEmail(conf.getAdminEmail()); |
65 | Role userRole = roleRepository.findByRole("ADMIN"); | 63 | Role userRole = roleRepository.findByRole("ADMIN"); |
66 | - n.setRoles(new HashSet<>(Arrays.asList(userRole))); | ||
67 | - | ||
68 | - ////////////////////////////////////////// | ||
69 | - /* | ||
70 | - Customer p = new Customer(); | ||
71 | - p.setEmail("admin@admin.fr"); | ||
72 | - p.setPassword(bCryptPasswordEncoder.encode("azerty")); | ||
73 | - p.setId((int)(customerRepository.count() + 2)); | ||
74 | - p.setActive(1); | ||
75 | - | ||
76 | - Role userRole2 = roleRepository.findByRole("USER"); | ||
77 | - p.setRoles(new HashSet<>(Arrays.asList(userRole2))); | ||
78 | - customerRepository.save(p); | ||
79 | - */ | ||
80 | - /////////////////////////////////// | 64 | + n.addRole(userRole); |
81 | 65 | ||
82 | if(temp == null) { | 66 | if(temp == null) { |
83 | customerRepository.save(n); | 67 | customerRepository.save(n); |
84 | - | ||
85 | } | 68 | } |
86 | - | ||
87 | /* Partie sur les groupes */ | 69 | /* Partie sur les groupes */ |
88 | Team g = new Team(); | 70 | Team g = new Team(); |
89 | g.setTeamId((int)(teamRepository.count() +1)); | 71 | g.setTeamId((int)(teamRepository.count() +1)); |
90 | g.setTeam("Labo1"); | 72 | g.setTeam("Labo1"); |
91 | - Set<Customer> tempC = new HashSet<>(); | ||
92 | - tempC.add(n); | ||
93 | - //tempC.add(p); | ||
94 | - g.setCustomers(tempC); | ||
95 | - //g.setCustomers(new HashSet<>(Arrays.asList(n, p))); | 73 | + g.addCustomer(n); |
96 | teamRepository.save(g); | 74 | teamRepository.save(g); |
97 | - ////////////////////////// | ||
98 | - | ||
99 | } | 75 | } |
100 | } | 76 | } |
101 | \ No newline at end of file | 77 | \ No newline at end of file |
PFE06/src/main/java/com/PFE/ServerManager/Customer.java
1 | package com.PFE.ServerManager; | 1 | package com.PFE.ServerManager; |
2 | 2 | ||
3 | import javax.persistence.*; | 3 | import javax.persistence.*; |
4 | +import java.util.HashSet; | ||
4 | import java.util.Set; | 5 | import java.util.Set; |
5 | 6 | ||
6 | @Entity | 7 | @Entity |
@@ -35,7 +36,16 @@ public class Customer{ | @@ -35,7 +36,16 @@ public class Customer{ | ||
35 | 36 | ||
36 | 37 | ||
37 | public void setRoles(Set<Role> roles) { this.roles = roles; } | 38 | public void setRoles(Set<Role> roles) { this.roles = roles; } |
39 | + public void addRole(Role role){ | ||
40 | + if(roles == null){ | ||
41 | + roles = new HashSet<>(); | ||
42 | + } | ||
43 | + this.roles.add(role); | ||
44 | + } | ||
38 | public Set<Role> getRoles() { return roles; } | 45 | public Set<Role> getRoles() { return roles; } |
46 | + public String getRole(){ | ||
47 | + return roles.iterator().next().getRole(); | ||
48 | + } | ||
39 | 49 | ||
40 | public void setUpdate(Set<Update> update) { | 50 | public void setUpdate(Set<Update> update) { |
41 | this.update = update; | 51 | this.update = update; |
@@ -44,10 +54,7 @@ public class Customer{ | @@ -44,10 +54,7 @@ public class Customer{ | ||
44 | return update; | 54 | return update; |
45 | } | 55 | } |
46 | 56 | ||
47 | - public String getRole(){ | ||
48 | - return roles.iterator().next().getRole(); | ||
49 | - } | ||
50 | - public void setId(Integer id) { | 57 | + public void setCustomerId(Integer id) { |
51 | this.customerId = id; | 58 | this.customerId = id; |
52 | } | 59 | } |
53 | public Integer getCustomerId() { return customerId; } | 60 | public Integer getCustomerId() { return customerId; } |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
@@ -76,7 +76,7 @@ public class MainController { | @@ -76,7 +76,7 @@ public class MainController { | ||
76 | Customer customer = customerRepository.findByEmail(auth.getName()); | 76 | Customer customer = customerRepository.findByEmail(auth.getName()); |
77 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | 77 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
78 | modelAndView.addObject("customerRole", customer.getRole()); | 78 | modelAndView.addObject("customerRole", customer.getRole()); |
79 | - modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdate()); | 79 | + modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdates()); |
80 | List<Node> nodes = nodeRepository.findAll(); | 80 | List<Node> nodes = nodeRepository.findAll(); |
81 | modelAndView.addObject("nodes", nodes); | 81 | modelAndView.addObject("nodes", nodes); |
82 | 82 | ||
@@ -98,7 +98,6 @@ public class MainController { | @@ -98,7 +98,6 @@ public class MainController { | ||
98 | 98 | ||
99 | modelAndView.addObject("customerFiles", filesName); | 99 | modelAndView.addObject("customerFiles", filesName); |
100 | modelAndView.setViewName("update"); | 100 | modelAndView.setViewName("update"); |
101 | - | ||
102 | return modelAndView; | 101 | return modelAndView; |
103 | } | 102 | } |
104 | 103 | ||
@@ -125,11 +124,11 @@ public class MainController { | @@ -125,11 +124,11 @@ public class MainController { | ||
125 | Customer n = new Customer(); | 124 | Customer n = new Customer(); |
126 | n.setEmail(email); | 125 | n.setEmail(email); |
127 | n.setPassword(bCryptPasswordEncoder.encode(password)); | 126 | n.setPassword(bCryptPasswordEncoder.encode(password)); |
128 | - n.setId((int)(customerRepository.count() + 1)); | 127 | + n.setCustomerId((int)(customerRepository.count() + 1)); |
129 | n.setActive(1); | 128 | n.setActive(1); |
130 | Customer temp = customerRepository.findByEmail(email); | 129 | Customer temp = customerRepository.findByEmail(email); |
131 | Role userRole = roleRepository.findByRole(role); | 130 | Role userRole = roleRepository.findByRole(role); |
132 | - n.setRoles(new HashSet<Role>(Arrays.asList(userRole))); | 131 | + n.addRole(userRole); |
133 | 132 | ||
134 | //utilisé uniquement pour continuer à afficher l'utilisateur connecté// | 133 | //utilisé uniquement pour continuer à afficher l'utilisateur connecté// |
135 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 134 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
PFE06/src/main/java/com/PFE/ServerManager/Role.java
@@ -23,4 +23,5 @@ public class Role { | @@ -23,4 +23,5 @@ public class Role { | ||
23 | 23 | ||
24 | public void setRoleId(Integer roleId) { this.roleId = roleId; } | 24 | public void setRoleId(Integer roleId) { this.roleId = roleId; } |
25 | public Integer getRoleId() { return roleId; } | 25 | public Integer getRoleId() { return roleId; } |
26 | + | ||
26 | } | 27 | } |
27 | \ No newline at end of file | 28 | \ No newline at end of file |
PFE06/src/main/java/com/PFE/ServerManager/Team.java
1 | package com.PFE.ServerManager; | 1 | package com.PFE.ServerManager; |
2 | 2 | ||
3 | import javax.persistence.*; | 3 | import javax.persistence.*; |
4 | +import java.util.HashSet; | ||
4 | import java.util.Set; | 5 | import java.util.Set; |
5 | 6 | ||
6 | @Entity | 7 | @Entity |
@@ -18,7 +19,7 @@ public class Team { | @@ -18,7 +19,7 @@ public class Team { | ||
18 | 19 | ||
19 | @ManyToMany(cascade = CascadeType.ALL) | 20 | @ManyToMany(cascade = CascadeType.ALL) |
20 | @JoinTable(name = "team_update", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "updateId")) | 21 | @JoinTable(name = "team_update", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "updateId")) |
21 | - private Set<Update> update; | 22 | + private Set<Update> updates; |
22 | 23 | ||
23 | @ManyToMany(cascade = CascadeType.ALL) | 24 | @ManyToMany(cascade = CascadeType.ALL) |
24 | @JoinTable(name = "team_customer", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "customerId")) | 25 | @JoinTable(name = "team_customer", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "customerId")) |
@@ -45,12 +46,23 @@ public class Team { | @@ -45,12 +46,23 @@ public class Team { | ||
45 | public Set<Customer> getCustomers() { | 46 | public Set<Customer> getCustomers() { |
46 | return customers; | 47 | return customers; |
47 | } | 48 | } |
49 | + public void addCustomer(Customer customer){ | ||
50 | + if(updates == null){ | ||
51 | + updates = new HashSet<>(); | ||
52 | + } | ||
53 | + this.customers.add(customer); | ||
54 | + } | ||
48 | 55 | ||
49 | - public void setUpdate(Set<Update> update) { | ||
50 | - this.update = update; | 56 | + public void setUpdates(Set<Update> updates) { |
57 | + this.updates = updates; | ||
58 | + } | ||
59 | + public Set<Update> getUpdates() { | ||
60 | + return updates; | ||
51 | } | 61 | } |
52 | - public Set<Update> getUpdate() { | ||
53 | - return update; | 62 | + public void addUpdate(Update update){ |
63 | + if(updates == null) { | ||
64 | + updates = new HashSet<>(); | ||
65 | + } | ||
66 | + this.updates.add(update); | ||
54 | } | 67 | } |
55 | - public void addUpdate(Update update){this.update.add(update);} | ||
56 | } | 68 | } |