
import java.math.BigDecimal;

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

/**
 * <p>Titre : Jwbwmom1Web</p>
 * <p>Description : Classe de ajout, modification, suppression d'une météo</p>
 * <p>Copyright : Copyright (c) 2009</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR <i>25/10/2011</i>
 * @version 1.0
 */
public class Jwbwmom1Web {	
		private static String PRINT = "NO";
		/**
		 * <p>Titre : getInfosMeteo</p>
		 * <p>Description : Visualisation d'une météo</p>
		 * <p>Copyright : Copyright (c) 2011</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR <i>25/10/2011</i>
		 * @version 1.0
		 */
		public static Jwbwmom1 getInfosMeteo(
			String id_meteo,
			
			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 entrées
			    Jwbwmom1 Jwbwmom1 = new Jwbwmom1(broker, Utils.formatSrvAddr (rpc_name));
					
				// Initialisation de la vWebent depuis les informations de connexion
				Jwbwmom1.Nwlwmom1Axwebent vWebent = Jwbwmom1.new Nwlwmom1Axwebent();
				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 	  = "WBWEFLSM";
				vWebent.fonction 		  = "I";
				vWebent.cd_cible 		  = cd_cible;
				vWebent.cd_stegrp 		  = cd_stegrp;
				vWebent.cd_application 	  = Constantes.CD_APPLICATION;
				Jwbwmom1.setNwlwmom1Axwebent (vWebent);
			        
				// Initialisation de la demande (tous à vide pour l'instant)
				Jwbwmom1.Nwlwmom1Awlwmom1 vLwmom1 = Jwbwmom1.new Nwlwmom1Awlwmom1();
				if(!"".equals(id_meteo) && id_meteo!=null){
					System.out.println("id_meteo_avant"+id_meteo) ;
					id_meteo 		 = Utils.LPad(id_meteo, 9, '0') ;
					System.out.println("id_meteo_après"+id_meteo) ;
					vLwmom1.id_meteo = new BigDecimal(id_meteo);
				}
				Jwbwmom1.setNwlwmom1Awlwmom1(vLwmom1);
					
				// CALL SERVER
				Jwbwmom1.nwlwmom1();
					                                
			    // Verification du code retour
				vWebent = Jwbwmom1.getNwlwmom1Axwebent();
				System.out.println("Code retour nwlwmom1() = " + 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() + "'");
				   	}
				}
				
				return Jwbwmom1;
	   } // End getInfosMeteo
	   
	   
	   
	   /**
		 * <p>Titre : setInfosMeteo</p>
		 * <p>Description : mise à jour d'un météo</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>26/03/2012</i>
		 * @version 1.0
		 */
		public static Jwbwmom1 setInfosMeteo(
			String fonction,
			String id_meteo,
			String dt_debut,
			String dt_fin,
			String lig_info,
			String cd_prt,
			String cd_zpo[],
			String type_portage[],
			String id_tournee[],
			
			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 entrées
	    Jwbwmom1 Jwbwmom1 = new Jwbwmom1(broker, Utils.formatSrvAddr (rpc_name));
		
		// Initialisation de la vWebent depuis les informations de connexion
		Jwbwmom1.Nwlwmom1Axwebent vWebent = Jwbwmom1.new Nwlwmom1Axwebent();
		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 	  = "WBWEFLSM";
		vWebent.fonction 		  = fonction;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		Jwbwmom1.setNwlwmom1Axwebent (vWebent);
	        
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwbwmom1.Nwlwmom1Awlwmom1 vLwmom1 = Jwbwmom1.new Nwlwmom1Awlwmom1();
		if(!"".equals(id_meteo) && id_meteo!=null){
			System.out.println("id_meteo_avant"+id_meteo) ;
			id_meteo 		 = Utils.LPad(id_meteo, 9, '0') ;
			System.out.println("id_meteo_après"+id_meteo) ;
			vLwmom1.id_meteo = new BigDecimal(id_meteo);
		}
		
		if(!"".equals(dt_debut) && dt_debut!=null){
			vLwmom1.dt_debut = new BigDecimal(dt_debut);
		}
		if(!"".equals(dt_fin) && dt_fin!=null){
			vLwmom1.dt_fin = new BigDecimal(dt_fin);
		}
		vLwmom1.cd_prt = cd_prt;
		vLwmom1.lig_info = lig_info;
		
		//initialisation de la liste des tournée
		Jwbwmom1.Nwlwmom1Awlwmom1Liste_locListe_tournee[] listeTourne = new Jwbwmom1.Nwlwmom1Awlwmom1Liste_locListe_tournee[20];
		if(id_tournee.length!=0 || id_tournee != null){
			for(int i=0;i<20;i++){
				listeTourne[i] = Jwbwmom1.new Nwlwmom1Awlwmom1Liste_locListe_tournee();
				listeTourne[i].id_tournee = id_tournee[i];
			}
		}else{
			for(int i=0;i<20;i++){
				listeTourne[i] = Jwbwmom1.new Nwlwmom1Awlwmom1Liste_locListe_tournee();
				listeTourne[i].id_tournee = null;
			}
		}
		Jwbwmom1.Nwlwmom1Awlwmom1Liste_loc vLwmom1_loc = Jwbwmom1.new Nwlwmom1Awlwmom1Liste_loc();
		vLwmom1_loc.liste_tournee  = listeTourne;
		vLwmom1_loc.type_portage   = type_portage;
		vLwmom1_loc.cd_zpo 		   = cd_zpo;
		vLwmom1.liste_loc 		   = vLwmom1_loc;
		
		Jwbwmom1.setNwlwmom1Awlwmom1(vLwmom1);
			
		// CALL SERVER
		Jwbwmom1.nwlwmom1();
			                                
	    // Verification du code retour
		vWebent = Jwbwmom1.getNwlwmom1Axwebent();
		System.out.println("Code retour nwlwmom1() = " + 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() + "'");
		   	}
		}
			
		return Jwbwmom1;
	   } // End setInfosMeteo
	   
		
		 /**
		 * <p>Titre : deleteInfosMeteo</p>
		 * <p>Description : supression d'un météo</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author PY <i>09/05/2012</i>
		 * @version 1.0
		 */
		public static Jwbwmom1 deleteInfoMeteo(
			String id_meteo,
			
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_stegrp,
			String cd_cible,
			String dbid,
			String rpc_name,
			Broker broker)throws BrokerException{
			String[] id_tour 	  = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			String[] type_portage = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			String[] cd_zpo    	  = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			
			Jwbwmom1 Jwbwmom1 = setInfosMeteo ("S", id_meteo, 
			null, null, null,null,cd_zpo,type_portage,id_tour, 
			groupe_exploitant,numero_session,utilisateur,cd_stegrp,cd_cible,dbid,rpc_name,broker);
			return Jwbwmom1;
		}	
		
		
		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2011</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>26/03/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";
			
			//test pour Intérogation
			//-------------------Donnée test----------------
			/*String id_meteo = "2000581";
			//-------------------Donnée test----------------
			Jwbwmom1 Jwbwmom1 = getInfosMeteo(
			id_meteo,
			groupe_exploitant, numero_session, utilisateur, cd_stegrp, cd_cible, dbid,rpc_name,broker);
			//retour
			Jwbwmom1.Nwlwmom1Awlwmom1 Jwbwmom1Reponse = Jwbwmom1.getNwlwmom1Awlwmom1() ;
			System.out.println("ID_METEO=" + Jwbwmom1Reponse.id_meteo + "\n") ;
			System.out.println("DT-DEBUT=" + Jwbwmom1Reponse.dt_debut + "\n") ;
			System.out.println("DT-FIN="   + Jwbwmom1Reponse.dt_fin + "\n") ;
			System.out.println("LIG-INFO=" + Jwbwmom1Reponse.lig_info + "\n") ;
			for(int k=0;k<20;k++){
				System.out.println("CD-ZPO["+k+"]="+ Jwbwmom1Reponse.liste_loc.cd_zpo[k] + "\n") ;
			}
			System.out.println("=====================DEBUT liste des ID_TOURNER=============================") ;
			for(int j=0;j<20;j++){
				System.out.println("ID-TOURNEE["+j+"]="+ Jwbwmom1Reponse.liste_loc.liste_tournee[j].id_tournee + "\n") ;
			}
			System.out.println("=====================fIN de liste des ID_TOURNER=============================") ;
			*/
			
			// mise à jour
			//test pour le modification (M) et création(C)
			String id_meteo = "2000649";
			String[] id_tour = {null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			String[] cd_zpo = {"0003",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			String[] type_portage = {"N",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null};
			Jwbwmom1 Jwbwmom1 = setInfosMeteo ("M", id_meteo,"20140330","20140406","PatrickR","0003",cd_zpo,type_portage,id_tour,
												groupe_exploitant,numero_session,utilisateur,cd_stegrp,cd_cible,dbid,rpc_name,broker);
			//'M', '2000650', '20140330', '20140405', 'PANNE DE VOITUR...', '0003', Array, Array, Array, 'G00ADMIN', 1, 'MADAE01 ', ' ', '00', '14', 'SRV1', Object(com.softwareag.entirex.aci.Broker)
			//retour
			System.out.println("Début retour .......................");
			Jwbwmom1.Nwlwmom1Awlwmom1 Jwbwmom1Reponse = Jwbwmom1.getNwlwmom1Awlwmom1() ;
			System.out.println("ID-METEO="		 + Jwbwmom1Reponse.id_meteo + "\n") ;
			System.out.println("DT-DEBUT="		 + Jwbwmom1Reponse.dt_debut + "\n") ;
			System.out.println("DT-FIN="		 + Jwbwmom1Reponse.dt_fin + "\n") ;
			System.out.println("LIG-INFO="	 	 + Jwbwmom1Reponse.lig_info + "\n") ;
			System.out.println("CD-PRT="		 + Jwbwmom1Reponse.cd_prt + "\n") ;
			System.out.println("CD-ZPO[0]="		 + Jwbwmom1Reponse.liste_loc.cd_zpo[0] + "\n") ;
			System.out.println("CD-ZPO[1]="	   	 + Jwbwmom1Reponse.liste_loc.cd_zpo[1] + "\n") ;
			System.out.println("TYPE-PORTAGE[0]="+ Jwbwmom1Reponse.liste_loc.type_portage[0] + "\n") ;
			System.out.println("TYPE-PORTAGE[1]="+ Jwbwmom1Reponse.liste_loc.type_portage[1] + "\n") ;
			System.out.println("ID-TOURNEE[0]="	 + Jwbwmom1Reponse.liste_loc.liste_tournee[0].id_tournee + "\n") ;
			System.out.println("ID-TOURNEE[1]="	 + Jwbwmom1Reponse.liste_loc.liste_tournee[1].id_tournee + "\n") ;					
			//
			JxweblogBw.closeConnexion (rpc_name, jxweblog, broker);			
			JxweblogBw.closeBroker (broker);		
			System.out.println("Fin de Test.......................");
	   }
} // END Jwbwmom1Web