import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
* <p>Titre : Jwbwadl4Web</p>
* <p>Description : Consultation , Liste CP</p>
* <p>Copyright : Copyright (c) 2012</p>
* <p>Societe : ENSOR</p>
* @author AR & DR & PY <i>29/06/2012</i>
* @version 1.0
 */
public class Jwbwadl4Web {	

		private static String PRINT = "NO";
		/**
		 * <p>Titre : getListeCP</p>
		 * <p>Description : Consultation , Liste CP</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>29/06/2012</i>
		 * @version 1.0
		 */
		public static Jwbwadl4 getListeCP(
			String nbrep,
			String page,
			String fonction,
			String f_commune,
			String f_departement,
			
			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
	     	Jwbwadl4 Jwbwadl4 = new Jwbwadl4(broker, Utils.formatSrvAddr (rpc_name));
			// Initialisation de la vWebent depuis les informations de connexion
			Jwbwadl4.Nwlwadl4Axwebent vWebent = Jwbwadl4.new Nwlwadl4Axwebent();
			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;
			Jwbwadl4.setNwlwadl4Axwebent (vWebent);
	        
			// Initialisation des paramètres de pagination
			Jwbwadl4.Nwlwadl4Axweblst vWeblst = Jwbwadl4.new Nwlwadl4Axweblst();
			vWeblst.nb_rep_souhait 			  = new BigDecimal(nbrep);
			vWeblst.num_page_souhait 		  = new BigDecimal(page);
			Jwbwadl4.setNwlwadl4Axweblst (vWeblst);

			// Initialisation des critères (tous à vide pour l'instant)
			Jwbwadl4.Nwlwadl4Awlwadl4 vLwadl4 = Jwbwadl4.new Nwlwadl4Awlwadl4();
			Jwbwadl4.Nwlwadl4Awlwadl4Demande vLwadl4Demande = Jwbwadl4.new Nwlwadl4Awlwadl4Demande();
			Jwbwadl4.Nwlwadl4Awlwadl4DemandeCritere_select vLwadl4DemandeCritere = Jwbwadl4.new Nwlwadl4Awlwadl4DemandeCritere_select();
			vLwadl4DemandeCritere.f_departement = f_departement;
            vLwadl4DemandeCritere.f_commune     = f_commune;
            
			vLwadl4Demande.critere_select = vLwadl4DemandeCritere;
			vLwadl4.demande = vLwadl4Demande;

			Jwbwadl4.setNwlwadl4Awlwadl4 (vLwadl4);
			
		    // CALL SERVER
		    Jwbwadl4.nwlwadl4();
				                                
	        // Verification du code retour
			vWebent = Jwbwadl4.getNwlwadl4Axwebent();
			System.out.println("Code retour nwlwadl4() = " + 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
				Jwbwadl4.Nwlwadl4Awlwadl4_tab vWeblsttab = Jwbwadl4.getNwlwadl4Awlwadl4_tab();
	
				Jwbwadl4.Nwlwadl4Awlwadl4DemandeCritere_select demande = Jwbwadl4.getNwlwadl4Awlwadl4().demande.critere_select;
				//Affichage de la liste des résultats
				if(PRINT == "YES") {
					
					System.out.println("=====  DEMANDE  =========");
					System.out.println("F-DEPARTEMENT = " + demande.f_departement);
					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 (
									  "  departement="		   + vWeblsttab.liste_ref[i].departement
									+ "; bureau_distributeur=" + vWeblsttab.liste_ref[i].bureau_distributeur   
									+ "; commune=" 			   + vWeblsttab.liste_ref[i].commune
									+ "; lieu_dit=" 		   + vWeblsttab.liste_ref[i].lieu_dit
									+ "; code_postal="  	   + vWeblsttab.liste_ref[i].code_postal
									+ "; particularite=" 	   + vWeblsttab.liste_ref[i].particularite
									); 
							System.out.println("\n");
					}
					//Affichage des informations de pagination
					System.out.println ("nb_rep_rendues : "    + Jwbwadl4.getNwlwadl4Axweblst().nb_rep_rendues);
					System.out.println ("num_page_rendue : "   + Jwbwadl4.getNwlwadl4Axweblst().num_page_rendue);
					System.out.println ("top_page_suivante : " + Jwbwadl4.getNwlwadl4Axweblst().top_page_suivante);
					System.out.println ("nb_pages_totales : "  + Jwbwadl4.getNwlwadl4Axweblst().nb_pages_totales);
				}
			}
			return Jwbwadl4;
			
	   } // End getListeCP

		/**
		 * <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>29/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 		= "20";
			String page 		= "1";
			String fonction 	= "I";
			String f_commune 	= "PARIS";
			String f_departement= null;
			//--------------------Donnée test------------------
			getListeCP(nbrep, page, fonction, 
					f_commune, f_departement, 
					groupe_exploitant, numero_session, utilisateur, cd_stegrp, cd_cible, dbid, rpc_name,broker);
			JxweblogBw.closeConnexion (rpc_name, jxweblog, broker);			
			JxweblogBw.closeBroker (broker);
	   }
} // END Jwbwadl4Web