import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwzom4Web</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 Jwlwzom4Web {
	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 Jwlwzom4 setVoie(
		String cd_zpo[],
		String type_portage[],
		String zpo_ordre[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom4 jwlwzom4 		  = new Jwlwzom4(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom4.Nwlwzom4Axwebent vWebent = jwlwzom4.new Nwlwzom4Axwebent();
		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 		  = "MODIFORD";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwzom4.setNwlwzom4Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom4.Nwlwzom4Awlwzom4 vLwzom4 				= jwlwzom4.new Nwlwzom4Awlwzom4();
		Jwlwzom4.Nwlwzom4Awlwzom4Demande vLwzom4Demande = jwlwzom4.new Nwlwzom4Awlwzom4Demande();
		
		String tab_cd_zpo[] 	  = new String[TAILLE];
		String tab_type_portage[] = new String[TAILLE];
		String tab_zpo_ordre[]    = new String[TAILLE];
		
		for (int i = 0; i < cd_zpo.length; i++) {
			tab_cd_zpo[i] = cd_zpo[i];
		}
		for (int i = 0; i < type_portage.length; i++) {
			tab_type_portage[i] = type_portage[i];
		}
		for (int i = 0; i < zpo_ordre.length; i++) {
			tab_zpo_ordre[i] = zpo_ordre[i];
		}
		
		vLwzom4Demande.cd_zpo   	 = tab_cd_zpo;
		vLwzom4Demande.type_portage	 = tab_type_portage;
		vLwzom4Demande.zpo_ordre 	 = tab_zpo_ordre;
		
		vLwzom4.demande = vLwzom4Demande;
		
		jwlwzom4.setNwlwzom4Awlwzom4(vLwzom4);
		
		// CALL SERVER
		jwlwzom4.nwlwzom4();
		
		// Verification du code retour
		vWebent = jwlwzom4.getNwlwzom4Axwebent();
		System.out.println("Code retour nwlwzom4() = " + 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 jwlwzom4;
	   } // 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 cd_zpo[]  = new String[TAILLE];
			cd_zpo[0]	= "AHAHA";
			cd_zpo[1]	= "AHAHA";
			
			String type_portage[] = new String[TAILLE];
			type_portage[0]= "N";
			type_portage[1]= "T";
			
			String zpo_ordre[] = new String[TAILLE];
			zpo_ordre[0] 	= "1";
			zpo_ordre[1] 	= "2";
			//---------Donnee Test---------------
			setVoie(cd_zpo, type_portage, zpo_ordre,
					groupe_exploitant, numero_session, utilisateur,
					cd_cible, cd_stegrp, broker);
		}

	//FIN  Test

}