import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwdrm1Web</p>
 * <p>Description : Modification des departements et regions.
	* </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>06/02/2013</i>
 * @version 1.0
 */
 
public class Jwlwdrm1Web {

	/**
	 * <p>Titre : getDepartement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>08/02/2013</i>
	 * @version 1.0
	 */
	public static Jwlwdrm1 getDepartement(
				String f_cd_dept,
				String f_num_region,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwdrm1 jwlwdrm1 = new Jwlwdrm1(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwdrm1.Nwlwdrm1Axwebent vWebent = jwlwdrm1.new Nwlwdrm1Axwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "VISU";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwdrm1.setNwlwdrm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwdrm1.Nwlwdrm1Awlwdrm1 vLwdrm1 					= jwlwdrm1.new Nwlwdrm1Awlwdrm1();
		Jwlwdrm1.Nwlwdrm1Awlwdrm1Demande vLwdrm1Demande = jwlwdrm1.new Nwlwdrm1Awlwdrm1Demande();
		
		vLwdrm1Demande.f_cd_dept	= " "+f_cd_dept;
		
		if(!"".equals(f_num_region) && f_num_region!=null){
			vLwdrm1Demande.f_num_region = new BigDecimal(f_num_region);
		}
	
		vLwdrm1.demande = vLwdrm1Demande;
		
		jwlwdrm1.setNwlwdrm1Awlwdrm1(vLwdrm1);
		
		// CALL SERVER
		jwlwdrm1.nwlwdrm1();
		
		// Verification du code retour
		vWebent = jwlwdrm1.getNwlwdrm1Axwebent();
		System.out.println("Code retour nwlwdrm1() = " + 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{
			//affichage de reponse
			Jwlwdrm1.Nwlwdrm1Awlwdrm1 jwlwdrm1Reponse = jwlwdrm1.getNwlwdrm1Awlwdrm1() ;
			Jwlwdrm1.Nwlwdrm1Awlwdrm1Reponse reponse  = jwlwdrm1Reponse.reponse;
			System.out.println("cd_dept="	 + reponse.cd_dept) ;
			System.out.println("num_region=" + reponse.num_region) ;
			System.out.println("lib_dept="	 + reponse.lib_dept) ;
		}
		return jwlwdrm1;
	   } // End getDepartement
	   
	//FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : setDepartement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>08/02/2013</i>
	 * @version 1.0
	 */
	public static Jwlwdrm1 setDepartement(
		String f_cd_dept,
		String f_num_region,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwdrm1 jwlwdrm1 		  = new Jwlwdrm1(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwdrm1.Nwlwdrm1Axwebent vWebent = jwlwdrm1.new Nwlwdrm1Axwebent();
		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 	  = "WLWSTLST";
		vWebent.fonction 		  = "MODIF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwdrm1.setNwlwdrm1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwdrm1.Nwlwdrm1Awlwdrm1 vLwdrm1 				= jwlwdrm1.new Nwlwdrm1Awlwdrm1();
		Jwlwdrm1.Nwlwdrm1Awlwdrm1Demande vLwdrm1Demande = jwlwdrm1.new Nwlwdrm1Awlwdrm1Demande();
		
		vLwdrm1Demande.f_cd_dept = " "+f_cd_dept;
		
		if(!"".equals(f_num_region) && f_num_region!=null){
			vLwdrm1Demande.f_num_region = new BigDecimal(f_num_region);
		}
		
		vLwdrm1.demande = vLwdrm1Demande;
		
		jwlwdrm1.setNwlwdrm1Awlwdrm1(vLwdrm1);
		
		// CALL SERVER
		jwlwdrm1.nwlwdrm1();
		
		// Verification du code retour
		vWebent = jwlwdrm1.getNwlwdrm1Axwebent();
		System.out.println("Code retour nwlwdrm1() = " + 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{
			//affichage de reponse		
			System.out.println(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwdrm1;
	   } // End setDepartement
	/**
		 * <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>08/02/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA72");
			Broker broker 				    	= JxweblogWeb.logonBroker();
			Jxweblog jxweblog 				    = JxweblogWeb.getConnexion(broker);
			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;
			
			//Test de INTEROGATION
			//---------Donnee Test---------------
			
			String f_cd_dept 	= "10";
			String f_num_region = null;
			//---------Donnee Test---------------
			getDepartement(f_cd_dept, f_num_region,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			//Test de MODIFICATION
			//---------Donnee Test---------------
			/*String f_cd_dept	= "10";
			String f_num_region	= "5";
			//---------Donnee Test---------------
			setDepartement(f_cd_dept, f_num_region,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
		}			
}