import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwtcm2Web</p>
 * <p>Description : Inversion des bornes.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>05/04/2013</i>
 * @version 1.0
 */
 
public class Jwlwtcm2Web {
	private static final int TAILLE = 50;

	/**
	 * <p>Titre : ordoTroncon</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>05/04/2013</i>
	 * @version 1.0
	 * top_deplacement="AP"
	 */
	public static Jwlwtcm2 ordoTroncon(
				String mode,
				String top_deplacement,
				String no_ordre_refer,
				String tpo_id[],
				String cd_zpo,
				String type_portage,
				String tpr_groupe,
				String tpr_num,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtcm2 jwlwtcm2 = new Jwlwtcm2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtcm2.Nwlwtcm2Axwebent vWebent = jwlwtcm2.new Nwlwtcm2Axwebent();
		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 		  = null;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwtcm2.setNwlwtcm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtcm2.Nwlwtcm2Awlwtcm2 vLwtcm2 			= jwlwtcm2.new Nwlwtcm2Awlwtcm2();
		Jwlwtcm2.Nwlwtcm2Awlwtcm2Param vLwtcm2Param = jwlwtcm2.new Nwlwtcm2Awlwtcm2Param();
		vLwtcm2Param.mode 			 = mode;
		vLwtcm2Param.cd_action 		 = "O";
		vLwtcm2Param.top_deplacement = top_deplacement;
		vLwtcm2Param.cd_zpo 		 = cd_zpo;
		vLwtcm2Param.type_portage 	 = type_portage;
		vLwtcm2Param.tpr_groupe 	 = tpr_groupe;
		vLwtcm2Param.tpr_num 		 = tpr_num;
		
//		if(!"".equals(no_ordre_refer) && no_ordre_refer!=null){
//			vLwtcm2Param.no_ordre_refer 	 = new BigDecimal(no_ordre_refer);
			vLwtcm2Param.no_ordre_refer 	 = no_ordre_refer;			
//		}
		Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock vLwtcm2tabStock[] = new Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock[TAILLE];
		for (int i = 0; i < TAILLE ; i++) {
			vLwtcm2tabStock[i] = jwlwtcm2.new Nwlwtcm2Awlwtcm2ParamTab_stock();
		}
		for (int i = 0; i < tpo_id.length; i++) {
			if(!"".equals(tpo_id[i]) && tpo_id[i]!=null){
				vLwtcm2tabStock[i].tpo_id = new BigDecimal(tpo_id[i]);
			}
		}
		vLwtcm2Param.tab_stock = vLwtcm2tabStock;
		vLwtcm2.param = vLwtcm2Param;
		
		jwlwtcm2.setNwlwtcm2Awlwtcm2(vLwtcm2);
		
		// CALL SERVER
		jwlwtcm2.nwlwtcm2();
		
		// Verification du code retour
		vWebent = jwlwtcm2.getNwlwtcm2Axwebent();
		System.out.println("Code retour nwlwtcm2() = " + 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{
			Jwlwtcm2.Nwlwtcm2Awlwtcm2Info_retour infoRetour = jwlwtcm2.new Nwlwtcm2Awlwtcm2Info_retour();
			infoRetour = jwlwtcm2.getNwlwtcm2Awlwtcm2().info_retour;
			System.out.println("Message: "); ;
			System.out.println(" CODE-RET: " + infoRetour.code_ret.trim() ); ;
			System.out.println(" TYPE-RET: " + infoRetour.type_ret.trim() ); ;
			System.out.println(" LIB-RET : " + infoRetour.lib_ret.trim() ); ;
			
			vLwtcm2tabStock = jwlwtcm2.getNwlwtcm2Awlwtcm2().param.tab_stock ;
			for (int i = 0; i < vLwtcm2tabStock.length; i++) {
				System.out.println("borne_deb_imp:" + vLwtcm2tabStock[i].borne_deb_imp 
						+ " ; borne_deb_pair:" 		+ vLwtcm2tabStock[i].borne_deb_pair
						+ " ; borne_fin_imp:" 		+ vLwtcm2tabStock[i].borne_fin_imp
						+ " ; borne_fin_pair:" 		+ vLwtcm2tabStock[i].borne_fin_pair
						);
			}
		}
		return jwlwtcm2;
	   }
	
	
	/**
	 * <p>Titre : inverTroncon</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 * mode = M ou T
	 */
	public static Jwlwtcm2 inverTroncon(
		String mode,
		String tpo_id[],
		String cd_zpo,
		String type_portage,
		String tpr_groupe,
		String tpr_num,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtcm2 jwlwtcm2 		  = new Jwlwtcm2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtcm2.Nwlwtcm2Axwebent vWebent = jwlwtcm2.new Nwlwtcm2Axwebent();
		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 		  = null;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwtcm2.setNwlwtcm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtcm2.Nwlwtcm2Awlwtcm2 vLwtcm2 				= jwlwtcm2.new Nwlwtcm2Awlwtcm2();
		Jwlwtcm2.Nwlwtcm2Awlwtcm2Param vLwtcm2Param = jwlwtcm2.new Nwlwtcm2Awlwtcm2Param();
		
		vLwtcm2Param.mode 			= mode;
		vLwtcm2Param.cd_action 		= "I" ;
		vLwtcm2Param.cd_zpo 		= cd_zpo;
		vLwtcm2Param.type_portage 	= type_portage;
		vLwtcm2Param.tpr_groupe 	= tpr_groupe;
		vLwtcm2Param.tpr_num 		= tpr_num;
		
		Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock vLwtcm2tabStock[] = new Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock[TAILLE];
		for (int i = 0; i < TAILLE ; i++) {
			vLwtcm2tabStock[i] = jwlwtcm2.new Nwlwtcm2Awlwtcm2ParamTab_stock();
		}
		
		for (int i = 0; i < tpo_id.length; i++) {
			if(!"".equals(tpo_id[i]) && tpo_id[i]!=null)
				vLwtcm2tabStock[i].tpo_id = new BigDecimal(tpo_id[i]);
		}
		vLwtcm2Param.tab_stock = vLwtcm2tabStock;
		vLwtcm2.param = vLwtcm2Param;
		
		jwlwtcm2.setNwlwtcm2Awlwtcm2(vLwtcm2);
		
		// CALL SERVER
		jwlwtcm2.nwlwtcm2();
		
		// Verification du code retour
		vWebent = jwlwtcm2.getNwlwtcm2Axwebent();
		System.out.println("Code retour nwlwtcm2() = " + 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{
			Jwlwtcm2.Nwlwtcm2Awlwtcm2Info_retour infoRetour = jwlwtcm2.new Nwlwtcm2Awlwtcm2Info_retour();
			infoRetour = jwlwtcm2.getNwlwtcm2Awlwtcm2().info_retour;
			System.out.println("Message: "); ;
			System.out.println(" CODE-RET: " + infoRetour.code_ret.trim() ); ;
			System.out.println(" TYPE-RET: " + infoRetour.type_ret.trim() ); ;
			System.out.println(" LIB-RET : " + infoRetour.lib_ret.trim() ); ;
			
			vLwtcm2tabStock = jwlwtcm2.getNwlwtcm2Awlwtcm2().param.tab_stock ;
			for (int i = 0; i < vLwtcm2tabStock.length; i++) {
				System.out.println("borne_deb_imp:" + vLwtcm2tabStock[i].borne_deb_imp 
						+ " ; borne_deb_pair:" 		+ vLwtcm2tabStock[i].borne_deb_pair
						+ " ; borne_fin_imp:" 		+ vLwtcm2tabStock[i].borne_fin_imp
						+ " ; borne_fin_pair:" 		+ vLwtcm2tabStock[i].borne_fin_pair
						);
			}
		}
		
		return jwlwtcm2;
	   } 
	   
	//FIN  ordoION
	
	
	/**
	 * <p>Titre : modifTroncon</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 Jwlwtcm2 modifTroncon(
		String mode,
		String tpo_id[],
		String no_ordre[],
		String tpo_id_refer,
		String no_ordre_refer,
		String cd_zpo,
		String type_portage,
		String tpr_groupe,
		String tpr_num,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtcm2 jwlwtcm2 		  = new Jwlwtcm2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtcm2.Nwlwtcm2Axwebent vWebent = jwlwtcm2.new Nwlwtcm2Axwebent();
		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 		  = null;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwtcm2.setNwlwtcm2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwtcm2.Nwlwtcm2Awlwtcm2 vLwtcm2 				= jwlwtcm2.new Nwlwtcm2Awlwtcm2();
		Jwlwtcm2.Nwlwtcm2Awlwtcm2Param vLwtcm2Param 	= jwlwtcm2.new Nwlwtcm2Awlwtcm2Param();
		
		vLwtcm2Param.mode 			= mode;
		vLwtcm2Param.cd_action 		= "M" ;
		vLwtcm2Param.cd_zpo 		= cd_zpo;
		vLwtcm2Param.type_portage 	= type_portage;
		vLwtcm2Param.tpr_groupe 	= tpr_groupe;
		vLwtcm2Param.tpr_num 		= tpr_num;
		
		Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock vLwtcm2tabStock[] = new Jwlwtcm2.Nwlwtcm2Awlwtcm2ParamTab_stock[TAILLE];
		for (int i = 0; i < TAILLE ; i++) {
			vLwtcm2tabStock[i] = jwlwtcm2.new Nwlwtcm2Awlwtcm2ParamTab_stock();
		}
		
		for (int i = 0; i < tpo_id.length; i++) {
			if(!"".equals(tpo_id[i]) && tpo_id[i]!=null){
				vLwtcm2tabStock[i].tpo_id = new BigDecimal(tpo_id[i]);
			}
			if(!"".equals(no_ordre[i]) && no_ordre[i]!=null){
				vLwtcm2tabStock[i].no_ordre = new BigDecimal(no_ordre[i]);
			}
		}
//		if(!"".equals(tpo_id_refer) && tpo_id_refer!=null){
//			vLwtcm2Param.tpo_id_refer 	= new BigDecimal(tpo_id_refer);
		    vLwtcm2Param.tpo_id_refer 	= tpo_id_refer;
//		}
//		if(!"".equals(no_ordre_refer) && no_ordre_refer!=null){
//			vLwtcm2Param.no_ordre_refer = new BigDecimal(no_ordre_refer);
		    vLwtcm2Param.no_ordre_refer = no_ordre_refer;
//		}
		
		
		vLwtcm2Param.tab_stock = vLwtcm2tabStock;
		vLwtcm2.param = vLwtcm2Param;
		
		jwlwtcm2.setNwlwtcm2Awlwtcm2(vLwtcm2);
		
		// CALL SERVER
		jwlwtcm2.nwlwtcm2();
		
		// Verification du code retour
		vWebent = jwlwtcm2.getNwlwtcm2Axwebent();
		System.out.println("Code retour nwlwtcm2() = " + 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{
			Jwlwtcm2.Nwlwtcm2Awlwtcm2Info_retour infoRetour = jwlwtcm2.new Nwlwtcm2Awlwtcm2Info_retour();
			infoRetour = jwlwtcm2.getNwlwtcm2Awlwtcm2().info_retour;
			System.out.println("Message: "); ;
			System.out.println(" CODE-RET: " + infoRetour.code_ret.trim() ); ;
			System.out.println(" TYPE-RET: " + infoRetour.type_ret.trim() ); ;
			System.out.println(" LIB-RET : " + infoRetour.lib_ret.trim() ); ;
			
			vLwtcm2tabStock = jwlwtcm2.getNwlwtcm2Awlwtcm2().param.tab_stock ;
			for (int i = 0; i < vLwtcm2tabStock.length; i++) {
				System.out.println("borne_deb_imp:" + vLwtcm2tabStock[i].borne_deb_imp 
						+ " ; borne_deb_pair:" 		+ vLwtcm2tabStock[i].borne_deb_pair
						+ " ; borne_fin_imp:" 		+ vLwtcm2tabStock[i].borne_fin_imp
						+ " ; borne_fin_pair:" 		+ vLwtcm2tabStock[i].borne_fin_pair
						);
			}
		}
		
		return jwlwtcm2;
	   } 

	/**
		 * <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 ("MADAE01");
			JxweblogWeb.setPassword ("ENSOR18");
			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 ORDO
			//---------Donnee Test---------------
			/*String mode 		   = "M";
			String top_deplacement = "AP";
			String no_ordre_refer  = "0";
			String cd_zpo 		   = "ZR01";
			String type_portage    = "N";
			String tpr_groupe 	   = "9";
			String tpr_num 		   = "901";
			
			String[] tpo_id 	   = new String[]{"19184784"};
					
			//---------Donnee Test---------------
			ordoTroncon(mode, top_deplacement, no_ordre_refer,
					tpo_id, cd_zpo, type_portage, tpr_groupe, tpr_num,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			//Test de INVERSION
			//---------Donnee Test---------------
			/*String mode 		   = "M";
			String cd_zpo 		   = "ZR01";
			String type_portage    = "N";
			String tpr_groupe 	   = "9";
			String tpr_num 		   = "901";
			
			String[] tab_tpo_id 	   = new String[]{"19184783", "19184784", "19184785"};
					
			//---------Donnee Test---------------
			inverTroncon(mode, tab_tpo_id, cd_zpo, 
					type_portage, tpr_groupe, tpr_num, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			//Test de MODIFICATION
			//---------Donnee Test---------------
			String mode 		   = "M";
			String cd_zpo 		   = "0003";
			String type_portage    = "N";
			String tpr_groupe 	   = "5";
			String tpr_num 		   = "102";
			
			String[] tab_tpo_id    = new String[]{null};					
			String no_ordre[] 	   = new String[]{null};
			
			String tpo_id_refer    = null;
			String no_ordre_refer  = "0";
			
			//---------Donnee Test---------------
			modifTroncon(mode, tab_tpo_id, no_ordre, tpo_id_refer, no_ordre_refer, cd_zpo,type_portage, tpr_groupe, tpr_num, 
					     groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
		}
}