import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwzom2Web</p>
 * <p>Description : Mise a jour  prestataires par zone portage.
 * </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>07/03/2013</i>
 * @version 1.0
 */
 
public class Jwlwzom2Web {
	private static final int TAILLE = 40;

	/**
	 * <p>Titre : creatPrestataire</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwzom2 creatPrestataire(
				String cd_zpo_creat,
				String type_portage_creat,
				String cd_prt_creat,
				String hprt_date_debut_creat,
				String hprt_date_fin_creat,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom2 jwlwzom2 = new Jwlwzom2(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom2.Nwlwzom2Axwebent vWebent = jwlwzom2.new Nwlwzom2Axwebent();
		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;
		jwlwzom2.setNwlwzom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom2.Nwlwzom2Awlwzom2 vLwzom2 					= jwlwzom2.new Nwlwzom2Awlwzom2();
		Jwlwzom2.Nwlwzom2Awlwzom2Creation vLwzom2create = jwlwzom2.new Nwlwzom2Awlwzom2Creation();
		vLwzom2create.cd_zpo_creat   	   = cd_zpo_creat;
		vLwzom2create.type_portage_creat   = type_portage_creat;
		vLwzom2create.cd_prt_creat	       = cd_prt_creat;
		
		if(!"".equals(hprt_date_debut_creat) && hprt_date_debut_creat!=null){
			vLwzom2create.hprt_date_debut_creat = new BigDecimal(hprt_date_debut_creat);
		}
		if(!"".equals(hprt_date_fin_creat) && hprt_date_fin_creat!=null){
			vLwzom2create.hprt_date_fin_creat = new BigDecimal(hprt_date_fin_creat);
		}
		
		vLwzom2.creation = vLwzom2create;
		
		jwlwzom2.setNwlwzom2Awlwzom2(vLwzom2);
		
		// CALL SERVER
		jwlwzom2.nwlwzom2();
		
		// Verification du code retour
		vWebent = jwlwzom2.getNwlwzom2Axwebent();
		System.out.println("Code retour nwlwzom2() = " + 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(vWebent.t_ano[0].lib_ano.trim());
			//affichage de reponse
			System.out.println("suite normal...");
		}
		return jwlwzom2;
	   } // End getPrestataire
	   
	//FIN  CREATION
	
	
	/**
	 * <p>Titre : setPrestataire</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwzom2 setPrestataire(
		String[] cd_zpo,
		String[] type_portage,
		String[] cd_prt,
		String[] res_dt_deb,
		String[] res_dt_fin,
		String[] res_isn,
		String[] hprt_date_debut,           
		String[] hprt_date_fin,       
		String[] protect_deb,
		String[] protect_fin,
		String[] res_libelle_prt,
		String[] libelle_prt,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom2 jwlwzom2 		  = new Jwlwzom2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom2.Nwlwzom2Axwebent vWebent = jwlwzom2.new Nwlwzom2Axwebent();
		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;
		jwlwzom2.setNwlwzom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom2.Nwlwzom2Awlwzom2 vLwzom2 				= jwlwzom2.new Nwlwzom2Awlwzom2();
		Jwlwzom2.Nwlwzom2Awlwzom2Demande vLwzom2Demande = jwlwzom2.new Nwlwzom2Awlwzom2Demande();

		String[] tab_cd_zpo 		= new String[TAILLE] ;
		String[] tab_type_portage 	= new String[TAILLE] ;
		String[] tab_cd_prt 		= new String[TAILLE] ;
		String[] tab_protect_deb 	= new String[TAILLE] ;
		String[] tab_protect_fin 	= new String[TAILLE] ;
		String[] tab_res_libelle_prt= new String[TAILLE] ;
		String[] tab_libelle_prt 	= new String[TAILLE] ;
		BigDecimal[] tab_res_dt_deb = new BigDecimal[TAILLE] ;
		BigDecimal[] tab_res_dt_fin = new BigDecimal[TAILLE] ;
		BigDecimal[] tab_res_isn 	= new BigDecimal[TAILLE] ;
		BigDecimal[] tab_date_debut = new BigDecimal[TAILLE] ;
		BigDecimal[] tab_date_fin 	= new BigDecimal[TAILLE] ;
		
		for (int i = 0; i < res_dt_deb.length; i++) {
			if(!"".equals(res_dt_deb[i]) && res_dt_deb[i]!=null){
				tab_res_dt_deb[i] = new BigDecimal(res_dt_deb[i]);
			}
			if(!"".equals(res_dt_fin[i]) && res_dt_fin[i]!=null){
				tab_res_dt_fin[i] = new BigDecimal(res_dt_fin[i]);
			}
			if(!"".equals(res_isn[i]) && res_isn[i]!=null){
				tab_res_isn[i] = new BigDecimal(res_isn[i]);
			}
			if(!"".equals(hprt_date_debut[i]) && hprt_date_debut[i]!=null){
				tab_date_debut[i] = new BigDecimal(hprt_date_debut[i]);
			}
			if(!"".equals(hprt_date_fin[i]) && hprt_date_fin[i]!=null){
				tab_date_fin[i] = new BigDecimal(hprt_date_fin[i]);
			}
			tab_cd_zpo[i] 			= cd_zpo[i] ;
			tab_type_portage[i] 	= type_portage[i] ;
			tab_cd_prt[i] 			= cd_prt[i] ;
			tab_protect_deb[i] 		= protect_deb[i] ;
			tab_protect_fin[i] 		= protect_fin[i] ;
			tab_res_libelle_prt[i]  = res_libelle_prt[i];
			tab_libelle_prt[i] 		= libelle_prt[i];
		}
		vLwzom2Demande.cd_zpo    	   = tab_cd_zpo;
		vLwzom2Demande.type_portage    = tab_type_portage;
		vLwzom2Demande.cd_prt          = tab_cd_prt;
		vLwzom2Demande.res_dt_deb      = tab_res_dt_deb;
		vLwzom2Demande.res_dt_fin      = tab_res_dt_fin;
		vLwzom2Demande.res_isn         = tab_res_isn;
		vLwzom2Demande.hprt_date_debut = tab_date_debut;
		vLwzom2Demande.hprt_date_fin   = tab_date_fin;
		vLwzom2Demande.protect_deb     = tab_protect_deb;
		vLwzom2Demande.protect_fin     = tab_protect_fin;
		vLwzom2Demande.res_libelle_prt = tab_res_libelle_prt;
		vLwzom2Demande.libelle_prt     = tab_libelle_prt;
		vLwzom2.demande = vLwzom2Demande;
		
		jwlwzom2.setNwlwzom2Awlwzom2(vLwzom2);
		
		// CALL SERVER
		jwlwzom2.nwlwzom2();
		
		// Verification du code retour
		vWebent = jwlwzom2.getNwlwzom2Axwebent();
		System.out.println("Code retour nwlwzom2() = " + 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(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwzom2;
	   } // End setPrestataire
	   
	   //FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : setPrestataire</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>07/03/2013</i>
	 * @version 1.0
	 */
	public static Jwlwzom2 deletePrestataire(
		String[] lig_sel,
		String[] cd_zpo,
		String[] type_portage,
		String[] cd_prt,
		String[] res_isn,
		String[] hprt_date_debut,
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom2 jwlwzom2 		  = new Jwlwzom2(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom2.Nwlwzom2Axwebent vWebent = jwlwzom2.new Nwlwzom2Axwebent();
		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;
		jwlwzom2.setNwlwzom2Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom2.Nwlwzom2Awlwzom2 vLwzom2 				= jwlwzom2.new Nwlwzom2Awlwzom2();
		Jwlwzom2.Nwlwzom2Awlwzom2Demande vLwzom2Demande = jwlwzom2.new Nwlwzom2Awlwzom2Demande();
		
		int len = cd_zpo.length ;
		String[] tab_lig_sel 		= new String[40] ;
		String[] tab_cd_zpo 		= new String[40] ;
		String[] tab_type_portage 	= new String[40] ;
		String[] tab_cd_prt 		= new String[40] ;
		BigDecimal[] tab_date_debut = new BigDecimal[40] ;
		BigDecimal[] tab_res_isn 	= new BigDecimal[40] ;
		
		for (int i = 0; i < len; i++) {
			if(!"".equals(hprt_date_debut[i]) && hprt_date_debut[i]!=null){
				tab_date_debut[i] = new BigDecimal(hprt_date_debut[i]);
			}
			if(!"".equals(res_isn[i]) && res_isn[i]!=null){
				tab_res_isn[i] = new BigDecimal(res_isn[i]);
			}
			tab_lig_sel[i] = lig_sel[i] ;
			tab_cd_zpo[i] = cd_zpo[i] ;
			tab_type_portage[i] = type_portage[i] ;
			tab_cd_prt[i] = cd_prt[i] ;
		}
		vLwzom2Demande.lig_sel 		   = tab_lig_sel;
		vLwzom2Demande.cd_zpo    	   = tab_cd_zpo;
		vLwzom2Demande.type_portage    = tab_type_portage;
		vLwzom2Demande.cd_prt          = tab_cd_prt;
		vLwzom2Demande.hprt_date_debut = tab_date_debut ; 
		vLwzom2Demande.res_isn 		   = tab_res_isn ; 
		
		vLwzom2.demande = vLwzom2Demande;
		
		jwlwzom2.setNwlwzom2Awlwzom2(vLwzom2);
		
		// CALL SERVER
		jwlwzom2.nwlwzom2();
		
		// Verification du code retour
		vWebent = jwlwzom2.getNwlwzom2Axwebent();
		System.out.println("Code retour nwlwzom2() = " + 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(vWebent.t_ano[0].lib_ano.trim());
			System.out.println ("Suite normale ...");
		}
		
		return jwlwzom2;
	   } // End setPrestataire			

	/**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA82");
			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[] cd_zpo 	     = new String[1] ;
			String[] type_portage    = new String[1] ;
			String[] cd_prt 	     = new String[1] ;
			String[] res_dt_deb      = new String[1] ;
			String[] res_dt_fin	     = new String[1] ;
			String[] res_isn	     = new String[1] ;
			String[] hprt_date_debut = new String[1] ;        
			String[] hprt_date_fin	 = new String[1] ;      
			String[] protect_deb	 = new String[1] ;
			String[] protect_fin	 = new String[1] ;
			String[] res_libelle_prt = new String[1] ;
			String[] libelle_prt	 = new String[1] ;
			cd_zpo[0] ="0006";
			type_portage[0] = "N" ;
			cd_prt[0] = "0012" ;
			res_dt_deb[0] = "20080328";
			res_dt_fin[0] = "99999999";
			res_isn[0] = "521";
			hprt_date_debut[0] ="20080328";
			hprt_date_fin[0] ="20130308";
			protect_deb[0] = "O";
			protect_fin[0] = "N";
			setPrestataire(
				cd_zpo,
				type_portage,
				cd_prt,
				res_dt_deb,
				res_dt_fin,
				res_isn,
				hprt_date_debut,           
				hprt_date_fin,       
				protect_deb,
				protect_fin,res_libelle_prt,libelle_prt,
				groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			//Test de SUPPRESSION
			//---------Donnee Test---------------
			
			/*String lig_sel[] = new String[1] ;
			String cd_zpo[] = new String[1] ;
			String type_portage[]= new String[1] ;
			String cd_prt[]= new String[1] ;
			String res_isn[]= new String[1] ;
			String hprt_date_debut[]= new String[1] ;
			lig_sel[0]="S" ;
			cd_zpo[0]="AHAH" ;
			type_portage[0]="N" ;
			cd_prt[0]="0447" ;
			res_isn[0]="8" ;
			hprt_date_debut[0]="20630704" ;
			
			//---------Donnee Test---------------
			deletePrestataire(
					lig_sel,
					cd_zpo,
					type_portage,
					cd_prt,
					res_isn,
					hprt_date_debut,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);*/
			
		}

	//FIN  INTERROGATION

}