2023-02-11 09:43:12 +01:00
package MEPTL ;
import java.text.ParseException ;
import java.util.ArrayList ;
import java.util.Date ;
import java.util.Dictionary ;
import java.util.Hashtable ;
2024-03-24 14:48:24 +01:00
import javax.swing.JEditorPane ;
2023-02-11 09:43:12 +01:00
import cXML.Run ;
import cXML.node ;
import calcul.formatDateWriter ;
public class VerificationHistorique {
/ * *
* Vérirication des historiques
* @param verification
* @param a
* @return le node verif
* @throws ParseException
2023-02-12 17:12:11 +01:00
* @throws CloneNotSupportedException
2023-02-11 09:43:12 +01:00
* /
2024-03-24 14:48:24 +01:00
public static node verificationHistorique ( node verification , Run a , JEditorPane txt ) throws ParseException , CloneNotSupportedException {
2023-02-11 09:43:12 +01:00
node verif = new node ( ) ;
verif . setNomElt ( " verification " ) ;
verif . setAttributs ( verification . getAttributs ( ) ) ;
verif . getAttributs ( ) . put ( " number_match " , String . valueOf ( commandes . number_match ) ) ;
verif . getAttributs ( ) . put ( " mini_number_modification " , String . valueOf ( commandes . mini_number_modification ) ) ;
verif . getAttributs ( ) . put ( " nombres_modifications_simultané_maxi " , String . valueOf ( commandes . nombres_modifications_simultané_maxi ) ) ;
ArrayList < node > LesFichiers = verification . retourneLesEnfantsByName ( " fichier " , new ArrayList < node > ( ) ) ;
System . out . println ( ) ;
System . out . println ( " ***** DEBUT VERIFICATION DES HISTORIQUES DES MODIFICATION **** " ) ;
System . out . println ( ) ;
commandes . message . append ( " \ n \ n***** DEBUT VERIFICATION DES HISTORIQUES DES MODIFICATION **** \ n " ) ;
2024-03-24 14:48:24 +01:00
int nbFichier = LesFichiers . size ( ) ;
for ( int i = 0 ; i < LesFichiers . size ( ) ; i + + ) {
2023-02-11 09:43:12 +01:00
node nodStudent = new node ( ) ;
nodStudent . setNomElt ( " fichier " ) ;
nodStudent . setAttributs ( LesFichiers . get ( i ) . getAttributs ( ) ) ;
//String nameStudent1 = LesFichiers.get(i).getAttributs().get("dossier");
ArrayList < node > HitoriqueDuFichier = LesFichiers . get ( i ) . retourneEnfantsByName ( " text:changed-region " , new ArrayList < node > ( ) ) ;
2024-03-14 20:52:22 +01:00
2023-02-11 09:43:12 +01:00
int nombreModifications = HitoriqueDuFichier . size ( ) ;
nodStudent . getAttributs ( ) . put ( " nombre_modification " , String . valueOf ( nombreModifications ) ) ;
int compteurnombreCorrespondance = 0 ;
int compteurnombreCorrespondancesSuivi = 0 ;
int compteurnombreCorrespondancesconsecutive = 0 ;
2024-03-24 14:48:24 +01:00
// Affichage
2024-03-24 21:00:03 +01:00
String AffichageMessageEcran = " Analyse du fichier " + i + " / " + nbFichier + " \ n " + LesFichiers . get ( i ) . getAttributs ( ) . get ( " dossier " ) + " - number of modifications : " + nombreModifications ;
txt . setText ( AffichageMessageEcran ) ;
2023-02-11 09:43:12 +01:00
commandes . message . append ( " \ n " + LesFichiers . get ( i ) . getAttributs ( ) . get ( " dossier " ) + " - number of modifications : " + nombreModifications ) ;
@SuppressWarnings ( " unchecked " )
ArrayList < node > LesFichiers2 = ( ArrayList < node > ) LesFichiers . clone ( ) ;
LesFichiers2 . remove ( i ) ;
Dictionary < String , Integer > lesdates = new Hashtable < String , Integer > ( ) ;
Date DateMini = null ; //Première date de modification
2023-02-12 17:12:11 +01:00
ArrayList < String > listeModification = new ArrayList < String > ( ) ;
2023-02-11 09:43:12 +01:00
// Parcours toutes les modifications dans l'historique
for ( int j = 0 ; j < HitoriqueDuFichier . size ( ) ; j + + ) {
node nodDate = null ;
node nodDateCreator = null ;
String dcdate1 = " " ;
@SuppressWarnings ( " unused " )
String dccreator = " " ;
2023-02-12 17:12:11 +01:00
String typeModification = " " ;
String xmlid = " " ;
2023-02-11 09:43:12 +01:00
nodDate = HitoriqueDuFichier . get ( j ) . retourneFirstEnfantsByName ( " dc:date " ) ;
nodDateCreator = HitoriqueDuFichier . get ( j ) . retourneFirstEnfantsByName ( " dc:creator " ) ;
2023-02-12 17:12:11 +01:00
typeModification = HitoriqueDuFichier . get ( j ) . getNodes ( ) . get ( 0 ) . getNomElt ( ) ;
xmlid = HitoriqueDuFichier . get ( j ) . getAttributs ( ) . get ( " xml:id " ) ;
2023-02-11 09:43:12 +01:00
2023-02-14 09:20:58 +01:00
if ( ! typeModification . equals ( " text:UnknownChange " ) ) { //&&!typeModification.equals("text:format-change")
2023-02-11 09:43:12 +01:00
2023-02-12 17:12:11 +01:00
if ( nodDate ! = null ) {
dcdate1 = nodDate . getContenu ( ) . get ( 0 ) ;
}
if ( nodDate ! = null ) {
dccreator = nodDateCreator . getContenu ( ) . get ( 0 ) ;
}
Date DcDate1 = formatDateWriter . DateLibreOffice ( dcdate1 ) ;
2023-02-11 09:43:12 +01:00
2023-02-12 17:12:11 +01:00
2023-03-18 16:30:10 +01:00
//Le copié et collé dans les fichiers
2023-02-12 17:12:11 +01:00
if ( ! xmlid . isEmpty ( ) ) {
if ( ! listeModification . contains ( xmlid ) ) {
listeModification . add ( xmlid ) ;
ArrayList < node > TousIdentiques = LesFichiers . get ( i ) . retourneEnfantsByNameAndValueAttribut ( " text:changed-region " , " xml:id " , xmlid , new ArrayList < node > ( ) ) ;
int NbrParagrapheModifier = 0 ;
for ( int n = 0 ; n < TousIdentiques . size ( ) ; n + + ) {
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " text:p " , new ArrayList < node > ( ) ) . size ( ) ;
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " text:h " , new ArrayList < node > ( ) ) . size ( ) ;
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " draw:frame " , new ArrayList < node > ( ) ) . size ( ) ;
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " text:list-item " , new ArrayList < node > ( ) ) . size ( ) ;
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " text:table-of-content " , new ArrayList < node > ( ) ) . size ( ) ;
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques . get ( n ) . retourneEnfantsByName ( " text:index-title " , new ArrayList < node > ( ) ) . size ( ) ;
}
if ( NbrParagrapheModifier < = 0 ) {
ArrayList < node > Applati = a . Applatir ( LesFichiers . get ( i ) . clone ( ) , new ArrayList < node > ( ) ) ;
node A = a . retourneFirstNodeByNameAttributValue ( Applati , " text:change-start " , " text:change-id " , xmlid ) ;
node B = a . retourneFirstNodeByNameAttributValue ( Applati , " text:change-end " , " text:change-id " , xmlid ) ;
int index1 = Applati . indexOf ( A ) ;
int index2 = Applati . indexOf ( B ) ;
for ( int k = index1 + 1 ; k < index2 ; k + + ) {
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " text:table-of-content " ) ) NbrParagrapheModifier + + ;
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " text:p " ) ) {
if ( ! Applati . get ( k ) . retourneLesContenusEnfants ( " " ) . isBlank ( ) ) {
NbrParagrapheModifier + + ;
}
}
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " text:h " ) ) {
if ( ! Applati . get ( k ) . retourneLesContenusEnfants ( " " ) . isBlank ( ) ) {
NbrParagrapheModifier + + ;
}
}
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " draw:frame " ) ) NbrParagrapheModifier + + ;
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " text:list " ) ) NbrParagrapheModifier + + ;
if ( Applati . get ( k ) . getNomElt ( ) . contains ( " text:list-item " ) ) NbrParagrapheModifier + + ;
}
}
node modificationsMemeDate = new node ( ) ;
modificationsMemeDate . setNomElt ( " memeinstant " ) ;
modificationsMemeDate . getAttributs ( ) . put ( " date " , dcdate1 ) ;
modificationsMemeDate . getAttributs ( ) . put ( " nombres_modifications_simultané " , String . valueOf ( NbrParagrapheModifier ) ) ;
if ( commandes . nombres_modifications_simultané_maxi < NbrParagrapheModifier ) {
modificationsMemeDate . getAttributs ( ) . put ( " copier_coller " , " true " ) ;
nodStudent . getAttributs ( ) . put ( " copier_coller " , " true " ) ;
} else {
modificationsMemeDate . getAttributs ( ) . put ( " copier_coller " , " false " ) ;
}
modificationsMemeDate . getAttributs ( ) . put ( " xml:id " , xmlid ) ;
modificationsMemeDate . getAttributs ( ) . put ( " type_modification " , typeModification ) ;
nodStudent . getNodes ( ) . add ( modificationsMemeDate ) ;
}
}
if ( DateMini = = null ) DateMini = DcDate1 ; // Amorçage de la date premère date de modification
if ( DateMini ! = null & & DateMini . after ( DcDate1 ) ) DateMini = DcDate1 ; //recherche la première date de modification
if ( lesdates . get ( dcdate1 ) = = null ) {
lesdates . put ( dcdate1 , 1 ) ;
} else {
int compteur = lesdates . get ( dcdate1 ) + 1 ;
lesdates . put ( dcdate1 , compteur ) ;
}
node N1 = HitoriqueDuFichier . get ( j ) . getNodes ( ) . get ( 0 ) ;
2024-03-05 21:23:22 +01:00
if ( commandes . analyse_exclure_name_creator ) {
2024-04-02 16:31:26 +02:00
String author = N1 . retourneFirstEnfantsByName ( " dc:creator " ) . getContenu ( ) . toString ( ) . trim ( ) . toLowerCase ( ) ;
2024-03-05 21:23:22 +01:00
if ( author . equalsIgnoreCase ( commandes . analyse_auteur_exclure_historique ) ) {
continue ;
}
}
2023-02-12 17:12:11 +01:00
// Rechercher les correspondances
for ( int i2 = 0 ; i2 < LesFichiers2 . size ( ) ; i2 + + ) {
String nameStudent2 = LesFichiers2 . get ( i2 ) . getAttributs ( ) . get ( " dossier " ) ;
2024-03-24 21:00:03 +01:00
2024-04-02 15:30:05 +02:00
if ( commandes . analyse_exclure_name_creator ) {
2024-04-02 16:31:26 +02:00
String author = nameStudent2 . trim ( ) . toLowerCase ( ) ;
2024-04-02 15:30:05 +02:00
if ( author . equalsIgnoreCase ( commandes . analyse_auteur_exclure_historique ) ) {
continue ;
}
}
2024-03-25 21:18:21 +01:00
txt . setText ( AffichageMessageEcran + " \ n " + " Recherche correspondance avec " + nameStudent2 ) ;
2024-03-24 21:00:03 +01:00
2023-02-12 17:12:11 +01:00
ArrayList < node > HitoriqueDuFichier2 = LesFichiers2 . get ( i2 ) . retourneEnfantsByName ( " text:changed-region " , new ArrayList < node > ( ) ) ;
for ( int j2 = 0 ; j2 < HitoriqueDuFichier2 . size ( ) ; j2 + + ) {
String dcdate2 = HitoriqueDuFichier2 . get ( j2 ) . retourneFirstEnfantsByName ( " dc:date " ) . getContenu ( ) . get ( 0 ) ;
String dccreator2 = HitoriqueDuFichier2 . get ( j2 ) . retourneFirstEnfantsByName ( " dc:creator " ) . getContenu ( ) . get ( 0 ) ;
node N2 = HitoriqueDuFichier2 . get ( j2 ) . retourneFirstEnfantsByName ( N1 . getNomElt ( ) ) ;
if ( Run . equalNode ( N1 , N2 ) ) { //Verification des deux nodes de l'historique identiques
if ( nodStudent . retourneFirstNodeByNameAndAttributValueExactStrict ( " correspondance " , " date " , dcdate2 ) = = null ) {
//affinage du match
compteurnombreCorrespondance + + ;
if ( compteurnombreCorrespondancesSuivi = = 0 ) {
2023-02-11 09:43:12 +01:00
compteurnombreCorrespondancesSuivi + + ;
} else {
2023-02-12 17:12:11 +01:00
ArrayList < node > correspondances = nodStudent . retourneEnfantsByName ( " correspondance " , new ArrayList < node > ( ) ) ;
node c = correspondances . get ( correspondances . size ( ) - 1 ) ;
if ( c . getAttributs ( ) . get ( " Avec_etudiant " ) . equals ( nameStudent2 ) & & c . getAttributs ( ) . get ( " dc:creator " ) . equals ( dccreator2 ) ) {
compteurnombreCorrespondancesSuivi + + ;
if ( compteurnombreCorrespondancesconsecutive + 1 > compteurnombreCorrespondancesconsecutive ) compteurnombreCorrespondancesconsecutive + + ;
} else {
compteurnombreCorrespondancesSuivi = 0 ;
}
2023-02-11 09:43:12 +01:00
}
2023-02-12 17:12:11 +01:00
node correspondance = new node ( ) ;
correspondance . getNodes ( ) . add ( N2 ) ;
correspondance . setNomElt ( " correspondance " ) ;
2023-03-18 16:30:10 +01:00
correspondance . getAttributs ( ) . put ( " date " , dcdate1 ) ; // formatDateWriter.DateLibreOffice(DateMini)
2023-02-12 17:12:11 +01:00
correspondance . getAttributs ( ) . put ( " type " , N1 . getNomElt ( ) ) ;
correspondance . getAttributs ( ) . put ( " Avec_etudiant " , nameStudent2 ) ;
correspondance . getAttributs ( ) . put ( " dc:creator " , dccreator2 ) ;
nodStudent . getNodes ( ) . add ( correspondance ) ;
commandes . message . append ( " \ n \ t** Trouve une correspondance ** " + dcdate1 ) ;
break ;
2023-02-11 09:43:12 +01:00
}
2023-02-12 17:12:11 +01:00
}
}
}
2023-02-11 09:43:12 +01:00
}
2023-02-12 17:12:11 +01:00
2023-02-11 09:43:12 +01:00
}
if ( compteurnombreCorrespondancesconsecutive > 0 ) compteurnombreCorrespondancesconsecutive + + ; //C'est histoire des arbres et des intervalles entre les arbres. Il faut ajouter plus 1 au nombre de correspondances consecutives.
nodStudent . getAttributs ( ) . put ( " nombre_correspondance " , String . valueOf ( compteurnombreCorrespondance ) ) ;
nodStudent . getAttributs ( ) . put ( " nombre_modifications_date_unique " , String . valueOf ( lesdates . size ( ) ) ) ;
nodStudent . getAttributs ( ) . put ( " nombre_correspondances_consecutives " , String . valueOf ( compteurnombreCorrespondancesconsecutive ) ) ;
2023-02-12 17:12:11 +01:00
if ( DateMini ! = null ) {
nodStudent . getAttributs ( ) . put ( " first_modification_date " , formatDateWriter . DateLibreOffice ( DateMini ) ) ;
} else {
nodStudent . getAttributs ( ) . put ( " first_modification_date " , " 0000-01-01T00:00:00 " ) ;
}
2023-02-11 09:43:12 +01:00
verif . getNodes ( ) . add ( nodStudent ) ;
System . out . println ( " \ tDate de modification date unique " + String . valueOf ( lesdates . size ( ) ) ) ;
commandes . message . append ( " \ n \ tDate de modification date unique " + String . valueOf ( lesdates . size ( ) ) ) ;
}
// Ci-dessous le code pour vérifier la première date de modification dans le fichier.
// Recherche dans le node verif
int lastIndex = verif . getNodes ( ) . size ( ) ;
for ( int i = 0 ; i < lastIndex ; i + + ) {
String D1 = verif . getNodes ( ) . get ( i ) . getAttributs ( ) . get ( " first_modification_date " ) ;
boolean trouve = false ;
for ( int j = 0 ; j < lastIndex ; j + + ) {
if ( i ! = j ) {
String D2 = verif . getNodes ( ) . get ( j ) . getAttributs ( ) . get ( " first_modification_date " ) ;
if ( ! D1 . equals ( " null " ) & & D1 . equals ( D2 ) ) {
if ( verif . getNodes ( ) . get ( i ) . getAttributs ( ) . get ( " " ) = = null ) {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_modification_identique " , verif . getNodes ( ) . get ( j ) . getAttributs ( ) . get ( " dossier " ) ) ;
} else {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_modification_identique_2 " , verif . getNodes ( ) . get ( j ) . getAttributs ( ) . get ( " dossier " ) ) ;
}
if ( verif . getNodes ( ) . get ( j ) . getAttributs ( ) . get ( " " ) = = null ) {
verif . getNodes ( ) . get ( j ) . getAttributs ( ) . put ( " first_modification_identique " , verif . getNodes ( ) . get ( i ) . getAttributs ( ) . get ( " dossier " ) ) ;
} else {
verif . getNodes ( ) . get ( j ) . getAttributs ( ) . put ( " first_modification_identique_2 " , verif . getNodes ( ) . get ( i ) . getAttributs ( ) . get ( " dossier " ) ) ;
}
trouve = true ;
}
}
}
if ( ! trouve ) {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_modification_identique " , " null " ) ;
} else {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " plagiat " , " probable " ) ;
}
//Verification la première date de modification postérieure à la date du contrôle.
if ( commandes . analyse_controleDateModificationMini ) {
Date dateFirstModifStudent = formatDateWriter . DateLibreOffice ( D1 ) ;
if ( commandes . analyse_modificationDateMini . after ( dateFirstModifStudent ) ) {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_date_modification_anterieur_date_du_controle " , " true " ) ;
} else {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_date_modification_anterieur_date_du_controle " , " false " ) ;
}
2023-02-11 14:41:27 +01:00
} else {
verif . getNodes ( ) . get ( i ) . getAttributs ( ) . put ( " first_date_modification_anterieur_date_du_controle " , " false " ) ;
2023-02-11 09:43:12 +01:00
}
}
System . out . println ( ) ;
System . out . println ( " ** FIN DE LA VERIFIACTION ** " ) ;
System . out . println ( ) ;
commandes . message . append ( " \ n** FIN DE LA VERIFICATION ** \ n " ) ;
return verif ;
}
}