import java.math.BigDecimal;
import java.sql.*;
import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;
import com.softwareag.entirex.aci.EntireXSecurity;

/**
* <p>Titre : Jwbwadl1Web</p>
* <p>Description : Consultation , Liste des voies </p>
* <p>Copyright : Copyright (c) 2012</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>04/06/2012</i>
* @version 1.0
 */
public class Jwbwadl1Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeVoies</p>
		 * <p>Description : Consultation , Liste des voies </p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>04/06/2012</i>
		 * @version 1.0
		 */
		public static Jwbwadl1 getListeVoies(
			String nbrep,
			String page,
			String fonction,
			String f_libelle_voie,
			String f_mot_directeur_voie,
			String f_code_insee,
			String f_cd_postal,
			String f_localite,
			String f_commune,
			String f_cd_zpo,
			String f_type_portage,
			String f_cd_prt,
			
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_stegrp,
			String cd_cible,
			String dbid,
			String rpc_name,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwbwadl1 Jwbwadl1 = new Jwbwadl1(broker, Utils.formatSrvAddr (rpc_name));
			// Initialisation de la vWebent depuis les informations de connexion
			Jwbwadl1.Nwlwadl1Axwebent vWebent = Jwbwadl1.new Nwlwadl1Axwebent();
			vWebent.dbid = new BigDecimal (dbid);
			vWebent.cible_exploitant = cd_cible;
			vWebent.groupe_exploitant = groupe_exploitant;
			vWebent.numero_session = new BigDecimal (numero_session);
			vWebent.utilisateur =  utilisateur;
			vWebent.transaction 	  = "WBWEFLSA";
			vWebent.fonction 		  = fonction;
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			Jwbwadl1.setNwlwadl1Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwbwadl1.Nwlwadl1Axweblst vWeblst = Jwbwadl1.new Nwlwadl1Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			Jwbwadl1.setNwlwadl1Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwbwadl1.Nwlwadl1Awlwadl1 vLwadl1 = Jwbwadl1.new Nwlwadl1Awlwadl1();
			Jwbwadl1.Nwlwadl1Awlwadl1Demande vLwadl1Demande = Jwbwadl1.new Nwlwadl1Awlwadl1Demande();
			Jwbwadl1.Nwlwadl1Awlwadl1DemandeCritere_select vLwadl1DemandeCritere = Jwbwadl1.new Nwlwadl1Awlwadl1DemandeCritere_select();
			vLwadl1DemandeCritere.f_libelle_voie	   = f_libelle_voie;
            vLwadl1DemandeCritere.f_mot_directeur_voie = f_mot_directeur_voie;
            vLwadl1DemandeCritere.f_code_insee         = f_code_insee;
            vLwadl1DemandeCritere.f_cd_postal          = f_cd_postal;
            vLwadl1DemandeCritere.f_localite           = f_localite;
            vLwadl1DemandeCritere.f_commune            = f_commune;
            vLwadl1DemandeCritere.f_cd_zpo 			   = f_cd_zpo;
            vLwadl1DemandeCritere.f_type_portage 	   = f_type_portage;
            vLwadl1DemandeCritere.f_cd_prt			   = f_cd_prt;
            

			vLwadl1Demande.critere_select = vLwadl1DemandeCritere;
			vLwadl1.demande = vLwadl1Demande;

			Jwbwadl1.setNwlwadl1Awlwadl1 (vLwadl1);
			
		    // CALL SERVER
		    Jwbwadl1.nwlwadl1();
				                                
	        // Verification du code retour
			vWebent = Jwbwadl1.getNwlwadl1Axwebent();
			System.out.println("Code retour nwlwadl1() = " + 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 {
				//Récupération du résultat si code retour OK
				Jwbwadl1.Nwlwadl1Awlwadl1_tab vWeblsttab = Jwbwadl1.getNwlwadl1Awlwadl1_tab();
				Jwbwadl1.Nwlwadl1Awlwadl1Reponse reponse = Jwbwadl1.getNwlwadl1Awlwadl1().reponse;
				//Jwbwadl1.Nwlwadl1Awlwadl1Filtre_immediat filtre = Jwbwadl1.getNwlwadl1Awlwadl1().filtre_immediat;
	
				Jwbwadl1.Nwlwadl1Awlwadl1DemandeCritere_select demande = Jwbwadl1.getNwlwadl1Awlwadl1().demande.critere_select;
				//Affichage de la liste des résultats
				if(PRINT == "YES") {
					System.out.println("=====  REPONSE  =========");
					System.out.println("f_numero_voie       = "	+ reponse.f_numero_voie);
					System.out.println("f_numero_ordre_voie = " + reponse.f_numero_ordre_voie);
					System.out.println("cd_ret = " 				+ reponse.cd_ret);
					
					System.out.println("\n");
					
					System.out.println("=====  DEMANDE  =========");
					System.out.println("F-LIBELLE-VOIE = " + demande.f_libelle_voie);
					System.out.println("F-LOCALITE = " 	   + demande.f_localite);
					System.out.println("F-CD-POSTAL = "    + demande.f_cd_postal);
					System.out.println("F-COMMUNE = " 	   + demande.f_commune);
					System.out.println("\n");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "mot_directeur_voie="		+ vWeblsttab.liste_ref[i].mot_directeur_voie 
									+ "; libelle_voie=" 		+ vWeblsttab.liste_ref[i].libelle_voie
									+ "; code_postal="  		+ vWeblsttab.liste_ref[i].code_postal
									+ "; bureau_distributeur="  + vWeblsttab.liste_ref[i].bureau_distributeur 
									+ "; matricule_voie=" 		+ vWeblsttab.liste_ref[i].matricule_voie
									+ "; matricule_cible=" 		+ vWeblsttab.liste_ref[i].matricule_cible
									+ "; code_insee=" 			+ vWeblsttab.liste_ref[i].code_insee 
									+ "; localite=" 			+ vWeblsttab.liste_ref[i].localite
									+ "; borne_impaire_1=" 		+ vWeblsttab.liste_ref[i].borne_impaire_1
									+ "; borne_paire_1=" 		+ vWeblsttab.liste_ref[i].borne_paire_1
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + Jwbwadl1.getNwlwadl1Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + Jwbwadl1.getNwlwadl1Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + Jwbwadl1.getNwlwadl1Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + Jwbwadl1.getNwlwadl1Axweblst().nb_pages_totales);
				}
			}
			return Jwbwadl1;
			
	   } // End getListeVoies

		/**
		 * <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>04/06/2012</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("BW") ;
			JxweblogBw.setUtilisateur ("MADAA01");
			JxweblogBw.setPassword ("MADAAF1");
			PRINT = "YES";
			Broker broker 	  = JxweblogBw.logonBroker();
			Jxweblog jxweblog = JxweblogBw.getConnexion("00", "14", "SRV1", broker);
			PRINT = "YES";
			
			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_stegrp = connexion.cd_stegrp;
			String cd_cible = connexion.cd_cible;
			String dbid = "14";
			String rpc_name = "SRV1";		
			//--------------------Donnée test------------------
			String nbrep 				= "3";
			String page 				= "1";
			String fonction 			= "I";
			String f_libelle_voie 		= "RUE LEGENDRE";
			String f_mot_directeur_voie = null;
			String f_code_insee 		= null;
			String f_cd_postal 			= "75017";
			String f_localite 			= null;
			String f_commune 			= null;
			String f_cd_zpo 			= null;
			String f_type_portage 		= null;
			String f_cd_prt 		= null;
			//--------------------Donnée test------------------
			getListeVoies(nbrep, page, fonction, 
					f_libelle_voie, f_mot_directeur_voie, f_code_insee, f_cd_postal, 
					f_localite,f_commune,f_cd_zpo,f_type_portage,f_cd_prt,
					groupe_exploitant, numero_session, utilisateur, cd_stegrp, cd_cible, dbid, rpc_name, broker);
			JxweblogBw.closeConnexion (rpc_name, jxweblog, broker);			
			JxweblogBw.closeBroker (broker);
	   }
} // END Jwbwadl1Web