
import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwstm1Web</p>
 * <p>Description : Classe de ajout, modification, suppression d'un suivi terrain</p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>25/03/2012</i>
 * @version 1.0
 */
public class Jwlwstm1Web {	

		/**
		 * <p>Titre : setReponseSuiviTerrain</p>
		 * <p>Description : Modification d'un suivi terrain</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 Jwlwstm1 setReponseSuiviTerrain(
			String cd_cible_1,
	        String num_cli,
	        String id_suivi,
	        String cd_reponse,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {						
		// Initialisation des variables en entrees
	    Jwlwstm1 jwlwstm1 = new Jwlwstm1(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwstm1.Nwlwstm1Axwebent vWebent = jwlwstm1.new Nwlwstm1Axwebent();
		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;
		jwlwstm1.setNwlwstm1Axwebent (vWebent);
	        
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwstm1.Nwlwstm1Awlwstm1 vLwdim2 = jwlwstm1.new Nwlwstm1Awlwstm1();
		//vLwdim2.fonction = fonction;
		Jwlwstm1.Nwlwstm1Awlwstm1Cle_suivi vLwdim2Demande = jwlwstm1.new Nwlwstm1Awlwstm1Cle_suivi();	
		vLwdim2Demande.cd_cible = cd_cible_1;
		if(!"".equals(num_cli) && num_cli!=null){
			num_cli = Utils.transformNumClient(num_cli) ;
		}
		vLwdim2Demande.num_cli = num_cli;
		if(!"".equals(id_suivi) && id_suivi!=null){
			vLwdim2Demande.id_suivi = new BigDecimal(id_suivi);
		}
		vLwdim2Demande.cd_reponse = cd_reponse;
		vLwdim2.cle_suivi 		  = vLwdim2Demande;
		jwlwstm1.setNwlwstm1Awlwstm1(vLwdim2);
			
		// CALL SERVER
		jwlwstm1.nwlwstm1();
			                                
	    // Verification du code retour
		vWebent = jwlwstm1.getNwlwstm1Axwebent();
		System.out.println("Code retour nwlwstm1() = " + 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("DEBUT.................") ;
			Jwlwstm1.Nwlwstm1Awlwstm1 Jwlwstm1Reponse = jwlwstm1.getNwlwstm1Awlwstm1() ;
			Jwlwstm1.Nwlwstm1Awlwstm1Cle_suivi cle_suivi = Jwlwstm1Reponse.cle_suivi ;
			System.out.println("CD-CIBLE="  + cle_suivi.cd_cible   + "\n") ;
			System.out.println("NUM-CLI="   + cle_suivi.num_cli    + "\n") ;
			System.out.println("ID-SUIVI="  + cle_suivi.id_suivi   + "\n") ;
			System.out.println("CD-REPONSE="+ cle_suivi.cd_reponse + "\n") ;
			
			System.out.println("FIN.................") ;
		}
			
		return jwlwstm1;
	   } // End setReponseSuiviTerrain

		/**
		 * <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;
			Jwlwstm1 jwlwstm1 		 = setReponseSuiviTerrain ("08", "5/124758", "434", "PORT", 
										groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp,broker);
				//retour
			Jwlwstm1.Nwlwstm1Awlwstm1 Jwlwstm1Reponse = jwlwstm1.getNwlwstm1Awlwstm1() ;
			Jwlwstm1.Nwlwstm1Awlwstm1Cle_suivi cle_suivi = Jwlwstm1Reponse.cle_suivi ;
			System.out.println("CD-CIBLE="	+ cle_suivi.cd_cible   + "\n") ;
			System.out.println("NUM-CLI="	+ cle_suivi.num_cli    + "\n") ;
			System.out.println("ID-SUIVI="	+ cle_suivi.id_suivi   + "\n") ;
			System.out.println("CD-REPONSE="+ cle_suivi.cd_reponse + "\n") ;
			
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} 