import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwzom3Web</p>
 * <p>Description : Mise a jour  prestataires par zone portage.
 * </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 Jwlwzom3Web {
	private static final int TAILLE = 50;

	/**
	 * <p>Titre : creatPrestataire</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 Jwlwzom3 creatPrestataire(
				String i_cd_titre_crea,
				String i_cd_zpo_crea,
				String i_type_portage_crea,
				String i_type_trt_crea,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom3 jwlwzom3 = new Jwlwzom3(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom3.Nwlwzom3Axwebent vWebent = jwlwzom3.new Nwlwzom3Axwebent();
		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 		  = "CREAT";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwzom3.setNwlwzom3Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom3.Nwlwzom3Awlwzom3 vLwzom3 					= jwlwzom3.new Nwlwzom3Awlwzom3();
		Jwlwzom3.Nwlwzom3Awlwzom3Creation vLwzom3create = jwlwzom3.new Nwlwzom3Awlwzom3Creation();
		vLwzom3create.i_cd_titre_crea   	  = i_cd_titre_crea;
		vLwzom3create.i_cd_zpo_crea	          = i_cd_zpo_crea;
		vLwzom3create.i_type_portage_crea	  = i_type_portage_crea;
		vLwzom3create.i_type_trt_crea	      = i_type_trt_crea;
		vLwzom3.creation = vLwzom3create;
		
		jwlwzom3.setNwlwzom3Awlwzom3(vLwzom3);
		
		// CALL SERVER
		jwlwzom3.nwlwzom3();
		
		// Verification du code retour
		vWebent = jwlwzom3.getNwlwzom3Axwebent();
		System.out.println("Code retour nwlwzom3() = " + 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());
			//affichage de reponse
			System.out.println("suite normal...");
		}
		return jwlwzom3;
	   } // End getPrestataire
	   
	//FIN  CREATION
	
	
	/**
	 * <p>Titre : setPrestataire</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 Jwlwzom3 setPrestataire(
		String i_cd_titre[],
		String i_cd_zpo[],
		String i_type_portage[],
		String i_type_trt[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom3 jwlwzom3 		  = new Jwlwzom3(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom3.Nwlwzom3Axwebent vWebent = jwlwzom3.new Nwlwzom3Axwebent();
		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 		  = "MODIF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwzom3.setNwlwzom3Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom3.Nwlwzom3Awlwzom3 vLwzom3 				= jwlwzom3.new Nwlwzom3Awlwzom3();
		Jwlwzom3.Nwlwzom3Awlwzom3Maj vLwzom3Maj		    = jwlwzom3.new Nwlwzom3Awlwzom3Maj();
		
		String tab_i_cd_titre[] = new String[TAILLE];
		String tab_i_cd_zpo[] = new String[TAILLE];
		String tab_i_type_portage[] = new String[TAILLE];
		String tab_i_type_trt[] = new String[TAILLE];
		
		for (int i = 0; i < i_cd_titre.length; i++) {
			tab_i_cd_titre[i] = i_cd_titre[i];
		}
		for (int i = 0; i < i_cd_zpo.length; i++) {
			tab_i_cd_zpo[i] = i_cd_zpo[i];
		}
		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_type_trt.length; i++) {
			tab_i_type_trt[i] = i_type_trt[i];
		}
		
		vLwzom3Maj.i_cd_titre     = tab_i_cd_titre;
		vLwzom3Maj.i_cd_zpo       = tab_i_cd_zpo;
		vLwzom3Maj.i_type_portage = tab_i_type_portage;
		vLwzom3Maj.i_type_trt     = tab_i_type_trt;
		
		vLwzom3.maj = vLwzom3Maj;
		
		jwlwzom3.setNwlwzom3Awlwzom3(vLwzom3);
		
		// CALL SERVER
		jwlwzom3.nwlwzom3();
		
		// Verification du code retour
		vWebent = jwlwzom3.getNwlwzom3Axwebent();
		System.out.println("Code retour nwlwzom3() = " + 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 jwlwzom3;
	   } // End setPrestataire
	   
	   //FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : setPrestataire</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 Jwlwzom3 deletePrestataire(
		String i_cd_titre[],
		String i_cd_zpo[],
		String i_type_portage[],
		String i_type_trt[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom3 jwlwzom3 		  = new Jwlwzom3(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom3.Nwlwzom3Axwebent vWebent = jwlwzom3.new Nwlwzom3Axwebent();
		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 		  = "SUPP";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwzom3.setNwlwzom3Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom3.Nwlwzom3Awlwzom3 vLwzom3 	   = jwlwzom3.new Nwlwzom3Awlwzom3();
		Jwlwzom3.Nwlwzom3Awlwzom3Maj vLwzom3Maj= jwlwzom3.new Nwlwzom3Awlwzom3Maj();
		
		String tab_i_cd_titre[] = new String[TAILLE];
		String tab_i_cd_zpo[] = new String[TAILLE];
		String tab_i_type_portage[] = new String[TAILLE];
		String tab_i_type_trt[] = new String[TAILLE];
		
		for (int i = 0; i < i_cd_titre.length; i++) {
			tab_i_cd_titre[i] = i_cd_titre[i];
		}
		for (int i = 0; i < i_cd_zpo.length; i++) {
			tab_i_cd_zpo[i] = i_cd_zpo[i];
		}
		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_type_trt.length; i++) {
			tab_i_type_trt[i] = i_type_trt[i];
		}
		
		vLwzom3Maj.i_cd_titre     = tab_i_cd_titre;
		vLwzom3Maj.i_cd_zpo       = tab_i_cd_zpo;
		vLwzom3Maj.i_type_portage = tab_i_type_portage;
		vLwzom3Maj.i_type_trt     = tab_i_type_trt;
		
		vLwzom3.maj = vLwzom3Maj;
		
		jwlwzom3.setNwlwzom3Awlwzom3(vLwzom3);
	
		// CALL SERVER
		jwlwzom3.nwlwzom3();
		
		// Verification du code retour
		vWebent = jwlwzom3.getNwlwzom3Axwebent();
		System.out.println("Code retour nwlwzom3() = " + 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 jwlwzom3;
	   } // End setPrestataire			

	/**
		 * <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 CREATION
			//---------Donnee Test---------------
			/*String i_cd_titre_crea  	   = "MIP";
			String i_cd_zpo_crea 		   = "ZZZZ";
			String i_type_portage_crea 	   = "N";
			String i_type_trt_crea 		   = "N";
			//---------Donnee Test---------------
			creatPrestataire(i_cd_titre_crea, i_cd_zpo_crea,
					i_type_portage_crea, i_type_trt_crea, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
			//Test de MODIFICATION
			//---------Donnee Test---------------
			String i_cd_titre[] 	= new String[TAILLE];
			String i_cd_zpo[] 		= new String[TAILLE];
			String i_type_portage[] = new String[TAILLE];
			String i_type_trt[] 	= new String[TAILLE];
			i_cd_titre[0] 	 = "EQU";
			i_cd_zpo[0] 	 = "MOMO";
			i_type_portage[0]= "N";
			i_type_trt[0] 	 = "R";
			//---------Donnee Test---------------
			setPrestataire(i_cd_titre, i_cd_zpo, i_type_portage, i_type_trt,
						groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			//Test de SUPPRESSION
			//---------Donnee Test---------------
			/*String i_cd_titre[] 	= new String[TAILLE];
			String i_cd_zpo[] 		= new String[TAILLE];
			String i_type_portage[] = new String[TAILLE];
			String i_type_trt[] 	= new String[TAILLE];
			String i_action[] 		= new String[TAILLE];
			i_cd_titre[0] = "MIP";
			i_cd_zpo[0] = "ZZZZ";
			i_type_portage[0] = "N";
			i_type_trt[0] = "R";
			i_action[0] = "S";
			//---------Donnee Test---------------
			deletePrestataire(i_cd_titre, i_cd_zpo, i_type_portage, i_type_trt,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
				
		}

	//FIN  INTERROGATION

}