+++ /dev/null
-package fr.mbdx.parapheur;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.activiti.engine.delegate.DelegateExecution;
-import org.activiti.engine.delegate.JavaDelegate;
-import org.apache.log4j.Logger;
-
-import fr.mbdx.parapheur.client.Annexe;
-import fr.mbdx.parapheur.client.Client;
-import fr.mbdx.parapheur.client.Dossier;
-import fr.mbdx.parapheur.client.LogDossier;
-import fr.mbdx.parapheur.client.Statut;
-import fr.mbdx.service.ParapheurService;
-
-/**
- * Tache d'interrogation et de demande d'information au parapheur
- *
- */
-// @Component("interrogationParapheur")
-public class TaskInterrogationParapheur implements JavaDelegate {
- protected static Logger log = Logger.getLogger(TaskInterrogationParapheur.class);
-
- public final static String NOM_IMPRESSION_DOSSIER = "\"iParapheur_impression_dossier.pdf\"";
-
- protected Client clientParapheur;
-
- protected ParapheurService parapheurService;
-
- @Override
- public void execute(DelegateExecution execution) {
-
- if (parapheurService.getEnvoisencours() > 0) {
- log.debug("Il reste " + parapheurService.getEnvoisencours()
- + " dossier(s) à envoyer au parapheur, on attend pour l'interroger sur l'état du dossier en cours");
- return;
- }
-
- // Ajout instruction synchronized pour empêcher absolument que deux threads accédent
- // en même temps à ce bout de code pour éviter un deadlock du côté du parapheur
-
- synchronized (TaskInterrogationParapheur.class) {
-
- final String dossierId = (String) execution.getVariable("dossierId");
- final String nodeRef = (String) execution.getVariable("nodeRef");
-
- byte[] contentValue = null;
- String contentType = null;
- String annotationPrivee = null;
- String annotationPublique = null;
- byte[] fichierPESContent = null;
- String fichierPESContentType = null;
- byte[] signatureDocPrincipalContent = null;
- String signatureDocPrincipalContentType = null;
- String xpathSignatureXML = null;
- String statutDossier = null;
-
- log.debug("Demande d'information au parapheur pour le document " + nodeRef);
-
- try {
- clientParapheur.setUp();
-
- final List<String> listDossierID = new ArrayList<String>();
- listDossierID.add(dossierId);
- final List<LogDossier> listLogDossier = clientParapheur.rechercherListeDossiers(listDossierID);
- if (!listLogDossier.isEmpty()) {
- LogDossier logDossier = listLogDossier.get(0);
-
- Statut statutActuel = logDossier.getStatut();
- if (statutActuel.equals(Statut.Archive)) {
- List<LogDossier> listHistoDossier = clientParapheur.getHistoDossier(dossierId);
- if (listHistoDossier != null) {
- int size = listHistoDossier.size();
- if (size > 1) {
- statutDossier = listHistoDossier.get(size - 2).getStatut().value();
- } else {
- statutDossier = statutActuel.value();
- }
- }
- } else {
- statutDossier = statutActuel.value();
- }
-
- // On ne récupère le dossier que si le processus est arrivé à son terme, c'est-à-dire son archivage
- if (statutActuel == Statut.Archive || statutActuel == Statut.RejetSignataire) {
- // TODO tester la propriété logDossier.getAccessible() avant de faire un getDossier()
- final Dossier dossier = clientParapheur.getDossier(dossierId);
- if (dossier != null) {
- annotationPrivee = dossier.getAnnotationPrivee();
- annotationPublique = dossier.getAnnotationPublique();
-
- if (dossier.getFichierPESContent() != null && dossier.getFichierPESContent().getValue() != null) {
- fichierPESContent = dossier.getFichierPESContent().getValue();
- fichierPESContentType = dossier.getFichierPESContent().getType();
- }
-
- if (dossier.getSignatureDocPrincipalContent() != null && dossier.getSignatureDocPrincipalContent().getValue() != null) {
- signatureDocPrincipalContent = dossier.getSignatureDocPrincipalContent().getValue();
- signatureDocPrincipalContentType = dossier.getSignatureDocPrincipalContent().getType();
- }
-
- // TODO demander à Adullact si ce XPath est le même que lors de la création du dossier ?
- xpathSignatureXML = dossier.getxPathPourSignatureXML();
-
- final List<Annexe> annexes = dossier.getAnnexes();
- if (annexes != null) {
- for (Annexe ann : annexes) {
- String nom = ann.getNom();
- if (nom.equals(NOM_IMPRESSION_DOSSIER)) {
- contentValue = ann.getFichier().getValue();
- contentType = ann.getMimetype();
- break;
- }
- }
- }
- }
- }
- }
-
- log.debug("Demande d'information envoyée au parapheur pour le document " + nodeRef);
- } catch (Exception e) {
- log.error("Erreur au cours de la demande d'information envoyée au parapheur pour le document " + nodeRef);
- log.error(e.getMessage(), e);
- }
-
- if (contentValue != null) {
- statutDossier = Statut.RejetSignataire.value().equals(statutDossier) ? Statut.Archive.value() : statutDossier; // FIXME A SUPPRIMER
- execution.setVariable("statutDossier", statutDossier);
- execution.setVariable("contentValue", contentValue);
- execution.setVariable("contentType", contentType);
- execution.setVariable("annotationPrivee", annotationPrivee);
- execution.setVariable("annotationPublique", annotationPublique);
- if (fichierPESContent != null) {
- execution.setVariable("fichierPESContent", fichierPESContent);
- execution.setVariable("fichierPESContentType", fichierPESContentType);
- }
- if (signatureDocPrincipalContent != null) {
- execution.setVariable("signatureDocPrincipalContent", signatureDocPrincipalContent);
- execution.setVariable("signatureDocPrincipalContentType", signatureDocPrincipalContentType);
- }
- execution.setVariable("xpathSignatureXML", xpathSignatureXML);
- execution.setVariable("signatureFin", Boolean.TRUE);
- } else {
- execution.setVariable("signatureFin", Boolean.FALSE);
- }
- }
- }
-
- /**
- * @param clientParapheur
- * the clientParapheur to set
- */
- public void setClientParapheur(Client clientParapheur) {
- this.clientParapheur = clientParapheur;
- }
-
- public void setParapheurService(ParapheurService parapheurService) {
- this.parapheurService = parapheurService;
- }
-}