import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwcdm8Web</p>
 * <p>Description : Mise a jour des criteres d une sous commande.
 * </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>17/09/2012</i>
 * @version 1.0
 */
 
public class Jwlwcdm8Web {

	/**
	 * <p>Titre : getCritereSousCommande</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>17/09/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm8 getCritereSousCommande(
				String f_cd_cible,
				String f_id_cmd,
				String f_id_sscmd,
				String f_id_critere,
				String f_code,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm8 jwlwcdm8 = new Jwlwcdm8(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm8.Nwlwcdm8Axwebent vWebent = jwlwcdm8.new Nwlwcdm8Axwebent();
		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;
		jwlwcdm8.setNwlwcdm8Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm8.Nwlwcdm8Awlwcdm8 vLwcdm8 					= jwlwcdm8.new Nwlwcdm8Awlwcdm8();
		Jwlwcdm8.Nwlwcdm8Awlwcdm8Demande vLwcdm8Demande = jwlwcdm8.new Nwlwcdm8Awlwcdm8Demande();
		vLwcdm8Demande.f_cd_cible   = f_cd_cible;
		vLwcdm8Demande.f_code   	= f_code;
		
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm8Demande.f_id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_id_sscmd) && f_id_sscmd!=null){
			vLwcdm8Demande.f_id_sscmd = new BigDecimal(f_id_sscmd);
		}
		if(!"".equals(f_id_critere) && f_id_critere!=null){
			vLwcdm8Demande.f_id_critere = new BigDecimal(f_id_critere);
		}
		
		vLwcdm8.demande = vLwcdm8Demande;
		
		jwlwcdm8.setNwlwcdm8Awlwcdm8(vLwcdm8);
		
		// CALL SERVER
		jwlwcdm8.nwlwcdm8();
		
		// Verification du code retour
		vWebent = jwlwcdm8.getNwlwcdm8Axwebent();
		System.out.println("Code retour nwlwcdm8() = " + 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
			Jwlwcdm8.Nwlwcdm8Awlwcdm8 jwlwcdm8Reponse = jwlwcdm8.getNwlwcdm8Awlwcdm8() ;
			Jwlwcdm8.Nwlwcdm8Awlwcdm8Reponse reponse  = jwlwcdm8Reponse.reponse;
			System.out.println("cd_critere=" 	  + reponse.cd_critere) ;
			System.out.println("lib_critere="	  + reponse.lib_critere) ;
			System.out.println("val_critere="	  + reponse.val_critere) ;
			System.out.println("lib_val_critere=" + reponse.lib_val_critere) ;
		}
		return jwlwcdm8;
	   } // End getCritereSousCommande
	   
	//FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : setCritereSousCommande</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>17/09/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm8 setCritereSousCommande(
		String fonction,
		String f_cd_cible,
		String f_id_cmd,
		String f_id_sscmd,
		String f_id_critere,
		String f_code,
		String cd_critere,
		String val_critere,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm8 jwlwcdm8 		  = new Jwlwcdm8(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm8.Nwlwcdm8Axwebent vWebent = jwlwcdm8.new Nwlwcdm8Axwebent();
		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;
		jwlwcdm8.setNwlwcdm8Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm8.Nwlwcdm8Awlwcdm8 vLwcdm8 				= jwlwcdm8.new Nwlwcdm8Awlwcdm8();
		Jwlwcdm8.Nwlwcdm8Awlwcdm8Demande vLwcdm8Demande = jwlwcdm8.new Nwlwcdm8Awlwcdm8Demande();
		Jwlwcdm8.Nwlwcdm8Awlwcdm8Reponse vLwcdm8reponse = jwlwcdm8.new Nwlwcdm8Awlwcdm8Reponse();
		
		vLwcdm8Demande.f_cd_cible  = f_cd_cible;
		vLwcdm8Demande.f_code      = f_code;
		
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm8Demande.f_id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_id_sscmd) && f_id_sscmd!=null){
			vLwcdm8Demande.f_id_sscmd = new BigDecimal(f_id_sscmd);
		}
		if(!"".equals(f_id_critere) && f_id_critere!=null){
			vLwcdm8Demande.f_id_critere = new BigDecimal(f_id_critere);
		}
		
		vLwcdm8reponse.cd_critere	 	= cd_critere;
		vLwcdm8reponse.val_critere	 	= val_critere;
		
		vLwcdm8.reponse = vLwcdm8reponse;
		vLwcdm8.demande = vLwcdm8Demande;
		
		jwlwcdm8.setNwlwcdm8Awlwcdm8(vLwcdm8);
		
		// CALL SERVER
		jwlwcdm8.nwlwcdm8();
		
		// Verification du code retour
		vWebent = jwlwcdm8.getNwlwcdm8Axwebent();
		System.out.println("Code retour nwlwcdm8() = " + 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 jwlwcdm8;
	   } // End setCritereSousCommande
	   
	   /**
		 * <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 ("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 INTEROGATION
			//---------Donnee Test---------------
			/*String f_cd_cible   = "50";
			String f_id_cmd     = "673";
			String f_id_sscmd   = "13";
			String f_id_critere = "9";
			String f_code 		= null;
			//---------Donnee Test---------------
			getCritereSousCommande( f_cd_cible, f_id_cmd, f_id_sscmd, f_id_critere,f_code, 
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
			
			//Test de CREATION
			//---------Donnee Test---------------
			
			String fonction 		 = "CREAT";
			String f_cd_cible 	 	 = "50";
			String f_id_cmd 	 	 = "918";
			String f_id_sscmd 	     = "3";
			String f_id_critere  	 = null;
			String f_cd_critere 	 = "RCCODEPOSTAL" ;
			String f_val_critere 	 = "1234";
			String f_code 	 		 = null;
			//---------Donnee Test---------------
			
			setCritereSousCommande(fonction,
					f_cd_cible, f_id_cmd, f_id_sscmd, f_id_critere,
					f_code, f_cd_critere, f_val_critere,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
		}			
}