import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwlwpll2Web</p>
* <p>Description : Consultation , Liste des Localites Non 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 Jwlwpll2Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeLocalites</p>
		 * <p>Description : Consultation , Liste des Localites Non 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 Jwlwpll2 getListeLocalites(
			String nbrep,
			String page,
			String fonction,
			String f_cd_insee,
			String f_localite,
			String f_cd_zpo,
			String f_type_portage,
			String f_lib_zpo,
			String f_top_ts,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
	     	Jwlwpll2 jwlwpll2 = new Jwlwpll2(broker, Constantes.SERVER_ADRESSE);
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwpll2.Nwlwpll2Axwebent vWebent = jwlwpll2.new Nwlwpll2Axwebent();
			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;
			jwlwpll2.setNwlwpll2Axwebent (vWebent);
	        
			// Initialisation des parametres de pagination
			Jwlwpll2.Nwlwpll2Axweblst vWeblst = jwlwpll2.new Nwlwpll2Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			jwlwpll2.setNwlwpll2Axweblst (vWeblst);

			// Initialisation des criteres (tous a vide pour l instant)
			Jwlwpll2.Nwlwpll2Awlwpll2 vLwpll2 = jwlwpll2.new Nwlwpll2Awlwpll2();
			Jwlwpll2.Nwlwpll2Awlwpll2Demande vLwpll2Demande = jwlwpll2.new Nwlwpll2Awlwpll2Demande();
			Jwlwpll2.Nwlwpll2Awlwpll2DemandeCritere_select vLwpll2DemandeCritere = jwlwpll2.new Nwlwpll2Awlwpll2DemandeCritere_select();
            
            vLwpll2DemandeCritere.f_cd_insee 	 = f_cd_insee;
            vLwpll2DemandeCritere.f_localite 	 = f_localite;
            vLwpll2DemandeCritere.f_cd_zpo	 	 = f_cd_zpo;
            vLwpll2DemandeCritere.f_type_portage = f_type_portage;
            vLwpll2DemandeCritere.f_lib_zpo	 	 = f_lib_zpo;
            vLwpll2DemandeCritere.f_top_ts 	 	 = f_top_ts;

			vLwpll2Demande.critere_select = vLwpll2DemandeCritere;
			vLwpll2.demande = vLwpll2Demande;

			jwlwpll2.setNwlwpll2Awlwpll2 (vLwpll2);
			
		    // CALL SERVER
		    jwlwpll2.nwlwpll2();
				                                
	        // Verification du code retour
			vWebent = jwlwpll2.getNwlwpll2Axwebent();
			System.out.println("Code retour nwlwpll2() = " + 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
				Jwlwpll2.Nwlwpll2Awlwpll2_tab vWeblsttab = jwlwpll2.getNwlwpll2Awlwpll2_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_cible=" 	+ vWeblsttab.ligne_ref[i].cd_insee
									+ "; code_titre="   + vWeblsttab.ligne_ref[i].lib_localite
									+ "; nom_titre=" 	+ vWeblsttab.ligne_ref[i].cd_zpo 
									+ "; nb_zones=" 	+ vWeblsttab.ligne_ref[i].lib_zone
									+ "; nb_trt_n=" 	+ vWeblsttab.ligne_ref[i].type_portage
									+ "; type_trt_n=" 	+ vWeblsttab.ligne_ref[i].lib_type
									);
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + jwlwpll2.getNwlwpll2Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + jwlwpll2.getNwlwpll2Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + jwlwpll2.getNwlwpll2Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + jwlwpll2.getNwlwpll2Axweblst().nb_pages_totales);
				}
			}
			return jwlwpll2;
			
	   } // 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 ("MADAA62");
			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 	  = null;
			String f_localite 	  = null;
			String f_cd_zpo 	  = null;
			String f_type_portage = null;
			String f_lib_portage  = null;
			String f_top_ts       = null;
			//--------------------Donnee test------------------
			getListeLocalites(nbrep, page, fonction,
					f_cd_insee, f_localite, f_cd_zpo, f_type_portage, f_lib_portage,f_top_ts,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
											
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwpll2Web