254 lines
9.3 KiB
Java
254 lines
9.3 KiB
Java
package baseEvaluations;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.nio.file.Paths;
|
|
import java.util.Date;
|
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JOptionPane;
|
|
|
|
import MEPTL.commandes;
|
|
import MEPTL.meptl;
|
|
import MEPTL.verificationFichierAnalyse_node_commandesSujet;
|
|
import cXML.Run;
|
|
import cXML.node;
|
|
import fenetres.ChargeFichierXML;
|
|
|
|
public class chargeEvaluationSelected {
|
|
|
|
public chargeEvaluationSelected(Integer index) {
|
|
|
|
//* Relecture du node de l'évaluation car le node n'est pas complet
|
|
String directoryName = "";
|
|
File file = null;
|
|
node evaluation = new node();
|
|
if(commandes.PathBaseEvaluationDefaut) {
|
|
directoryName = Paths.get("").toAbsolutePath().toString();
|
|
}else {
|
|
directoryName = commandes.PathBaseEvaluations;
|
|
}
|
|
|
|
if(commandes.os.contains("Win")) {
|
|
file = new File(directoryName + "\\" + commandes.NameBaseEvaluations);
|
|
}else {
|
|
file = new File(directoryName + "/" + commandes.NameBaseEvaluations);
|
|
}
|
|
|
|
|
|
if(file!=null) {
|
|
BufferedReader br;
|
|
try {
|
|
br = new BufferedReader(
|
|
new InputStreamReader(
|
|
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
|
|
String line;
|
|
StringBuilder targetString = new StringBuilder();
|
|
while ((line = br.readLine()) != null) {
|
|
targetString.append(line);
|
|
}
|
|
evaluation = evaluation.chargeNodeEvaluationIndex(index,targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
|
|
}catch (Exception e) {
|
|
JFrame frame = new JFrame();
|
|
JLabel texte = new JLabel("<html><p>La base de données ne se trouve pas dans le même dossier que celui de l'application.</p><br>"
|
|
+"<p>Vous pouvez charger la base de données depuis la fenêtre \"<b>base de données d'évaluation</b>\" de l'application.</p>"
|
|
+ "<p>Sinon, une nouvelle base de données sera créé dans le dossier de l'application.</p></html>");
|
|
JOptionPane.showMessageDialog(frame, texte);
|
|
}
|
|
|
|
|
|
//* Charge le node sujet provisoirement
|
|
commandes.evaluationChargeEnMemoire = evaluation;
|
|
commandes.NameEvaluationCharger= evaluation.getAttributs().get("name");
|
|
commandes.path = evaluation.getAttributs().get("path"); //Dossier des fichiers des étudiants
|
|
node sujetLoad = new node(Run.ecritureXMLDansStringBuilder(evaluation.retourneFirstEnfantsByName("fichier"), Run.TypeFile.Sujet).replace("\t","").replace("\r", "").replace("\n", ""));
|
|
commandes.sujet = sujetLoad;
|
|
|
|
// Chargement provisoire du node sujet depuis la base
|
|
commandes.nameSujet = evaluation.getAttributs().get("analysis_filename");
|
|
commandes.PathFilenameAnalysis = evaluation.getAttributs().get("PathFilenameAnalysis");
|
|
|
|
//** Les paramètres
|
|
commandes.versionEvaluation = evaluation.getAttributs().get("version");
|
|
commandes.fichierStudentMoodle = Boolean.valueOf(evaluation.getAttributs().get("fichierStudentMoodle"));
|
|
commandes.sansFeeback = Boolean.valueOf(evaluation.getAttributs().get("sansFeeback"));
|
|
commandes.noDetail = Boolean.valueOf(evaluation.getAttributs().get("noDetail"));
|
|
commandes.noNote = Boolean.valueOf(evaluation.getAttributs().get("noNote"));
|
|
commandes.zipfeedback = Boolean.valueOf(evaluation.getAttributs().get("zipfeedback"));
|
|
commandes.verifHisto2 = Boolean.valueOf(evaluation.getAttributs().get("verifHisto2"));
|
|
commandes.ecritNoteCSV = Boolean.valueOf(evaluation.getAttributs().get("ecritNoteCSV"));
|
|
commandes.newLogo = Boolean.valueOf(evaluation.getAttributs().get("newLogo"));
|
|
commandes.noLogo = Boolean.valueOf(evaluation.getAttributs().get("noLogo"));
|
|
commandes.fourniCSV = Boolean.valueOf(evaluation.getAttributs().get("fourniCSV"));
|
|
commandes.nameCSV = evaluation.getAttributs().get("nameCSV");
|
|
|
|
if(evaluation.getAttributs().get("analyse_nombres_modifications_simultané_maxi")!=null) {
|
|
commandes.analyse_nombres_modifications_simultané_maxi = Integer.valueOf(evaluation.getAttributs().get("analyse_nombres_modifications_simultané_maxi"));
|
|
}
|
|
|
|
commandes.fourniCSV = Boolean.valueOf(evaluation.getAttributs().get("fourniCSV"));
|
|
commandes.nameSVG = evaluation.getAttributs().get("nameSVG");
|
|
|
|
|
|
commandes.nodeCSV = evaluation.retourneFirstEnfantsByName("fileCSV");
|
|
|
|
commandes.contenuFichierSVG = evaluation.retourneFirstEnfantsByName("nodSVG").retourneLesContenusEnfants("");
|
|
|
|
commandes.fichierAnalyseValide = true;
|
|
|
|
|
|
|
|
//* Rechercher la source
|
|
String CheminVersFileXML = "";
|
|
if(commandes.os.contains("Win")) {
|
|
commandes.PathFilenameAnalysis.replaceAll("/", "\\"); // Sur Windows
|
|
CheminVersFileXML = commandes.PathFilenameAnalysis + "\\" + commandes.nameSujet;
|
|
|
|
}else {
|
|
commandes.PathFilenameAnalysis.replaceAll("\\", "/"); // Sur Windows // Sur mac & Linux
|
|
CheminVersFileXML = commandes.PathFilenameAnalysis + "/" + commandes.nameSujet;
|
|
}
|
|
|
|
file = new File(CheminVersFileXML);
|
|
if(file.exists()) {
|
|
|
|
if (recupereDateFichierAnalyseSource(file)!=null) {
|
|
|
|
Date DateFichierSource = recupereDateFichierAnalyseSource(file);
|
|
Date DateFichierAnalyseBase = calcul.formatDateWriter.dateNodeSujet();
|
|
|
|
if(DateFichierAnalyseBase.before(DateFichierSource)) {
|
|
JFrame frame = new JFrame();
|
|
JLabel text = new JLabel();
|
|
text.setText("<html><p>Le fichier d'analyse est déjà chargé depuis la base de données.</p><br>"
|
|
+ "<p>Cependant, vous avez le fichier d'analyse qui se trouve dans le dossier :</p>"
|
|
+ "<p>"+CheminVersFileXML+"</p>"
|
|
+ "<p>Et dont la date est plus récente que le fichier d'analyse qui se trouve dans la base.</p><br><hr>"
|
|
+ "<p>Voulez-vous le charger depuis ce dossier ?</p></html>");
|
|
if (JOptionPane.showConfirmDialog(frame, text, "WARNING",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
|
chargeLeNodeSujet(file);
|
|
commandes.path = evaluation.getAttributs().get("path"); //Recharge le chemin vers le dossier contenant les fichiers des étudiants
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
commandes.initialiseParametresSettingProprietes();
|
|
try {
|
|
commandes.sujetSauvegarde = commandes.sujet.clone();
|
|
} catch (CloneNotSupportedException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
//Chargement des paramètres du fichier d'analyse
|
|
meptl.chargementParametresFichierAnalyse();
|
|
|
|
|
|
|
|
//** Remise à zéro de la base dans la mémoire de l'application
|
|
commandes.evaluationsBase = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Charge le fichier d'analyse de l'évaluation.<br>
|
|
* @param file
|
|
*/
|
|
private void chargeLeNodeSujet(File file) {
|
|
|
|
BufferedReader br;
|
|
try {
|
|
br = new BufferedReader(
|
|
new InputStreamReader(
|
|
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
|
|
String line;
|
|
StringBuilder targetString = new StringBuilder();
|
|
while ((line = br.readLine()) != null) {
|
|
targetString.append(line);
|
|
}
|
|
|
|
//node.node2(targetString);
|
|
node sujetLoad = new node(targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
|
|
|
|
// Vérification de la conformité du fichier d'analyse
|
|
if(!ChargeFichierXML.fichierSujetValide(sujetLoad)) {
|
|
JOptionPane.showMessageDialog(null, "Le fichier d'analyse n'est pas valide.");
|
|
}else {
|
|
commandes.initialiseParametresSettingProprietes();
|
|
commandes.sujet = sujetLoad;
|
|
commandes.sujetSauvegarde = commandes.sujet.clone();
|
|
|
|
//Chargement des paramètres du fichier d'analyse
|
|
System.out.println( "Chargement des paramètres du fichier d'analyse");
|
|
meptl.chargementParametresFichierAnalyse();
|
|
|
|
// Rechercher des erreurs dans le fichier d'analyse
|
|
System.out.println( "Vérification du fichier d'analyse" );
|
|
new verificationFichierAnalyse_node_commandesSujet();
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
e1.printStackTrace();
|
|
} catch (FileNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
} catch (Exception e) {
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Récupère la date de modification du fichier d'analyse.
|
|
* @param file
|
|
* @return
|
|
*/
|
|
private Date recupereDateFichierAnalyseSource(File file) {
|
|
BufferedReader br;
|
|
try {
|
|
br = new BufferedReader(
|
|
new InputStreamReader(
|
|
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
|
|
String line;
|
|
StringBuilder targetString = new StringBuilder();
|
|
while ((line = br.readLine()) != null) {
|
|
targetString.append(line);
|
|
}
|
|
|
|
//node.node2(targetString);
|
|
node sujetLoad = new node(targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
|
|
|
|
// Vérification de la conformité du fichier d'analyse
|
|
if(!ChargeFichierXML.fichierSujetValide(sujetLoad)) {
|
|
JOptionPane.showMessageDialog(null, "Le fichier d'analyse n'est pas valide.");
|
|
}else {
|
|
if(sujetLoad.getAttributs().get("date")!=null) {
|
|
String dateString = sujetLoad.getAttributs().get("date");
|
|
return calcul.formatDateWriter.DateLibreOffice(dateString);
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
e1.printStackTrace();
|
|
} catch (FileNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
} catch (Exception e) {
|
|
}
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|