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 | |
9 | 9 | import javax.annotation.PostConstruct; |
10 | 10 | import java.io.*; |
11 | -import java.util.*; | |
12 | - | |
13 | 11 | |
14 | 12 | @Component |
15 | 13 | public class AppConfig { |
... | ... | @@ -58,43 +56,21 @@ public class AppConfig { |
58 | 56 | Customer n = new Customer(); |
59 | 57 | n.setEmail(conf.getAdminEmail()); |
60 | 58 | n.setPassword(bCryptPasswordEncoder.encode(conf.getAdminPassword())); |
61 | - n.setId((int)(customerRepository.count() + 1)); | |
59 | + n.setCustomerId((int)(customerRepository.count() + 1)); | |
62 | 60 | n.setActive(1); |
63 | 61 | |
64 | 62 | Customer temp = customerRepository.findByEmail(conf.getAdminEmail()); |
65 | 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 | 66 | if(temp == null) { |
83 | 67 | customerRepository.save(n); |
84 | - | |
85 | 68 | } |
86 | - | |
87 | 69 | /* Partie sur les groupes */ |
88 | 70 | Team g = new Team(); |
89 | 71 | g.setTeamId((int)(teamRepository.count() +1)); |
90 | 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 | 74 | teamRepository.save(g); |
97 | - ////////////////////////// | |
98 | - | |
99 | 75 | } |
100 | 76 | } |
101 | 77 | \ No newline at end of file | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/Customer.java
1 | 1 | package com.PFE.ServerManager; |
2 | 2 | |
3 | 3 | import javax.persistence.*; |
4 | +import java.util.HashSet; | |
4 | 5 | import java.util.Set; |
5 | 6 | |
6 | 7 | @Entity |
... | ... | @@ -35,7 +36,16 @@ public class Customer{ |
35 | 36 | |
36 | 37 | |
37 | 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 | 45 | public Set<Role> getRoles() { return roles; } |
46 | + public String getRole(){ | |
47 | + return roles.iterator().next().getRole(); | |
48 | + } | |
39 | 49 | |
40 | 50 | public void setUpdate(Set<Update> update) { |
41 | 51 | this.update = update; |
... | ... | @@ -44,10 +54,7 @@ public class Customer{ |
44 | 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 | 58 | this.customerId = id; |
52 | 59 | } |
53 | 60 | public Integer getCustomerId() { return customerId; } | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
... | ... | @@ -76,7 +76,7 @@ public class MainController { |
76 | 76 | Customer customer = customerRepository.findByEmail(auth.getName()); |
77 | 77 | modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); |
78 | 78 | modelAndView.addObject("customerRole", customer.getRole()); |
79 | - modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdate()); | |
79 | + modelAndView.addObject("customerMaj", (teamRepository.findByCustomersContaining(customer)).getUpdates()); | |
80 | 80 | List<Node> nodes = nodeRepository.findAll(); |
81 | 81 | modelAndView.addObject("nodes", nodes); |
82 | 82 | |
... | ... | @@ -98,7 +98,6 @@ public class MainController { |
98 | 98 | |
99 | 99 | modelAndView.addObject("customerFiles", filesName); |
100 | 100 | modelAndView.setViewName("update"); |
101 | - | |
102 | 101 | return modelAndView; |
103 | 102 | } |
104 | 103 | |
... | ... | @@ -125,11 +124,11 @@ public class MainController { |
125 | 124 | Customer n = new Customer(); |
126 | 125 | n.setEmail(email); |
127 | 126 | n.setPassword(bCryptPasswordEncoder.encode(password)); |
128 | - n.setId((int)(customerRepository.count() + 1)); | |
127 | + n.setCustomerId((int)(customerRepository.count() + 1)); | |
129 | 128 | n.setActive(1); |
130 | 129 | Customer temp = customerRepository.findByEmail(email); |
131 | 130 | Role userRole = roleRepository.findByRole(role); |
132 | - n.setRoles(new HashSet<Role>(Arrays.asList(userRole))); | |
131 | + n.addRole(userRole); | |
133 | 132 | |
134 | 133 | //utilisé uniquement pour continuer à afficher l'utilisateur connecté// |
135 | 134 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ... | ... |
PFE06/src/main/java/com/PFE/ServerManager/Role.java
PFE06/src/main/java/com/PFE/ServerManager/Team.java
1 | 1 | package com.PFE.ServerManager; |
2 | 2 | |
3 | 3 | import javax.persistence.*; |
4 | +import java.util.HashSet; | |
4 | 5 | import java.util.Set; |
5 | 6 | |
6 | 7 | @Entity |
... | ... | @@ -18,7 +19,7 @@ public class Team { |
18 | 19 | |
19 | 20 | @ManyToMany(cascade = CascadeType.ALL) |
20 | 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 | 24 | @ManyToMany(cascade = CascadeType.ALL) |
24 | 25 | @JoinTable(name = "team_customer", joinColumns = @JoinColumn(name = "teamId"), inverseJoinColumns = @JoinColumn(name = "customerId")) |
... | ... | @@ -45,12 +46,23 @@ public class Team { |
45 | 46 | public Set<Customer> getCustomers() { |
46 | 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 | } | ... | ... |