+++ /dev/null
-/*
- * Copyright
- * 2010 axYus - www.axyus.com
- * 2010 C.Marchand - christophe.marchand@axyus.com
- *
- * This file is part of XEMELIOS.
- *
- * XEMELIOS is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * XEMELIOS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with XEMELIOS; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package fr.gouv.finances.dgfip.xemelios.controls.etatFrais.chorus;
-
-import java.util.Hashtable;
-import java.util.Stack;
-import java.util.Vector;
-
-import org.apache.log4j.Logger;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-import fr.gouv.finances.dgfip.xemelios.controls.core.AbstractUnitControl;
-import fr.gouv.finances.dgfip.xemelios.controls.core.Anomalie;
-import fr.gouv.finances.dgfip.xemelios.controls.core.IdGenerator;
-import fr.gouv.finances.dgfip.xemelios.controls.core.Node;
-
-/**
- * Contrôle de la présence du IdChorusTiers sur chaque Invoice
- * L'élément EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/IdChorusTiers est obligatoire pour un EF si le texte de l\91élément EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/TypeTiers est égal à \92ZCPD\92
-
- * @author christophe Marchand
- */
-public class M060 extends AbstractUnitControl {
- public static final String CTRL_ID = "CTL-M060" ;
- public static final transient String RESET_COUNTER_PATH = "EtatsFrais/Invoice/";
- public static final transient String REQUIRED_PATH = "EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/IdChorusTiers/";
- public static final transient String CHEMIN_TYPETIERS = "EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/TypeTiers/";
- public static final transient String INVOICEID_PATH = "EtatsFrais/Invoice/ID/";
- public static final transient String ANO_PATH = "EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/";
- public static final transient String RETURN_ANOMALIES_PATH = RESET_COUNTER_PATH;
-
- private static final Logger logger = Logger.getLogger(M060.class);
-
- // pour stocker tous les paramètres d'execution des controles
- private Hashtable<String,Object> hParams;
-
- // on va compter le nombre de IdChorusTiers que l'on va rencontrer par Invoice
- private int idChorusTiersCounter = 0;
- // pour stocker l'identifiant de l'invoice, on en a besoin pour générer l'anomalie
- private String invoiceId = null;
- private String ID_Invoice_Unique = "";
- private String typeTiers = null;
-
- // pour récupérer le texte des balises
- private Stack<StringBuffer> chars = new Stack<StringBuffer>();
-
- // pour stocker les anomalies que l'on génère
- Vector<Anomalie> anomalies = null;
-
- boolean isSecteurEtat = true; // par défaut, on est dans le secteur etat
-
- private String anoNodeId = null;
-
- public void endDocument() throws SAXException { }
-
- public void startElement(String uri, String localName, String qName, Attributes atts, String xpath) throws SAXException {
- if(!isSecteurEtat) return;
- if(xpath.equals(RESET_COUNTER_PATH)) {
- // on commence une nouvelle invoice :
- // on remet le compteur à 0,
- // on remet la liste des anomalies à vide
- // on remet l'invoice id à null
- idChorusTiersCounter = 0;
- anomalies = new Vector<Anomalie>();
- invoiceId = "";
- typeTiers = "";
- ID_Invoice_Unique = atts.getValue("ano:unique-id");
- } else if(xpath.equals(ANO_PATH)) {
- anoNodeId = atts.getValue("ano:node-id");
- }
- chars.push(new StringBuffer());
- }
-
- public Vector<Anomalie> endElement(String uri, String localName, String qName, String xpath) throws SAXException {
- // notre controle ne concerne que le secteur etat
- if(!isSecteurEtat) return null;
- // pour le moment
- if (xpath.equals(REQUIRED_PATH) && !chars.peek().toString().equals("")) {
- // sur la fermeture di IdChorusTiers, on incrémente le compteur
- idChorusTiersCounter++;
- // pour information, si nécessaireadmin
-
- String idChorusTiersText = chars.peek().toString();
- } else if(xpath.equals(CHEMIN_TYPETIERS)) {
- typeTiers = chars.peek().toString();
- } else if(xpath.equals(INVOICEID_PATH)) {
- invoiceId = chars.peek().toString();
- } else if(xpath.equals(RETURN_ANOMALIES_PATH) && typeTiers.equals("ZCPD")) {
- // on est à la fin de l'invoice, on compte le nombre de IdChorusTiers qu'on a rencontré
- switch(idChorusTiersCounter) {
- case 0: {
- // il y a un manque
- String anoId = IdGenerator.nextId();
- Hashtable<String, Object> xslParams = new Hashtable<String, Object>();
- xslParams.put("anoId", anoId);
- xslParams.put("presentation","src");
- String libelleLien = "Invoice "+invoiceId;
-
- String path = "@ano:unique-id='" + ID_Invoice_Unique + "'";
- // on reconstitue le message
- String message = getDocumentModel().getControlById(CTRL_ID).getMessage().getHtmlContent();
- message = message.replace("#INVOICE_ID#", invoiceId);
- Anomalie ano = new Anomalie(anoId,
- getDocumentModel().getControlById(CTRL_ID),
- getDocumentModel().getDocumentId(),
- "EtatFrais",
- "invoice",
- invoiceId,
- localName, // l'élément en anomalie est bien Invoice
- libelleLien,
- message,
- getDocumentModel().getControlById(CTRL_ID).getRegle().getHtmlContent(),
- getDocumentModel().getControlById(CTRL_ID).getSeverity(),
- path,
- xslParams);
- ano.addNode(new Node(anoNodeId));
- anomalies.add(ano);
- }
- default: break; // c'est ce qu'on voulait, parfait, on ne renvoie rien
- }
- chars.pop();
- return anomalies;
- }
- chars.pop();
- return null;
- }
-
- public void characters(char[] ch, int start, int length, String xpath) throws SAXException {
- if(!isSecteurEtat) return;
- // on met les caractères lus dans la pile
- chars.peek().append(ch, start, length);
- }
-
- public void ignorableWhitespace(char[] ch, int start, int length, String xpath) throws SAXException { }
-
- public void processingInstruction(String target, String data, String xpath) throws SAXException { }
-
- public void skippedEntity(String name, String xpath) throws SAXException { }
-
- public void setParameters(Hashtable<String, Object> params) {
- this.hParams=params;
- }
-
- public void setDocumentLocator(Locator locator) { }
-
- public void startDocument() throws SAXException {
- isSecteurEtat = hParams.get("secteur").equals("Etat");
- }
-
- public void startPrefixMapping(String prefix, String uri, String xpath) throws SAXException { }
-
- public void endPrefixMapping(String prefix, String xpath) throws SAXException { }
-}