Commit 8799baa63555f69ea66c267fdf0588adebc3ff3b
1 parent
c4e83d00
Ajout des entitées principales restantes
Showing
7 changed files
with
299 additions
and
25 deletions
Show diff stats
src/main/java/etunicorn/SecurityInterceptor.java
@@ -55,14 +55,17 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter { | @@ -55,14 +55,17 @@ public class SecurityInterceptor extends HandlerInterceptorAdapter { | ||
55 | Permission requiredPermission = permissionRepository.findByNom(annotation.value()); | 55 | Permission requiredPermission = permissionRepository.findByNom(annotation.value()); |
56 | 56 | ||
57 | if (annotation.authentifie()) { | 57 | if (annotation.authentifie()) { |
58 | + BaseController baseController = new BaseController(); | ||
59 | + baseController.setRequest(request); | ||
60 | + | ||
58 | if (requiredPermission == null) { | 61 | if (requiredPermission == null) { |
59 | response.setStatus(HttpStatus.NOT_IMPLEMENTED.value()); | 62 | response.setStatus(HttpStatus.NOT_IMPLEMENTED.value()); |
60 | - // TODO utiliser base controller | 63 | + |
64 | + ResponseEntity responseEntity = baseController.generateError(HttpStatus.NOT_IMPLEMENTED); | ||
65 | + responseEntityToServletResponse(responseEntity, response); | ||
61 | return false; | 66 | return false; |
62 | } | 67 | } |
63 | 68 | ||
64 | - BaseController baseController = new BaseController(); | ||
65 | - baseController.setRequest(request); | ||
66 | if (session == null) { | 69 | if (session == null) { |
67 | ResponseEntity responseEntity = baseController.generateError(HttpStatus.UNAUTHORIZED); | 70 | ResponseEntity responseEntity = baseController.generateError(HttpStatus.UNAUTHORIZED); |
68 | responseEntityToServletResponse(responseEntity, response); | 71 | responseEntityToServletResponse(responseEntity, response); |
src/main/java/etunicorn/controller/PersonneController.java
@@ -55,24 +55,27 @@ public class PersonneController extends BaseController implements etunicorn.gene | @@ -55,24 +55,27 @@ public class PersonneController extends BaseController implements etunicorn.gene | ||
55 | return generateError(HttpStatus.BAD_REQUEST, "La date ou la carte doivent être au moins renseignés."); | 55 | return generateError(HttpStatus.BAD_REQUEST, "La date ou la carte doivent être au moins renseignés."); |
56 | } | 56 | } |
57 | if (updatePersonneRequest.getRole() != null) { | 57 | if (updatePersonneRequest.getRole() != null) { |
58 | - System.out.println("HELLO"); | ||
59 | - LinkedHashMap<String, String> roleMap = (LinkedHashMap<String, String>) updatePersonneRequest.getRole(); | ||
60 | - Role role = roleRepository.findByNom(roleMap.get("nom")); | ||
61 | - if (role == null) { | ||
62 | - return generateError(HttpStatus.NOT_FOUND, "Rôle inconnu"); | ||
63 | - } | ||
64 | - if (personne.getRole() != role) { | ||
65 | - if (hasPermission("PERSONNE_ROLE")) { | ||
66 | - personne.setRole(role); | ||
67 | - } else { | ||
68 | - return generateError(HttpStatus.FORBIDDEN, "Vous ne pouvez pas changer le rôle"); | 58 | + if (updatePersonneRequest.getRole() instanceof LinkedHashMap) { |
59 | + LinkedHashMap<String, String> roleMap = (LinkedHashMap<String, String>) updatePersonneRequest.getRole(); | ||
60 | + Role role = roleRepository.findByNom(roleMap.get("nom")); | ||
61 | + if (role == null) { | ||
62 | + return generateError(HttpStatus.NOT_FOUND, "Rôle inconnu"); | ||
63 | + } | ||
64 | + if (personne.getRole() != role) { | ||
65 | + if (hasPermission("PERSONNE_ROLE")) { | ||
66 | + personne.setRole(role); | ||
67 | + } else { | ||
68 | + return generateError(HttpStatus.FORBIDDEN, "Vous ne pouvez pas changer le rôle"); | ||
69 | + } | ||
69 | } | 70 | } |
71 | + } else { | ||
72 | + return generateError(HttpStatus.BAD_REQUEST, "Le rôle est un objet"); | ||
70 | } | 73 | } |
71 | } | 74 | } |
72 | try { | 75 | try { |
73 | this.personneRepository.save(personne); | 76 | this.personneRepository.save(personne); |
74 | } catch (DataIntegrityViolationException e) { | 77 | } catch (DataIntegrityViolationException e) { |
75 | - return new ResponseEntity<Object>(HttpStatus.CONFLICT); | 78 | + return generateError(HttpStatus.CONFLICT, "Un utilisateur avec la même carte ou le même login existe déjà"); |
76 | } | 79 | } |
77 | return new ResponseEntity<Object>(personne, HttpStatus.CREATED); | 80 | return new ResponseEntity<Object>(personne, HttpStatus.CREATED); |
78 | } | 81 | } |
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +package etunicorn.entity; | ||
2 | + | ||
3 | +import javax.persistence.*; | ||
4 | + | ||
5 | +/** | ||
6 | + * etunicorn-server | ||
7 | + * Copyright © 2017 Le Club Info Polytech Lille | ||
8 | + * Tous droits réservés | ||
9 | + */ | ||
10 | +@Entity | ||
11 | +public class Consommation { | ||
12 | + @Id | ||
13 | + @GeneratedValue(strategy = GenerationType.AUTO) | ||
14 | + private int id; | ||
15 | + | ||
16 | + @Column(unique = true) | ||
17 | + private String nom; | ||
18 | + | ||
19 | + private float prix; | ||
20 | + | ||
21 | + public Consommation() { | ||
22 | + } | ||
23 | + | ||
24 | + public int getId() { | ||
25 | + return id; | ||
26 | + } | ||
27 | + | ||
28 | + public void setId(int id) { | ||
29 | + this.id = id; | ||
30 | + } | ||
31 | + | ||
32 | + public String getNom() { | ||
33 | + return nom; | ||
34 | + } | ||
35 | + | ||
36 | + public void setNom(String nom) { | ||
37 | + this.nom = nom; | ||
38 | + } | ||
39 | + | ||
40 | + public float getPrix() { | ||
41 | + return prix; | ||
42 | + } | ||
43 | + | ||
44 | + public void setPrix(float prix) { | ||
45 | + this.prix = prix; | ||
46 | + } | ||
47 | +} |
@@ -0,0 +1,76 @@ | @@ -0,0 +1,76 @@ | ||
1 | +package etunicorn.entity; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
5 | + | ||
6 | +import javax.persistence.*; | ||
7 | +import java.util.Date; | ||
8 | +import java.util.List; | ||
9 | + | ||
10 | +/** | ||
11 | + * etunicorn-server | ||
12 | + * Copyright © 2017 Le Club Info Polytech Lille | ||
13 | + * Tous droits réservés | ||
14 | + */ | ||
15 | +@Entity | ||
16 | +public class Evenement { | ||
17 | + @Id | ||
18 | + @GeneratedValue(strategy = GenerationType.AUTO) | ||
19 | + private int id; | ||
20 | + | ||
21 | + @Column(unique = true) | ||
22 | + private String nom; | ||
23 | + | ||
24 | + private float prix; | ||
25 | + | ||
26 | + private Date date; | ||
27 | + | ||
28 | + @ManyToMany(mappedBy = "participations") | ||
29 | + private List<Personne> participants; | ||
30 | + | ||
31 | + public Evenement(String nom) { | ||
32 | + this.nom = nom; | ||
33 | + } | ||
34 | + | ||
35 | + public int getId() { | ||
36 | + return id; | ||
37 | + } | ||
38 | + | ||
39 | + public void setId(int id) { | ||
40 | + this.id = id; | ||
41 | + } | ||
42 | + | ||
43 | + public String getNom() { | ||
44 | + return nom; | ||
45 | + } | ||
46 | + | ||
47 | + public void setNom(String nom) { | ||
48 | + this.nom = nom; | ||
49 | + } | ||
50 | + | ||
51 | + public float getPrix() { | ||
52 | + return prix; | ||
53 | + } | ||
54 | + | ||
55 | + public void setPrix(float prix) { | ||
56 | + this.prix = prix; | ||
57 | + } | ||
58 | + | ||
59 | + @JsonFormat(pattern = "YYYY-MM-DD hh:mm:ss") | ||
60 | + public Date getDate() { | ||
61 | + return date; | ||
62 | + } | ||
63 | + | ||
64 | + public void setDate(Date date) { | ||
65 | + this.date = date; | ||
66 | + } | ||
67 | + | ||
68 | + @JsonIgnore | ||
69 | + public List<Personne> getParticipants() { | ||
70 | + return participants; | ||
71 | + } | ||
72 | + | ||
73 | + public void setParticipants(List<Personne> participants) { | ||
74 | + this.participants = participants; | ||
75 | + } | ||
76 | +} |
src/main/java/etunicorn/entity/Personne.java
1 | package etunicorn.entity; | 1 | package etunicorn.entity; |
2 | 2 | ||
3 | import com.fasterxml.jackson.annotation.JsonFormat; | 3 | import com.fasterxml.jackson.annotation.JsonFormat; |
4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
4 | 5 | ||
5 | import javax.persistence.*; | 6 | import javax.persistence.*; |
6 | import java.util.Date; | 7 | import java.util.Date; |
8 | +import java.util.List; | ||
7 | 9 | ||
8 | /** | 10 | /** |
9 | * etunicorn-server | 11 | * etunicorn-server |
@@ -13,18 +15,30 @@ import java.util.Date; | @@ -13,18 +15,30 @@ import java.util.Date; | ||
13 | @Entity | 15 | @Entity |
14 | public class Personne { | 16 | public class Personne { |
15 | 17 | ||
16 | - | ||
17 | - @ManyToOne | ||
18 | - public Role role; | ||
19 | @Id | 18 | @Id |
20 | @GeneratedValue(strategy = GenerationType.AUTO) | 19 | @GeneratedValue(strategy = GenerationType.AUTO) |
21 | private int id; | 20 | private int id; |
21 | + | ||
22 | @Column(unique = true) | 22 | @Column(unique = true) |
23 | private String carte; | 23 | private String carte; |
24 | + | ||
24 | private Date naissance; | 25 | private Date naissance; |
26 | + | ||
25 | @Column(unique = true) | 27 | @Column(unique = true) |
26 | private String login; | 28 | private String login; |
27 | 29 | ||
30 | + @ManyToOne | ||
31 | + private Role role; | ||
32 | + | ||
33 | + @OneToMany(mappedBy = "participant") | ||
34 | + private List<Transaction> operations; | ||
35 | + | ||
36 | + @OneToMany(mappedBy = "acteur") | ||
37 | + private List<Transaction> realisees; | ||
38 | + | ||
39 | + @ManyToMany() | ||
40 | + private List<Evenement> participations; | ||
41 | + | ||
28 | 42 | ||
29 | public Personne() { | 43 | public Personne() { |
30 | } | 44 | } |
@@ -80,4 +94,31 @@ public class Personne { | @@ -80,4 +94,31 @@ public class Personne { | ||
80 | public boolean hasPermission(Permission permission) { | 94 | public boolean hasPermission(Permission permission) { |
81 | return role.hasPermission(permission); | 95 | return role.hasPermission(permission); |
82 | } | 96 | } |
97 | + | ||
98 | + @JsonIgnore | ||
99 | + public List<Transaction> getOperations() { | ||
100 | + return operations; | ||
101 | + } | ||
102 | + | ||
103 | + public void setOperations(List<Transaction> operations) { | ||
104 | + this.operations = operations; | ||
105 | + } | ||
106 | + | ||
107 | + @JsonIgnore | ||
108 | + public List<Transaction> getRealisees() { | ||
109 | + return realisees; | ||
110 | + } | ||
111 | + | ||
112 | + public void setRealisees(List<Transaction> realisees) { | ||
113 | + this.realisees = realisees; | ||
114 | + } | ||
115 | + | ||
116 | + @JsonIgnore | ||
117 | + public List<Evenement> getParticipations() { | ||
118 | + return participations; | ||
119 | + } | ||
120 | + | ||
121 | + public void setParticipations(List<Evenement> participations) { | ||
122 | + this.participations = participations; | ||
123 | + } | ||
83 | } | 124 | } |
src/main/java/etunicorn/entity/Role.java
1 | package etunicorn.entity; | 1 | package etunicorn.entity; |
2 | 2 | ||
3 | -import javax.persistence.Column; | ||
4 | -import javax.persistence.Entity; | ||
5 | -import javax.persistence.Id; | ||
6 | -import javax.persistence.OneToMany; | ||
7 | -import java.util.ArrayList; | 3 | +import com.fasterxml.jackson.annotation.JsonIgnore; |
4 | + | ||
5 | +import javax.persistence.*; | ||
8 | import java.util.Collection; | 6 | import java.util.Collection; |
9 | import java.util.List; | 7 | import java.util.List; |
10 | 8 | ||
@@ -19,8 +17,11 @@ public class Role { | @@ -19,8 +17,11 @@ public class Role { | ||
19 | @Column(unique = true) | 17 | @Column(unique = true) |
20 | private String nom = "etudiant"; | 18 | private String nom = "etudiant"; |
21 | 19 | ||
22 | - @OneToMany | ||
23 | - private List<Permission> permissions = new ArrayList<>(); | 20 | + @ManyToMany |
21 | + private List<Permission> permissions; | ||
22 | + | ||
23 | + @OneToMany(mappedBy = "role") | ||
24 | + private List<Personne> membres; | ||
24 | 25 | ||
25 | public Role() { | 26 | public Role() { |
26 | } | 27 | } |
@@ -57,4 +58,13 @@ public class Role { | @@ -57,4 +58,13 @@ public class Role { | ||
57 | public void delPermission(Permission permission) { | 58 | public void delPermission(Permission permission) { |
58 | this.permissions.remove(permission); | 59 | this.permissions.remove(permission); |
59 | } | 60 | } |
61 | + | ||
62 | + @JsonIgnore | ||
63 | + public List<Personne> getMembres() { | ||
64 | + return membres; | ||
65 | + } | ||
66 | + | ||
67 | + public void setMembres(List<Personne> membres) { | ||
68 | + this.membres = membres; | ||
69 | + } | ||
60 | } | 70 | } |
@@ -0,0 +1,94 @@ | @@ -0,0 +1,94 @@ | ||
1 | +package etunicorn.entity; | ||
2 | + | ||
3 | +import com.fasterxml.jackson.annotation.JsonFormat; | ||
4 | + | ||
5 | +import javax.persistence.*; | ||
6 | +import java.util.Date; | ||
7 | + | ||
8 | +/** | ||
9 | + * etunicorn-server | ||
10 | + * Copyright © 2017 Le Club Info Polytech Lille | ||
11 | + * Tous droits réservés | ||
12 | + */ | ||
13 | +@Entity | ||
14 | +public class Transaction { | ||
15 | + @Id | ||
16 | + @GeneratedValue(strategy = GenerationType.AUTO) | ||
17 | + private int id; | ||
18 | + | ||
19 | + private Date date; | ||
20 | + | ||
21 | + private float prix; | ||
22 | + | ||
23 | + @ManyToOne() | ||
24 | + private Personne acteur; | ||
25 | + | ||
26 | + @ManyToOne() | ||
27 | + private Personne participant; | ||
28 | + | ||
29 | + @ManyToOne | ||
30 | + private Consommation consommation; | ||
31 | + | ||
32 | + @ManyToOne | ||
33 | + private Evenement evenement; | ||
34 | + | ||
35 | + public Transaction() { | ||
36 | + } | ||
37 | + | ||
38 | + public int getId() { | ||
39 | + return id; | ||
40 | + } | ||
41 | + | ||
42 | + public void setId(int id) { | ||
43 | + this.id = id; | ||
44 | + } | ||
45 | + | ||
46 | + @JsonFormat(pattern = "YYYY-MM-DD hh:mm:ss") | ||
47 | + public Date getDate() { | ||
48 | + return date; | ||
49 | + } | ||
50 | + | ||
51 | + public void setDate(Date date) { | ||
52 | + this.date = date; | ||
53 | + } | ||
54 | + | ||
55 | + public float getPrix() { | ||
56 | + return prix; | ||
57 | + } | ||
58 | + | ||
59 | + public void setPrix(float prix) { | ||
60 | + this.prix = prix; | ||
61 | + } | ||
62 | + | ||
63 | + public Personne getActeur() { | ||
64 | + return acteur; | ||
65 | + } | ||
66 | + | ||
67 | + public void setActeur(Personne acteur) { | ||
68 | + this.acteur = acteur; | ||
69 | + } | ||
70 | + | ||
71 | + public Personne getParticipant() { | ||
72 | + return participant; | ||
73 | + } | ||
74 | + | ||
75 | + public void setParticipant(Personne participant) { | ||
76 | + this.participant = participant; | ||
77 | + } | ||
78 | + | ||
79 | + public Consommation getConsommation() { | ||
80 | + return consommation; | ||
81 | + } | ||
82 | + | ||
83 | + public void setConsommation(Consommation consommation) { | ||
84 | + this.consommation = consommation; | ||
85 | + } | ||
86 | + | ||
87 | + public Evenement getEvenement() { | ||
88 | + return evenement; | ||
89 | + } | ||
90 | + | ||
91 | + public void setEvenement(Evenement evenement) { | ||
92 | + this.evenement = evenement; | ||
93 | + } | ||
94 | +} |