Mise en place du json
这个提交包含在:
父节点
51c81a61e3
当前提交
c4e5f8c1cd
共有 8 个文件被更改,包括 76 次插入 和 39 次删除
|
@ -22,6 +22,7 @@ javafx {
|
|||
|
||||
|
||||
dependencies {
|
||||
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
|
||||
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
chatapp/Launcher.java
|
||||
chatapp.Launcher
|
||||
chatapp/Model/ListUtilisateurs.java
|
||||
chatapp.Model.ListUtilisateurs
|
||||
chatapp/Model/MessageHorodate.java
|
||||
chatapp.Model.MessageHorodate
|
||||
chatapp/Model/DataBase.java
|
||||
chatapp.Model.DataBase
|
||||
chatapp/Model/Utilisateur.java
|
||||
chatapp.Model.Utilisateur
|
||||
chatapp/Protocol/RunnerEcouteTCP.java
|
||||
chatapp.Protocol.RunnerEcouteTCP
|
||||
chatapp/View/FenetreSession.java
|
||||
chatapp.View.FenetreSession
|
||||
chatapp/Controller/ChatApp.java
|
||||
chatapp.Controller.ChatApp
|
||||
chatapp/View/DemarrerSession.java
|
||||
chatapp.View.DemarrerSession
|
||||
chatapp/Model/DataBase.java
|
||||
chatapp.Model.DataBase
|
||||
chatapp/View/ChangementPseudo.java
|
||||
chatapp.View.ChangementPseudo
|
||||
chatapp/Protocol/RunnerEcouteUDP.java
|
||||
chatapp.Protocol.RunnerEcouteUDP
|
||||
chatapp/Model/ListUtilisateurs.java
|
||||
chatapp.Model.ListUtilisateurs
|
||||
chatapp/Protocol/UDPEchange.java
|
||||
chatapp.Protocol.RunnerUDP
|
||||
chatapp.Protocol.UDPEchange
|
||||
chatapp/Model/MessageHorodate.java
|
||||
chatapp.Model.MessageHorodate
|
||||
chatapp/Main.java
|
||||
chatapp.Main
|
||||
chatapp/View/Clavardage.java
|
||||
|
@ -28,13 +26,15 @@ chatapp/View/Clavardage.java
|
|||
chatapp.View.Clavardage$1
|
||||
chatapp/Protocol/SessionClavardage.java
|
||||
chatapp.Protocol.SessionClavardage
|
||||
chatapp/Protocol/HttpEchange.java
|
||||
chatapp.Protocol.HttpEchange
|
||||
chatapp/View/View_Utilisateurs.java
|
||||
chatapp.View.View_Utilisateurs
|
||||
chatapp/View/View_Menu.java
|
||||
chatapp.View.View_Menu
|
||||
chatapp/View/ChangementPseudo.java
|
||||
chatapp.View.ChangementPseudo
|
||||
chatapp/View/ConnexionScreen.java
|
||||
chatapp.View.ConnexionScreen
|
||||
chatapp/View/View_Utilisateurs.java
|
||||
chatapp.View.View_Utilisateurs
|
||||
chatapp/Model/Utilisateur.java
|
||||
chatapp.Model.Utilisateur
|
||||
chatapp/View/View_Menu.java
|
||||
chatapp.View.View_Menu
|
||||
chatapp/Protocol/HttpEchange.java
|
||||
chatapp.Protocol.HttpEchange
|
||||
chatapp/View/DemarrerSession.java
|
||||
chatapp.View.DemarrerSession
|
||||
|
|
|
@ -6,9 +6,13 @@ import chatapp.Model.Utilisateur;
|
|||
import chatapp.Protocol.*;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
|
@ -54,11 +58,18 @@ public class ChatApp implements PropertyChangeListener {
|
|||
private boolean connecte;
|
||||
|
||||
/* Acces a la base de donnée */
|
||||
//private DataBase db;
|
||||
private DataBase db;
|
||||
|
||||
/* Variable stockant les communications grâce aux IDs des utilisateurs */
|
||||
public ArrayList<String> listeCommunication = new ArrayList<>();
|
||||
|
||||
/* Variable stockant le backslash nécessaire pour creer l'adresse du fichier json */
|
||||
public static String FILE_SEPARATOR = System.getProperty("file.separator");
|
||||
|
||||
|
||||
|
||||
private JSONObject configJSON;
|
||||
|
||||
/**
|
||||
* <p> Getter : Connecte
|
||||
* <br> Permet de savoir si l'on est connecté</p>
|
||||
|
@ -80,8 +91,21 @@ public class ChatApp implements PropertyChangeListener {
|
|||
this.me = new Utilisateur(pseudo,port,ip);
|
||||
this.actifUsers.addList(getMe());
|
||||
this.main = main;
|
||||
//this.db= DataBase.getInstance();
|
||||
this.db= DataBase.getInstance();
|
||||
this.connecte=false;
|
||||
|
||||
String path = System.getProperty("user.dir")+ FILE_SEPARATOR + "config.json";
|
||||
System.out.println("Path is : "+path);
|
||||
JSONParser jsonP = new JSONParser();
|
||||
try {
|
||||
this.configJSON = (JSONObject) jsonP.parse(new FileReader(path));
|
||||
} catch (IOException e) {
|
||||
System.out.println("Fichier JSON non trouvable");
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
System.out.println("Fichier JSON mal formé");
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.externeEchange = new HttpEchange(this);
|
||||
}
|
||||
|
||||
|
@ -135,7 +159,7 @@ public class ChatApp implements PropertyChangeListener {
|
|||
if(externeEchange.sendPost("Pseudo " + nouveau)){
|
||||
reussi = true ;
|
||||
this.getMe().setPseudo(nouveau);
|
||||
//db.majPseudo(this.me.getId(),nouveau);
|
||||
db.majPseudo(this.me.getId(),nouveau);
|
||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
||||
this.getActifUsers().afficherListeUtilisateurs();
|
||||
}
|
||||
|
@ -176,7 +200,7 @@ public class ChatApp implements PropertyChangeListener {
|
|||
//-------Change son propre nom d'utilisateur-------//
|
||||
this.getActifUsers().modifierList(this.getMe().getPseudo(), nouveau);
|
||||
this.getMe().setPseudo(nouveau);
|
||||
// db.majPseudo(this.me.getId(),nouveau);
|
||||
db.majPseudo(this.me.getId(),nouveau);
|
||||
System.out.println("Changement pseudo accepte, nouvelle liste des utilisateurs actifs:");
|
||||
this.getActifUsers().afficherListeUtilisateurs();
|
||||
return true;
|
||||
|
@ -222,8 +246,8 @@ public class ChatApp implements PropertyChangeListener {
|
|||
this.me.setPseudo(pseudo);
|
||||
if(externeEchange.sendPost("Connexion")){
|
||||
this.connecte=true;
|
||||
//this.db.ajoutUtilisateurs(this.me.getId(),pseudo);
|
||||
//this.db.majUtilisateursActifs(true,this.me.getId());
|
||||
this.db.ajoutUtilisateurs(this.me.getId(),pseudo);
|
||||
this.db.majUtilisateursActifs(true,this.me.getId());
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
|
@ -252,8 +276,8 @@ public class ChatApp implements PropertyChangeListener {
|
|||
if (UDPEchange.getConnecte()) {
|
||||
System.out.println("Connexion reussie");
|
||||
this.connecte=true;
|
||||
//this.db.ajoutUtilisateurs(this.me.getId(),pseudo);
|
||||
//this.db.majUtilisateursActifs(true,this.me.getId());
|
||||
this.db.ajoutUtilisateurs(this.me.getId(),pseudo);
|
||||
this.db.majUtilisateursActifs(true,this.me.getId());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -324,7 +348,7 @@ public class ChatApp implements PropertyChangeListener {
|
|||
else{
|
||||
System.out.println("Deconnexion echouee");
|
||||
}
|
||||
//db.majUtilisateursActifs(false,this.me.getId());
|
||||
db.majUtilisateursActifs(false,this.me.getId());
|
||||
this.connecte=false;
|
||||
try {
|
||||
main.stop();
|
||||
|
@ -345,7 +369,7 @@ public class ChatApp implements PropertyChangeListener {
|
|||
// Message que l'on envoie à tous les utilisateurs actifs
|
||||
String broadcastMessage = "Deconnexion\n" + this.getMe().toString() ;
|
||||
UDPEchange.envoiBroadcast(broadcastMessage);
|
||||
//db.majUtilisateursActifs(false,this.me.getId());
|
||||
db.majUtilisateursActifs(false,this.me.getId());
|
||||
this.connecte=false;
|
||||
try {
|
||||
main.stop();
|
||||
|
@ -403,7 +427,7 @@ public class ChatApp implements PropertyChangeListener {
|
|||
* </p>
|
||||
* @return La base de donnee associée
|
||||
*/
|
||||
//public DataBase getDb(){return this.db;}
|
||||
public DataBase getDb(){return this.db;}
|
||||
|
||||
/**
|
||||
* <p> Getter : Externe
|
||||
|
@ -440,4 +464,10 @@ public class ChatApp implements PropertyChangeListener {
|
|||
}
|
||||
return communication;
|
||||
}
|
||||
|
||||
|
||||
public JSONObject getConfigJSON() {
|
||||
return configJSON;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package chatapp.Model;
|
||||
|
||||
import chatapp.Controller.ChatApp;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
|
@ -28,16 +30,16 @@ import java.sql.*;
|
|||
public class DataBase {
|
||||
|
||||
/* URL pour accéder à la BDD */
|
||||
private final String dBurl = "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/tp_servlet_006?" ;
|
||||
private String dBurl = "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/tp_servlet_006?" ;
|
||||
|
||||
/* Connection avec la BDD */
|
||||
private Connection connection = null;
|
||||
|
||||
/* Login pour se connecter à la BDD */
|
||||
private final String login = "tp_servlet_006";
|
||||
private String login = "tp_servlet_006";
|
||||
|
||||
/* Mdp pour se connecter à la BDD */
|
||||
private final String pswd = "baePh9ei";
|
||||
private String pswd = "baePh9ei";
|
||||
|
||||
/* Singleton */
|
||||
private static final DataBase instance = null;
|
||||
|
@ -47,6 +49,9 @@ public class DataBase {
|
|||
* <br> On installe le driver et on établit la connection.
|
||||
*/
|
||||
public DataBase() {
|
||||
this.dBurl = (String) ChatApp.getInstance().getConfigJSON().get("BaseDeDonnesURL");
|
||||
this.login = (String) ChatApp.getInstance().getConfigJSON().get("BaseDeDonnesLogin");
|
||||
this.pswd = (String) ChatApp.getInstance().getConfigJSON().get("BaseDeDonnesMDP");
|
||||
try {
|
||||
//Besoin d'installer le driver JDBC entre java IDE et le system DBMS pour faire un pont entre les deux
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
|
|
|
@ -29,7 +29,7 @@ public class Utilisateur {
|
|||
private final String id ;
|
||||
|
||||
/* La taille maximum d'un ID */
|
||||
Integer TAILLE_MAX = 5;
|
||||
Integer TAILLE_MAX = 10;
|
||||
|
||||
/**
|
||||
* Constructeur : Utilisateur (3 paramètres)
|
||||
|
|
|
@ -33,6 +33,7 @@ public class HttpEchange {
|
|||
*/
|
||||
public HttpEchange(ChatApp chatapp){
|
||||
this.chatapp = chatapp;
|
||||
this.url = (String) chatapp.getConfigJSON().get("ServeurURL");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,7 +151,7 @@ public class SessionClavardage extends Thread {
|
|||
MessageHorodate msgh = new MessageHorodate(getU2(),getApp().getMe(),msg,1);
|
||||
try {
|
||||
getOut().writeObject(msgh.toString());
|
||||
//app.getDb().ajoutHistorique(u2.getId(), app.getMe().getId(),msg);
|
||||
app.getDb().ajoutHistorique(u2.getId(), app.getMe().getId(),msg);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ public class SessionClavardage extends Thread {
|
|||
String plaintext;
|
||||
MessageHorodate msg = null;
|
||||
System.out.println("Session demarre");
|
||||
//app.getDb().creationTableHistorique(app.getMe().getId(), u2.getId());
|
||||
app.getDb().creationTableHistorique(app.getMe().getId(), u2.getId());
|
||||
while(true) {
|
||||
try {
|
||||
plaintext = (String) getIn().readObject();
|
||||
|
|
|
@ -144,9 +144,9 @@ public class Clavardage implements Initializable, PropertyChangeListener {
|
|||
* @param actionEvent L'utilisateur a appuye sur le bouton plus pour obtenir tout l'utilisateur
|
||||
*/
|
||||
public void ajouterMessagesHistorique(ActionEvent actionEvent) {
|
||||
//this.nomTable = this.session.getApp().getDb().getNomTable(u2,this.session.getApp().getMe());
|
||||
//String historique = this.session.getApp().getDb().recupNMsg(session.getApp().getMe().getId(),this.u2.getId(), this.session.getApp().getDb().tailleBDD(nomTable));
|
||||
//ChatText.clear();
|
||||
//ChatText.insertText(0,historique);
|
||||
this.nomTable = this.session.getApp().getDb().getNomTable(u2,this.session.getApp().getMe());
|
||||
String historique = this.session.getApp().getDb().recupNMsg(session.getApp().getMe().getId(),this.u2.getId(), this.session.getApp().getDb().tailleBDD(nomTable));
|
||||
ChatText.clear();
|
||||
ChatText.insertText(0,historique);
|
||||
}
|
||||
}
|
正在加载…
在新工单中引用