import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwto80Web</p>
 * <p>Description : Programmes de Contrôle et Transfert/Copie 
 * 					des Tronçons/Tournées/Groupes/Zones.
 * </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>27/09/2012</i>
 * @version 1.0
 */
 
public class Jwlwto80Web {
	
	/**
	 * <p>Titre : setControles</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>14/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwto80 setControles(
		String fonction,
		String type_trt,
		String type_maj,
		String action,
		String niveau,
		String ori_zpo,
		String ori_typ,
		String ori_grp,
		String ori_tpr,
		String ori_tpo_id,
		String ori_tpo_deb,
		String ori_tpo_fin,
		String cib_zpo,
		String cib_typ,
		String cib_grp,
		String cib_tpr,
		String cib_tpo_ord,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwto80 jwlwto80 		  = new Jwlwto80(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwto80.Nwlwto80Axwebent vWebent = jwlwto80.new Nwlwto80Axwebent();
		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 		  = fonction;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwto80.setNwlwto80Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwto80.Nwlwto80Awlwto80 vLwto80 				= jwlwto80.new Nwlwto80Awlwto80();
		
		vLwto80.type_trt = type_trt;
		vLwto80.type_maj = type_maj;
		vLwto80.action 	 = action;
		vLwto80.niveau 	 = niveau;
		vLwto80.ori_zpo  = ori_zpo;
		vLwto80.ori_typ  = ori_typ;
		vLwto80.ori_grp  = ori_grp;
		vLwto80.ori_tpr  = ori_tpr;
		vLwto80.cib_zpo  = cib_zpo;
		vLwto80.cib_typ  = cib_typ;
		vLwto80.cib_grp  = cib_grp;
		vLwto80.cib_tpr  = cib_tpr;
		
		if(!"".equals(ori_tpo_deb) && ori_tpo_deb!=null){
			vLwto80.ori_tpo_deb = new BigDecimal(ori_tpo_deb);
		}
		
		if(!"".equals(ori_tpo_fin) && ori_tpo_fin!=null){
			vLwto80.ori_tpo_fin = new BigDecimal(ori_tpo_fin);
		}
		if(!"".equals(ori_tpo_id) && ori_tpo_id!=null){
			vLwto80.ori_tpo_id = new BigDecimal(ori_tpo_id);
		}
		if(!"".equals(cib_tpo_ord) && cib_tpo_ord!=null){
			vLwto80.cib_tpo_ord = new BigDecimal(cib_tpo_ord);
		}
		
		jwlwto80.setNwlwto80Awlwto80(vLwto80);
		
		// CALL SERVER
		jwlwto80.nwlwto80();
		
		// Verification du code retour
		vWebent = jwlwto80.getNwlwto80Axwebent();
		System.out.println("Code retour nwlwto80() = " + 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{
			Jwlwto80.Nwlwto80Awlwto80AnomalieT_ano tAno = jwlwto80.new Nwlwto80Awlwto80AnomalieT_ano();
			tAno = jwlwto80.getNwlwto80Awlwto80().anomalie.t_ano[0];
			System.out.println("Message :"+ tAno.num_ano+" "+tAno.lib_ano);
			System.out.println ("Suite normale ...");
		}
		
		return jwlwto80;
	   } // End setControles
	   
	
	   /**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2012</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 fonction  = "A";
			String type_trt  = "T"; //Mode TEST
			String type_maj  = "T"; //T ou B
			String action    = "T"; //C ou T
			String niveau    = "T"; //Z, G, N, T
			String ori_zpo   = "E001";
			String ori_typ 	 = "N";
			String ori_grp 	 = "2";
			String ori_tpr    = "201";
			String ori_tpo_id = "31100"; //Tronçon id
			String ori_tpo_deb = null;
			String ori_tpo_fin = null;
			String cib_zpo 	  = "E001";
			String cib_typ    = "N";
			String cib_grp    = "2";
			String cib_tpr    = "201";
			//---------Donnee Test---------------
			//****TEST SELECTION TOP PRESSE PLUS
			setControles(fonction, type_trt, type_maj, action, niveau, ori_zpo,
					ori_typ, ori_grp, ori_tpr, ori_tpo_id,ori_tpo_deb,ori_tpo_fin, cib_zpo, cib_typ, cib_grp, cib_tpr, null,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);	
		}			
}