import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwtpm1Web</p>
 * <p>Description : Mise à jours type prestataire </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author  PY <i>18/05/2012</i>
 * @version 1.0
 */
public class Jwlwtpm1Web {	
	/**
	 * <p>Titre : getTypePrestataire</p>
	 * <p>Description : sélection d'un type prestataire </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author  PY <i>18/05/2012</i>
	 * @version 1.0
	 */
	public static Jwlwtpm1 getTypePrestataire(
			String code_tpe,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtpm1 jwlwtpm1 = new Jwlwtpm1(broker, Constantes.SERVER_ADRESSE);
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtpm1.Nwlwtpm1Axwebent vWebent = jwlwtpm1.new Nwlwtpm1Axwebent();
		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       = "WLWCLLST";
		vWebent.fonction          = "VISU";
		vWebent.cd_cible          = cd_cible;
		vWebent.cd_stegrp         = cd_stegrp;
		vWebent.cd_application    = Constantes.CD_APPLICATION;
		jwlwtpm1.setNwlwtpm1Axwebent (vWebent);
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwtpm1.Nwlwtpm1Awlwtpm1 vLwtpm1 = jwlwtpm1.new Nwlwtpm1Awlwtpm1();
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Demande demande = jwlwtpm1.new Nwlwtpm1Awlwtpm1Demande();
		Jwlwtpm1.Nwlwtpm1Awlwtpm1DemandeCritere_select select = jwlwtpm1.new Nwlwtpm1Awlwtpm1DemandeCritere_select();
		select.cd_tpe = code_tpe;
		demande.critere_select = select;
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Reponse reponse = jwlwtpm1.new Nwlwtpm1Awlwtpm1Reponse();
		
		vLwtpm1.demande		   = demande;
		vLwtpm1.reponse 	   = reponse;
		jwlwtpm1.setNwlwtpm1Awlwtpm1(vLwtpm1);
		
		// CALL SERVER
		jwlwtpm1.nwlwtpm1();
		
		// Verification du code retour
		vWebent = jwlwtpm1.getNwlwtpm1Axwebent();
		System.out.println("Code retour nwlwtpm1() = " + 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 ("... Affichage de Reponse ...");
			System.out.println(" code_tpe = "		+reponse.code_tpe);
			System.out.println(" cd_tdi = "			+reponse.cd_tdi.intValue());
			System.out.println(" tpe_libelle = "	+reponse.tpe_libelle);
			System.out.println(" tpe_support = "	+reponse.tpe_support);
			System.out.println(" tpe_ind_coiffe = "	+reponse.tpe_ind_coiffe);
		}
		return jwlwtpm1;
	}
	/**
	 * <p>Titre : deleteTypePrestataire</p>
	 * <p>Description : Suppression d'un type prestataire </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author  PY <i>18/05/2012</i>
	 * @version 1.0
	 */
	public static Jwlwtpm1 deleteTypePrestataire(
			String cd_tpe,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
		    Jwlwtpm1 jwlwtpm1 = new Jwlwtpm1(broker, Constantes.SERVER_ADRESSE);
				
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwtpm1.Nwlwtpm1Axwebent vWebent = jwlwtpm1.new Nwlwtpm1Axwebent();
			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       = "WLWCLLST";
			vWebent.fonction          = "SUPPR";
			vWebent.cd_cible          = cd_cible;
			vWebent.cd_stegrp         = cd_stegrp;
			vWebent.cd_application    = Constantes.CD_APPLICATION;
			jwlwtpm1.setNwlwtpm1Axwebent (vWebent);
			
			// Initialisation de la demande (tous à vide pour l'instant)
			Jwlwtpm1.Nwlwtpm1Awlwtpm1 vLwtpm1 = jwlwtpm1.new Nwlwtpm1Awlwtpm1();
			Jwlwtpm1.Nwlwtpm1Awlwtpm1Demande demande = jwlwtpm1.new Nwlwtpm1Awlwtpm1Demande();
			Jwlwtpm1.Nwlwtpm1Awlwtpm1DemandeCritere_select select = jwlwtpm1.new Nwlwtpm1Awlwtpm1DemandeCritere_select();
			select.cd_tpe 		   = cd_tpe;
			demande.critere_select = select;
			vLwtpm1.demande 	   = demande;
			jwlwtpm1.setNwlwtpm1Awlwtpm1(vLwtpm1);
			
			// CALL SERVER
			jwlwtpm1.nwlwtpm1();
			
			// Verification du code retour
			vWebent = jwlwtpm1.getNwlwtpm1Axwebent();
			System.out.println("Code retour nwlwtpm1() = " + 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 ("Suite normale");
			}
			return jwlwtpm1;
		   } // End setTypesPrestataire

	/**
	 * <p>Titre : setTypePrestataire</p>
	 * <p>Description : Modification d'un type prestataire </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author  PY <i>18/05/2012</i>
	 * @version 1.0
	 */
	public static Jwlwtpm1 setTypePrestataire(
			String code_tpe,
			String cd_tdi,
			String tpe_libelle,
			String tpe_support,
			String tpe_ind_coiffe,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtpm1 jwlwtpm1 = new Jwlwtpm1(broker, Constantes.SERVER_ADRESSE);
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtpm1.Nwlwtpm1Axwebent vWebent = jwlwtpm1.new Nwlwtpm1Axwebent();
		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       = "WLWCLLST";
		vWebent.fonction          = "MODIF";
		vWebent.cd_cible          = cd_cible;
		vWebent.cd_stegrp         = cd_stegrp;
		vWebent.cd_application    = Constantes.CD_APPLICATION;
		jwlwtpm1.setNwlwtpm1Axwebent (vWebent);
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwtpm1.Nwlwtpm1Awlwtpm1 vLwtpm1 = jwlwtpm1.new Nwlwtpm1Awlwtpm1();
		
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Demande demande = jwlwtpm1.new Nwlwtpm1Awlwtpm1Demande();
		Jwlwtpm1.Nwlwtpm1Awlwtpm1DemandeCritere_select select = jwlwtpm1.new Nwlwtpm1Awlwtpm1DemandeCritere_select();
		select.cd_tpe = code_tpe;
		demande.critere_select = select;
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Reponse reponse = jwlwtpm1.new Nwlwtpm1Awlwtpm1Reponse();

		if(!"".equals(cd_tdi) && cd_tdi!=null){
			reponse.cd_tdi 	   = new BigDecimal(cd_tdi);
		}
		reponse.tpe_libelle    = tpe_libelle;
		reponse.tpe_support    = tpe_support;
		reponse.tpe_ind_coiffe = tpe_ind_coiffe;
		
		vLwtpm1.demande		   = demande;
		vLwtpm1.reponse 	   = reponse;
		jwlwtpm1.setNwlwtpm1Awlwtpm1(vLwtpm1);
		
		// CALL SERVER
		jwlwtpm1.nwlwtpm1();
		
		// Verification du code retour
		vWebent = jwlwtpm1.getNwlwtpm1Axwebent();
		System.out.println("Code retour nwlwtpm1() = " + 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 ("Suite normale");
		}
		return jwlwtpm1;
	}
	/**
	 * <p>Titre : createTypePrestataire</p>
	 * <p>Description : création d'un type prestataire </p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author  PY <i>18/05/2012</i>
	 * @version 1.0
	 */
	public static Jwlwtpm1 createTypePrestataire(
			String code_tpe,
			String cd_tdi,
			String tpe_libelle,
			String tpe_support,
			String tpe_ind_coiffe,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwtpm1 jwlwtpm1 = new Jwlwtpm1(broker, Constantes.SERVER_ADRESSE);
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwtpm1.Nwlwtpm1Axwebent vWebent = jwlwtpm1.new Nwlwtpm1Axwebent();
		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       = "WLWCLLST";
		vWebent.fonction          = "CREAT";
		vWebent.cd_cible          = cd_cible;
		vWebent.cd_stegrp         = cd_stegrp;
		vWebent.cd_application    = Constantes.CD_APPLICATION;
		jwlwtpm1.setNwlwtpm1Axwebent (vWebent);
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwtpm1.Nwlwtpm1Awlwtpm1 vLwtpm1 = jwlwtpm1.new Nwlwtpm1Awlwtpm1();
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Demande demande = jwlwtpm1.new Nwlwtpm1Awlwtpm1Demande();
		Jwlwtpm1.Nwlwtpm1Awlwtpm1DemandeCritere_select select = jwlwtpm1.new Nwlwtpm1Awlwtpm1DemandeCritere_select();
		select.cd_tpe = code_tpe;
		demande.critere_select = select;
		Jwlwtpm1.Nwlwtpm1Awlwtpm1Reponse reponse = jwlwtpm1.new Nwlwtpm1Awlwtpm1Reponse();

		if(!"".equals(cd_tdi) && cd_tdi!=null){
			reponse.cd_tdi 	   = new BigDecimal(cd_tdi);
		}
		reponse.tpe_libelle    = tpe_libelle;
		reponse.tpe_support    = tpe_support;
		reponse.tpe_ind_coiffe = tpe_ind_coiffe;
		
		vLwtpm1.demande		   = demande;
		vLwtpm1.reponse 	   = reponse;
		jwlwtpm1.setNwlwtpm1Awlwtpm1(vLwtpm1);
		
		// CALL SERVER
		jwlwtpm1.nwlwtpm1();
		
		// Verification du code retour
		vWebent = jwlwtpm1.getNwlwtpm1Axwebent();
		System.out.println("Code retour nwlwtpm1() = " + 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 ("Suite normale");
		}
		return jwlwtpm1;
	}
	   
	   /**
		 * <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 ("MADAA01");
			JxweblogWeb.setPassword ("MADAA01");
			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;
			
			
			//Constructeur TEST CREATION
			//System.out.println("DEBUT TEST CREATION : type prestataire .................") ;
			/*//---------------Debut données test--------------------------
			String code_tpe		 = "80";
			String cd_tdi		 = "003";
			String tpe_libelle	 = "Diffuseur";
			String tpe_support	 = "journal";
			String tpe_ind_coiffe= "O";
			//---------------Fin données test--------------------------
			createTypePrestataire(code_tpe, cd_tdi, tpe_libelle, tpe_support, tpe_ind_coiffe,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			
			
			//Constructeur TEST MODIFICATION
			System.out.println("DEBUT TEST MODIFICATION : type prestataire .................") ;
			//---------------Debut données test--------------------------
			String code_tpe		 = "TESTZA";
			String cd_tdi		 = "006";
			String tpe_libelle	 = "DiffuseurPap";
			String tpe_support	 = "journalpap";
			String tpe_ind_coiffe= "N";
			//---------------Fin données test--------------------------
			setTypePrestataire(code_tpe, cd_tdi, tpe_libelle, tpe_support, tpe_ind_coiffe,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			
			//Constructeur TEST INTERROGATION
			System.out.println("DEBUT TEST INTERROGATION : type prestataire .................") ;
			//---------------Debut données test--------------------------
			String code_tpe_verif		 = "TESTZA";
			//---------------Fin données test--------------------------
			getTypePrestataire(code_tpe_verif, groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			
			//Constructeur TEST SUPPRESSION
			/*System.out.println("DEBUT TEST SUPPRESSION : type prestataire .................") ;
			//---------------Debut données test--------------------------
			String cd_tpe		 = "80";
			//---------------Fin données test--------------------------
			deleteTypePrestataire(cd_tpe, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			
			System.out.println("...Fin de test ...");
		}
			
}