172 lines
6.2 KiB
Java
172 lines
6.2 KiB
Java
package action;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.KeyEvent;
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.text.ParseException;
|
|
import java.util.Date;
|
|
|
|
import javax.swing.AbstractAction;
|
|
import javax.swing.Action;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.filechooser.FileSystemView;
|
|
|
|
import MEPTL.commandes;
|
|
import cXML.Run;
|
|
import cXML.node;
|
|
import fenetres.create;
|
|
|
|
public class actSaveHistoriqueEvaluation extends AbstractAction{
|
|
{
|
|
putValue( Action.NAME, "Sauvegarder l'évaluation" );
|
|
putValue( Action.SMALL_ICON, new ImageIcon(create.class.getResource("/resources/sauvegardehistoriqueevaluationmini.png")) );
|
|
putValue( Action.MNEMONIC_KEY, KeyEvent.VK_O );
|
|
putValue( Action.SHORT_DESCRIPTION, "Sauvegarder l'évaluation" );
|
|
}
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
if(commandes.fichierAnalyseValide) {
|
|
|
|
|
|
String name = JOptionPane.showInputDialog(null,"Donner un nom à cette évaluation ?","Nom de l'évaluation");
|
|
|
|
if(!name.isBlank()) {
|
|
node evaluations = nodeEvaluations();
|
|
if(!isEvaluationExist(evaluations, name)) {
|
|
evaluations.getNodes().add(0, creationNodeEvaluation(new node(), name));
|
|
// evaluations.getNodes().add(creationNodeEvaluation(new node(), name));
|
|
}else {
|
|
evaluations.getNodes().add(creationNodeEvaluation(evaluations.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", name), name));
|
|
}
|
|
|
|
//Mise à jour de la base de données
|
|
Date aujourdhui = new Date();
|
|
evaluations.getAttributs().put("version", commandes.version);
|
|
try {
|
|
evaluations.getAttributs().put("date", calcul.formatDateWriter.DateLibreOffice(aujourdhui));
|
|
ecritureBaseEvaluation(evaluations);
|
|
} catch (ParseException | IOException e1) {
|
|
e1.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private boolean isEvaluationExist(node evaluations, String nameEvaluation) {
|
|
if(evaluations!=null) {
|
|
if(evaluations.retourneFirstNodeByNameAndAttributValueExactStrict("evaluation", "name", nameEvaluation)!=null) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
private node nodeEvaluations() {
|
|
node evaluations = new node();
|
|
evaluations.setNomElt("evaluations");
|
|
File directory = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath());
|
|
if (directory.exists()){
|
|
File file = null;
|
|
if(commandes.os.contains("Win")) {
|
|
file = new File(directory.getAbsolutePath() + "\\" + "base_evaluations_analyseWriter.xml");
|
|
}else {
|
|
file = new File(directory.getAbsolutePath() + "/" + "base_evaluations_analyseWriter.xml");
|
|
}
|
|
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);
|
|
}
|
|
evaluations = new node(targetString.toString().replace("\t","").replace("\r", "").replace("\n", ""));
|
|
}catch (Exception e) {
|
|
|
|
}
|
|
}
|
|
}
|
|
return evaluations;
|
|
}
|
|
|
|
private node creationNodeEvaluation(node evaluation, String name) {
|
|
evaluation.setNomElt("evaluation");
|
|
Date aujourdhui = new Date();
|
|
evaluation.getAttributs().put("version", commandes.version);
|
|
evaluation.getAttributs().put("name", name);
|
|
evaluation.getAttributs().put("PathFilenameAnalysis", commandes.PathFilenameAnalysis);
|
|
evaluation.getAttributs().put("path", commandes.path);
|
|
evaluation.getAttributs().put("fichierStudentMoodle", String.valueOf(commandes.fichierStudentMoodle));
|
|
evaluation.getAttributs().put("sansFeeback", String.valueOf(commandes.sansFeeback) );
|
|
evaluation.getAttributs().put("noDetail", String.valueOf(commandes.noDetail) );
|
|
evaluation.getAttributs().put("noNote", String.valueOf(commandes.noNote) );
|
|
evaluation.getAttributs().put("zipfeedback", String.valueOf(commandes.zipfeedback) );
|
|
evaluation.getAttributs().put("verifHisto2", String.valueOf(commandes.verifHisto2) );
|
|
evaluation.getAttributs().put("ecritNoteCSV", String.valueOf(commandes.ecritNoteCSV) );
|
|
evaluation.getAttributs().put("newLogo", String.valueOf(commandes.newLogo) );
|
|
evaluation.getAttributs().put("noLogo", String.valueOf(commandes.noLogo) );
|
|
|
|
evaluation.getNodes().add(commandes.sujet);
|
|
if(commandes.sujet.getAttributs().get("analysis_filename").contains(".xml")) {
|
|
evaluation.getAttributs().put("analysis_filename",commandes.sujet.getAttributs().get("analysis_filename"));
|
|
}else {
|
|
evaluation.getAttributs().put("analysis_filename",commandes.nameSujet);
|
|
}
|
|
|
|
|
|
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
|
|
if(commandes.nameCSV!=null) {
|
|
evaluation.getAttributs().put("nameCSV", commandes.nameCSV );
|
|
}else {
|
|
evaluation.getAttributs().put("nameCSV", "");
|
|
}
|
|
|
|
evaluation.getAttributs().put("fourniCSV", String.valueOf(commandes.fourniCSV) );
|
|
if(commandes.nameSVG!=null) {
|
|
evaluation.getAttributs().put("nameSVG", commandes.nameSVG );
|
|
}else {
|
|
evaluation.getAttributs().put("nameSVG", "" );
|
|
}
|
|
|
|
|
|
|
|
evaluation.getNodes().add(commandes.nodeCSV);
|
|
|
|
try {
|
|
evaluation.getAttributs().put("date", calcul.formatDateWriter.DateLibreOffice(aujourdhui));
|
|
} catch (ParseException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if(commandes.nameSVG!=null) {
|
|
if(!commandes.nameSVG.isBlank() && !commandes.contenuFichierSVG.isBlank()) {
|
|
node SVG = new node();
|
|
SVG.setNomElt("nodSVG");
|
|
SVG.setContenu(commandes.contenuFichierSVG);
|
|
evaluation.getNodes().add(SVG);
|
|
}
|
|
}
|
|
|
|
return evaluation;
|
|
|
|
}
|
|
|
|
private void ecritureBaseEvaluation(node evaluations) throws IOException {
|
|
File directory = new File(FileSystemView.getFileSystemView().getDefaultDirectory().getPath());
|
|
Run.ecritureNodeEnXML(evaluations, "base_evaluations_analyseWriter.xml", directory.getAbsolutePath(), Run.TypeFile.Evaluation);
|
|
}
|
|
}
|