
import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwstm2Web</p>
 * <p>Description : Classe de ajout, modification, suppression d'un suivi terrain</p>
 * <p>Copyright : Copyright (c) 2009</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR <i>25/10/2011</i>
 * @version 1.0
 */
public class Jwlwstm2Web {	

		/**
		 * <p>Titre : getInfosSuiviTerrain</p>
		 * <p>Description : Visualisation d'un suivi terrain</p>
		 * <p>Copyright : Copyright (c) 2011</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR <i>25/10/2011</i>
		 * @version 1.0
		 */
		public static Jwlwstm2 getInfosSuiviTerrain(
			String cd_cible_1,
			String num_cli,
			String stegrp,
			String id_suivi,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {						
		// Initialisation des variables en entrees
	    Jwlwstm2 jwlwstm2 = new Jwlwstm2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwstm2.Nwlwstm2Axwebent vWebent = jwlwstm2.new Nwlwstm2Axwebent();
		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;
		jwlwstm2.setNwlwstm2Axwebent (vWebent);
	        
		// Initialisation de la demande (tous à vide pour l'instant)
		Jwlwstm2.Nwlwstm2Awlwstm2 vLwstm2 				  = jwlwstm2.new Nwlwstm2Awlwstm2();
		Jwlwstm2.Nwlwstm2Awlwstm2Cle_suivi vLwstm2Demande = jwlwstm2.new Nwlwstm2Awlwstm2Cle_suivi();
		vLwstm2Demande.cd_cible = cd_cible_1;
		if(!"".equals(num_cli) && num_cli!=null){
			System.out.println("num_cli avant = " + num_cli);
			num_cli = Utils.transformNumClient(num_cli) ;
			System.out.println("num_cli après = " + num_cli);
		}
		vLwstm2Demande.num_cli = num_cli;
		vLwstm2Demande.cd_stegrp = stegrp;
		if(!"".equals(id_suivi) && id_suivi!=null){
			vLwstm2Demande.id_suivi = new BigDecimal(id_suivi);
		}
		vLwstm2.cle_suivi = vLwstm2Demande;
		
		jwlwstm2.setNwlwstm2Awlwstm2(vLwstm2);
			
		// CALL SERVER
		jwlwstm2.nwlwstm2();
			                                
	    // Verification du code retour
		vWebent = jwlwstm2.getNwlwstm2Axwebent();
		System.out.println("Code retour nwlwstm2() = " + 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() + "'");
		   	}
			
			/*Jwlwstm2.Nwlwstm2Axgsterr nwlwstm2Aagfterr = jwlwstm2.new Nwlwstm2Axgsterr();
			nwlwstm2Aagfterr = jwlwstm2.getNwlwstm2Axgsterr();
			for(int i=0; i < nwlwstm2Aagfterr.nb_ano; i++){
			   System.out.println(nwlwstm2Aagfterr.tab_ano[i].code_ano + "[" + nwlwstm2Aagfterr.tab_ano[i].type_ano + "] : '" + nwlwstm2Aagfterr.tab_ano[i].lib_ano.trim() + "'");
		   	   }
			}*/
				
		}
		else{
			System.out.println ("Suite normale");
		}

		return jwlwstm2;
	   } // End getInfosSuiviTerrain

		/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2011</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR <i>25/10/2011</i>
		 * @version 1.0
		 */
	   	public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAE03");
			JxweblogWeb.setPassword ("MADAE23");
			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;
			
			//------------------ données test-------------
			String cd_cible_1 	= "08";
			String num_cli 		= "5/121259";
			String stegrp 		= null;
			String id_suivi 	= "37";
			//------------------ données test-------------
			Jwlwstm2 jwlwstm2 	= getInfosSuiviTerrain ( 
					cd_cible_1, num_cli, stegrp, id_suivi,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp,broker);
			
			System.out.println("DEBUT.................") ;
			Jwlwstm2.Nwlwstm2Awlwstm2 jwlwstm2Reponse = jwlwstm2.getNwlwstm2Awlwstm2() ;
			Jwlwstm2.Nwlwstm2Awlwstm2Cle_suivi cle_suivi = jwlwstm2Reponse.cle_suivi;
			System.out.println("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") ;

			Jwlwstm2.Nwlwstm2Awlwstm2Info_adresse info_adresse = jwlwstm2Reponse.info_adresse ;
			System.out.println("LIG-NOM=" + info_adresse.lig_nom  + "\n") ;
			System.out.println("LIG-ADR=" + info_adresse.lig_adr  + "\n") ;
			System.out.println("COMMUNE=" + info_adresse.commune  + "\n") ;
			System.out.println("CD-POSTE="+ info_adresse.cd_poste + "\n") ;
			System.out.println("LOCALITE="+ info_adresse.localite + "\n") ;
			
			Jwlwstm2.Nwlwstm2Awlwstm2Info_reclam info_reclam = jwlwstm2Reponse.info_reclam ;
			System.out.println("DT-DEB-RECLAM=" + info_reclam.dt_deb_reclam + "\n") ;
			System.out.println("DT-FIN-RECLAM=" + info_reclam.dt_fin_reclam + "\n") ;
			System.out.println("CD-SOURCE="	    + info_reclam.cd_source 	+ "\n") ;
			System.out.println("CD-MEDIA="		+ info_reclam.cd_media 		+ "\n") ;
			System.out.println("HR-CREAT="		+ info_reclam.hr_creat 		+ "\n") ;
			String[] lig_msg = info_reclam.lig_msg ;
			for(int i=0; i< lig_msg.length; i++){
				System.out.println("LIG-MSG " +i +"=="+ lig_msg[i] + "\n") ;
			}
			Jwlwstm2.Nwlwstm2Awlwstm2Reponse_suivi reponse_suivi = jwlwstm2Reponse.reponse_suivi ;
			String[] cd_reponse  = reponse_suivi.cd_reponse ;
			String[] lib_reponse = reponse_suivi.lib_reponse ;
			for(int i=0; i< cd_reponse.length; i++){
				System.out.println("i="+i+" ;"+cd_reponse[i]+"; lib="+lib_reponse[i]) ;
			}
			JxweblogWeb.closeConnexion (jxweblog);
	   }
} // END Jwlwstm2Web