import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwvom7Web</p>
 * <p>Description :  Réaffectation de la voie.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>07/03/2013</i>
 * @version 1.0
 */
 
public class Jwlwvom7Web {
	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>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwvom7 setVoie(
		String matricule_mere_ori,
		String cd_insee_ori,
		String matricule_cible_ori,
		String type_portage_ntr_ori,
		String voi_xx,
		String matricule_mere_cib_1,
		String matricule_mere_cib_2,
		String type_portage_ntr_cib_1,
		String type_portage_ntr_cib_2,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom7 jwlwvom7 		  = new Jwlwvom7(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom7.Nwlwvom7Axwebent vWebent = jwlwvom7.new Nwlwvom7Axwebent();
		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 		  = "REAFF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom7.setNwlwvom7Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom7.Nwlwvom7Awlwvom7 vLwvom7 				= jwlwvom7.new Nwlwvom7Awlwvom7();
		Jwlwvom7.Nwlwvom7Awlwvom7Demande vLwvom7Demande = jwlwvom7.new Nwlwvom7Awlwvom7Demande();
		vLwvom7Demande.matricule_cible_ori     = matricule_cible_ori;
		vLwvom7Demande.type_portage_ntr_ori    = type_portage_ntr_ori;
		vLwvom7Demande.cd_insee_ori 		   = cd_insee_ori;
		vLwvom7Demande.matricule_cible_ori     = matricule_cible_ori;
		vLwvom7Demande.voi_xx   		       = voi_xx;
		vLwvom7Demande.type_portage_ntr_cib_1  = type_portage_ntr_cib_1;
		vLwvom7Demande.type_portage_ntr_cib_2  = type_portage_ntr_cib_2;
		
		if(!"".equals(matricule_mere_cib_1) && matricule_mere_cib_1!=null){
			vLwvom7Demande.matricule_mere_cib_1  = new BigDecimal(matricule_mere_cib_1);
		}
		if(!"".equals(matricule_mere_cib_2) && matricule_mere_cib_2!=null){
			vLwvom7Demande.matricule_mere_cib_2  = new BigDecimal(matricule_mere_cib_2);
		}
		
		vLwvom7.demande = vLwvom7Demande;
		
		jwlwvom7.setNwlwvom7Awlwvom7(vLwvom7);
		
		// CALL SERVER
		jwlwvom7.nwlwvom7();
		
		// Verification du code retour
		vWebent = jwlwvom7.getNwlwvom7Axwebent();
		System.out.println("Code retour nwlwvom7() = " + 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 jwlwvom7;
	   } // 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 ("MADAA01X");
			JxweblogWeb.setPassword ("MADAA81");
			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_ori 	 = "1456880";
			String cd_insee_ori 		 = "75116";
			String matricule_cible_ori   = "00";
			String type_portage_ntr_ori  = null;
			String voi_xx 				 = "N";
			String matricule_mere_cib_1  = "1456576";
			String matricule_mere_cib_2  = null;
			
			String type_portage_ntr_cib_1 = null;
			String type_portage_ntr_cib_2 = null;
			
			//---------Donnee Test---------------
			setVoie(matricule_mere_ori, cd_insee_ori, matricule_cible_ori, type_portage_ntr_ori,
					voi_xx, matricule_mere_cib_1, matricule_mere_cib_2,
					type_portage_ntr_cib_1, type_portage_ntr_cib_2,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
		}

	//FIN  Test

}