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
|
public void notificationActeursSupprimes() throws UnsupportedEncodingException, MailSendException, MessagingException, FieldException{
List<ReferentielPersonne> referentielPersonnes = referentielPersonneDao.findAll();
String id="";
List<String> templates = new ArrayList<String>();
InternetAddress ia=new InternetAddress();
String ad="";
List <String> listeId= new ArrayList<String>();
List <String> listeIdResponsabilitesGlobal = new ArrayList<String>();
ArrayList<HashMap<String, String>> mapParams = new ArrayList <HashMap<String, String>>();
Personne personne = null;
PersonneVO persVO = null;
Boolean modeMailNotification = new Boolean(parametreServiceHelper.getConstantBooleanValue(ParametreGeneral.BOOLEAN_NOTIFICATION_MAIL_MAJ_LDAP));
for(ReferentielPersonne referentielPersonne:referentielPersonnes){
if(id == "" || !id.equals(referentielPersonne.getId())){
personne = personneDao.recupererPersonne(referentielPersonne.getId());
if(personne != null){
persVO = personneService.recupererPersonne(personne.getId());
if(mapParams.size() > 0){
if (modeMailNotification){
mailService.sendEmailGlobal(ia, templates, mapParams);
}
mapParams.clear();
templates.clear();
listeIdResponsabilitesGlobal.clear();
}
//on cree un nouveau mail
ad = personne.getEmail();
ia = new InternetAddress(ad, "");
}
}
if(persVO != null){
Long profil = referentielPersonne.getProfil().getId();
Long entite = new Long(0);
String nomEntite = "";
if(referentielPersonne.getEntiteSecurite()!= null){
entite = referentielPersonne.getEntiteSecurite().getId();
nomEntite = referentielPersonne.getEntiteSecurite().getLibelle();
}
List<String> idresponsabilites = referentielPersonneDao.findResponsabilites(profil, entite);
if(idresponsabilites != null){
for(String idresponsabilite:idresponsabilites){
Personne responsabilite = personneDao.recupererPersonne(idresponsabilite);
if(responsabilite !=null){
PersonneVO responsabiliteVO = personneService.recupererPersonne(idresponsabilite);
if(responsabiliteVO != null){
//la personne est dans le ldap
if(!responsabilite.getEntite().equals(responsabiliteVO.getEntite()) && !listeIdResponsabilitesGlobal.contains(responsabilite.getId())){
templates.add("TemplateChangement");
HashMap<String, String> mapParam = new HashMap<String, String>();
if(responsabilite.getNom() == null){
mapParam.put("nom", "");
mapParam.put("prenom", "");
}
else{
mapParam.put("nom", responsabilite.getNom());
mapParam.put("prenom", responsabilite.getPrenom());
}
mapParam.put("entite_ldap", responsabiliteVO.getEntite());
String profilResponsabilite="profil";
mapParam.put("profil", profilResponsabilite);
mapParam.put("entite", nomEntite);
mapParams.add(mapParam);
responsabilite.setNom(responsabiliteVO.getNom());
responsabilite.setPrenom(responsabiliteVO.getPrenom());
responsabilite.setEmail(responsabiliteVO.getEmail());
personneDao.persist(responsabilite);
listeIdResponsabilitesGlobal.add(responsabilite.getId());
}
}
else{
//la personne n'est pas ds le ldap
if(!listeIdResponsabilitesGlobal.contains(responsabilite.getId())){
personneDao.supprimePersonne(responsabilite.getId());
templates.add("TemplateSuppression");
HashMap<String, String> mapParam = new HashMap<String, String>();
if(responsabilite.getNom() == null){
mapParam.put("nom", "");
mapParam.put("prenom", "");
}
else{
mapParam.put("nom", responsabilite.getNom());
mapParam.put("prenom", responsabilite.getPrenom());
}
String profilResponsabilite;
profilResponsabilite = "\"profil\"";
mapParam.put("profil", profilResponsabilite);
mapParam.put("entite", nomEntite);
mapParam.put("id", responsabilite.getId());
mapParams.add(mapParam);
listeId.add(responsabilite.getId());
listeIdResponsabilitesGlobal.add(responsabilite.getId());
}
}
}
if(persVO.getEntite().equals(personne.getEntite())){
personne.setId(persVO.getId());
personne.setNom(persVO.getNom());
personne.setPrenom(persVO.getPrenom());
personne.setEmail(persVO.getEmail());
personneDao.persist(personne);
}
}
}
id=referentielPersonne.getId();
}
} |
Partager