import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwclm2Web</p>
 * <p>Description : Classe de ajout, modification, suppression </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>13/06/2012</i>
 * @version 1.0
 */
public class Jwlwclm2Web {

	/**
	 * <p>Titre : getFiltreImmediat</p>
	 * <p>Description : Interrogation d'une Filtre Immediat</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>13/06/2012</i>
	 * @version 1.0
	 */
	public static Jwlwclm2 getFiltreImmediat(
				String f_cd_cible_1,
				String f_num_cli,
				String f_matricule_voie,
				String f_numero_voie,
				String f_cd_postal,
				String f_cd_insee,
				String f_tpr_groupe,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwclm2 jwlwclm2 = new Jwlwclm2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwclm2.Nwlwclm2Axwebent vWebent = jwlwclm2.new Nwlwclm2Axwebent();
		vWebent.dbid = new BigDecimal (Constantes.DBID);
		vWebent.cible_exploitant  = Constantes.CD_CIBLE;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session 	  = new BigDecimal (numero_session);
		vWebent.utilisateur 	  = utilisateur;
		vWebent.transaction 	  = "WLWFPLST";
		vWebent.fonction 		  = "VISU";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwclm2.setNwlwclm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwclm2.Nwlwclm2Awlwclm2 vLwclm2 					= jwlwclm2.new Nwlwclm2Awlwclm2();
		Jwlwclm2.Nwlwclm2Awlwclm2Demande demande = jwlwclm2.new Nwlwclm2Awlwclm2Demande();
		demande.f_cd_cible = f_cd_cible_1;
		if(!"".equals(f_num_cli) && f_num_cli!=null){
			System.out.println("f_num_cli avant = " + f_num_cli);
			demande.f_num_cli = Utils.transformNumClient(f_num_cli) ;
			System.out.println("f_num_cli après = " + demande.f_num_cli);
		}
		if(!"".equals(f_matricule_voie) && f_matricule_voie!=null){
			demande.f_matricule_voie 	= new BigDecimal(f_matricule_voie);
		}
		
		demande.f_numero_voie = f_numero_voie;
		demande.f_cd_postal   = f_cd_postal;
		demande.f_cd_insee 	  = f_cd_insee;
		demande.f_tpr_groupe  = f_tpr_groupe;
		
		
		vLwclm2.demande = demande;
		
		jwlwclm2.setNwlwclm2Awlwclm2(vLwclm2);
		
		// CALL SERVER
		jwlwclm2.nwlwclm2();
		
		// Verification du code retour
		vWebent = jwlwclm2.getNwlwclm2Axwebent();
		System.out.println("Code retour nwlwclm2() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return jwlwclm2;
	   }
	   
	/**
	 * <p>Titre : setFiltreImmediat</p>
	 * <p>Description : Mise à jour d'une Filtre Immediat </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>13/06/2012</i>
	 * @version 1.0
	 */
	public static Jwlwclm2 setFiltreImmediat(
		String fonction,
		String f_cd_cible_1,
		String f_num_cli,
		String f_matricule_voie,
		String f_numero_voie,
		String f_cd_postal,
		String f_cd_insee,
		String f_tpr_groupe,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwclm2 jwlwclm2 = new Jwlwclm2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwclm2.Nwlwclm2Axwebent vWebent = jwlwclm2.new Nwlwclm2Axwebent();
		vWebent.dbid 			  = new BigDecimal (Constantes.DBID);
		vWebent.cible_exploitant  = Constantes.CD_CIBLE;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session 	  = new BigDecimal (numero_session);
		vWebent.utilisateur 	  = utilisateur;
		vWebent.transaction 	  = "WLWFPLST";
		vWebent.fonction 		  = fonction;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwclm2.setNwlwclm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwclm2.Nwlwclm2Awlwclm2 vLwclm2 					= jwlwclm2.new Nwlwclm2Awlwclm2();
		Jwlwclm2.Nwlwclm2Awlwclm2Demande demande = jwlwclm2.new Nwlwclm2Awlwclm2Demande();
		demande.f_cd_cible = f_cd_cible_1;
		if(!"".equals(f_num_cli) && f_num_cli!=null){
			System.out.println("f_num_cli avant = " + f_num_cli);
			demande.f_num_cli = Utils.transformNumClient(f_num_cli) ;
			System.out.println("f_num_cli après = " + demande.f_num_cli);
		}
		if(!"".equals(f_matricule_voie) && f_matricule_voie!=null){
			demande.f_matricule_voie 	= new BigDecimal(f_matricule_voie);
		}
		
		demande.f_numero_voie = f_numero_voie;
		demande.f_cd_postal   = f_cd_postal;
		demande.f_cd_insee 	  = f_cd_insee;
		demande.f_tpr_groupe  = f_tpr_groupe;
		
		vLwclm2.demande = demande;
		
		jwlwclm2.setNwlwclm2Awlwclm2(vLwclm2);
		
		// CALL SERVER
		jwlwclm2.nwlwclm2();
		
		// Verification du code retour
		vWebent = jwlwclm2.getNwlwclm2Axwebent();
		System.out.println("Code retour nwlwclm2() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return jwlwclm2;
	   } // End setFiltreImmediat

	/**
	 * <p>Titre : annulerFiltreImmediat</p>
	 * <p>Description : Annulation d'une Filtre Immediat </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>13/06/2012</i>
	 * @version 1.0
	 */
	public static Jwlwclm2 annulerFiltreImmediat(
		String f_cd_cible_1,
		String f_num_cli,
		String f_matricule_voie,
		String f_numero_voie,
		String f_cd_postal,
		String f_cd_insee, 
		String f_tpr_groupe,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwclm2 jwlwclm2 = new Jwlwclm2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwclm2.Nwlwclm2Axwebent vWebent = jwlwclm2.new Nwlwclm2Axwebent();
		vWebent.dbid 			  = new BigDecimal (Constantes.DBID);
		vWebent.cible_exploitant  = Constantes.CD_CIBLE;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session 	  = new BigDecimal (numero_session);
		vWebent.utilisateur 	  = utilisateur;
		vWebent.transaction 	  = "WLWFPLST";
		vWebent.fonction 		  = "ANNULER";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwclm2.setNwlwclm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwclm2.Nwlwclm2Awlwclm2 vLwclm2 					= jwlwclm2.new Nwlwclm2Awlwclm2();
		Jwlwclm2.Nwlwclm2Awlwclm2Demande demande = jwlwclm2.new Nwlwclm2Awlwclm2Demande();
		demande.f_cd_cible = f_cd_cible_1;
		if(!"".equals(f_num_cli) && f_num_cli!=null){
			System.out.println("f_num_cli avant = " + f_num_cli);
			demande.f_num_cli = Utils.transformNumClient(f_num_cli) ;
			System.out.println("f_num_cli après = " + demande.f_num_cli);
		}
		if(!"".equals(f_matricule_voie) && f_matricule_voie!=null){
			demande.f_matricule_voie 	= new BigDecimal(f_matricule_voie);
		}
		
		demande.f_numero_voie = f_numero_voie;
		demande.f_cd_postal   = f_cd_postal;
		demande.f_cd_insee 	  = f_cd_insee;
		demande.f_tpr_groupe  = f_tpr_groupe;
		
		vLwclm2.demande = demande;
		
		jwlwclm2.setNwlwclm2Awlwclm2(vLwclm2);
		
		// CALL SERVER
		jwlwclm2.nwlwclm2();
		
		// Verification du code retour
		vWebent = jwlwclm2.getNwlwclm2Axwebent();
		System.out.println("Code retour nwlwclm2() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] : '" + vWebent.t_ano[i].lib_ano.trim() + "'");
		   	}
		}
		else{
			System.out.println ("Suite normale");
		}
		
		return jwlwclm2;
	   } // End annulerFiltreImmediat
	   
	   /**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2012</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA32");
			Broker broker     = JxweblogWeb.logonBroker();
			Jxweblog jxweblog = JxweblogWeb.getConnexion(broker);
			Jxweblog.NxweblogAxwebent connexion = jxweblog.getNxweblogAxwebent();
			
			String groupe_exploitant = connexion.groupe_exploitant;
			String numero_session 	 = Integer.toString(connexion.numero_session.intValue());
			String utilisateur 		 = connexion.utilisateur;
			String cd_cible 		 = connexion.cd_cible;
			String cd_stegrp 		 = connexion.cd_stegrp;
			
			//Constructeur TEST
			//------------------ données test-------------
			String f_cd_cible_1 	= "08";
			String f_num_cli 		= "0/127591";
			String f_matricule_voie = "135464";
			String f_numero_voie 	= "115";
			String f_cd_postal 	    = "75016";
			String f_cd_insee 	    = "75116";
			String f_tpr_groupe 	= "7";
			//-------------------donnée de test-----------
			Jwlwclm2 jwlwclm2 = getFiltreImmediat(
					f_cd_cible_1, f_num_cli, f_matricule_voie, f_numero_voie, f_cd_postal, f_cd_insee, f_tpr_groupe,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			//retour
			System.out.println("DEBUT TEST CONTROLE .......................") ;
			Jwlwclm2.Nwlwclm2Awlwclm2 jwlwclm2Reponse = jwlwclm2.getNwlwclm2Awlwclm2() ; 
			Jwlwclm2.Nwlwclm2Awlwclm2Retour retour = jwlwclm2Reponse.retour;
			Jwlwclm2.Nwlwclm2Awlwclm2Filtre_immediat fi = jwlwclm2Reponse.filtre_immediat;

			System.out.println("code_retour  ="   + retour.code_retour) ;
			System.out.println("message_retour =" + retour.message_retour) ;
			
			System.out.println("code_retour  ="   + fi.cd_zpo) ;
			System.out.println("message_retour =" + fi.type_portage) ;
			System.out.println("message_retour =" + fi.tpr_groupe) ;
			System.out.println("message_retour =" + fi.tpr_num) ;
	
			System.out.println("...Fin de test ...");
		}
			
}