import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwtim1Web</p>
 * <p>Description : affectation titre à une zone portage.
	* </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 Jwlwtim1Web {
	public final static int TAILLE = 40;
	
	/**
	 * <p>Titre : setTitre</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 Jwlwtim1 setTitre(
		String f_cd_zpo_affect,
		String f_type_portage_affect,
		String f_type_trt_affect,
		String f_cd_insee_affect,
		String f_localite_affect,
		String f_code_postal_affect,
		String code_titre[],
		String top_select_affect[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtim1 jwlwtim1 		  = new Jwlwtim1(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtim1.Nwlwtim1Axwebent vWebent = jwlwtim1.new Nwlwtim1Axwebent();
		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;
		jwlwtim1.setNwlwtim1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtim1.Nwlwtim1Awlwtim1 vLwtim1 				= jwlwtim1.new Nwlwtim1Awlwtim1();
		Jwlwtim1.Nwlwtim1Awlwtim1Demande vLwtim1Demande = jwlwtim1.new Nwlwtim1Awlwtim1Demande();
		Jwlwtim1.Nwlwtim1Awlwtim1Action vLwtim1Action   = jwlwtim1.new Nwlwtim1Awlwtim1Action();
		
		vLwtim1Demande.f_cd_zpo_affect		= f_cd_zpo_affect;
		vLwtim1Demande.f_type_portage_affect= f_type_portage_affect;
		vLwtim1Demande.f_type_trt_affect	= f_type_trt_affect;
		vLwtim1Demande.f_cd_insee_affect	= f_cd_insee_affect;
		vLwtim1Demande.f_localite_affect	= f_localite_affect;
		vLwtim1Demande.f_code_postal_affect	= f_code_postal_affect;
		
		String[] tab_code_titre = new String[40];
		String[] tab_top_select_affect = new String[40];
		int len = code_titre.length ;
		if(code_titre!=null){
			for(int i=0;i< len;i++){
				tab_code_titre[i]   = code_titre[i];
				tab_top_select_affect[i]   = top_select_affect[i];
			}
		}
		
		vLwtim1Action.code_titre 			= tab_code_titre;
		vLwtim1Action.top_select_affect 	= tab_top_select_affect;
		
		vLwtim1.demande = vLwtim1Demande;
		vLwtim1.action  = vLwtim1Action;
		
		jwlwtim1.setNwlwtim1Awlwtim1(vLwtim1);
		
		// CALL SERVER
		jwlwtim1.nwlwtim1();
		
		// Verification du code retour
		vWebent = jwlwtim1.getNwlwtim1Axwebent();
		System.out.println("Code retour nwlwtim1() = " + 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("Message :"+vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwtim1;
	   } // End setTitre
	
	/**
	 * <p>Titre : deleteTitre</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>19/02/2013</i>
	 * @version 1.0
	 */
	public static Jwlwtim1 deleteTitre(
		String f_cd_zpo_affect,
		String f_type_portage_affect,
		String f_type_trt_affect,
		
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtim1 jwlwtim1 		  = new Jwlwtim1(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtim1.Nwlwtim1Axwebent vWebent = jwlwtim1.new Nwlwtim1Axwebent();
		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 		  = "SUPP";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwtim1.setNwlwtim1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtim1.Nwlwtim1Awlwtim1 vLwtim1 				= jwlwtim1.new Nwlwtim1Awlwtim1();
		Jwlwtim1.Nwlwtim1Awlwtim1Demande vLwtim1Demande = jwlwtim1.new Nwlwtim1Awlwtim1Demande();
		
		vLwtim1Demande.f_cd_zpo_affect		= f_cd_zpo_affect;
		vLwtim1Demande.f_type_portage_affect= f_type_portage_affect;
		vLwtim1Demande.f_type_trt_affect	= f_type_trt_affect;
		
		vLwtim1.demande = vLwtim1Demande;
		
		jwlwtim1.setNwlwtim1Awlwtim1(vLwtim1);
		
		// CALL SERVER
		jwlwtim1.nwlwtim1();
		
		// Verification du code retour
		vWebent = jwlwtim1.getNwlwtim1Axwebent();
		System.out.println("Code retour nwlwtim1() = " + 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 jwlwtim1;
	   } // End deleteTitre
	
	/**
		 * <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 ("MADAA12");
			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 MODIFICATION
			//---------Donnee Test---------------
			/*
			String f_cd_zpo_affect       = "0001"; 
            String f_type_portage_affect = "N"; 
            String f_type_trt_affect     = "N";
			String f_cd_insee_affect	 = null;
			String f_localite_affect 	 = "VILLEMOISSON SUR ORGE";
			String f_code_postal_affect	 = null;					
            String code_titre[]          = new String[TAILLE]; 	
            String top_select_affect[]   = new String[TAILLE]; 	
    		code_titre[0] 				 = "AGE";
    		top_select_affect[0]		 = "X";
    		//---------Donnee Test---------------
			setTitre(f_cd_zpo_affect, f_type_portage_affect, f_type_trt_affect, f_cd_insee_affect, f_localite_affect, f_code_postal_affect,
					code_titre,top_select_affect,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);			  
			
			*/
			//Test de SUPPRESSION
			//---------Donnee Test---------------
			String f_cd_zpo_affect       = null;
            String f_type_portage_affect = null; 
            String f_type_trt_affect     = null;
			
            //String f_nbre_select         = null; 
            
			//---------Donnee Test---------------
			
			deleteTitre(f_cd_zpo_affect, f_type_portage_affect, f_type_trt_affect, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			
		}			
}