import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : JwlwztomWeb</p>
 * <p>Description : Soumission d’ordo, de zonage et d’affectation de tournée.
 * </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 JwlwztomWeb {
	private static final int TAILLE = 500;
	
	/**
	 * <p>Titre : setSoumission</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 Jwlwztom setSoumission(
		String i_cd_insee,
		String i_cd_postal,
		String i_action[],
		String i_cd_insee_postal[],
		String i_nb_voies[],
		String i_cd_cible,
		String i_cd_zpo_affect,
		String i_type_portage_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
	    Jwlwztom jwlwztom 		  = new Jwlwztom(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwztom.NwlwztomAxwebent vWebent = jwlwztom.new NwlwztomAxwebent();
		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;
		jwlwztom.setNwlwztomAxwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwztom.NwlwztomAwlwztom vLwztom 				= jwlwztom.new NwlwztomAwlwztom();
		Jwlwztom.NwlwztomAwlwztomDemande vLwztomDemande = jwlwztom.new NwlwztomAwlwztomDemande();
		
		vLwztomDemande.i_cd_insee    	 = i_cd_insee;
		vLwztomDemande.i_cd_postal 		 = i_cd_postal;
		vLwztomDemande.i_cd_cible        = i_cd_cible;
		vLwztomDemande.i_cd_zpo_affect   = i_cd_zpo_affect;
		vLwztomDemande.i_type_portage_affect = i_type_portage_affect;
		vLwztomDemande.i_tpr_groupe_affect   = i_tpr_groupe_affect;
		vLwztomDemande.i_tpr_num_affect      = i_tpr_num_affect;
		
		String tab_i_action[] = new String[TAILLE];
		String tab_i_cd_insee_postal[] = new String[TAILLE];
		BigDecimal tab_i_nb_voies[] = new BigDecimal[TAILLE];
		for (int i = 0; i < i_action.length; i++) {
			tab_i_action[i] = i_action[i];
		}
		for (int i = 0; i < i_cd_insee_postal.length; i++) {
			tab_i_cd_insee_postal[i] = i_cd_insee_postal[i];
		}
		for (int i = 0; i < TAILLE; i++) {
			if(!"".equals(i_nb_voies[i]) && i_nb_voies[i]!=null){
				tab_i_nb_voies[i]  = new BigDecimal(i_nb_voies[i]);
			}
		}
		
		vLwztomDemande.i_action       	 = tab_i_action;
		vLwztomDemande.i_cd_insee_postal = tab_i_cd_insee_postal;
		vLwztomDemande.i_nb_voies        = tab_i_nb_voies;
		
		vLwztom.demande = vLwztomDemande;
		
		jwlwztom.setNwlwztomAwlwztom(vLwztom);
		
		// CALL SERVER
		jwlwztom.nwlwztom();
		
		// Verification du code retour
		vWebent = jwlwztom.getNwlwztomAxwebent();
		System.out.println("Code retour nwlwztom() = " + 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 jwlwztom;
	   } // End setSoumission
	   
	   //FIN  INTERROGATION
	
	
	/**
		 * <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 ("MADAE05");
			JxweblogWeb.setPassword ("ENSOR16");
			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 		     = "91667";
			String i_cd_postal 		     = null;
			String i_cd_cible 		     = null;
			String i_cd_zpo_affect 	     = null;
			String i_type_portage_affect = "N";
			String i_tpr_groupe_affect   = null;
			String i_tpr_num_affect 	 = null;
			
			String i_action[] 		   = new String[TAILLE];
			i_action[0] = "9";
			
			String i_cd_insee_postal[] = new String[TAILLE];
			i_cd_insee_postal[0] = "91667";
			
			String i_nb_voies[] 	   = new String[TAILLE];
			i_nb_voies[0] = "137";
			
			//---------Donnee Test---------------
			setSoumission(i_cd_insee, i_cd_postal, i_action, i_cd_insee_postal,
					i_nb_voies, i_cd_cible, i_cd_zpo_affect, i_type_portage_affect,
					i_tpr_groupe_affect, i_tpr_num_affect,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
		}

}