	import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwpll1Web</p>
* <p>Description : Consultation , Liste des Localites Portees</p>
* <p>Copyright : Copyright (c) 2013</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>24/01/2013</i>
* @version 1.0
 */
public class Jwlwpll1Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeLocalites</p>
		 * <p>Description : Consultation , Liste des Localites Portees </p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>24/01/2013</i>
		 * @version 1.0
		 */
		public static Jwlwpll1 getListeLocalites(
			String nbrep,
			String page,
			String fonction,
			String f_cd_insee,
			String f_localite,
			String f_action,
			String f_cd_postal,
			String f_aff_cd_postal,
			String f_aff_cd_insee,
			String f_aff_portage,
			String f_aff_voie_loca,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwpll1 jwlwpll1 = new Jwlwpll1(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwpll1.Nwlwpll1Axwebent vWebent = jwlwpll1.new Nwlwpll1Axwebent();
			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 	  = "WLWCLLST";
			vWebent.fonction 		  = fonction;
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			jwlwpll1.setNwlwpll1Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwlwpll1.Nwlwpll1Axweblst vWeblst = jwlwpll1.new Nwlwpll1Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwpll1.setNwlwpll1Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwlwpll1.Nwlwpll1Awlwpll1 vLwpll1 = jwlwpll1.new Nwlwpll1Awlwpll1();
			Jwlwpll1.Nwlwpll1Awlwpll1Demande vLwpll1Demande = jwlwpll1.new Nwlwpll1Awlwpll1Demande();
			Jwlwpll1.Nwlwpll1Awlwpll1DemandeCritere_select vLwpll1DemandeCritere = jwlwpll1.new Nwlwpll1Awlwpll1DemandeCritere_select();
            
            vLwpll1DemandeCritere.f_cd_insee  = f_cd_insee;
			vLwpll1DemandeCritere.f_action  = f_action;
            vLwpll1DemandeCritere.f_localite  = f_localite;
            vLwpll1DemandeCritere.f_cd_postal = f_cd_postal;
            vLwpll1DemandeCritere.f_aff_cd_postal = f_aff_cd_postal;
            vLwpll1DemandeCritere.f_aff_cd_insee  = f_aff_cd_insee;
            vLwpll1DemandeCritere.f_aff_portage   = f_aff_portage;
            vLwpll1DemandeCritere.f_aff_voie_loca = f_aff_voie_loca;

			vLwpll1Demande.critere_select = vLwpll1DemandeCritere;
			vLwpll1.demande = vLwpll1Demande;

			jwlwpll1.setNwlwpll1Awlwpll1 (vLwpll1);
			
		    // CALL SERVER
		    jwlwpll1.nwlwpll1();
				                                
	        // Verification du code retour
			vWebent = jwlwpll1.getNwlwpll1Axwebent();
			System.out.println("Code retour nwlwpll1() = " + 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 {
				//Recuperation du resultat si code retour OK
				Jwlwpll1.Nwlwpll1Awlwpll1_tab vWeblsttab = jwlwpll1.getNwlwpll1Awlwpll1_tab();
				
				//Affichage de la liste des resultats
				if(PRINT == "YES") {
					
					System.out.println("\n");
					for(int i = 0; i < new BigDecimal(nbrep).intValue(); i++){
							System.out.println (
									  "  cd_insee=" 	+ vWeblsttab.ligne_ref[i].cd_insee
									+ "  cd_postal=" 	+ vWeblsttab.ligne_ref[i].cd_postal
									+ "; lib_localite="   + vWeblsttab.ligne_ref[i].lib_localite
									+ "; nb_localites=" + vWeblsttab.ligne_ref[i].nb_localites
									+ "; nb_voies="     + vWeblsttab.ligne_ref[i].nb_voies
									+ "; nom_titre=" 	+ vWeblsttab.ligne_ref[i].top_portage
									);
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwpll1.getNwlwpll1Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwpll1.getNwlwpll1Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwpll1.getNwlwpll1Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwpll1.getNwlwpll1Axweblst().nb_pages_totales);
				}
			}
			return jwlwpll1;
			
	   } // End getListeLocalites

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>24/01/2013</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA82");
			Broker broker 	  = JxweblogWeb.logonBroker();
			Jxweblog jxweblog = JxweblogWeb.getConnexion(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_cible						= connexion.cd_cible;
			String cd_stegrp 					= connexion.cd_stegrp;
		
			//--------------------Donnee test------------------
			String nbrep 		= "20";
			String page 		= "1";
			String fonction 	= "I";
			String f_cd_insee 	= "75119";
			String f_localite 	= null;
			String f_action 	= "P";
			String f_cd_postal 	= null;
			String f_aff_cd_postal = null;
			String f_aff_cd_insee  = null;
			String f_aff_portage   = null;
			String f_aff_voie_loca = null;
			//--------------------Donnee test------------------
			getListeLocalites(nbrep, page, fonction,
					f_cd_insee,f_localite,f_action,f_cd_postal,f_aff_cd_postal,f_aff_cd_insee,f_aff_portage,f_aff_voie_loca,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwpll1Web