import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwvom3Web</p>
 * <p>Description : Ordo + Zonage + Tronçons automatique
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>02/04/2013</i>
 * @version 1.0
 */
 
public class Jwlwvom3Web {
	private static final int TAILLE = 50;
	/**
	 * <p>Titre : setOrdonnancement</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>02/04/2013</i>
	 * @version 1.0
	 */
	public static Jwlwvom3 setOrdonnancement(
		String i_action,
		String i_matricule_mere[],
		String i_mot_directeur[],
		String i_matricule_cible[],
		String i_type_portage[],
		String i_top_voie_mere[],
		String i_cd_insee_rech,
		String i_type_portage_affect,
		String i_cd_zpo_affect,
		String i_tpr_groupe_affect,
		String i_tpr_num_affect,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwvom3 jwlwvom3 		  = new Jwlwvom3(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwvom3.Nwlwvom3Axwebent vWebent = jwlwvom3.new Nwlwvom3Axwebent();
		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 		  = "VISU";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwvom3.setNwlwvom3Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwvom3.Nwlwvom3Awlwvom3 vLwvom3 				= jwlwvom3.new Nwlwvom3Awlwvom3();
		Jwlwvom3.Nwlwvom3Awlwvom3Demande vLwvom3Demande = jwlwvom3.new Nwlwvom3Awlwvom3Demande();
		Jwlwvom3.Nwlwvom3Awlwvom3Affect vLwvom3Affect   = jwlwvom3.new Nwlwvom3Awlwvom3Affect();
		
		
		vLwvom3Demande.i_cd_insee_rech 	 = i_cd_insee_rech;
		
		String tab_i_mot_directeur[] 	= new String[TAILLE];
		String tab_i_matricule_cible[] 	= new String[TAILLE];
		String tab_i_type_portage[] 	= new String[TAILLE];
		String tab_i_top_voie_mere[] 	= new String[TAILLE];
		String tab_matricule_mere[] = new String[TAILLE];
		
		for (int i = 0; i < i_type_portage.length; i++) {
			tab_i_type_portage[i] = i_type_portage[i];
		}
		for (int i = 0; i < i_mot_directeur.length; i++) {
			tab_i_mot_directeur[i] = i_mot_directeur[i];
		}
		for (int i = 0; i < i_matricule_cible.length; i++) {
			tab_i_matricule_cible[i] = i_matricule_cible[i];
		}
		for (int i = 0; i < i_top_voie_mere.length; i++) {
			tab_i_top_voie_mere[i] = i_top_voie_mere[i];
		}
		for (int i = 0; i < i_matricule_mere.length; i++) {
			tab_matricule_mere[i] = i_matricule_mere[i];
		}

		vLwvom3Demande.i_action 		 = i_action;
		vLwvom3Demande.i_mot_directeur 	 = tab_i_mot_directeur;
		vLwvom3Demande.i_matricule_cible = tab_i_matricule_cible;
		vLwvom3Demande.i_type_portage 	 = tab_i_type_portage;
		vLwvom3Demande.i_top_voie_mere 	 = tab_i_top_voie_mere;
		vLwvom3Demande.i_matricule_mere  = tab_matricule_mere;
		
		vLwvom3Affect.i_type_portage_affect = i_type_portage_affect;
		vLwvom3Affect.i_cd_zpo_affect 		= i_cd_zpo_affect;
		vLwvom3Affect.i_tpr_groupe_affect 	= i_tpr_groupe_affect;
		vLwvom3Affect.i_tpr_num_affect 		= i_tpr_num_affect;
		
		vLwvom3.demande = vLwvom3Demande;
		vLwvom3.affect = vLwvom3Affect;
		
		jwlwvom3.setNwlwvom3Awlwvom3(vLwvom3);
		
		// CALL SERVER
		jwlwvom3.nwlwvom3();
		
		// Verification du code retour
		vWebent = jwlwvom3.getNwlwvom3Axwebent();
		System.out.println("Code retour nwlwvom3() = " + 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 jwlwvom3;
	   } // End setOrdonnancement			

	/**
		 * <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 i_cd_insee_rech = "02100" ;
			
			String i_action		  = "1";	
			
			String i_matricule_mere[] = new String[TAILLE] ;
			i_matricule_mere[0] = "244873";
			i_matricule_mere[1] = "3348539";
			
			String i_mot_directeur[]  = new String[TAILLE] ;
			i_mot_directeur[0]  = "IMPASSE";
			i_mot_directeur[1]  = "ROUTE";
			
			String i_matricule_cible[]= new String[TAILLE] ;
			i_matricule_cible[0]= "00";
			i_matricule_cible[1]= "00";
			String i_type_portage[]	  = new String[TAILLE] ;
			
			String i_top_voie_mere[]  = new String[TAILLE] ;
			i_top_voie_mere[0] = "M";
			i_top_voie_mere[1] = "M";
			
			
			String i_type_portage_affect = "R";
			String i_cd_zpo_affect 		 = "2222";
			String i_tpr_groupe_affect 	 = "3";
			String i_tpr_num_affect 	 = "303";
			
			
			//---------Donnee Test---------------
			setOrdonnancement(i_action, i_matricule_mere, i_mot_directeur,
					i_matricule_cible, i_type_portage, i_top_voie_mere, i_cd_insee_rech,
					i_type_portage_affect,i_cd_zpo_affect,i_tpr_groupe_affect,i_tpr_num_affect,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
	   }
}