import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwvom6Web</p>
 * <p>Description : mise à jour multi 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 Jwlwvom6Web {

	/**
	 * <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 Jwlwvom6 setVoie(
		String f_matricule_mere_org,
		String f_voi_id_org,
		String f_matricule_voie_org,
		String f_type_portage_sel,
		String f_matricule_cible_sel,
		String f_matricule_mere_sel,
		String f_matricule_voie_sel,
		String f_voi_id_sel,
		String nbre_select,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom6 jwlwvom6 		  = new Jwlwvom6(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom6.Nwlwvom6Axwebent vWebent = jwlwvom6.new Nwlwvom6Axwebent();
		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 		  = "RATT";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom6.setNwlwvom6Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom6.Nwlwvom6Awlwvom6 vLwvom6 				= jwlwvom6.new Nwlwvom6Awlwvom6();
		Jwlwvom6.Nwlwvom6Awlwvom6Demande vLwvom6Demande = jwlwvom6.new Nwlwvom6Awlwvom6Demande();
		
		vLwvom6Demande.f_type_portage_sel   	 = f_type_portage_sel;
		vLwvom6Demande.f_matricule_cible_sel   	 = f_matricule_cible_sel;		
		if(!"".equals(f_matricule_mere_org) && f_matricule_mere_org!=null){
			vLwvom6Demande.f_matricule_mere_org = new BigDecimal(f_matricule_mere_org);
		}
		if(!"".equals(f_voi_id_org) && f_voi_id_org!=null){
			vLwvom6Demande.f_voi_id_org = new BigDecimal(f_voi_id_org);
		}
		if(!"".equals(f_matricule_voie_org) && f_matricule_voie_org!=null){
			vLwvom6Demande.f_matricule_voie_org = new BigDecimal(f_matricule_voie_org);
		}
		if(!"".equals(f_matricule_mere_sel) && f_matricule_mere_sel!=null){
			vLwvom6Demande.f_matricule_mere_sel = new BigDecimal(f_matricule_mere_sel);
		}
		if(!"".equals(f_matricule_voie_sel) && f_matricule_voie_sel!=null){
			vLwvom6Demande.f_matricule_voie_sel = new BigDecimal(f_matricule_voie_sel);
		}
		if(!"".equals(f_voi_id_sel) && f_voi_id_sel!=null){
			vLwvom6Demande.f_voi_id_sel = new BigDecimal(f_voi_id_sel);
		}
		if(!"".equals(nbre_select) && nbre_select!=null){
			vLwvom6Demande.nbre_select = new Short(nbre_select);
		}
		vLwvom6.demande = vLwvom6Demande;
		
		jwlwvom6.setNwlwvom6Awlwvom6(vLwvom6);
		
		// CALL SERVER
		jwlwvom6.nwlwvom6();
		
		// Verification du code retour
		vWebent = jwlwvom6.getNwlwvom6Axwebent();
		System.out.println("Code retour nwlwvom6() = " + 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 jwlwvom6;
	   } // 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 REAFFECTATION
			//---------Donnee Test---------------
			String f_matricule_mere_org  = "1456880";
			String f_voi_id_org 		 = "0";
			String f_matricule_voie_org  = "1456880";
			String f_type_portage_sel 	 = "N R";
			String f_matricule_cible_sel = "00";
			String f_matricule_mere_sel  = "1456881";
			String f_matricule_voie_sel  = "1456881";
			String f_voi_id_sel          = "247044";
			String nbre_select 			 = "1";
			//---------Donnee Test---------------
			setVoie(f_matricule_mere_org, f_voi_id_org, f_matricule_voie_org, f_type_portage_sel,
					f_matricule_cible_sel, f_matricule_mere_sel, f_matricule_voie_sel, f_voi_id_sel, nbre_select,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
		}

	//FIN  INTERROGATION

}