Add Session.html and lombok, change property access into field access to lombok.
Tested add Session to user, add method UtilisateurDAO.addToSession Please rerun mvn clean install
This commit is contained in:
18
pom.xml
18
pom.xml
@@ -49,7 +49,7 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<version>1.18.42</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -70,19 +70,29 @@
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.4.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.11.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source> <!-- depending on your project -->
|
||||
<target>1.8</target> <!-- depending on your project -->
|
||||
<source>11</source> <!-- depending on your project -->
|
||||
<target>11</target> <!-- depending on your project -->
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${org.mapstruct.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</path>
|
||||
<!-- other annotation processors -->
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
|
||||
@@ -14,9 +14,6 @@ public class SessionDAO extends GenericDAOImpl<Integer, Session> {
|
||||
this.setClass(Session.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<Session> findByTheme(String theme){
|
||||
EntityTransaction t=em.getTransaction();
|
||||
t.begin();
|
||||
|
||||
@@ -2,8 +2,11 @@ package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||
public UtilisateurDAO() {
|
||||
super();
|
||||
@@ -29,4 +32,25 @@ public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||
t.commit();
|
||||
return u;
|
||||
}
|
||||
|
||||
public void addToSession(int sessionId, int userId) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Session s = em.find(Session.class, sessionId);
|
||||
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||
|
||||
//ERROR NULLPOINTEREXCEPTION
|
||||
if (u.getSession() == null) {
|
||||
u.setSession(new ArrayList<>());
|
||||
}
|
||||
if (s.getUtilisateurs() == null) {
|
||||
s.setUtilisateurs(new ArrayList<>());
|
||||
}
|
||||
|
||||
//FAUT AJOUTER OWNING SIDE ( Ici u --> s)
|
||||
u.getSession().add(s);
|
||||
s.getUtilisateurs().add(u);
|
||||
em.merge(u);
|
||||
t.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,18 @@ import java.util.ArrayList;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
||||
public class Choix extends Reponse{
|
||||
ArrayList<String> choix;
|
||||
|
||||
public Choix() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ArrayList<String> getChoix() {
|
||||
return this.choix;
|
||||
}
|
||||
|
||||
public void setChoix(ArrayList<String> choix) {
|
||||
this.choix = choix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
String res = "";
|
||||
|
||||
@@ -1,51 +1,27 @@
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Question implements Serializable {
|
||||
private int id;
|
||||
private String question;
|
||||
private Reponse reponse;
|
||||
private Quizz quizz;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
private int id;
|
||||
private String question;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name ="bonne_reponse", referencedColumnName = "id")
|
||||
public Reponse getReponse() {
|
||||
return reponse;
|
||||
}
|
||||
|
||||
public void setReponse(Reponse reponse) {
|
||||
this.reponse = reponse;
|
||||
}
|
||||
private Reponse reponse;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_quizz")
|
||||
public Quizz getQuizz(){
|
||||
return this.quizz;
|
||||
}
|
||||
|
||||
public void setQuizz(Quizz quizz){
|
||||
this.quizz = quizz;
|
||||
}
|
||||
|
||||
public String getQuestion(){
|
||||
return this.question;
|
||||
}
|
||||
|
||||
public void setQuestion(String question){
|
||||
this.question = question;
|
||||
}
|
||||
|
||||
private Quizz quizz;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,30 @@
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Quizz implements Serializable {
|
||||
private Session session;
|
||||
private int id;
|
||||
private Utilisateur utilisateur;
|
||||
private List<Question> questions;
|
||||
|
||||
public Quizz(){
|
||||
super();
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id){
|
||||
this.id=id;
|
||||
}
|
||||
private int id;
|
||||
|
||||
@ManyToOne
|
||||
public Session getSession(){
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(Session session){
|
||||
this.session=session;
|
||||
}
|
||||
private Session session;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_utilisateur")
|
||||
public Utilisateur getUtilisateur(){
|
||||
return utilisateur;
|
||||
}
|
||||
|
||||
public void setUtilisateur(Utilisateur u){
|
||||
this.utilisateur=u;
|
||||
}
|
||||
private Utilisateur utilisateur;
|
||||
|
||||
@OneToMany(mappedBy = "quizz")
|
||||
public List<Question> getQuestions(){
|
||||
return this.questions;
|
||||
}
|
||||
|
||||
|
||||
public void setQuestions(List<Question> questions){
|
||||
this.questions = questions;
|
||||
}
|
||||
|
||||
private List<Question> questions=new ArrayList<Question>();
|
||||
}
|
||||
@@ -4,44 +4,25 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@Inheritance(strategy=InheritanceType.JOINED)
|
||||
@DiscriminatorColumn(name="Type_reponse")
|
||||
@DiscriminatorValue("Reponse")
|
||||
public abstract class Reponse implements Serializable {
|
||||
private int id;
|
||||
private Question question;
|
||||
public List<String> reponses;
|
||||
|
||||
public Reponse(){}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
private int id;
|
||||
|
||||
@OneToOne
|
||||
public Question getQuestion(){
|
||||
return this.question;
|
||||
}
|
||||
|
||||
public void setQuestion(Question question){
|
||||
this.question=question;
|
||||
}
|
||||
|
||||
public List<String> getReponses(){
|
||||
return this.reponses;
|
||||
}
|
||||
|
||||
public void setReponses(List<String> reponses){
|
||||
this.reponses=reponses;
|
||||
}
|
||||
private Question question;
|
||||
public List<String> reponses;
|
||||
|
||||
public String valHTML(){
|
||||
return "";
|
||||
|
||||
@@ -2,23 +2,18 @@ package metier;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@PrimaryKeyJoinColumn(name = "RC_Id")
|
||||
public class ReponseCourte extends Reponse{
|
||||
String value;
|
||||
|
||||
public ReponseCourte(){
|
||||
super();
|
||||
}
|
||||
|
||||
public void setValue(String value){
|
||||
this.value = value;
|
||||
}
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
return "INPUT";
|
||||
|
||||
@@ -5,54 +5,22 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Session implements Serializable {
|
||||
private int codePIN;
|
||||
private List<Quizz> quizzs;
|
||||
private List<Utilisateur> utilisateurs;
|
||||
private String theme;
|
||||
|
||||
public Session(){
|
||||
}
|
||||
|
||||
public void setCodePIN(int codePIN){
|
||||
this.codePIN = codePIN;
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getCodePIN(){
|
||||
return this.codePIN;
|
||||
}
|
||||
|
||||
public void setQuizzs(List<Quizz> quizzs){
|
||||
this.quizzs = quizzs;
|
||||
}
|
||||
private int codePIN;
|
||||
|
||||
@OneToMany(mappedBy="session")
|
||||
public List<Quizz> getQuizzs(){
|
||||
return this.quizzs;
|
||||
}
|
||||
private List<Quizz> quizzs = new ArrayList<>();
|
||||
private List<Utilisateur> utilisateurs = new ArrayList<>();
|
||||
private String theme;
|
||||
|
||||
public void setUtilisateurs(List<Utilisateur> utilisateurs){
|
||||
this.utilisateurs = utilisateurs;
|
||||
}
|
||||
|
||||
@ManyToMany(mappedBy = "session")
|
||||
public List<Utilisateur> getUtilisateurs() {
|
||||
return this.utilisateurs;
|
||||
}
|
||||
|
||||
public String getTheme(){
|
||||
return this.theme;
|
||||
}
|
||||
|
||||
public void setTheme(String theme){
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public void addUser(Utilisateur user){
|
||||
this.utilisateurs.add(user);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,24 @@
|
||||
package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import lombok.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Utilisateur implements Serializable {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private List<Session> session;
|
||||
private String email;
|
||||
private String password;
|
||||
private List<Quizz> quizzs;
|
||||
|
||||
public Utilisateur() {}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
@Column(unique=true)
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
@@ -50,28 +26,9 @@ public class Utilisateur implements Serializable {
|
||||
joinColumns = @JoinColumn(name="utilisateur_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "session_pin")
|
||||
)
|
||||
public List<Session> getSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
public void setSession(List<Session> session){
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
private List<Session> session= new ArrayList<>();;
|
||||
|
||||
@OneToMany(mappedBy = "utilisateur")
|
||||
public List<Quizz> getQuizzs() {
|
||||
return quizzs;
|
||||
}
|
||||
private List<Quizz> quizzs;
|
||||
|
||||
public void setQuizzs(List<Quizz> quizzs) {
|
||||
this.quizzs = quizzs;
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,28 @@ import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
@WebServlet(name="session", urlPatterns={"/SessionInfo"})
|
||||
public class SessionInfo extends HttpServlet {
|
||||
@WebServlet(name = "session", urlPatterns = {"/SessionInfo"})
|
||||
public class SessionInfo extends HttpServlet {
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
UtilisateurDAO uDAO = new UtilisateurDAO();
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
req.getRequestDispatcher("/Session.html").forward(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// Créer une nouvelle session
|
||||
String theme = req.getParameter("theme");
|
||||
Session s = new Session();
|
||||
s.setTheme(theme);
|
||||
sessionDAO.create(s);
|
||||
|
||||
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||
s.getCodePIN() + "</h1>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
package servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -10,7 +11,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import metier.Utilisateur;
|
||||
|
||||
@WebServlet(name="userinfo", urlPatterns={"/UserInfo"})
|
||||
@WebServlet(name = "userinfo", urlPatterns = {"/UserInfo"})
|
||||
public class UserInfo extends HttpServlet {
|
||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
|
||||
@@ -21,18 +22,27 @@ public class UserInfo extends HttpServlet {
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
String action = request.getParameter("action");
|
||||
|
||||
Utilisateur u = new Utilisateur();
|
||||
u.setName(request.getParameter("name"));
|
||||
u.setEmail(request.getParameter("email"));
|
||||
if ("addUser".equals(action)) {
|
||||
Utilisateur u = new Utilisateur();
|
||||
u.setName(request.getParameter("name"));
|
||||
u.setEmail(request.getParameter("email"));
|
||||
|
||||
utilisateurDAO.create(u);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<HTML>\n<BODY>\n" +
|
||||
"<H1>Recapitulatif des informations de Tibo</H1>\n" +
|
||||
"<UL>\n" + " <LI>Nom: " + request.getParameter("name") +
|
||||
"\n" + " <LI>Email: " + request.getParameter("email") + "\n" +
|
||||
"</BODY></HTML>");
|
||||
utilisateurDAO.create(u);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<HTML>\n<BODY>\n" +
|
||||
"<H1>Recapitulatif des informations de Tibo</H1>\n" +
|
||||
"<UL>\n" + " <LI>Nom: " + request.getParameter("name") +
|
||||
"\n" + " <LI>Email: " + request.getParameter("email") + "\n" +
|
||||
"</BODY></HTML>");
|
||||
} else if ("addSession".equals(action)) {
|
||||
int sessionId = Integer.parseInt(request.getParameter("sessionId"));
|
||||
int userId = Integer.parseInt(request.getParameter("userId"));
|
||||
utilisateurDAO.addToSession(sessionId, userId);
|
||||
response.getWriter().println("<h1> Reussi d'ajouter utilisateur " +
|
||||
userId + " au session " + sessionId + "</h1>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<form action="QuizzInfo" method="POST">
|
||||
<h1>Creer session</h1>
|
||||
Theme Session : <INPUT type="text" name="theme" size="20"><BR>
|
||||
<INPUT type="submit" value="Creer Quizz"></INPUT>
|
||||
</form>
|
||||
</body>
|
||||
<body>
|
||||
<h1>Creer une session</h1>
|
||||
<form action="SessionInfo" method="POST">
|
||||
<input type="hidden" name="action" value="createSession">
|
||||
Theme: <input type="text" name="theme">
|
||||
<input type="submit" value="Creer Session">
|
||||
</form>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<body>
|
||||
<FORM Method="POST" Action="/UserInfo">
|
||||
<h1>Creer l'utilisateur</h1>
|
||||
<FORM Method="POST" Action="UserInfo">
|
||||
<input type="hidden" name="action" value="addUser">
|
||||
Name : <INPUT type="text" size="20" name="name"><BR>
|
||||
Email : <INPUT type="text" size="20" name="email"><BR>
|
||||
<INPUT type="submit" value="Send">
|
||||
</FORM>
|
||||
|
||||
<h1>Ajouter utilisateur dans une session</h1>
|
||||
<form action="UserInfo" method="POST">
|
||||
<input type="hidden" name="action" value="addSession">
|
||||
ID Session: <input type="number" name="sessionId"><br>
|
||||
ID Utilisateur: <input type="number" name="userId"><br>
|
||||
<input type="submit" value="Ajouter">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
<a href =http://localhost:8080/myform.html>myform</a>
|
||||
<a href =http://localhost:8080/UserInfo.html>myform</a>
|
||||
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
||||
|
||||
<a href =Show>show</a>
|
||||
|
||||
Reference in New Issue
Block a user