1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
public class AnalyseDelta {
public static String FichierDeltaTestCharge = "//cheminfichier.txt";
public static String containerName;
public static String[] attributs;
public static String dn;
public static String utilisateur;
public void LireDelta()
{
ServiceLdap sl = new ServiceLdap();
String entitee="";
String line="",LineDebut="",LineChangeType="",LineFin="",ChangetypeMode="";
String adr1="",adr2="",adr3="",adr4="",adr5="",nom="",prenom="";
String affec1="",affec2="",affec3="",affec4="",affec5="",civilite="",codeaffec="",codece="",codecentrefrais="",codeefs="",codemploi="";
String struct1="",struct2="",struct3="",struct4="",struct5="",struct6="",struct7="",struct8="",cptprincipal="",datedeb="",datefin="";
String degre="",fonction="",identback="",identifiant="",identhierar="",libaffec="",libcentre="",libentite="",liblieugeo="",liblongstrn1="";
String liblongstrn2="",liblongstrn3="",libsociete="",libstruct1="",libstruct2="",libstruct3="",libstruct4="",libstruct5="";
String libstruct6="",libstruct7="",libstruct8="",lieugeotra="",mail="",memoid="",numpc="",numsalarie="",profil1="",profil2="";
String profil3="",profil4="",profil5="",teldirect="",telfax="",telportable="",telsecretariat="",typecontrat="";
int j=0,x=0;
try
{
BufferedReader b = new BufferedReader(new FileReader(FichierDeltaTestCharge));
try{
while(b.ready()) { // tant que le fichier n'est pas finit
line=b.readLine();
if(line.length()>17){identhierar=line.substring(0,18);}
if(line.length()>15){codecentrefrais=codeaffec=affec1=affec2=affec3=affec4=affec5=LineFin=line.substring(0,16);}
if(line.length()>15){struct1=struct2=struct3=struct4=struct5=struct6=struct7=struct8=line.substring(0,16);}
if(line.length()>14){libstruct1=libstruct2=libcentre=libaffec=datefin=datedeb=line.substring(0,15);}
if(line.length()>14){telsecretariat=libstruct3=libstruct4=libstruct5=libstruct6=libstruct7=libstruct8=line.substring(0,15);}
if(line.length()>13){liblieugeo=adr5=adr4=adr3=adr2=adr1=line.substring(0,14);}
if(line.length()>12){liblongstrn1=liblongstrn2=liblongstrn3=cptprincipal=line.substring(0,13);}
if(line.length()>11){typecontrat=identifiant=identback=line.substring(0,12);}
if(line.length()>10){telportable=numsalarie=lieugeotra=libsociete=LineChangeType=line.substring(0,11);}
if(line.length()>9){teldirect=libentite=codemploi=line.substring(0,10);}
if(line.length()>8){fonction=civilite=line.substring(0,9);}
if(line.length()>7){profil1=profil2=profil3=profil4=profil5=codeefs=line.substring(0,8);}
if(line.length()>6){telfax=memoid=codece=prenom=LineDebut=line.substring(0,7);}
if(line.length()>5){numpc=degre=line.substring(0,6);}
if(line.length()>4){mail=line.substring(0,5);}
if(line.length()>3){nom=line.substring(0,4);}
if(LineDebut.equals("dn: CN=") == true) //detecte si nous sommes au debut d'un utilisateur
{
StringTokenizer st = new StringTokenizer(line,"=,");
st.nextToken();
utilisateur = st.nextToken();
st.nextToken();st.nextToken();st.nextToken();
entitee = st.nextToken();
dn = "uid=" + utilisateur + ",ou=personnel," + "ou=" + entitee + "," + containerName;
}
if(LineChangeType.equals("changetype:") == true) //detecte le changetype
{
StringTokenizer st0 = new StringTokenizer(line," ");
st0.nextToken();
ChangetypeMode = st0.nextToken();
if(ChangetypeMode.equals("add") == true)
{
j=1;
}
if(ChangetypeMode.equals("delete") == true)
{
j=2;
}
if(ChangetypeMode.equals("Mask") == true)
{
j=3;
}
if(ChangetypeMode.equals("Modify") == true)
{
j=4;
}
}
if(j == 1) // procédure d'ajout d'une personne
{
if(adr1.equals("ADRLIEUGEOTRA1:") == true)
{
StringTokenizer st1 = new StringTokenizer(line);
st1.nextToken();
while((st1.hasMoreTokens()))
attributs[2] = attributs[2] + " " + st1.nextToken();
}
if(adr2.equals("ADRLIEUGEOTRA2:") == true)
{
StringTokenizer st1 = new StringTokenizer(line);
st1.nextToken();
while((st1.hasMoreTokens()))
attributs[3] = attributs[3] + " " + st1.nextToken();
}
if(adr3.equals("ADRLIEUGEOTRA3:") == true)
{
StringTokenizer st1 = new StringTokenizer(line);
st1.nextToken();
while((st1.hasMoreTokens()))
attributs[4] = attributs[4] + " " + st1.nextToken();
}
if(adr4.equals("ADRLIEUGEOTRA4:") == true)
{
StringTokenizer st1 = new StringTokenizer(line);
st1.nextToken();
while((st1.hasMoreTokens()))
attributs[5] = attributs[5] + " " + st1.nextToken();
}
if(adr5.equals("ADRLIEUGEOTRA5:") == true)
{
StringTokenizer st1 = new StringTokenizer(line);
st1.nextToken();
while((st1.hasMoreTokens()))
attributs[6] = attributs[6] + " " + st1.nextToken();
}
...
...
...
if(LineFin.equals("FinCollaborateur") == true)
{
x=1;
}
if(x == 1)
{
int i;
attributs[7] = attributs[2]+attributs[3]+attributs[4]+attributs[5]+attributs[6];
//rajout d'un cn car la classe person de LDAP necessite l'attribut cn (common name)
attributs[68] = utilisateur;
for(i=0;i<attributs.length;i++)
{
if((attributs[i].equals(" ") || attributs[i].equals(" ")) == false)
{
attributs[i]=attributs[i].trim();
}
}
sl.AjouterPersonne(attributs,dn);
for(i=0;i<attributs.length;i++)
attributs[i]=" ";
j=x=0;
}
}
if(j==2)
{
sl.EnleverPersonne(dn);
}
}
}
finally
{
b.close();
}
}
catch(IOException ioe)
{
System.err.println("IO erreur :" + ioe);
}
}
public AnalyseDelta()
{
containerName = "XXX";
attributs = new String[70];
int i = 0;
for(i=0;i<attributs.length;i++)
attributs[i]=" ";
}
public static void main(String[] args)
{
AnalyseDelta lp = new AnalyseDelta();
lp.LireDelta();
} |
Partager