import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwcdm7Web</p>
 * <p>Description : Fiche commande catalogue.
 * </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>31/10/2012</i>
 * @version 1.0
 */
 
public class Jwlwcdm7Web {

	/**
	 * <p>Titre : getCommandeCatalogue</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>31/10/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm7 getCommandeCatalogue(
				String f_cd_cible,
				String f_id_cmd,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm7 jwlwcdm7 = new Jwlwcdm7(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm7.Nwlwcdm7Axwebent vWebent = jwlwcdm7.new Nwlwcdm7Axwebent();
		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;
		jwlwcdm7.setNwlwcdm7Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm7.Nwlwcdm7Awlwcdm7 vLwcdm7 					= jwlwcdm7.new Nwlwcdm7Awlwcdm7();
		Jwlwcdm7.Nwlwcdm7Awlwcdm7Demande vLwcdm7Demande = jwlwcdm7.new Nwlwcdm7Awlwcdm7Demande();
		vLwcdm7Demande.cd_cible   = f_cd_cible;
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm7Demande.id_cmd = new BigDecimal(f_id_cmd);
		}
	
		vLwcdm7.demande = vLwcdm7Demande;
		
		jwlwcdm7.setNwlwcdm7Awlwcdm7(vLwcdm7);
		
		// CALL SERVER
		jwlwcdm7.nwlwcdm7();
		
		// Verification du code retour
		vWebent = jwlwcdm7.getNwlwcdm7Axwebent();
		System.out.println("Code retour nwlwcdm7() = " + 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{
			//affichage de reponse
			Jwlwcdm7.Nwlwcdm7Awlwcdm7 jwlwcdm7Reponse = jwlwcdm7.getNwlwcdm7Awlwcdm7() ;
			Jwlwcdm7.Nwlwcdm7Awlwcdm7Reponse reponse  = jwlwcdm7Reponse.reponse;
			System.out.println("code_titre="+ reponse.code_titre) ;
			System.out.println("cd_cmd="	+ reponse.cd_cmd) ;
			System.out.println("type_cmd="	+ reponse.type_cmd) ;
			System.out.println("ordre="		+ reponse.ordre) ;
			System.out.println("libelle="	+ reponse.libelle) ;
			System.out.println("dt_maj="	+ reponse.dt_maj) ;
		}
		return jwlwcdm7;
	   } // End getCommandeCatalogue
	   
	//FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : deleteCommandeCatalogue</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>31/10/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm7 deleteCommandeCatalogue(
		String f_cd_cible,
		String f_id_cmd,
		String f_ordre,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm7 jwlwcdm7 		  = new Jwlwcdm7(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm7.Nwlwcdm7Axwebent vWebent = jwlwcdm7.new Nwlwcdm7Axwebent();
		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;
		jwlwcdm7.setNwlwcdm7Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm7.Nwlwcdm7Awlwcdm7 vLwcdm7 				= jwlwcdm7.new Nwlwcdm7Awlwcdm7();
		Jwlwcdm7.Nwlwcdm7Awlwcdm7Demande vLwcdm7Demande = jwlwcdm7.new Nwlwcdm7Awlwcdm7Demande();
		Jwlwcdm7.Nwlwcdm7Awlwcdm7Reponse vLwcdm7reponse = jwlwcdm7.new Nwlwcdm7Awlwcdm7Reponse();
		
		vLwcdm7Demande.cd_cible   = f_cd_cible;
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm7Demande.id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_ordre) && f_ordre!=null){
			vLwcdm7reponse.ordre = new BigDecimal(f_ordre);
		}
		
		vLwcdm7.reponse = vLwcdm7reponse;
		vLwcdm7.demande = vLwcdm7Demande;
		
		jwlwcdm7.setNwlwcdm7Awlwcdm7(vLwcdm7);
		
		// CALL SERVER
		jwlwcdm7.nwlwcdm7();
		
		// Verification du code retour
		vWebent = jwlwcdm7.getNwlwcdm7Axwebent();
		System.out.println("Code retour nwlwcdm7() = " + 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 jwlwcdm7;
	   } // End setCommandeCatalogue
	
	/**
	 * <p>Titre : createCommandeCatalogue</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>31/10/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm7 createCommandeCatalogue(
		String f_cd_cible,
		String f_id_cmd,
		String f_code_titre,
		String f_cd_cmd,
		String f_type_cmd,
		String f_libelle,
		String f_ordre,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm7 jwlwcdm7 		  = new Jwlwcdm7(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm7.Nwlwcdm7Axwebent vWebent = jwlwcdm7.new Nwlwcdm7Axwebent();
		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;
		jwlwcdm7.setNwlwcdm7Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
				Jwlwcdm7.Nwlwcdm7Awlwcdm7 vLwcdm7 				= jwlwcdm7.new Nwlwcdm7Awlwcdm7();
				Jwlwcdm7.Nwlwcdm7Awlwcdm7Demande vLwcdm7Demande = jwlwcdm7.new Nwlwcdm7Awlwcdm7Demande();
				Jwlwcdm7.Nwlwcdm7Awlwcdm7Reponse vLwcdm7reponse = jwlwcdm7.new Nwlwcdm7Awlwcdm7Reponse();
				
				vLwcdm7Demande.cd_cible   = f_cd_cible;
				if(!"".equals(f_id_cmd) && f_id_cmd!=null){
					vLwcdm7Demande.id_cmd = new BigDecimal(f_id_cmd);
				}
				
				vLwcdm7reponse.code_titre	= f_code_titre;
				vLwcdm7reponse.cd_cmd 		= f_cd_cmd;
				vLwcdm7reponse.type_cmd 	= f_type_cmd;
				vLwcdm7reponse.libelle 		= f_libelle;
				if(!"".equals(f_ordre) && f_ordre!=null){
					vLwcdm7reponse.ordre 		= new BigDecimal(f_ordre);
				}
				
				vLwcdm7.reponse = vLwcdm7reponse;
				vLwcdm7.demande = vLwcdm7Demande;
		jwlwcdm7.setNwlwcdm7Awlwcdm7(vLwcdm7);
		
		// CALL SERVER
		jwlwcdm7.nwlwcdm7();
		
		// Verification du code retour
		vWebent = jwlwcdm7.getNwlwcdm7Axwebent();
		System.out.println("Code retour nwlwcdm7() = " + 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 jwlwcdm7;
	   } // End createCommandeCatalogue
	
	   /**
	 * <p>Titre : deleteCommandeCatalogue</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>31/10/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm7 setCommandeCatalogue(
		String f_cd_cible,
		String f_id_cmd,
		String f_libelle,
		String f_ordre,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm7 jwlwcdm7 		  = new Jwlwcdm7(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm7.Nwlwcdm7Axwebent vWebent = jwlwcdm7.new Nwlwcdm7Axwebent();
		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;
		jwlwcdm7.setNwlwcdm7Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm7.Nwlwcdm7Awlwcdm7 vLwcdm7 				= jwlwcdm7.new Nwlwcdm7Awlwcdm7();
		Jwlwcdm7.Nwlwcdm7Awlwcdm7Demande vLwcdm7Demande = jwlwcdm7.new Nwlwcdm7Awlwcdm7Demande();
		Jwlwcdm7.Nwlwcdm7Awlwcdm7Reponse vLwcdm7reponse = jwlwcdm7.new Nwlwcdm7Awlwcdm7Reponse();
		
		vLwcdm7Demande.cd_cible   = f_cd_cible;
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm7Demande.id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_ordre) && f_ordre!=null){
			vLwcdm7reponse.ordre = new BigDecimal(f_ordre);
		}
		vLwcdm7reponse.libelle = f_libelle ;
		vLwcdm7.reponse = vLwcdm7reponse;
		vLwcdm7.demande = vLwcdm7Demande;
		
		jwlwcdm7.setNwlwcdm7Awlwcdm7(vLwcdm7);
		
		// CALL SERVER
		jwlwcdm7.nwlwcdm7();
		
		// Verification du code retour
		vWebent = jwlwcdm7.getNwlwcdm7Axwebent();
		System.out.println("Code retour nwlwcdm7() = " + 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 jwlwcdm7;
	   } // End setCommandeCatalogue
	
	   /**
		 * <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>31/10/2012</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA62");
			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 f_cd_cible = "50";
			String f_id_cmd   = "592";
			String f_libelle= "TEST MODIF" ;
			String f_ordre= "1" ;
			//--------------------Donnee test------------------
			getCommandeCatalogue(f_cd_cible, f_id_cmd,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			setCommandeCatalogue(f_cd_cible, f_id_cmd, f_libelle, f_ordre,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker) ;
			
			getCommandeCatalogue(f_cd_cible, f_id_cmd,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			//Test de CREATION
			//--------------------Donnee test------------------
			/*String f_cd_cible 	= "50";
			String f_id_cmd  	= "674";
			String code_titre	= "FIQ";
			String cd_cmd	 	= "TEXPPORT";
			String type_cmd		= "P";
			String libelle		= "Expedition POSTE";
			String ordre = null ;
			
			//--------------------Donnee test------------------
			/*createCommandeCatalogue(
					f_cd_cible, f_id_cmd,
					code_titre, cd_cmd, type_cmd, libelle, ordre,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
			getCommandeCatalogue(f_cd_cible, f_id_cmd,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			
			/*
			//Test de SUPPRESSION
			//--------------------Donnee test------------------
			/*String f_cd_cible 	= "50";
			String f_id_cmd  	= "759";
			String f_ordre		= "0";
			
			//--------------------Donnee test------------------
			deleteCommandeCatalogue(
					f_cd_cible, f_id_cmd, f_ordre,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			getCommandeCatalogue(f_cd_cible, f_id_cmd,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
		}			
}