+++ /dev/null
-/*
- * Copyright
- * 2010 axYus - www.axyus.com
- * 2010 C. ESCOBAR - christel.escobar@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 IdFoncTiers sur chaque Invoice
- * Le texte de l'élément /dgfip:AgentChorus/dgfip:IdFoncTiers doit vérifier les caractéristiques suivantes selon le texte de l'élément /dgfip:AgentChorus/dgfip:TypeTiers :<br/>
- * Si TypeTiers='ZCOM' alors donnée numérique sur 6 chiffres
- * -Si TypeTiers='ZCPD' alors donnée numérique sur 10 ou 14 chiffres
- * -Si TypeTiers='ZETR' alors donnée sur 2 caractères min et 37 max
- * -Si TypeTiers='ZEUR' alors pas de contrainte de longueur et de format
- * -Si TypeTiers='ZFRA' alors donnée numérique sur 14 chiffres
- * -Si TypeTiers='ZPHY' alors donnée sur 10 caractères min et 80 max
- * -Si TypeTiers='ZREG' alors donnée sur 12 caractères composée de 4 lettres + 7 chiffres + 1 lettre
- * -Si TypeTiers='ZSRV' alors donnée sur 10 caractères composée de 1 lettre + 6 chiffres + 3 alphanumériques
- * -Si TypeTiers='ZTAE' alors donnée sur 10 caractères min et 80 max
- *
- * @author Christel ESCOBAR
- */
-public class M062 extends AbstractUnitControl {
- public static final String CTRL_ID = "CTL-M062" ;
- public static final transient String RESET_COUNTER_PATH = "EtatsFrais/Invoice/";
- public static final transient String CHEMIN_IDFONCTIERS = "EtatsFrais/Invoice/UBLExtensions/UBLExtension/ExtensionContent/EtatFraisExtension/OrdreMission/Agent/AgentChorus/IdFoncTiers/";
- 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(M062.class);
-
- // pour stocker tous les paramètres d'execution des controles
- private Hashtable<String,Object> hParams;
-
- // 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 = "";
- private String idFoncTiers = "";
-
- // 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;
-
- 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(xpath.equals(RESET_COUNTER_PATH)) {
- anomalies = new Vector<Anomalie>();
- anoNodeId = "";
- invoiceId = "";
- typeTiers = idFoncTiers = "";
- 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 {
- if(xpath.equals(CHEMIN_IDFONCTIERS)) {
- idFoncTiers = 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)) {
- boolean err = false;
-
- if (typeTiers.equals("ZCOM") && !idFoncTiers.matches("^[0-9]{9}$")&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZCPD") && !idFoncTiers.matches("^[0-9]{10}$") && !idFoncTiers.matches("^[0-9]{14}$")&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZETR") && (idFoncTiers.length()<2 || idFoncTiers.length()>37)&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZFRA") && !idFoncTiers.matches("^[0-9]{14}$")&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZPHY") && (idFoncTiers.length()<10 || idFoncTiers.length()>80)&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZREG") && !idFoncTiers.matches("^[a-zA-Z]{4}[0-9]{7}[a-zA-Z]{1}$") && !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZSRV") && !idFoncTiers.matches("^[a-zA-Z]{1}[0-9]{6}[a-zA-Z0-9]{3}$")&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
- if (typeTiers.equals("ZTAE") && (idFoncTiers.length()<10 || idFoncTiers.length()>80)&& !idFoncTiers.equals("")&& !idFoncTiers.equals(" "))
- err = true;
-
- if (err) {
- 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 + "'"; // le XPath qui permettra de retrouver le
- // on reconstitue le message
- String message = getDocumentModel().getControlById(CTRL_ID).getMessage().getHtmlContent();
- String erreur = "Le texte de l'élément IdFoncTiers n'est pas au format attendu selon le type de tiers";
- message = message.replace("#INVOICE_ID#", invoiceId);
- message = message.replace("#TYPETIERS#", typeTiers);
- message = message.replace("#IDFONCTIERS#", idFoncTiers);
- message = message.replace("#ERREUR#", erreur);
- 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);
- }
- chars.pop();
- return anomalies;
- }
- chars.pop();
- return null;
- }
-
- public void characters(char[] ch, int start, int length, String xpath) throws SAXException {
- // 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 { }
-
- public void startPrefixMapping(String prefix, String uri, String xpath) throws SAXException { }
-
- public void endPrefixMapping(String prefix, String xpath) throws SAXException { }
-}