import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwvom8Web</p>
 * <p>Description :  Epuration des numéros voies.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>03/04/2013</i>
 * @version 1.0
 */
 
public class Jwlwvom8Web {
	private static final int TAILLE = 40;
	/**
	 * <p>Titre : setVoie</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>03/04/2013</i>
	 * @version 1.0
	 */
	public static Jwlwvom8 setVoie(
		String matricule_mere[],
		String matricule_cible[],
		String type_portage_ntr[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom8 jwlwvom8 		  = new Jwlwvom8(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom8.Nwlwvom8Axwebent vWebent = jwlwvom8.new Nwlwvom8Axwebent();
		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 		  = "E";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom8.setNwlwvom8Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom8.Nwlwvom8Awlwvom8 vLwvom8 				= jwlwvom8.new Nwlwvom8Awlwvom8();
		Jwlwvom8.Nwlwvom8Awlwvom8Demande vLwvom8Demande = jwlwvom8.new Nwlwvom8Awlwvom8Demande();
		String tab_matricule_mere[] = new String[TAILLE];
		String tab_matricule_cible[] 	= new String[TAILLE];
		String tab_type_portage_ntr[] 	= new String[TAILLE];
		
		for (int i = 0; i < matricule_mere.length; i++) {
			tab_matricule_mere[i] = matricule_mere[i];
		}
		for (int i = 0; i < type_portage_ntr.length; i++) {
			tab_type_portage_ntr[i] = type_portage_ntr[i];
		}
		for (int i = 0; i < matricule_cible.length; i++) {
			tab_matricule_cible[i] = matricule_cible[i];
		}
		
		
		vLwvom8Demande.matricule_mere 	 = tab_matricule_mere;
		vLwvom8Demande.matricule_cible   = tab_matricule_cible;
		vLwvom8Demande.type_portage_ntr	 = tab_type_portage_ntr;
	
		
		vLwvom8.demande = vLwvom8Demande;
		
		jwlwvom8.setNwlwvom8Awlwvom8(vLwvom8);
		
		// CALL SERVER
		jwlwvom8.nwlwvom8();
		
		// Verification du code retour
		vWebent = jwlwvom8.getNwlwvom8Axwebent();
		System.out.println("Code retour nwlwvom8() = " + 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{
			System.out.println(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwvom8;
	   } // End setVoie
	
	/**
		 * <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>25/03/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA82");
			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 matricule_mere[]  = new String[TAILLE];
			matricule_mere[0]= "17152";
			
			String matricule_cible[] = new String[TAILLE];
			matricule_cible[0]= "00";
			
			String type_portage_ntr[] = new String[TAILLE];
			type_portage_ntr[0]= null;
			//---------Donnee Test---------------
			setVoie(matricule_mere, matricule_cible, type_portage_ntr,
					groupe_exploitant, numero_session, utilisateur,
					cd_cible, cd_stegrp, broker);
		}

	//FIN  Test

}